mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
* chore: setup initial bit-button-group using bitButton as template * feat: working radio group with preliminary styling * chore: cleanup * feat: implement proper basic styling * feat: implement focus handling and keyboard navigation * feat: implement size support * feat: add labeling support * feat: add input for button selection * feat: implement output handler on radio button interaction * feat: implement internal input/output seletion handling * feat: add external input support * feat: add external output support * chore: simplify storybook example a bit * fix: module imports * refactor: simplify both components * feat: remove size * chore: rename button-group to toggle-group * chore: rename toggle-group-element to toggle-group-button * chore: update story example * fix: compatibility with web vault * fix: imports in tests after rename * fix: remove unnecessary inject decorator * fix: clarify field names and html tags * feat: add badge centering fix * feat: set pointer cursor on label * chore: comment on special css rules * chore: remove focusable option from button * Update libs/components/src/toggle-group/toggle-group-button.component.ts Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com> * chore: rename to `bit-toggle` * fix: remove unecessary aria label function Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { Component } from "@angular/core";
|
|
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
|
|
import { By } from "@angular/platform-browser";
|
|
|
|
import { ToggleGroupModule } from "./toggle-group.module";
|
|
import { ToggleComponent } from "./toggle.component";
|
|
|
|
describe("Button", () => {
|
|
let fixture: ComponentFixture<TestApp>;
|
|
let testAppComponent: TestApp;
|
|
let buttonElements: ToggleComponent[];
|
|
let radioButtons: HTMLInputElement[];
|
|
|
|
beforeEach(waitForAsync(() => {
|
|
TestBed.configureTestingModule({
|
|
imports: [ToggleGroupModule],
|
|
declarations: [TestApp],
|
|
});
|
|
|
|
TestBed.compileComponents();
|
|
fixture = TestBed.createComponent(TestApp);
|
|
testAppComponent = fixture.debugElement.componentInstance;
|
|
buttonElements = fixture.debugElement
|
|
.queryAll(By.css("bit-toggle"))
|
|
.map((e) => e.componentInstance);
|
|
radioButtons = fixture.debugElement
|
|
.queryAll(By.css("input[type=radio]"))
|
|
.map((e) => e.nativeElement);
|
|
|
|
fixture.detectChanges();
|
|
}));
|
|
|
|
it("should select second element when setting selected to second", () => {
|
|
testAppComponent.selected = "second";
|
|
fixture.detectChanges();
|
|
|
|
expect(buttonElements[1].selected).toBe(true);
|
|
});
|
|
|
|
it("should not select second element when setting selected to third", () => {
|
|
testAppComponent.selected = "third";
|
|
fixture.detectChanges();
|
|
|
|
expect(buttonElements[1].selected).toBe(false);
|
|
});
|
|
|
|
it("should emit new value when changing selection by clicking on radio button", () => {
|
|
testAppComponent.selected = "first";
|
|
fixture.detectChanges();
|
|
|
|
radioButtons[1].click();
|
|
|
|
expect(testAppComponent.selected).toBe("second");
|
|
});
|
|
});
|
|
|
|
@Component({
|
|
selector: "test-app",
|
|
template: `
|
|
<bit-toggle-group [(selected)]="selected">
|
|
<bit-toggle value="first">First</bit-toggle>
|
|
<bit-toggle value="second">Second</bit-toggle>
|
|
<bit-toggle value="third">Third</bit-toggle>
|
|
</bit-toggle-group>
|
|
`,
|
|
})
|
|
class TestApp {
|
|
selected?: string;
|
|
}
|