From e977aa74417a8cf17c2fa3bac737039d97971dd2 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 17 Mar 2022 22:25:46 -0400 Subject: Adding unit tests --- webAO/client/__tests__/setEmote.test.js | 115 ++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 webAO/client/__tests__/setEmote.test.js (limited to 'webAO/client') diff --git a/webAO/client/__tests__/setEmote.test.js b/webAO/client/__tests__/setEmote.test.js new file mode 100644 index 0000000..d81c2cc --- /dev/null +++ b/webAO/client/__tests__/setEmote.test.js @@ -0,0 +1,115 @@ +import setEmote from '../setEmote'; +import Client from '../../client'; +import fileExistsSync from '../../utils/fileExistsSync'; +import transparentPng from '../../constants/transparentPng'; + +jest.mock('../../client'); +jest.mock('../../utils/fileExistsSync'); + +describe('setEmote', () => { + const AO_HOST = ''; + Client.mockReturnValue({ + lastChar: 'long', + chatmsg: { + name: 'byte', + }, + }); + const client = new Client('127.0.0.1'); + const firstExtension = '.gif'; + + test('Should have a client_def_char_img with a valid source', () => { + fileExistsSync.mockReturnValue(true); + document.body.innerHTML = ` + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'def'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + expect(document.getElementById('client_def_char_img').src).toEqual(expected); + }); + test('Should have a client_pro_char_img to have a valid src', () => { + document.body.innerHTML = ` + + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'pro'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + expect(document.getElementById('client_pro_char_img').src).toEqual(expected); + }); + test('Should have a client_wit_char_img', () => { + document.body.innerHTML = ` + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'wit'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_wit_char_img').src).toEqual(expected); + }); + test('Should have a client_def_pair_img', () => { + document.body.innerHTML = ` + + +`; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'def'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_def_pair_img').src).toEqual(expected); + }); + test('Should have a client_pro_pair_img', () => { + document.body.innerHTML = ` + + +`; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'pro'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_pro_pair_img').src).toEqual(expected); + }); + test('Should have a client_wit_pair_img', () => { + document.body.innerHTML = ` + + +`; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'wit'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_wit_pair_img').src).toEqual(expected); + }); + test('Should have a client_char_img', () => { + document.body.innerHTML = ` + + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 0, 'notvalid'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_char_img').src).toEqual(expected); + }); + test('Should have a client_pair_img', () => { + document.body.innerHTML = ` + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', '(a)', 1, 'notvalid'); + const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`; + + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); + test('Should handle .png urls differently', () => { + fileExistsSync.mockReturnValueOnce(false); + document.body.innerHTML = ` + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); + const expected = 'http://localhost/characters/salanto/coding.png'; + + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); + test('Should replace character if new character responds', () => { + fileExistsSync.mockReturnValue(false); + document.body.innerHTML = ` + + `; + setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid'); + const expected = transparentPng; + expect(document.getElementById('client_pair_img').src).toEqual(expected); + }); +}); -- cgit