Skip to content

Commit

Permalink
test: minimal repro for salesforce#4155
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Apr 16, 2024
1 parent 840999a commit 43e3d9b
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { createElement, swapStyle } from 'lwc';
import { extractDataIds } from 'test-utils';
import ShadowSimple from 'shadow/simple';
import ShadowStaleProp from 'shadow/staleProp';
import ShadowTweedledum from 'shadow/tweedledum';
import ShadowTweedledee from 'shadow/tweedledee';
import LightSimple from 'light/simple';
import LightStaleProp from 'light/staleProp';
import LightTweedledum from 'light/tweedledum';
import LightTweedledee from 'light/tweedledee';
import LightGlobalSimple from 'light-global/simple';
import LightGlobalStaleProp from 'light-global/staleProp';
import LightGlobalTweedledum from 'light-global/tweedledum';
import LightGlobalTweedledee from 'light-global/tweedledee';

function expectStyles(elm, styles) {
const computed = getComputedStyle(elm);
Expand All @@ -29,26 +35,32 @@ if (process.env.NODE_ENV !== 'production') {
components: {
Simple: ShadowSimple,
StaleProp: ShadowStaleProp,
Tweedledee: ShadowTweedledee,
Tweedledum: ShadowTweedledum,
},
},
{
testName: 'light',
components: {
Simple: LightSimple,
StaleProp: LightStaleProp,
Tweedledee: LightTweedledee,
Tweedledum: LightTweedledum,
},
},
{
testName: 'light-global',
components: {
Simple: LightGlobalSimple,
StaleProp: LightGlobalStaleProp,
Tweedledee: LightGlobalTweedledee,
Tweedledum: LightGlobalTweedledum,
},
},
];
scenarios.forEach(({ testName, components }) => {
describe(testName, () => {
const { Simple, StaleProp } = components;
const { Simple, StaleProp, Tweedledum, Tweedledee } = components;
it('should work with components with implicit style definition', async () => {
const { blockStyle, inlineStyle, noneStyle } = Simple;
const elm = createElement(`${testName}-simple`, { is: Simple });
Expand Down Expand Up @@ -151,6 +163,30 @@ if (process.env.NODE_ENV !== 'production') {
});
}
});

it('should handle stylesheet collisions correctly', async () => {
const { stylesV1, stylesV2 } = Tweedledum;
const elm1 = createElement(`${testName}-tweedledum`, { is: Tweedledum });
const elm2 = createElement(`${testName}-tweedledee`, { is: Tweedledee });
document.body.appendChild(elm1);
document.body.appendChild(elm2);

await Promise.resolve();
for (const elm of [elm1, elm2]) {
expectStyles(extractDataIds(elm).paragraph, {
marginTop: '19px',
});
}
swapStyle(stylesV1[0], stylesV2[0]);

await Promise.resolve();
expectStyles(extractDataIds(elm1).paragraph, {
marginTop: '37px',
});
expectStyles(extractDataIds(elm2).paragraph, {
marginTop: '19px',
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lwc:render-mode="light">
<p data-id="paragraph">tweedledee</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lwc:render-mode="light">
<p data-id="paragraph">tweedledum</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LightningElement } from 'lwc';
import stylesV1 from './tweedledum.css';
import stylesV2 from './tweedledum2.css';

export default class extends LightningElement {
static renderMode = 'light';
static stylesV1 = stylesV1;
static stylesV2 = stylesV2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 37px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lwc:render-mode="light">
<p data-id="paragraph">tweedledee</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {
static renderMode = 'light';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lwc:render-mode="light">
<p data-id="paragraph">tweedledum</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LightningElement } from 'lwc';
import stylesV1 from './tweedledum.scoped.css';
import stylesV2 from './tweedledum2.scoped.css';

export default class extends LightningElement {
static renderMode = 'light';
static stylesV1 = stylesV1;
static stylesV2 = stylesV2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 37px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p data-id="paragraph">tweedledee</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 19px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p data-id="paragraph">tweedledum</p>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LightningElement } from 'lwc';
import stylesV1 from './tweedledum.css';
import stylesV2 from './tweedledum2.css';

export default class extends LightningElement {
static stylesV1 = stylesV1;
static stylesV2 = stylesV2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p {
margin-top: 37px;
}

0 comments on commit 43e3d9b

Please sign in to comment.