1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
import setEmote from '../setEmote';
import Client from '../../client';
import fileExists from '../../utils/fileExists';
import transparentPng from '../../constants/transparentPng';
jest.mock('../../client');
jest.mock('../../utils/fileExists');
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', async () => {
fileExists.mockReturnValue(true);
document.body.innerHTML = `
<img id="client_def_char_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_pro_char_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_wit_char_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_def_pair_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_pro_pair_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_wit_pair_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_char_img" />
`;
await 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', async () => {
document.body.innerHTML = `
<img id="client_pair_img" />
`;
await 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', async () => {
fileExists.mockReturnValueOnce(false);
document.body.innerHTML = `
<img id="client_pair_img" />
`;
await 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', async () => {
fileExists.mockReturnValue(false);
document.body.innerHTML = `
<img id="client_pair_img" />
`;
await setEmote(AO_HOST, client, 'salanto', 'coding', 'prefixNotValid', 1, 'notvalid');
const expected = transparentPng;
expect(document.getElementById('client_pair_img').src).toEqual(expected);
});
});
|