Skip to content

Commit 966a03b

Browse files
committed
test(core): slot controller tests
wip
1 parent 80b0a7a commit 966a03b

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { expect, fixture, nextFrame } from '@open-wc/testing';
2+
3+
import { customElement } from 'lit/decorators/custom-element.js';
4+
import {
5+
ReactiveElement,
6+
html,
7+
render,
8+
type PropertyValues,
9+
type TemplateResult,
10+
} from 'lit';
11+
12+
import { SlotController } from '../slot-controller.js';
13+
14+
describe('SlotController', function() {
15+
describe('with named and anonymous slots', function() {
16+
@customElement('test-slot-controller-with-named-and-anonymous')
17+
class TestSlotControllerWithNamedAndAnonymous extends ReactiveElement {
18+
declare static template: TemplateResult;
19+
20+
controller = new SlotController(this, 'a', null);
21+
22+
render(): TemplateResult {
23+
return html`
24+
<slot name="a"></slot>
25+
<slot name="b"></slot>
26+
<slot></slot>
27+
`;
28+
}
29+
}
30+
describe('with no content', function() {
31+
let element: TestSlotControllerWithNamedAndAnonymous;
32+
beforeEach(async function() {
33+
element = await fixture(html`
34+
<test-slot-controller-with-named-and-anonymous></test-slot-controller-with-named-and-anonymous>
35+
`);
36+
});
37+
it('reports empty named slots', function() {
38+
expect(element.controller.hasSlotted('a')).to.be.false;
39+
expect(element.controller.isEmpty('a')).to.be.true;
40+
});
41+
it('reports empty default slot', function() {
42+
expect(element.controller.hasSlotted(null)).to.be.false;
43+
expect(element.controller.isEmpty(null)).to.be.true;
44+
});
45+
it('reports empty default slot with no arguments', function() {
46+
expect(element.controller.hasSlotted()).to.be.false;
47+
expect(element.controller.isEmpty()).to.be.true;
48+
});
49+
});
50+
51+
describe('with element content in default slot', function() {
52+
let element: TestSlotControllerWithNamedAndAnonymous;
53+
beforeEach(async function() {
54+
element = await fixture(html`
55+
<test-slot-controller-with-named-and-anonymous>
56+
<p>element</p>
57+
</test-slot-controller-with-named-and-anonymous>
58+
`);
59+
});
60+
it('reports empty named slots', function() {
61+
expect(element.controller.hasSlotted('a')).to.be.false;
62+
expect(element.controller.isEmpty('a')).to.be.true;
63+
});
64+
it('reports non-empty default slot', function() {
65+
expect(element.controller.hasSlotted(null)).to.be.true;
66+
expect(element.controller.isEmpty(null)).to.be.false;
67+
});
68+
it('reports non-empty default slot with no arguments', function() {
69+
expect(element.controller.hasSlotted()).to.be.true;
70+
expect(element.controller.isEmpty()).to.be.false;
71+
});
72+
});
73+
74+
describe('with element content in named slot', function() {
75+
let element: TestSlotControllerWithNamedAndAnonymous;
76+
beforeEach(async function() {
77+
element = await fixture(html`
78+
<test-slot-controller-with-named-and-anonymous>
79+
<p slot="a">element</p>
80+
</test-slot-controller-with-named-and-anonymous>
81+
`);
82+
});
83+
it('reports non-empty named slots', function() {
84+
expect(element.controller.hasSlotted('a')).to.be.true;
85+
expect(element.controller.isEmpty('a')).to.be.false;
86+
});
87+
it('reports empty default slot', function() {
88+
expect(element.controller.hasSlotted(null)).to.be.false;
89+
expect(element.controller.isEmpty(null)).to.be.true;
90+
});
91+
it('reports empty default slot with no arguments', function() {
92+
expect(element.controller.hasSlotted()).to.be.false;
93+
expect(element.controller.isEmpty()).to.be.true;
94+
});
95+
});
96+
97+
describe('with text content in default slot', function() {
98+
let element: TestSlotControllerWithNamedAndAnonymous;
99+
beforeEach(async function() {
100+
element = await fixture(html`
101+
<test-slot-controller-with-named-and-anonymous>
102+
text
103+
</test-slot-controller-with-named-and-anonymous>
104+
`);
105+
});
106+
it('reports empty named slots', function() {
107+
expect(element.controller.hasSlotted('a')).to.be.false;
108+
expect(element.controller.isEmpty('a')).to.be.true;
109+
});
110+
it('reports nonjgempty default slot', function() {
111+
expect(element.controller.hasSlotted(null)).to.be.true;
112+
expect(element.controller.isEmpty(null)).to.be.false;
113+
});
114+
it('reports non-empty default slot with no arguments', function() {
115+
expect(element.controller.hasSlotted()).to.be.true;
116+
expect(element.controller.isEmpty()).to.be.false;
117+
});
118+
});
119+
});
120+
});

0 commit comments

Comments
 (0)