import type {StoryObj} from "@storybook/web-components"; import {within, expect} from "@storybook/test"; import '../custom-element/custom-element.js'; import {CharsCountInTextarea, WordCountOnType} from './dom-merge.test.stories'; type CssProps = { title: string; tag: string; style: string; slot: string; payload: string }; const defs = {title: '', tag: '', style: '', slot: '', payload: ''}; type Story = StoryObj; function render(args: CssProps) { const {title, tag, style, slot, payload} = { ...defs, ...args }; return `
${ title } ${ payload }
`; } const meta = { title: 'Css', render }; export default meta; const GREEN = `green` const RED = `red` export const StyleDoesNotLeak: Story = { args: { title: `The default color should stay on this label, the message inside should be ${GREEN}` , style: `color:green` , slot: 'text has to be green' , payload: 'no tags' } , play: async ({canvasElement}) => { const canvas = within(canvasElement); const el = await canvas.findByText('text has to be green'); const st = getComputedStyle(el); const color = st.getPropertyValue('color'); // @ts-ignore expect(color).to.equal('rgb(0, 128, 0)') await expect( el.closest('custom-element')).toBeInTheDocument(); const dce = el.closest('custom-element'); await expect( dce.xsltString).toContain('2 instances: * ` } , play: async ({canvasElement}) => { await within(canvasElement).findByText('2 instances:'); const color = ( css:string )=> { const el = canvasElement.querySelector(css); const st = getComputedStyle( el! ); return st.getPropertyValue('color'); }; expect( color('legend' ) ).to.not.equal(color('b')); expect( color('legend' ) ).to.not.equal(color('b')); expect( color('#dce21 u') ).to .equal(color('b')); expect( color('#dce22 u') ).to .equal(color('b')); }, }; // noinspection CssInvalidPseudoSelector export const OverrideInPayload: Story = { args: { title: `${GREEN} in instance style can be overridden in payload as ${RED} in 1st instance` , style: `color:green` , slot: 'is green' , tag: 'dce-3' , payload: `should be ${RED}:
should be ${GREEN}: green ` } , play: async ({canvasElement}) => { await within(canvasElement).findByText('should be'); const color = ( css:string )=> { const el = canvasElement.querySelector(css); const st = getComputedStyle( el! ); return st.getPropertyValue('color'); }; expect( color('legend' ) ).to.not.equal(color('b')); expect( color('#dce31 u') ).to .equal(color('b')); expect( color('#dce32 u') ).to .equal(color('i')); }, }; //#region unit tests /* istanbul ignore else -- @preserve */ if( 'test' === import.meta.env.MODE && !import.meta.url.includes('skiptest') ) { const mod = await import('./css.test.stories.ts?skiptest'); const { testStoryBook } = await import('./testStoryBook') const { describe } = await import('vitest') describe(meta.title, () => testStoryBook( mod, meta ) ); } //#endregion