2022-09-15 18:31:15 +02:00
|
|
|
import { NO_ERRORS_SCHEMA } from "@angular/core";
|
|
|
|
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import { mock, MockProxy } from "jest-mock-extended";
|
|
|
|
|
2023-06-06 22:34:53 +02:00
|
|
|
import { I18nPipe } from "@bitwarden/angular/platform/pipes/i18n.pipe";
|
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
2023-03-10 21:39:46 +01:00
|
|
|
import { PasswordGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/password";
|
|
|
|
import { UsernameGenerationServiceAbstraction } from "@bitwarden/common/tools/generator/username";
|
2022-09-15 18:31:15 +02:00
|
|
|
|
|
|
|
import { GeneratorComponent } from "./generator.component";
|
|
|
|
|
|
|
|
describe("GeneratorComponent", () => {
|
|
|
|
let component: GeneratorComponent;
|
|
|
|
let fixture: ComponentFixture<GeneratorComponent>;
|
|
|
|
let platformUtilsServiceMock: MockProxy<PlatformUtilsService>;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
platformUtilsServiceMock = mock<PlatformUtilsService>();
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
declarations: [GeneratorComponent, I18nPipe],
|
|
|
|
providers: [
|
|
|
|
{
|
2023-03-10 21:39:46 +01:00
|
|
|
provide: PasswordGenerationServiceAbstraction,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<PasswordGenerationServiceAbstraction>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-03-10 21:39:46 +01:00
|
|
|
provide: UsernameGenerationServiceAbstraction,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<UsernameGenerationServiceAbstraction>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: StateService,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<StateService>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: PlatformUtilsService,
|
|
|
|
useValue: platformUtilsServiceMock,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: I18nService,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<I18nService>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: ActivatedRoute,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<ActivatedRoute>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: LogService,
|
2023-10-17 19:02:33 +02:00
|
|
|
useValue: mock<LogService>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
schemas: [NO_ERRORS_SCHEMA],
|
|
|
|
}).compileComponents();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
fixture = TestBed.createComponent(GeneratorComponent);
|
|
|
|
component = fixture.componentInstance;
|
|
|
|
fixture.detectChanges();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create", () => {
|
|
|
|
expect(component).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("usernameTypesLearnMore()", () => {
|
|
|
|
it("should call platformUtilsService.launchUri() once", () => {
|
|
|
|
component.usernameTypesLearnMore();
|
|
|
|
expect(platformUtilsServiceMock.launchUri).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|