mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
* [CL-50] feat: scaffold checkbox component * [CL-50] feat: implement control value accessor for checbox * [CL-50] feat: add form-field support to checkbox * [CL-50] feat: implement non-selected checkbox styling * [CL-50] feat: implement checkbox checked styles * [CL-50] feat: improve checkbox form-field compat * [CL-50] fix: checkbox border hover wrong color * [CL-50] feat: use svg instead of bwi font * [CL-50] feat: scaffold radio button * [EC-50] feat: implement radio logic * [CL-50] feat: add radio group tests * [CL-50] feat: add radio-button tests * [CL-50] feat: implement radio button styles * [CL-50] fix: checkbox style tweaks * [CL-50] feat: smooth radio button selection transition * [CL-50] chore: various fixes and cleanups * [CL-50] feat: add form field support * [EC-50] feat-wip: simplify checkbox styling * [EC-50] feat: extract checkbox into separate component * [CL-50] feat: add standalone form control component * [CL-50] feat: remove unnecessary checkbox-control It wasn't really doing anything, might as well use form control directly * [CL-50] chore: create separate folder with form examples * [CL-50] feat: switch to common bit-label * [CL-50] feat: let radio group act as form control * [CL-50] chore: restore form-field component * [CL-50] feat: add support for hint and error * [CL-50] fix: storybook build issue * [CL-50] fix: radio group label wrong text color * [CL-50] fix: translation * [CL-50] fix: put hint and errors outside label * [CL-50] feat: * [CL-50] feat: add custom checkbox example story * [CL-50] chore: remove 1 from full example name * [CL-50] chore: clean up unused icon * [CL-50] chore: clean up unused tailwind plugin * [CL-50] fix: ring offset color in custom example * [CL-50] chore: clean up unused icon * [CL-50] chore: add design link * [CL-50] chore: remove unused import * [CL-50] fix: pr review comments * [CL-50] fix: improve id handling
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import { Component } from "@angular/core";
|
|
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
|
|
import { By } from "@angular/platform-browser";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { I18nMockService } from "../utils/i18n-mock.service";
|
|
|
|
import { RadioButtonModule } from "./radio-button.module";
|
|
import { RadioGroupComponent } from "./radio-group.component";
|
|
|
|
describe("RadioButton", () => {
|
|
let mockGroupComponent: MockedButtonGroupComponent;
|
|
let fixture: ComponentFixture<TestApp>;
|
|
let testAppComponent: TestApp;
|
|
let radioButton: HTMLInputElement;
|
|
|
|
beforeEach(waitForAsync(() => {
|
|
mockGroupComponent = new MockedButtonGroupComponent();
|
|
|
|
TestBed.configureTestingModule({
|
|
imports: [RadioButtonModule],
|
|
declarations: [TestApp],
|
|
providers: [
|
|
{ provide: RadioGroupComponent, useValue: mockGroupComponent },
|
|
{ provide: I18nService, useValue: new I18nMockService({}) },
|
|
],
|
|
});
|
|
|
|
TestBed.compileComponents();
|
|
fixture = TestBed.createComponent(TestApp);
|
|
fixture.detectChanges();
|
|
testAppComponent = fixture.debugElement.componentInstance;
|
|
radioButton = fixture.debugElement.query(By.css("input[type=radio]")).nativeElement;
|
|
}));
|
|
|
|
it("should emit value when clicking on radio button", () => {
|
|
testAppComponent.value = "value";
|
|
fixture.detectChanges();
|
|
|
|
radioButton.click();
|
|
fixture.detectChanges();
|
|
|
|
expect(mockGroupComponent.onInputChange).toHaveBeenCalledWith("value");
|
|
});
|
|
|
|
it("should check radio button when selected matches value", () => {
|
|
testAppComponent.value = "value";
|
|
fixture.detectChanges();
|
|
|
|
mockGroupComponent.selected = "value";
|
|
fixture.detectChanges();
|
|
|
|
expect(radioButton.checked).toBe(true);
|
|
});
|
|
|
|
it("should not check radio button when selected does not match value", () => {
|
|
testAppComponent.value = "value";
|
|
fixture.detectChanges();
|
|
|
|
mockGroupComponent.selected = "nonMatchingValue";
|
|
fixture.detectChanges();
|
|
|
|
expect(radioButton.checked).toBe(false);
|
|
});
|
|
});
|
|
|
|
class MockedButtonGroupComponent implements Partial<RadioGroupComponent> {
|
|
onInputChange = jest.fn();
|
|
selected = null;
|
|
}
|
|
|
|
@Component({
|
|
selector: "test-app",
|
|
template: ` <bit-radio-button [value]="value">Element</bit-radio-button>`,
|
|
})
|
|
class TestApp {
|
|
value?: string;
|
|
}
|