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";
|
2022-10-10 17:19:01 +02:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2022-09-15 18:31:15 +02:00
|
|
|
import { Substitute } from "@fluffy-spoon/substitute";
|
|
|
|
import { mock, MockProxy } from "jest-mock-extended";
|
|
|
|
|
|
|
|
import { I18nPipe } from "@bitwarden/angular/pipes/i18n.pipe";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/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,
|
|
|
|
useClass: Substitute.for<PasswordGenerationServiceAbstraction>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
2023-03-10 21:39:46 +01:00
|
|
|
provide: UsernameGenerationServiceAbstraction,
|
|
|
|
useClass: Substitute.for<UsernameGenerationServiceAbstraction>(),
|
2022-09-15 18:31:15 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: StateService,
|
|
|
|
useClass: Substitute.for<StateService>(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: PlatformUtilsService,
|
|
|
|
useValue: platformUtilsServiceMock,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: I18nService,
|
|
|
|
useClass: Substitute.for<I18nService>(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: ActivatedRoute,
|
|
|
|
useClass: Substitute.for<ActivatedRoute>(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
provide: LogService,
|
|
|
|
useClass: Substitute.for<LogService>(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|