-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemba-contact-search.test.ts
110 lines (92 loc) · 3.03 KB
/
temba-contact-search.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
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
import { fixture, assert, expect } from '@open-wc/testing';
import { ContactSearch } from '../src/contactsearch/ContactSearch';
import { assertScreenshot, getClip, getHTML, mockPOST } from './utils.test';
import { useFakeTimers } from 'sinon';
import { CustomEventType } from '../src/interfaces';
import { Omnibox } from '../src/omnibox/Omnibox';
let clock: any;
function waitForSearch(search: ContactSearch) {
return new Promise<ContactSearch>((resolve) => {
search.addEventListener(
CustomEventType.ContentChanged,
async () => {
await clock.runAll();
resolve(search);
},
{ once: true }
);
});
}
describe('temba-contact-search', () => {
beforeEach(function () {
clock = useFakeTimers();
});
afterEach(function () {
clock.restore();
});
it('can be created', async () => {
const search: ContactSearch = await fixture(
getHTML('temba-contact-search')
);
assert.instanceOf(search, ContactSearch);
});
xit('handles bad queries', async () => {
const endpoint = '/contact-search-bad';
const search: ContactSearch = await fixture(
getHTML('temba-contact-search', {
advanced: true,
endpoint
})
);
// mock an error response
mockPOST(
/contact-search-bad/,
{ query: '', total: 0, error: "'Missing' is not a valid group name" },
{ 'X-Temba-Success': 'hide' }
);
search.query = 'group = "Missing"';
// run the query
await clock.runAll();
await clock.runAll();
await waitForSearch(search);
expect(search.errors).to.deep.equal([
"'Missing' is not a valid group name"
]);
await search.updateComplete;
await assertScreenshot('contact-search/missing-group', getClip(search));
});
xit('allows manual searches', async () => {
const endpoint = '/contact-search-manual';
const search: ContactSearch = await fixture(
getHTML('temba-contact-search', {
endpoint
})
);
const omnibox = search.shadowRoot.querySelector('temba-omnibox') as Omnibox;
omnibox.value = [];
search.advanced = true;
await search.updateComplete;
// mock successful response with some warnings
mockPOST(
/contact-search-manual/,
{
query: 'group = "Doctors"',
total: 1937,
warnings: [
'This flow does not specify a Facebook topic. You may still start this flow but Facebook contacts who have not sent an incoming message in the last 24 hours may not receive it.',
'This flow does not use message templates. You may still start this flow but WhatsApp contacts who have not sent an incoming message in the last 24 hours may not receive it.'
],
blockers: []
},
{ 'X-Temba-Success': 'hide' }
);
search.query = 'group = "Testers"';
// run the query
await clock.runAll();
await clock.runAll();
await waitForSearch(search);
await clock.runAll();
await search.updateComplete;
await assertScreenshot('contact-search/manual-search', getClip(search));
});
});