Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // noinspection DuplicatedCode // importmap is located at .storybook/preview-head.html // for vitest wrap `pathe.resolve` method to capture /tester/tester.html and redirect to its clone with ^^ injected // as in vite.config.js // test requires bin/vitest/vitest-browser-importmaps.mjs to inject importmap into tester.html // the relative path prefix in vitest is `../../..` import type { StoryObj } from '@storybook/web-components'; import {expect, getByTestId, within} from '@storybook/test'; import '../custom-element/custom-element.js'; import '../custom-element/module-url.js'; import {Demo, SrcAttribute} from './location-element.test.stories'; type TProps = { title: string; body:string}; type Story = StoryObj<TProps>; function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } function render(args: TProps) { const {title, body} = args; return ` <fieldset> <legend>${ title }</legend> ${ body } </fieldset> `; } const meta = { title: 'module-url' , render }; export default meta; // for StoryBook './demo/embed-1.html' is sufficient as current page is on root level // vitest page needs 3 levels up export const RelativeToPagePath:Story = { args : {title: '1. relative to page path', body:` <custom-element> <a href="../../../demo/embed-1.html"> <custom-element src="../../../demo/embed-1.html"></custom-element> </a> </custom-element> `} , play: async ({canvasElement}) => { const canvas = within(canvasElement); await canvas.findByText(RelativeToPagePath.args!.title as string); await expect(await canvas.findByText('🖖')).toBeInTheDocument(); await expect(await canvas.findByText('embed-1.html')).toBeInTheDocument(); }, }; export const ModuleBySymbolicName:Story = { args : {title: '2. module by symbolic name', body:` <custom-element> <template> <module-url slice="lib-url" src="embed-lib"></module-url> <if test="//lib-url/@error"> <p>error: <b>{//lib-url/@error}</b></p> </if> check the link: <a href="{//lib-url}"> <custom-element src="embed-lib#embed-lib-component"> failed to load </custom-element> </a> </template> </custom-element> `} , play: async ({canvasElement}) => { const p = import.meta.resolve('embed-lib'); const canvas = within(canvasElement); await canvas.findByText(ModuleBySymbolicName.args!.title as string); await expect(await canvas.findByText('check the link:')).toBeInTheDocument(); await expect(await canvas.findByText('👋 from embed-lib-component')).toBeInTheDocument(); }, }; export const MissingImportmapEntry:Story = { args : {title: '3. module by symbolic name with missing importmap entry', body:` <custom-element> <template> <module-url slice="lib-url" src="fakedemo-lib/embed-lib.html"></module-url> <if test="//lib-url/@error"> <p>error: <b>{//lib-url/@error}</b></p> </if> the link is broken: <a href="{//lib-url}"> <custom-element src="fakedemo-lib/embed-lib.html#embed-lib-component"> failed to load </custom-element> </a> </template> </custom-element> `} , play: async ({canvasElement}) => { const canvas = within(canvasElement); await canvas.findByText(MissingImportmapEntry.args!.title as string); await expect(await canvas.findByText('error:')).toBeInTheDocument(); await expect(await canvas.findByText('failed to load')).toBeInTheDocument(); }, }; export const ModuleByName:Story = { args : {title: '4. module path by symbolic name', body:` <custom-element> <template> <module-url slice="lib-url" src="lib-root/embed-lib.html#embed-relative-hash"></module-url> <module-url slice="img-url" src="lib-root/Smiley.svg"></module-url> <if test="//lib-url/@error"> <p>error: <b>{//lib-url/@error}</b></p> </if> check the link: <a href="{//lib-url}"> lib-root/embed-lib.html#embed-relative-hash <img src="{//img-url}" alt=""/></a> <custom-element src="lib-root/embed-lib.html#embed-relative-hash"> failed to load </custom-element> </template> </custom-element> `} , play: async ({canvasElement}) => { const canvas = within(canvasElement); await canvas.findByText(ModuleByName.args!.title as string); await expect(await canvas.findByText('👌 from embed-relative-hash invoking')).toBeInTheDocument(); await expect(await canvas.findByText('lib-root/embed-lib.html#embed-relative-hash')).toBeInTheDocument(); await expect(await canvas.findByText('#embed-lib-component')).toBeInTheDocument(); }, }; export const HashWithinLib:Story = { args : {title: '5. module path by symbolic name to internal link within lib', body:` <custom-element> <template> <module-url slice="lib-url" src="lib-root/embed-lib.html#embed-relative-file"></module-url> <if test="//lib-url/@error"> <p>error: <b>{//lib-url/@error}</b></p> </if> check the link: <a href="{//lib-url}"> lib-root/embed-lib.html#embed-relative-file </a> <custom-element src="lib-root/embed-lib.html#embed-relative-file"> failed to load </custom-element> </template> </custom-element> `} , play: async ({canvasElement}) => { const canvas = within(canvasElement); await canvas.findByText(HashWithinLib.args!.title as string); await expect(await canvas.findByText('lib-root/embed-lib.html#embed-relative-file')).toBeInTheDocument(); await expect(await canvas.findByText('👍 from embed-relative-file invoking')).toBeInTheDocument(); await expect(await canvas.findByText('../embed-1.html')).toBeInTheDocument(); await expect(await canvas.findByText('embed-1.html')).toBeInTheDocument(); await expect(await canvas.findByText('🖖')).toBeInTheDocument(); }, }; //#region unit tests /* istanbul ignore else -- @preserve */ if( 'test' === import.meta.env.MODE && !import.meta.url.includes('skiptest') ) { const mod = await import('./module-url.test.stories.ts?skiptest'); const { testStoryBook } = await import('./testStoryBook') const { describe } = await import('vitest') describe(meta.title, () => testStoryBook( mod, meta ) ); } //#endregion |