Skip to content

Commit 160ceab

Browse files
author
Ben Siggery
committed
add new tests
1 parent 29f683d commit 160ceab

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

apps/pie-storybook/test/utilities/index.test.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
22
import { html, render, type TemplateResult } from 'lit';
33
import { createStory, createVariantStory } from '../../utilities/index';
44
import { type StoryOptions } from '../../types/StoryOptions';
5-
5+
import CUSTOM_BACKGROUNDS from '../../.storybook/backgrounds';
66
type ComponentProps = {
77
size: string;
88
variant: string;
@@ -89,4 +89,67 @@ describe('createVariantStory', () => {
8989
// Check if argTypes are applied
9090
expect(story.argTypes).toEqual(storyOpts.argTypes);
9191
});
92+
93+
it('should apply custom background color from CUSTOM_BACKGROUNDS', () => {
94+
const propOptions = {
95+
size: ['small'],
96+
variant: ['primary']
97+
};
98+
99+
const story = createVariantStory(template, propOptions, { bgColor: 'background-subtle' });
100+
const renderResult = story.render();
101+
102+
const container = document.createElement('div');
103+
render(renderResult, container);
104+
105+
const templateContainer = container.querySelector('.template-container');
106+
const computedStyle = window.getComputedStyle(templateContainer!);
107+
108+
const backgroundColor = computedStyle.getPropertyValue('--background-color');
109+
expect(backgroundColor).toBeTruthy();
110+
expect(backgroundColor).not.toBe('#ffffff');
111+
112+
const matchingBackground = CUSTOM_BACKGROUNDS.values.find(bg => bg.name === 'background-subtle');
113+
expect(backgroundColor).toBe(matchingBackground?.value);
114+
});
115+
116+
it('should fallback to default white background when invalid bgColor is provided', () => {
117+
const propOptions = {
118+
size: ['small'],
119+
variant: ['primary']
120+
};
121+
122+
// @ts-expect-error - Testing invalid background color
123+
const story = createVariantStory(template, propOptions, { bgColor: 'background-invalid' });
124+
const renderResult = story.render();
125+
126+
const container = document.createElement('div');
127+
render(renderResult, container);
128+
129+
const templateContainer = container.querySelector('.template-container');
130+
const computedStyle = window.getComputedStyle(templateContainer!);
131+
132+
// Should fallback to default white background
133+
const backgroundColor = computedStyle.getPropertyValue('--background-color');
134+
expect(backgroundColor).toBe('#ffffff');
135+
});
136+
137+
it('should use default white background when bgColor is undefined', () => {
138+
const propOptions = {
139+
size: ['small'],
140+
variant: ['primary']
141+
};
142+
143+
const story = createVariantStory(template, propOptions);
144+
const renderResult = story.render();
145+
146+
const container = document.createElement('div');
147+
render(renderResult, container);
148+
149+
const templateContainer = container.querySelector('.template-container');
150+
const computedStyle = window.getComputedStyle(templateContainer!);
151+
152+
const backgroundColor = computedStyle.getPropertyValue('--background-color');
153+
expect(backgroundColor).toBe('#ffffff');
154+
});
92155
});

0 commit comments

Comments
 (0)