-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcarousel-indicator-container.spec.ts
More file actions
140 lines (118 loc) · 3.62 KB
/
Copy pathcarousel-indicator-container.spec.ts
File metadata and controls
140 lines (118 loc) · 3.62 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import { tabKey } from '../common/controllers/key-bindings.js';
import { defineComponents } from '../common/definitions/defineComponents.js';
import { first } from '../common/util.js';
import {
simulateClick,
simulateFocusOut,
simulateKeyboard,
simulatePointerDown,
simulatePointerUp,
} from '../common/utils.spec.js';
import IgcCarouselIndicatorComponent from './carousel-indicator.js';
import IgcCarouselIndicatorContainerComponent from './carousel-indicator-container.js';
describe('Carousel Indicator Container', () => {
before(() => {
defineComponents(
IgcCarouselIndicatorContainerComponent,
IgcCarouselIndicatorComponent
);
});
const createIndicatorContainerComponent = () => html`
<igc-carousel-indicator-container>
<button>1</button>
<button>2</button>
<button>3</button>
</igc-carousel-indicator-container>
`;
let container: IgcCarouselIndicatorContainerComponent;
let buttons: HTMLButtonElement[];
beforeEach(async () => {
container = await fixture(createIndicatorContainerComponent());
buttons = Array.from(container.querySelectorAll('button'));
});
it('is correctly initialized', () => {
expect(container).dom.to.equal(
`<igc-carousel-indicator-container>
<button>1</button>
<button>2</button>
<button>3</button>
</igc-carousel-indicator-container>`
);
expect(container).shadowDom.to.equal(
`<div part="base">
<slot></slot>
</div>`
);
});
it('should apply `focused` part on keyup', async () => {
expect(container).shadowDom.to.equal(
`<div part="base">
<slot></slot>
</div>`
);
simulateKeyboard(first(buttons), tabKey);
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base focused">
<slot></slot>
</div>`
);
});
it('should remove `focused` part on click', async () => {
simulateKeyboard(first(buttons), tabKey);
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base focused">
<slot></slot>
</div>`
);
simulatePointerDown(first(buttons));
simulatePointerUp(first(buttons));
simulateClick(first(buttons));
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base">
<slot></slot>
</div>`
);
});
it('it should remove `focused` part on focusout', async () => {
simulateKeyboard(first(buttons), tabKey);
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base focused">
<slot></slot>
</div>`
);
simulateFocusOut(first(buttons));
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base">
<slot></slot>
</div>`
);
});
it('it should not remove `focused` part on focusout if the target receiving focus is an `igc-carousel-indicator`', async () => {
simulateKeyboard(first(buttons), tabKey);
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base focused">
<slot></slot>
</div>`
);
const indicator = await fixture(
html`<igc-carousel-indicator>
<span>0</span>
<span slot="active">1</span>
</igc-carousel-indicator>`
);
simulateFocusOut(first(buttons), { relatedTarget: indicator });
await elementUpdated(container);
expect(container).shadowDom.to.equal(
`<div part="base focused">
<slot></slot>
</div>`
);
});
});