Skip to content

Commit 888651e

Browse files
test(statuslight): add second-gen test file
1 parent 1dd69f0 commit 888651e

File tree

1 file changed

+264
-0
lines changed

1 file changed

+264
-0
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
/**
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import { html } from 'lit';
14+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
15+
16+
import type { StatusLight } from '@swc/components/status-light';
17+
18+
import '@swc/components/status-light';
19+
20+
import { fixture } from '../../../utils/test-utils.js';
21+
22+
describe('swc-status-light', () => {
23+
beforeEach(() => {
24+
document.body.innerHTML = '';
25+
});
26+
27+
// ──────────────────────────────────────────────────────────────
28+
// TEST: Defaults
29+
// ──────────────────────────────────────────────────────────────
30+
31+
describe('defaults', () => {
32+
test('should render with shadow root', async () => {
33+
const statusLight = await fixture(html`
34+
<swc-status-light>Test Status</swc-status-light>
35+
`);
36+
37+
expect(statusLight.shadowRoot).toBeTruthy();
38+
expect(
39+
statusLight.shadowRoot?.querySelector('.spectrum-StatusLight')
40+
).toBeTruthy();
41+
});
42+
43+
test('should have correct default property values', async () => {
44+
const statusLight = await fixture<StatusLight>(
45+
html`<swc-status-light></swc-status-light>`
46+
);
47+
48+
expect(statusLight.variant).toBe('info');
49+
expect(statusLight.size).toBe('m');
50+
});
51+
});
52+
53+
// ──────────────────────────────────────────────────────────────
54+
// TEST: Properties / Attributes
55+
// ──────────────────────────────────────────────────────────────
56+
57+
describe('properties and attributes', () => {
58+
test('should reflect variant property to attribute', async () => {
59+
const statusLight = await fixture<StatusLight>(
60+
html`<swc-status-light></swc-status-light>`
61+
);
62+
63+
statusLight.variant = 'positive';
64+
await statusLight.updateComplete;
65+
66+
expect(statusLight.getAttribute('variant')).toBe('positive');
67+
expect(
68+
statusLight.shadowRoot?.querySelector(
69+
'.spectrum-StatusLight--positive'
70+
)
71+
).toBeTruthy();
72+
});
73+
74+
test('should set variant via attribute', async () => {
75+
const statusLight = await fixture<StatusLight>(html`
76+
<swc-status-light variant="negative"></swc-status-light>
77+
`);
78+
79+
expect(statusLight.variant).toBe('negative');
80+
expect(
81+
statusLight.shadowRoot?.querySelector(
82+
'.spectrum-StatusLight--negative'
83+
)
84+
).toBeTruthy();
85+
});
86+
87+
test('should handle semantic variants', async () => {
88+
const variants = [
89+
'neutral',
90+
'info',
91+
'positive',
92+
'negative',
93+
'notice',
94+
] as const;
95+
96+
for (const variant of variants) {
97+
const statusLight = await fixture<StatusLight>(html`
98+
<swc-status-light variant=${variant}></swc-status-light>
99+
`);
100+
101+
expect(statusLight.variant).toBe(variant);
102+
expect(
103+
statusLight.shadowRoot?.querySelector(
104+
`.spectrum-StatusLight--${variant}`
105+
)
106+
).toBeTruthy();
107+
}
108+
});
109+
110+
test('should handle color variants', async () => {
111+
const colorVariants = [
112+
'fuchsia',
113+
'indigo',
114+
'magenta',
115+
'purple',
116+
'seafoam',
117+
'yellow',
118+
'chartreuse',
119+
'celery',
120+
'cyan',
121+
'pink',
122+
'turquoise',
123+
'brown',
124+
'cinnamon',
125+
'silver',
126+
] as const;
127+
128+
for (const variant of colorVariants) {
129+
const statusLight = await fixture<StatusLight>(html`
130+
<swc-status-light variant=${variant}></swc-status-light>
131+
`);
132+
133+
expect(statusLight.variant).toBe(variant);
134+
expect(
135+
statusLight.shadowRoot?.querySelector(
136+
`.spectrum-StatusLight--${variant}`
137+
)
138+
).toBeTruthy();
139+
}
140+
});
141+
142+
test('should handle size property', async () => {
143+
const statusLight = await fixture<StatusLight>(
144+
html`<swc-status-light></swc-status-light>`
145+
);
146+
147+
expect(statusLight.size).toBe('m');
148+
149+
statusLight.size = 's';
150+
await statusLight.updateComplete;
151+
152+
expect(statusLight.getAttribute('size')).toBe('s');
153+
expect(
154+
statusLight.shadowRoot?.querySelector(
155+
'.spectrum-StatusLight--sizeS'
156+
)
157+
).toBeTruthy();
158+
});
159+
});
160+
161+
// ──────────────────────────────────────────────────────────────
162+
// TEST: Slots
163+
// ──────────────────────────────────────────────────────────────
164+
165+
describe('slots', () => {
166+
test('should render default slot content', async () => {
167+
const statusLight = await fixture(html`
168+
<swc-status-light>Status Label</swc-status-light>
169+
`);
170+
171+
expect(statusLight.textContent).toBe('Status Label');
172+
});
173+
});
174+
175+
// ──────────────────────────────────────────────────────────────
176+
// TEST: Events
177+
// ──────────────────────────────────────────────────────────────
178+
179+
describe.skip('events', () => {
180+
// StatusLight component does not dispatch custom events
181+
});
182+
183+
// ──────────────────────────────────────────────────────────────
184+
// TEST: Accessibility
185+
// ──────────────────────────────────────────────────────────────
186+
// @TODO: Add accessibility tests with axe-core / playwright
187+
describe('accessibility', () => {
188+
test('should be accessible to screen readers', async () => {
189+
const statusLight = await fixture(html`
190+
<swc-status-light variant="positive">Approved</swc-status-light>
191+
`);
192+
193+
const statusLightElement = statusLight.shadowRoot?.querySelector(
194+
'.spectrum-StatusLight'
195+
);
196+
expect(statusLightElement).toBeTruthy();
197+
expect(statusLight.textContent).toBe('Approved');
198+
});
199+
});
200+
201+
// ──────────────────────────────────────────────────────────────
202+
// TEST: Dev Mode Warnings
203+
// ──────────────────────────────────────────────────────────────
204+
205+
describe('dev mode warnings', () => {
206+
let originalWarn: typeof window.__swc.warn;
207+
let originalDebug: boolean;
208+
209+
beforeEach(() => {
210+
// Create __swc if it doesn't exist
211+
window.__swc = window.__swc || { warn: () => {} };
212+
// Store original warn function and debug state
213+
originalWarn = window.__swc.warn;
214+
originalDebug = window.__swc.DEBUG ?? false;
215+
// Reset issued warnings to avoid dedupe interference
216+
window.__swc.issuedWarnings = new Set();
217+
// Enable debug guard
218+
window.__swc.DEBUG = true;
219+
});
220+
221+
afterEach(() => {
222+
// Restore original warn function and debug state
223+
window.__swc.warn = originalWarn;
224+
window.__swc.DEBUG = originalDebug;
225+
});
226+
227+
test('should warn when unsupported variant is used', async () => {
228+
const warnSpy = vi.fn();
229+
window.__swc.warn = warnSpy as unknown as typeof window.__swc.warn;
230+
231+
const statusLight = await fixture<StatusLight>(html`
232+
<swc-status-light variant="accent"></swc-status-light>
233+
`);
234+
235+
await statusLight.updateComplete;
236+
237+
expect(warnSpy).toHaveBeenCalled();
238+
expect(warnSpy.mock.calls[0][0]).toBe(statusLight);
239+
expect(warnSpy.mock.calls[0][1]).toBe(
240+
`<${statusLight.localName}> element expects the "variant" attribute to be one of the following:`
241+
);
242+
});
243+
244+
test('should warn when disabled attribute is used', async () => {
245+
const warnSpy = vi.fn();
246+
window.__swc.warn = warnSpy as unknown as typeof window.__swc.warn;
247+
248+
const statusLight = await fixture<StatusLight>(html`
249+
<swc-status-light
250+
variant="positive"
251+
disabled
252+
></swc-status-light>
253+
`);
254+
255+
await statusLight.updateComplete;
256+
257+
expect(warnSpy).toHaveBeenCalled();
258+
expect(warnSpy.mock.calls[0][0]).toBe(statusLight);
259+
expect(warnSpy.mock.calls[0][1]).toContain(
260+
'does not support the disabled state'
261+
);
262+
});
263+
});
264+
});

0 commit comments

Comments
 (0)