1 | import SelectLazy from './select-ng__lazy';
|
2 |
|
3 | describe('Select Lazy', () => {
|
4 |
|
5 |
|
6 | let containerNode;
|
7 | let ctrl;
|
8 | beforeEach(() => {
|
9 | containerNode = document.createElement('div');
|
10 | ctrl = {};
|
11 | });
|
12 |
|
13 |
|
14 | it('should create lazy select', () => {
|
15 | const lazySelect = renderLazySelect();
|
16 | lazySelect.should.not.be.undefined;
|
17 | });
|
18 |
|
19 |
|
20 | it('should render static markup', () => {
|
21 | renderLazySelect();
|
22 | should.exist(findSelectNode(containerNode));
|
23 | });
|
24 |
|
25 |
|
26 | it('should render react select on click', () => {
|
27 | const lazySelect = renderLazySelect();
|
28 | simulateClick(lazySelect);
|
29 | ctrl.selectInstance.should.not.be.undefined;
|
30 | });
|
31 |
|
32 |
|
33 | it('should detach lazy select after render', () => {
|
34 | const lazySelect = renderLazySelect();
|
35 | sandbox.spy(lazySelect, '_clickHandler');
|
36 |
|
37 | simulateClick(lazySelect);
|
38 | simulateClick(lazySelect);
|
39 | simulateClick(lazySelect);
|
40 |
|
41 | lazySelect._clickHandler.should.be.calledOnce;
|
42 | });
|
43 |
|
44 |
|
45 | it('should not render markup for select dropdown', () => {
|
46 | renderDropdownSelect();
|
47 | should.not.exist(findSelectNode(containerNode));
|
48 | });
|
49 |
|
50 |
|
51 | it('should render select dropdown on click', () => {
|
52 | const lazySelect = renderDropdownSelect();
|
53 | simulateClick(lazySelect);
|
54 | should.exist(ctrl.selectInstance);
|
55 | });
|
56 |
|
57 |
|
58 | function simulateClick(select) {
|
59 | const clickEvent = new CustomEvent('click');
|
60 | select.container.dispatchEvent(clickEvent);
|
61 | }
|
62 |
|
63 |
|
64 | function renderDropdownSelect() {
|
65 | return renderLazySelect('dropdown');
|
66 | }
|
67 |
|
68 |
|
69 | function renderLazySelect(type = 'button') {
|
70 | const lazySelect = new SelectLazy(containerNode, {}, ctrl, type);
|
71 | lazySelect.render();
|
72 | return lazySelect;
|
73 | }
|
74 |
|
75 |
|
76 | function findSelectNode(container) {
|
77 | return container.querySelector('[data-test="ring-select"]');
|
78 | }
|
79 | });
|