-
Notifications
You must be signed in to change notification settings - Fork 7
/
temba-omnibox.test.ts
66 lines (56 loc) · 1.87 KB
/
temba-omnibox.test.ts
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
import { fixture, assert } from '@open-wc/testing';
import { Omnibox } from '../src/omnibox/Omnibox';
import { assertScreenshot, getClip } from './utils.test';
import { openAndClick } from './temba-select.test';
import { useFakeTimers, spy } from 'sinon';
export const getHTML = (attrs: any = { name: 'recipients' }): string => {
const selectHTML = `
<temba-omnibox${Object.keys(attrs)
.map((name: string) => {
// check if it's a string attribute
if (typeof attrs[name] === 'string') {
return ` ${name}="${attrs[name].replace(/"/g, '"')}"`;
}
return ` ${name}="${attrs[name]}"`;
})
.join(' ')}>
</temba-select>`;
return selectHTML;
};
export const createOmnibox = async (
clock: any,
attrs: any = {}
): Promise<Omnibox> => {
const parentNode = document.createElement('div');
parentNode.setAttribute('style', 'width: 250px;');
const omnibox: Omnibox = await fixture(getHTML(attrs), { parentNode });
clock.runAll();
await omnibox.updateComplete;
return omnibox;
};
describe('temba-omnibox', () => {
let clock: any;
beforeEach(function () {
clock = useFakeTimers();
setViewport({ width: 500, height: 1000, deviceScaleFactor: 2 });
});
afterEach(function () {
clock.restore();
});
it('can be created', async () => {
const omnibox: Omnibox = await fixture(
getHTML({ endpoint: '/test-assets/select/omnibox.json' })
);
assert.instanceOf(omnibox, Omnibox);
});
it('fires change events on selection', async () => {
const omnibox: Omnibox = await createOmnibox(clock, {
endpoint: '/test-assets/select/omnibox.json'
});
const changeEvent = spy();
omnibox.addEventListener('change', changeEvent);
await openAndClick(clock, omnibox, 0);
assert(changeEvent.called, 'change event not fired');
await assertScreenshot('omnibox/selected', getClip(omnibox));
});
});