diff options
| author | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-23 17:36:01 -0400 |
|---|---|---|
| committer | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-23 17:36:01 -0400 |
| commit | e28fcc59a76772eae64ed480919cddb60a3b5fce (patch) | |
| tree | db7ed6cf18f928fae734f3cc9430bb2b220ba2a0 /webAO/utils/__tests__ | |
| parent | a7facd6e825e3a2d60752df0b8526482b19a12de (diff) | |
| parent | ffa23343e0a0badd9e50a005359fdb79efead995 (diff) | |
Merge branch 'master' of https://github.com/AttorneyOnline/webAO into multipleBackgroundTypes
Diffstat (limited to 'webAO/utils/__tests__')
| -rw-r--r-- | webAO/utils/__tests__/aoml.test.ts | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/webAO/utils/__tests__/aoml.test.ts b/webAO/utils/__tests__/aoml.test.ts new file mode 100644 index 0000000..90967d7 --- /dev/null +++ b/webAO/utils/__tests__/aoml.test.ts @@ -0,0 +1,113 @@ +import request from '../../services/request' +import mlConfig from '../aoml'; + +jest.mock('../../services/request') +const networkRequest = ` +c0 = 247, 247, 247 +c0_name = White +c0_talking = 1 + +c2 = 247, 0, 57 +c2_name = Red +c2_start = ~ +c2_end = ~ +c2_remove = 1 +c2_talking = 1 + +c4 = 107, 198, 247 +c4_name = Blue +c4_start = ( +c4_end = ) +c4_remove = 0 +c4_talking = 0 + +c5 = 107, 198, 247 +c5_name = Blue +c5_start = [ +c5_end = ] +c5_remove = 1 +c5_talking = 0 + +c6 = 107, 198, 247 +c6_name = Blue +c6_start = | +c6_end = | +c6_remove = 0 +c6_talking = 0 +` + +const mockRequest = request as jest.MockedFunction<typeof request>; +mockRequest.mockReturnValue(Promise.resolve(networkRequest)) + + describe('mlConfig', () => { + beforeEach(() => { + // Clear all instances and calls to constructor and all methods: + mockRequest.mockClear(); + + }); + + it('Should make a network request', () => { + mlConfig('localhost') + expect(mockRequest).toHaveBeenCalledTimes(1); + }); + }) + describe('applyMarkdown', () => { + const config = mlConfig('localhost') + + beforeEach(() => { + // Clear all instances and calls to constructor and all methods: + mockRequest.mockClear(); + + }); + + it('Should create an array of spans containing letters', async () => { + const word = `hello` + const actual = await config.applyMarkdown(`hello`, `blue`) + let index = 0 + for (const element of actual) { + expect(element.innerHTML).toBe(word[index]) + index++ + } + }) + it('Should add colors based on settings', async () => { + const config = mlConfig('localhost') + const actual = await config.applyMarkdown(`(heya)`, `blue`) + expect(actual[0].getAttribute('style')).toBe('color: rgb(107, 198, 247);') + }) + it('Should keep a letter if remove = 0', async () => { + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`(What())Hey!`, `white`) + const expected = `(` + expect(actual[5].innerHTML).toBe(expected) + }) + it('Should remove a letter if remove = 1', async () => { + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) + const expected = `` + expect(actual[0].innerHTML).toBe(expected) + }) + it('Should remove a letter if remove = 1', async () => { + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) + const expected = `` + expect(actual[0].innerHTML).toBe(expected) + }) + it('Should keep a closing letter if remove = 0', async () => { + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~NO[]~!`, `white`) + const expected = `` + expect(actual[4].innerHTML).toBe(expected) + }) + it('Should remove a closing letter if remove = 1', async () => { + const config = mlConfig('localhost') + const actual = await config.applyMarkdown(`~NO||~!`, `white`) + const expected = `` + expect(actual[5].innerHTML).toBe(expected) + }) + + }) + |
