All files / src/stories version-select.test.stories.ts

55.55% Statements 10/18
100% Branches 3/3
33.33% Functions 2/6
60% Lines 9/15

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                                  6x 6x               1x               1x                                                                                                                         1x     1x 1x 1x 1x      
// noinspection DuplicatedCode
 
import type { StoryObj }                        from '@storybook/web-components';
import {expect, within} from '@storybook/test';
 
import '../custom-element/custom-element.js';
import '../custom-element/http-request.js';
import '../custom-element/location-element.js';
 
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: 'site'
// ,         tags: ['autodocs']
,       render
};
 
export default meta;
 
export const VersionsSelect:Story  =
{   args : {title: 'Versions of custom-element', body:`
    <p>Select the version of custom-element StoryBook.</p>
    <custom-element >
        <template>
            <variable name="url" select="//window-location/value/@href"></variable>
            <variable name="current-version" >0{
                substring-before(substring-after(substring($url, string-length(substring-before($url, '/')) - string-length(substring-before(substring-before($url, '/'), '@0')) + 2), '@0'), '/')
            }</variable>
            <location-element slice="window-location" live>
                <xsl:if test=" not(//selected-version = $current-version ) and not(//selected-version = '')  ">
                    <attribute name="src">{ concat( substring-before($url, $current-version), 
                                                    //selected-version, 
                                                    substring-after($url, $current-version) ) }</attribute>
                    <attribute name="method">location.href</attribute>
                </if>
            </location-element>
            <http-request 
                url="https://registry.npmjs.org/@epa-wg/custom-element-dist" 
                method="GET" 
                header-accept="application/json"
                slice="versions-ajax" ></http-request>
                    
            <label>version: 
                <xhtml:select slice="selected-version" autocomplete="off" name="version">
                    <for-each select="//versions/*">
                        <option value="{./@version}">
                            <variable name="item-version">{./@version}</variable>
                            { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
                        </option>
                    </for-each>
                    <for-each select="//versions/*">
                        <if test="./@version = $current-version">
                            <option selected value="{./@version}">
                                <variable name="item-version">{./@version}</variable>
                                { $item-version } - { substring( //time/*[@dce-object-name = $item-version ], 1,10)}
                            </option>    
                        </if>
                    </for-each>
                </xhtml:select>
            </label>
        </template>
    </custom-element>
    <dce-link id="dce1"></dce-link>
`}
,   play: async ({canvasElement}) =>
    {
        const titleText = VersionsSelect.args!.title as string;
        const canvas = within(canvasElement)
        , code = async (id) => (await canvas.findByTestId(id)).textContent.trim();
 
        window.location.hash = '#@epa-wg/custom-element-dist@0.0.24/storybook-static/index.html'
        await sleep(20)
        // expect( await code('p1') ).toEqual('default_P1' );
        // expect( await code('p2') ).toEqual('always_p2'  );
        // expect( await code('p3') ).toEqual('def_P3'     );
    },
};
 
 
//#region unit tests
/* istanbul ignore else -- @preserve */
if(  'test' === import.meta.env.MODE &&
    !import.meta.url.includes('skiptest') )
{
    const mod = await import('./attributes.test.stories.ts?skiptest');
    const { testStoryBook } = await import('./testStoryBook')
    const { describe } = await import('vitest')
    describe(meta.title, () => testStoryBook( mod, meta ) );
}
//#endregion