|
1 | 1 | import {expect, fixture, html} from '@open-wc/testing'; |
2 | | -import {$} from '../includes/test-helpers.js'; |
| 2 | +import {$, $$, clickOnElement} from '../includes/test-helpers.js'; |
3 | 3 | import '../vscode-radio/index.js'; |
4 | 4 | import {VscodeRadio} from '../vscode-radio/index.js'; |
5 | 5 | import {VscodeRadioGroup} from './index.js'; |
6 | 6 |
|
| 7 | +class DemoElement extends HTMLElement { |
| 8 | + static template = (() => { |
| 9 | + const t = document.createElement('template'); |
| 10 | + t.innerHTML = ` |
| 11 | + <vscode-radio-group> |
| 12 | + <vscode-radio value="1">Option 1</vscode-radio> |
| 13 | + <vscode-radio value="2">Option 2</vscode-radio> |
| 14 | + <vscode-radio value="3" default-checked>Option 3</vscode-radio> |
| 15 | + </vscode-radio-group> |
| 16 | + `; |
| 17 | + |
| 18 | + return t; |
| 19 | + })(); |
| 20 | + |
| 21 | + constructor() { |
| 22 | + super(); |
| 23 | + |
| 24 | + const shadow = this.attachShadow({mode: 'open'}); |
| 25 | + shadow.appendChild(DemoElement.template.content.cloneNode(true)); |
| 26 | + |
| 27 | + const sheet = new CSSStyleSheet(); |
| 28 | + sheet.replaceSync(` |
| 29 | + :host { |
| 30 | + display: block; |
| 31 | + padding: 16px; |
| 32 | + } |
| 33 | + `); |
| 34 | + |
| 35 | + shadow.adoptedStyleSheets = [sheet]; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +customElements.define('demo-element', DemoElement); |
| 40 | + |
7 | 41 | describe('vscode-radio-group', () => { |
8 | 42 | it('is defined', () => { |
9 | 43 | const el = document.createElement('vscode-radio-group'); |
@@ -48,4 +82,17 @@ describe('vscode-radio-group', () => { |
48 | 82 | expect(icon2.classList.contains('checked')).to.be.false; |
49 | 83 | expect(icon3.classList.contains('checked')).to.be.true; |
50 | 84 | }); |
| 85 | + |
| 86 | + it('works in shadow DOM', async () => { |
| 87 | + const el = await fixture<DemoElement>(html`<demo-element></demo-element>`); |
| 88 | + |
| 89 | + const radios = $$(el.shadowRoot!, 'vscode-radio'); |
| 90 | + const lastRadioDefaultChecked = radios[2].checked; |
| 91 | + |
| 92 | + await clickOnElement(radios[0]); |
| 93 | + |
| 94 | + expect(lastRadioDefaultChecked).to.be.true; |
| 95 | + expect(radios[0].checked).to.be.true; |
| 96 | + expect(radios[2].checked).to.be.false; |
| 97 | + }); |
51 | 98 | }); |
0 commit comments