Skip to content

Commit 86eb265

Browse files
committed
test(button): update clear-button dev mode test
1 parent e1cc07d commit 86eb265

File tree

2 files changed

+74
-25
lines changed

2 files changed

+74
-25
lines changed

packages/button/src/ClearButton.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,36 @@ export class ClearButton extends SizedMixin(StyledButton, {
6969
* @deprecated Use `static-color='white'` instead.
7070
*/
7171
@property({ reflect: true })
72-
public variant: 'overBackground' | undefined;
72+
public set variant(variant: 'overBackground' | undefined) {
73+
const oldValue = this.variant;
74+
if (variant !== 'overBackground') {
75+
this.removeAttribute('variant');
76+
this._variant = undefined;
77+
return;
78+
}
79+
80+
this.setAttribute('variant', variant);
81+
this._variant = variant;
82+
// Set staticColor to white to reflect the updated and expected attribute
83+
this.staticColor = 'white';
84+
85+
if (window.__swc.DEBUG) {
86+
window.__swc.warn(
87+
this,
88+
'The overBackground variant is deprecated. Please use `static-color="white"` instead.',
89+
'https://opensource.adobe.com/spectrum-web-components/components/clear-button/',
90+
{ level: 'deprecation' }
91+
);
92+
}
93+
94+
this.requestUpdate('variant', oldValue);
95+
}
96+
97+
public get variant(): 'overBackground' | undefined {
98+
return this._variant;
99+
}
100+
101+
private _variant: 'overBackground' | undefined;
73102

74103
/**
75104
* The visual variant to apply to this button.

packages/button/test/clear-button.test.ts

+44-24
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,60 @@ governing permissions and limitations under the License.
1212

1313
import '@spectrum-web-components/button/sp-clear-button.js';
1414
import { ClearButton } from '@spectrum-web-components/button';
15+
import { ElementSize } from '@spectrum-web-components/base';
1516
import { expect, fixture, html } from '@open-wc/testing';
1617
import { testForLitDevWarnings } from '../../../test/testing-helpers';
1718

1819
describe('Clear Button', () => {
1920
testForLitDevWarnings(
2021
async () =>
21-
await fixture<ClearButton>(
22-
html`
23-
<sp-clear-button size="m" label="Clear"></sp-clear-button>
24-
`
25-
)
22+
await fixture<ClearButton>(html`
23+
<sp-clear-button size="m" label="Clear"></sp-clear-button>
24+
`)
2625
);
27-
(
28-
['s', 'm', 'l', 'xl'] as (
29-
| 'xxs'
30-
| 'xs'
31-
| 's'
32-
| 'm'
33-
| 'l'
34-
| 'xl'
35-
| 'xxl'
36-
)[]
37-
).map((size) => {
26+
(['s', 'm', 'l', 'xl'] as ElementSize[]).map((size) => {
3827
it(`loads - ${size}`, async () => {
39-
const el = await fixture<ClearButton>(
40-
html`
41-
<sp-clear-button
42-
size=${size}
43-
label="Clear"
44-
></sp-clear-button>
45-
`
46-
);
28+
const el = await fixture<ClearButton>(html`
29+
<sp-clear-button size=${size} label="Clear"></sp-clear-button>
30+
`);
4731

4832
await expect(el).to.be.accessible();
4933
});
5034
});
35+
36+
describe('dev mode', () => {
37+
let consoleStub: SinonStub;
38+
before(() => {
39+
window.__swc.verbose = true;
40+
consoleStub = stub(console, 'warn');
41+
});
42+
43+
after(() => {
44+
window.__swc.verbose = false;
45+
consoleStub.restore();
46+
});
47+
48+
it('should log dev warning when overBackground variant is used', async () => {
49+
const el = await fixture<ClearButton>(html`
50+
<sp-clear-button
51+
label="Clear"
52+
variant="overBackground"
53+
></sp-clear-button>
54+
`);
55+
56+
await elementUpdated(el);
57+
58+
const warning = consoleStub.getCall(0).args.at(0);
59+
const expectedContent =
60+
'The overBackground variant is deprecated. Please use `static-color="white"` instead.';
61+
62+
expect(consoleStub).to.be.calledOnce;
63+
expect(warning.includes(expectedContent)).to.be.true;
64+
65+
// Check that the staticColor is set to white
66+
expect(el.staticColor).to.equal('white');
67+
expect(el.hasAttribute('static-color')).to.be.true;
68+
expect(el.getAttribute('static-color')).to.equal('white');
69+
});
70+
});
5171
});

0 commit comments

Comments
 (0)