Skip to content

Commit

Permalink
test: fix them
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Dec 19, 2024
1 parent ab03e7f commit d154064
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LitElement, PropertyValues } from 'lit';
import { isServer, type LitElement, type PropertyValues } from 'lit';
import { property } from 'lit/decorators.js';

import { getNextElementIndex, interactivityChecker, isArrowKeyPressed } from '../a11y.js';
Expand Down Expand Up @@ -66,7 +66,7 @@ export const SbbFormAssociatedRadioButtonMixin = <T extends Constructor<LitEleme
*/
@property({ type: Boolean })
public set checked(value: boolean) {
this._checked = value;
this._checked = !!value;

this.toggleAttribute('data-checked', this.checked);
this.internals.ariaChecked = this.checked.toString();
Expand Down Expand Up @@ -227,7 +227,7 @@ export const SbbFormAssociatedRadioButtonMixin = <T extends Constructor<LitEleme
* Add `this` to the radioButton registry
*/
private _connectToRegistry(): void {
if (!this.name) {
if (!this.name || isServer) {
return;
}

Expand Down
26 changes: 13 additions & 13 deletions src/elements/radio-button/radio-button/radio-button.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@ describe(`sbb-radio-button`, () => {
});

it('selects radio on click', async () => {
const stateChange = new EventSpy(SbbRadioButtonElement.events.stateChange);
const change = new EventSpy(SbbRadioButtonElement.events.change);

element.click();
await waitForLitRender(element);

expect(element).to.have.attribute('data-checked');
expect(element.checked).to.be.true;
await stateChange.calledOnce();
expect(stateChange.count).to.be.equal(1);
await change.calledOnce();
expect(change.count).to.be.equal(1);
});

it('does not deselect radio if already checked', async () => {
const stateChange = new EventSpy(SbbRadioButtonElement.events.stateChange);
const change = new EventSpy(SbbRadioButtonElement.events.change);

element.click();
await waitForLitRender(element);
expect(element.checked).to.be.true;
await stateChange.calledOnce();
expect(stateChange.count).to.be.equal(1);
await change.calledOnce();
expect(change.count).to.be.equal(1);

element.click();
await waitForLitRender(element);
expect(element.checked).to.be.true;
await stateChange.calledOnce();
expect(stateChange.count).to.be.equal(1);
await change.calledOnce();
expect(change.count).to.be.equal(1);
});

it('allows empty selection', async () => {
const stateChange = new EventSpy(SbbRadioButtonElement.events.stateChange);
const change = new EventSpy(SbbRadioButtonElement.events.change);

element.allowEmptySelection = true;
element.click();
await waitForLitRender(element);
expect(element.checked).to.be.true;
await stateChange.calledOnce();
expect(stateChange.count).to.be.equal(1);
await change.calledOnce();
expect(change.count).to.be.equal(1);

element.click();
await waitForLitRender(element);
expect(element.checked).to.be.false;
await stateChange.calledTimes(2);
expect(stateChange.count).to.be.equal(2);
await change.calledTimes(2);
expect(change.count).to.be.equal(2);
});

it('should convert falsy to false', async () => {
Expand Down

0 comments on commit d154064

Please sign in to comment.