Skip to content

Commit

Permalink
test: add snapshot tests for checkbox-group (#3518)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Mar 4, 2022
1 parent 4746f91 commit f717293
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 8 deletions.
8 changes: 0 additions & 8 deletions packages/checkbox-group/test/checkbox-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ describe('vaadin-checkbox-group', () => {
await nextFrame();
});

it('should set role attribute to group', () => {
expect(group.getAttribute('role')).to.equal('group');
});

it('should keep initial disabled property for checkboxes', () => {
expect(checkboxes[0].disabled).to.be.false;
expect(checkboxes[1].disabled).to.be.true;
Expand Down Expand Up @@ -69,10 +65,6 @@ describe('vaadin-checkbox-group', () => {
checkboxes = [...group.querySelectorAll('vaadin-checkbox')];
});

it('should set aria-disabled to true when disabled', () => {
expect(group.getAttribute('aria-disabled')).to.eq('true');
});

it('should propagate disabled property to checkboxes', () => {
checkboxes.forEach((checkbox) => {
expect(checkbox.disabled).to.be.true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/* @web/test-runner snapshot v1 */
export const snapshots = {};

snapshots["vaadin-checkbox-group host default"] =
`<vaadin-checkbox-group role="group">
<vaadin-checkbox
has-label=""
has-value=""
label="Checkbox 1"
value="1"
>
<label
for="vaadin-checkbox-0"
id="label-vaadin-checkbox-1"
slot="label"
>
Checkbox 1
</label>
<input
id="vaadin-checkbox-0"
slot="input"
type="checkbox"
value="1"
>
</vaadin-checkbox>
<vaadin-checkbox
has-label=""
has-value=""
label="Checkbox 2"
value="2"
>
<label
for="vaadin-checkbox-1"
id="label-vaadin-checkbox-2"
slot="label"
>
Checkbox 2
</label>
<input
id="vaadin-checkbox-1"
slot="input"
type="checkbox"
value="2"
>
</vaadin-checkbox>
<label
id="label-vaadin-checkbox-group-0"
slot="label"
>
</label>
<div
hidden=""
id="error-message-vaadin-checkbox-group-0"
slot="error-message"
>
</div>
</vaadin-checkbox-group>
`;
/* end snapshot vaadin-checkbox-group host default */

snapshots["vaadin-checkbox-group host disabled"] =
`<vaadin-checkbox-group
aria-disabled="true"
disabled=""
role="group"
>
<vaadin-checkbox
aria-disabled="true"
disabled=""
has-label=""
has-value=""
label="Checkbox 1"
value="1"
>
<label
for="vaadin-checkbox-2"
id="label-vaadin-checkbox-4"
slot="label"
>
Checkbox 1
</label>
<input
disabled=""
id="vaadin-checkbox-2"
slot="input"
tabindex="-1"
type="checkbox"
value="1"
>
</vaadin-checkbox>
<vaadin-checkbox
aria-disabled="true"
disabled=""
has-label=""
has-value=""
label="Checkbox 2"
value="2"
>
<label
for="vaadin-checkbox-3"
id="label-vaadin-checkbox-5"
slot="label"
>
Checkbox 2
</label>
<input
disabled=""
id="vaadin-checkbox-3"
slot="input"
tabindex="-1"
type="checkbox"
value="2"
>
</vaadin-checkbox>
<label
id="label-vaadin-checkbox-group-3"
slot="label"
>
</label>
<div
hidden=""
id="error-message-vaadin-checkbox-group-1"
slot="error-message"
>
</div>
</vaadin-checkbox-group>
`;
/* end snapshot vaadin-checkbox-group host disabled */

snapshots["vaadin-checkbox-group shadow default"] =
`<div class="vaadin-group-field-container">
<div part="label">
<slot name="label">
</slot>
<span
aria-hidden="true"
part="required-indicator"
>
</span>
</div>
<div part="group-field">
<slot>
</slot>
</div>
<div part="helper-text">
<slot name="helper">
</slot>
</div>
<div part="error-message">
<slot name="error-message">
</slot>
</div>
</div>
`;
/* end snapshot vaadin-checkbox-group shadow default */

33 changes: 33 additions & 0 deletions packages/checkbox-group/test/dom/checkbox-group.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync } from '@vaadin/testing-helpers';
import '../../vaadin-checkbox-group.js';

describe('vaadin-checkbox-group', () => {
let group;

beforeEach(() => {
group = fixtureSync(`
<vaadin-checkbox-group>
<vaadin-checkbox value="1" label="Checkbox 1"></vaadin-checkbox>
<vaadin-checkbox value="2" label="Checkbox 2"></vaadin-checkbox>
</vaadin-checkbox-group>
`);
});

describe('host', () => {
it('default', async () => {
await expect(group).dom.to.equalSnapshot();
});

it('disabled', async () => {
group.disabled = true;
await expect(group).dom.to.equalSnapshot();
});
});

describe('shadow', () => {
it('default', async () => {
await expect(group).shadowDom.to.equalSnapshot();
});
});
});

0 comments on commit f717293

Please sign in to comment.