Skip to content

Commit

Permalink
fixes for data-dce-id
Browse files Browse the repository at this point in the history
  • Loading branch information
sashafirsov committed Dec 26, 2023
1 parent eb9bd91 commit fd50d45
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
7 changes: 4 additions & 3 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const attr = (el, attr)=> el.getAttribute?.(attr)

function
ASSERT(x)
{ if(!x)
debugger
{
// if(!x)
// debugger
}
function
xml2dom( xmlString )
Expand Down Expand Up @@ -121,7 +122,7 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' )
{
if( templateNode.tagName === S || templateNode.documentElement?.tagName === S )
return tagUid(templateNode)
const sanitizeXsl = xml2dom(`<xsl:stylesheet version="1.0" xmlns:xsl="${ XSL_NS_URL }" xmlns:xhtml="${ HTML_NS_URL }" xmlns:exsl="${EXSL_NS_URL}" exclude-result-prefixes="exsl" >
const sanitizeXsl = xml2dom(`<xsl:stylesheet version="1.0" xmlns:xsl="${ XSL_NS_URL }" xmlns:xhtml="${ HTML_NS_URL }" xmlns:exsl="${EXSL_NS_URL}" exclude-result-prefixes="exsl" >
<xsl:output method="xml" />
<xsl:template match="/"><dce-root><xsl:apply-templates select="*"/></dce-root></xsl:template>
<xsl:template match="*[name()='template']"><xsl:apply-templates mode="sanitize" select="*|text()"/></xsl:template>
Expand Down
10 changes: 6 additions & 4 deletions test/http-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ describe('http-request', () =>
await aTimeout(50);
expect(el.querySelectorAll('[data-testid="request-section"]').length).to.equal(1);
const attrs = [...el.querySelectorAll('[data-testid="section-attribute"]')]
expect(attrs.length).to.equal(3);
expect(attrs.length).to.equal(4);
expect(attrs[0].innerText).to.equal('@url');
expect(attrs[0].nextElementSibling.innerText).to.equal('https://pokeapi.co/api/v2/noreturn');
expect(attrs[0].nextElementSibling.nextElementSibling.innerText).to.equal('https://pokeapi.co/api/v2/noreturn');
expect(attrs[1].innerText).to.equal('@slice');
expect(attrs[1].nextElementSibling.innerText).to.equal('request_slice');
expect(attrs[1].nextElementSibling.nextElementSibling.innerText).to.equal('request_slice');
expect(attrs[2].innerText).to.equal('@type');
expect(attrs[2].nextElementSibling.innerText).to.equal('text');
expect(attrs[2].nextElementSibling.nextElementSibling.innerText).to.equal('text');
expect(attrs[3].innerText).to.equal('@data-dce-id');
expect(el.innerText).to.include('\nrequest');
expect(el.innerText).not.to.include('\nresponse');
});
Expand All @@ -57,6 +58,7 @@ describe('http-request', () =>
expect( nextText() ).to.equal('@slice = request_slice');
expect( nextText() ).to.equal('@type = text');
expect( nextText() ).to.equal('@mode = cors');
expect( nextText() ).to.include('@data-dce-id');
expect( nextText() ).to.equal('headers\n@x-test = testing');

attr = responseSection.firstElementChild;
Expand Down
19 changes: 10 additions & 9 deletions test/local-storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ const renderStory = async (story) => fixture( story({ ...defs, ...story.args })

describe('local-storage', () => {

it('LocalStorageLoad', async () => {
it('LocalStorageLoad 1', async () => {
const el = await renderStory(LocalStorageLoad);
expect(localStorage['cherries']).to.equal(`πŸ’ from localStorage`);
expect(el.querySelectorAll('ls-test-component').length).to.equal(1);
const p = el.querySelector('ls-test-component');
expect(p.innerHTML).to.include('fruits slice: πŸ’ from localStorage');
expect(p.innerText).to.include('fruits slice: πŸ’ from localStorage');
});

it('LocalStorageLoad', async () => {
it('LocalStorageLoad 2', async () => {
const el = await renderStory(LocalStorageLive);
await aTimeout(10);
expect(localStorage['basket']).to.equal(`{"cherries": 12, "lemons":1 }`);
expect(el.querySelectorAll('ls-live-component').length).to.equal(1);
const p = el.querySelector('ls-live-component');
expect(p.innerHTML).to.include('cherries');
expect(p.innerHTML).to.include('lemons');
expect(p.innerHTML).to.include('td>12</');
expect(p.innerHTML).to.include('td>1</');
expect(p.innerHTML).to.include('th>13</');
expect(p.innerHTML).to.include('>12</');
expect(p.innerHTML).to.include('>1</');
expect(p.innerHTML).to.include('>13</');
localStorage.setItem('basket',`{"apples": 3, "oranges": 2 }`);
await aTimeout(10);
expect(p.innerHTML).to.not.include('lemons');
expect(p.innerHTML).to.include('apples');
expect(p.innerHTML).to.include('oranges');
expect(p.innerHTML).to.include('td>3</');
expect(p.innerHTML).to.include('td>2</');
expect(p.innerHTML).to.include('th>5</');
expect(p.innerHTML).to.include('>3</');
expect(p.innerHTML).to.include('>2</');
expect(p.innerHTML).to.include('>5</');

});

Expand Down
20 changes: 10 additions & 10 deletions test/location-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('location-element', () => {
}
window.location.hash = '#dce'
await aTimeout(10);
expect(el.innerText).to.include(`hash`+`#dce`); // actual change
expect(el.innerText).to.include(`hash\t#dce`); // actual change

match('protocol')
match('host')
Expand All @@ -74,15 +74,15 @@ describe('location-element', () => {
{
const el = await renderStory(LocationElementSrc);
expect(el.querySelector('location-element').getAttribute('src')).to.equals('https://my.example/?a=1&b=2#3'); // actual change
expect(el.innerText).to.include(`href`+`https://my.example/?a=1&b=2#3`);
expect(el.innerText).to.include(`protocol`+`https:`);
expect(el.innerText).to.include(`host`+`my.example`);
expect(el.innerText).to.include(`hostname`+`my.example`);
expect(el.innerText).to.include(`pathname`+`/`);
expect(el.innerText).to.include(`search`+`?a=1&b=2`);
expect(el.innerText).to.include(`hash`+`#3`);
expect(el.innerText).to.include(`a`+`1`);
expect(el.innerText).to.include(`b`+`2`);
expect(el.innerText).to.include(`href\thttps://my.example/?a=1&b=2#3`);
expect(el.innerText).to.include(`protocol\thttps:`);
expect(el.innerText).to.include(`host\tmy.example`);
expect(el.innerText).to.include(`hostname\tmy.example`);
expect(el.innerText).to.include(`pathname\t/`);
expect(el.innerText).to.include(`search\t?a=1&b=2`);
expect(el.innerText).to.include(`hash\t#3`);
expect(el.innerText).to.include(`a\t1`);
expect(el.innerText).to.include(`b\t2`);
});

});
22 changes: 8 additions & 14 deletions test/src-attribute.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fixture, expect } from '@open-wc/testing';
import { fixture, expect, aTimeout } from '@open-wc/testing';

import '../src/custom-element.js';
import defaults, {
Expand All @@ -11,12 +11,6 @@ import defaults, {

} from '../stories/src-attribute.stories.js';

function sleep(timeMs) {
return new Promise((resolve) => {
setTimeout(resolve, timeMs)
})
}

const defs = {}; Object.keys(defaults.argTypes).map( k=> defs[k]= defaults.argTypes[k].defaultValue);
const renderStory = async (story) => fixture( story({ ...defs, ...story.args }) );

Expand All @@ -38,7 +32,7 @@ describe('src attribute', () => {
it('src=svg', async () => {
Svg.args.src='/src/demo/confused.svg';
const el = await renderStory(Svg);
sleep(100)
await aTimeout(100)

expect(el.querySelectorAll('my-component').length).to.equal(0);
expect(el.querySelector('custom-element').firstElementChild.localName.startsWith('dce-')).to.equal(true);
Expand All @@ -49,7 +43,7 @@ describe('src attribute', () => {
it('src=404', async () => {
NoSvg.args.src='/src/demo/404.svg';
const el = await renderStory(NoSvg);
sleep(100)
await aTimeout(100)

expect(el.querySelectorAll('my-component').length).to.equal(0);
expect(el.querySelector('custom-element').getAttribute('tag')).to.equal('');
Expand All @@ -60,7 +54,7 @@ describe('src attribute', () => {
it('src=xsl', async () => {
Xsl.args.src='/src/demo/tree.xsl';
const el = await renderStory(Xsl);
sleep(100)
await aTimeout(100)
expect(el.innerText).to.include('data-smile');
expect(el.innerText).to.include('πŸ‘Ό');
expect(el.innerText).to.include('attr-1\na1');
Expand All @@ -69,21 +63,21 @@ describe('src attribute', () => {

it('src=html', async () => {
const el = await renderStory(HtmlTemplate);
await sleep(1000)
await aTimeout(1000)
expect(el.innerHTML).to.include('<svg');
expect(el.innerText).to.include('πŸ‘‹');
expect(el.innerText).to.include('πŸ‘Œ');
});

it('src=html#id', async () => {
const el = await renderStory(HtmlById);
await sleep(100)
await aTimeout(100)
expect(el.innerText).to.include('πŸ‘‹');
});

it('src=xhtml#xslt-id', async () => {
const el = await renderStory(XsltById);
await sleep(100)
await aTimeout(100)
expect(el.innerText).to.include('data-smile');
expect(el.innerText).to.include('πŸ‘Ό');
expect(el.innerText).to.include('attr-1\na1');
Expand All @@ -92,7 +86,7 @@ describe('src attribute', () => {

it('src= with embedded src ', async () => {
const el = await renderStory(EmbeddedDce);
await sleep(100)
await aTimeout(100)
expect(el.innerText).to.include('πŸ––');
});

Expand Down

0 comments on commit fd50d45

Please sign in to comment.