mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 15:23:33 +00:00
* Rename service-factory folder * Move cryptographic service factories * Move crypto models * Move crypto services * Move domain base class * Platform code owners * Move desktop log services * Move log files * Establish component library ownership * Move background listeners * Move background background * Move localization to Platform * Move browser alarms to Platform * Move browser state to Platform * Move CLI state to Platform * Move Desktop native concerns to Platform * Move flag and misc to Platform * Lint fixes * Move electron state to platform * Move web state to Platform * Move lib state to Platform * Fix broken tests * Rename interface to idiomatic TS * `npm run prettier` 🤖 * Resolve review feedback * Set platform as owners of web core and shared * Expand moved services * Fix test types --------- Co-authored-by: Hinton <hinton@users.noreply.github.com>
80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { Component } from "@angular/core";
|
|
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
|
|
import { FormsModule } from "@angular/forms";
|
|
import { By } from "@angular/platform-browser";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
import { I18nMockService } from "../utils/i18n-mock.service";
|
|
|
|
import { RadioButtonComponent } from "./radio-button.component";
|
|
import { RadioButtonModule } from "./radio-button.module";
|
|
|
|
describe("RadioGroupComponent", () => {
|
|
let fixture: ComponentFixture<TestApp>;
|
|
let testAppComponent: TestApp;
|
|
let buttonElements: RadioButtonComponent[];
|
|
let radioButtons: HTMLInputElement[];
|
|
|
|
beforeEach(waitForAsync(() => {
|
|
TestBed.configureTestingModule({
|
|
imports: [FormsModule, RadioButtonModule],
|
|
declarations: [TestApp],
|
|
providers: [{ provide: I18nService, useValue: new I18nMockService({}) }],
|
|
});
|
|
|
|
TestBed.compileComponents();
|
|
fixture = TestBed.createComponent(TestApp);
|
|
fixture.detectChanges();
|
|
testAppComponent = fixture.debugElement.componentInstance;
|
|
buttonElements = fixture.debugElement
|
|
.queryAll(By.css("bit-radio-button"))
|
|
.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", async () => {
|
|
testAppComponent.selected = "second";
|
|
fixture.detectChanges();
|
|
await fixture.whenStable();
|
|
|
|
expect(buttonElements[1].selected).toBe(true);
|
|
});
|
|
|
|
it("should not select second element when setting selected to third", async () => {
|
|
testAppComponent.selected = "third";
|
|
fixture.detectChanges();
|
|
await fixture.whenStable();
|
|
|
|
expect(buttonElements[1].selected).toBe(false);
|
|
});
|
|
|
|
it("should emit new value when changing selection by clicking on radio button", async () => {
|
|
testAppComponent.selected = "first";
|
|
fixture.detectChanges();
|
|
await fixture.whenStable();
|
|
|
|
radioButtons[1].click();
|
|
|
|
expect(testAppComponent.selected).toBe("second");
|
|
});
|
|
});
|
|
|
|
@Component({
|
|
selector: "test-app",
|
|
template: `
|
|
<bit-radio-group [(ngModel)]="selected">
|
|
<bit-radio-button value="first">First</bit-radio-button>
|
|
<bit-radio-button value="second">Second</bit-radio-button>
|
|
<bit-radio-button value="third">Third</bit-radio-button>
|
|
</bit-radio-group>
|
|
`,
|
|
})
|
|
class TestApp {
|
|
selected?: string;
|
|
}
|