Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Siggery committed Feb 11, 2025
1 parent 29f683d commit 160ceab
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion apps/pie-storybook/test/utilities/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { html, render, type TemplateResult } from 'lit';
import { createStory, createVariantStory } from '../../utilities/index';
import { type StoryOptions } from '../../types/StoryOptions';

import CUSTOM_BACKGROUNDS from '../../.storybook/backgrounds';

Check failure on line 5 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Expected 1 empty line after import statement not followed by another import
type ComponentProps = {
size: string;
variant: string;
Expand Down Expand Up @@ -89,4 +89,67 @@ describe('createVariantStory', () => {
// Check if argTypes are applied
expect(story.argTypes).toEqual(storyOpts.argTypes);
});

it('should apply custom background color from CUSTOM_BACKGROUNDS', () => {
const propOptions = {
size: ['small'],
variant: ['primary']

Check failure on line 96 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Missing trailing comma
};

const story = createVariantStory(template, propOptions, { bgColor: 'background-subtle' });
const renderResult = story.render();

const container = document.createElement('div');
render(renderResult, container);

const templateContainer = container.querySelector('.template-container');
const computedStyle = window.getComputedStyle(templateContainer!);

Check warning on line 106 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Forbidden non-null assertion

Check failure on line 107 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Trailing spaces not allowed
const backgroundColor = computedStyle.getPropertyValue('--background-color');
expect(backgroundColor).toBeTruthy();
expect(backgroundColor).not.toBe('#ffffff');

Check failure on line 111 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Trailing spaces not allowed
const matchingBackground = CUSTOM_BACKGROUNDS.values.find(bg => bg.name === 'background-subtle');

Check failure on line 112 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Expected parentheses around arrow function argument
expect(backgroundColor).toBe(matchingBackground?.value);
});

it('should fallback to default white background when invalid bgColor is provided', () => {
const propOptions = {
size: ['small'],
variant: ['primary']

Check failure on line 119 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Missing trailing comma
};

// @ts-expect-error - Testing invalid background color
const story = createVariantStory(template, propOptions, { bgColor: 'background-invalid' });
const renderResult = story.render();

const container = document.createElement('div');
render(renderResult, container);

const templateContainer = container.querySelector('.template-container');
const computedStyle = window.getComputedStyle(templateContainer!);

Check warning on line 130 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Forbidden non-null assertion

Check failure on line 131 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Trailing spaces not allowed
// Should fallback to default white background
const backgroundColor = computedStyle.getPropertyValue('--background-color');
expect(backgroundColor).toBe('#ffffff');
});

it('should use default white background when bgColor is undefined', () => {
const propOptions = {
size: ['small'],
variant: ['primary']

Check failure on line 140 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Missing trailing comma
};

const story = createVariantStory(template, propOptions);
const renderResult = story.render();

const container = document.createElement('div');
render(renderResult, container);

const templateContainer = container.querySelector('.template-container');
const computedStyle = window.getComputedStyle(templateContainer!);

Check warning on line 150 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Forbidden non-null assertion

Check failure on line 151 in apps/pie-storybook/test/utilities/index.test.ts

View workflow job for this annotation

GitHub Actions / lint-js

Trailing spaces not allowed
const backgroundColor = computedStyle.getPropertyValue('--background-color');
expect(backgroundColor).toBe('#ffffff');
});
});

0 comments on commit 160ceab

Please sign in to comment.