diff options
| author | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-24 00:42:24 -0400 |
|---|---|---|
| committer | caleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu> | 2022-03-24 00:42:24 -0400 |
| commit | 08916f6d4eb8db40e6e54f78c744071f3b5298d7 (patch) | |
| tree | 04a311a423444705e7a36df230da8558f989ac68 /webAO | |
| parent | e28fcc59a76772eae64ed480919cddb60a3b5fce (diff) | |
Adding typescript support and unit tests
Diffstat (limited to 'webAO')
| -rw-r--r-- | webAO/utils/__tests__/tryUrls.test.ts | 31 | ||||
| -rw-r--r-- | webAO/utils/tryUrls.ts (renamed from webAO/utils/tryUrls.js) | 2 |
2 files changed, 32 insertions, 1 deletions
diff --git a/webAO/utils/__tests__/tryUrls.test.ts b/webAO/utils/__tests__/tryUrls.test.ts new file mode 100644 index 0000000..444664e --- /dev/null +++ b/webAO/utils/__tests__/tryUrls.test.ts @@ -0,0 +1,31 @@ +import fileExists from '../fileExists' +import tryUrls from '../tryUrls'; +import transparentPng from '../../constants/transparentPng' +jest.mock('../fileExists') + +const mockFileExists = fileExists as jest.MockedFunction<typeof fileExists>; + +describe('tryUrls', () => { + it('Should try multiple file extensions', async () => { + const url = "localhost/stoneddiscord/assets" + mockFileExists + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(true)) + const actual = await tryUrls(url) + const expected = 'localhost/stoneddiscord/assets.apng' + expect(actual).toBe(expected); + }); + + it('Should return a transparent png if it cant find any assets', async () => { + const url = "localhost/stoneddiscord/assets" + mockFileExists + .mockReturnValue(Promise.resolve(false)) + const actual = await tryUrls(url) + const expected = transparentPng + expect(actual).toBe(expected); + }); +}) + + diff --git a/webAO/utils/tryUrls.js b/webAO/utils/tryUrls.ts index db07ec7..14ef885 100644 --- a/webAO/utils/tryUrls.js +++ b/webAO/utils/tryUrls.ts @@ -6,7 +6,7 @@ const urlExtensionsToTry = [ '.webp', '.apng' ] -const tryUrls = async (url) => { +const tryUrls = async (url: string) => { for (let i = 0; i < urlExtensionsToTry.length; i++) { const extension = urlExtensionsToTry[i] const fullFileUrl = url + extension |
