Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BTreston committed Nov 14, 2024
1 parent 00d2750 commit bd17d12
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { SYSTEM_THEME_OBSERVABLE } from "@bitwarden/angular/services/injection-t
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ThemeType } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { SharedModule } from "@bitwarden/components/src/shared";
import { I18nPipe } from "@bitwarden/components/src/shared/i18n.pipe";

import { IntegrationCardComponent } from "./integration-card.component";

describe("IntegrationCardComponent", () => {
let component: IntegrationCardComponent;
let fixture: ComponentFixture<IntegrationCardComponent>;
Expand All @@ -21,7 +23,7 @@ describe("IntegrationCardComponent", () => {
systemTheme$.next(ThemeType.Light);

await TestBed.configureTestingModule({
declarations: [IntegrationCardComponent, I18nPipe],
imports: [IntegrationCardComponent, SharedModule],
providers: [
{
provide: ThemeStateService,
Expand Down Expand Up @@ -49,7 +51,6 @@ describe("IntegrationCardComponent", () => {

component.name = "Integration Name";
component.image = "test-image.png";
component.linkText = "Get started with integration";
component.linkURL = "https://example.com/";

fixture.detectChanges();
Expand All @@ -63,10 +64,8 @@ describe("IntegrationCardComponent", () => {

it("renders card body", () => {
const name = fixture.nativeElement.querySelector("h3");
const link = fixture.nativeElement.querySelector("a");

expect(name.textContent).toBe("Integration Name");
expect(link.textContent.trim()).toBe("Get started with integration");
});

it("assigns external rel attribute", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";
import { of } from "rxjs";

import { SYSTEM_THEME_OBSERVABLE } from "@bitwarden/angular/services/injection-tokens";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ThemeTypes } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { I18nMockService } from "@bitwarden/components";

Expand Down Expand Up @@ -30,7 +32,7 @@ export default {
},
{
provide: SYSTEM_THEME_OBSERVABLE,
useValue: null,
useValue: of(ThemeTypes.Light),
},
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IntegrationType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { ThemeTypes } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { SharedModule } from "@bitwarden/components/src/shared";
import { I18nPipe } from "@bitwarden/components/src/shared/i18n.pipe";

import { IntegrationCardComponent } from "../integration-card/integration-card.component";
Expand Down Expand Up @@ -35,7 +36,7 @@ describe("IntegrationGridComponent", () => {

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [IntegrationGridComponent, IntegrationCardComponent, I18nPipe],
imports: [IntegrationGridComponent, IntegrationCardComponent, SharedModule],
providers: [
{
provide: ThemeStateService,
Expand All @@ -51,14 +52,16 @@ describe("IntegrationGridComponent", () => {
},
{
provide: I18nService,
useValue: mock<I18nService>(),
useValue: mock<I18nService>({ t: (key) => key }),
},
],
});

fixture = TestBed.createComponent(IntegrationGridComponent);
component = fixture.componentInstance;
component.integrations = integrations;
component.ariaI18nKey = "integrationCardAriaLabel";
component.tooltipI18nKey = "integrationCardTooltip";
fixture.detectChanges();
});

Expand Down Expand Up @@ -86,4 +89,10 @@ describe("IntegrationGridComponent", () => {
expect(card[0].componentInstance.externalURL).toBe(false);
expect(card[1].componentInstance.externalURL).toBe(true);
});

it("has a tool tip and aria label attributes", () => {
const card: HTMLElement = fixture.debugElement.queryAll(By.css("li"))[0].nativeElement;
expect(card.title).toBe("integrationCardTooltip");
expect(card.getAttribute("aria-label")).toBe("integrationCardAriaLabel");
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";
import { Observable } from "rxjs";
import { of } from "rxjs";

import {
SYSTEM_THEME_OBSERVABLE,
SafeInjectionToken,
} from "@bitwarden/angular/services/injection-tokens";
import { SYSTEM_THEME_OBSERVABLE } from "@bitwarden/angular/services/injection-tokens";
import { IntegrationType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { Theme } from "@bitwarden/common/platform/enums";
import { ThemeTypes } from "@bitwarden/common/platform/enums";
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
import { I18nMockService } from "@bitwarden/components";

Expand Down Expand Up @@ -39,7 +36,7 @@ export default {
},
{
provide: SYSTEM_THEME_OBSERVABLE,
useValue: new SafeInjectionToken<Observable<Theme>>("SYSTEM_THEME_OBSERVABLE"),
useValue: of(ThemeTypes.Light),
},
],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";

import { IntegrationsComponent } from "./integrations.component";

const routes: Routes = [
{
path: "",
component: IntegrationsComponent,
},
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class IntegrationsRoutingModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { By } from "@angular/platform-browser";
import { mock } from "jest-mock-extended";
import { of } from "rxjs";

import { SharedModule } from "@bitwarden/components/src/shared";
import { IntegrationCardComponent } from "@bitwarden/web-vault/src/app/shared/components/integrations/integration-card/integration-card.component";
import { IntegrationGridComponent } from "@bitwarden/web-vault/src/app/shared/components/integrations/integration-grid/integration-grid.component";

import { SYSTEM_THEME_OBSERVABLE } from "../../../../../../libs/angular/src/services/injection-tokens";
import { I18nService } from "../../../../../../libs/common/src/platform/abstractions/i18n.service";
import { ThemeType } from "../../../../../../libs/common/src/platform/enums";
import { ThemeStateService } from "../../../../../../libs/common/src/platform/theming/theme-state.service";
import { I18nPipe } from "../../../../../../libs/components/src/shared/i18n.pipe";

import { IntegrationsComponent } from "./integrations.component";

Expand All @@ -32,18 +32,12 @@ describe("IntegrationsComponent", () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
IntegrationsComponent,
IntegrationGridComponent,
IntegrationCardComponent,
MockHeaderComponent,
MockNewMenuComponent,
I18nPipe,
],
declarations: [IntegrationsComponent, MockHeaderComponent, MockNewMenuComponent],
imports: [IntegrationGridComponent, IntegrationCardComponent, SharedModule],
providers: [
{
provide: I18nService,
useValue: mock<I18nService>({ t: (key) => key }),
useValue: mock<I18nService>(),
},
{
provide: ThemeStateService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { Component } from "@angular/core";

import { IntegrationType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { HeaderModule } from "@bitwarden/web-vault/app/layouts/header/header.module";
import { IntegrationGridComponent } from "@bitwarden/web-vault/app/shared/components/integrations/integration-grid/integration-grid.component";
import { Integration } from "@bitwarden/web-vault/app/shared/components/integrations/models";

import { SecretsManagerSharedModule } from "../shared/sm-shared.module";

@Component({
selector: "sm-integrations",
templateUrl: "./integrations.component.html",
standalone: true,
imports: [SecretsManagerSharedModule, IntegrationGridComponent, HeaderModule],
})
export class IntegrationsComponent {
private integrationsAndSdks: Integration[] = [];

constructor(private i18nService: I18nService) {
constructor() {
this.integrationsAndSdks = [
{
name: "Rust",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NgModule } from "@angular/core";

import { IntegrationCardComponent } from "@bitwarden/web-vault/app/shared/components/integrations/integration-card/integration-card.component";
import { IntegrationGridComponent } from "@bitwarden/web-vault/app/shared/components/integrations/integration-grid/integration-grid.component";

import { SecretsManagerSharedModule } from "../shared/sm-shared.module";

import { IntegrationsRoutingModule } from "./integrations-routing.module";
import { IntegrationsComponent } from "./integrations.component";

@NgModule({
imports: [
SecretsManagerSharedModule,
IntegrationsRoutingModule,
IntegrationGridComponent,
IntegrationCardComponent,
],
declarations: [IntegrationsComponent],
})
export class IntegrationsModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authGuard } from "@bitwarden/angular/auth/guards";

import { organizationEnabledGuard } from "./guards/sm-org-enabled.guard";
import { canActivateSM } from "./guards/sm.guard";
import { IntegrationsComponent } from "./integrations/integrations.component";
import { IntegrationsModule } from "./integrations/integrations.module";
import { LayoutComponent } from "./layout/layout.component";
import { NavigationComponent } from "./layout/navigation.component";
import { OverviewModule } from "./overview/overview.module";
Expand Down Expand Up @@ -63,7 +63,7 @@ const routes: Routes = [
},
{
path: "integrations",
component: IntegrationsComponent,
loadChildren: () => IntegrationsModule,
data: {
titleId: "integrations",
},
Expand Down

0 comments on commit bd17d12

Please sign in to comment.