Skip to content

Migrate remaining components to standalone in libs/components #15053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/angular/src/jslib.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ import { IconComponent } from "./vault/components/icon.component";
TextDragDirective,
CopyClickDirective,
A11yTitleDirective,
AutofocusDirective,
],
declarations: [
A11yInvalidDirective,
ApiActionDirective,
AutofocusDirective,
BoxRowDirective,
DeprecatedCalloutComponent,
CopyTextDirective,
Expand Down
25 changes: 10 additions & 15 deletions libs/components/src/button/button.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component, DebugElement } from "@angular/core";
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";

import { ButtonModule } from "./index";
Expand All @@ -13,21 +11,18 @@ describe("Button", () => {
let disabledButtonDebugElement: DebugElement;
let linkDebugElement: DebugElement;

beforeEach(waitForAsync(() => {
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [ButtonModule],
declarations: [TestApp],
imports: [TestApp],
});

// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.compileComponents();
await TestBed.compileComponents();
fixture = TestBed.createComponent(TestApp);
testAppComponent = fixture.debugElement.componentInstance;
buttonDebugElement = fixture.debugElement.query(By.css("button"));
disabledButtonDebugElement = fixture.debugElement.query(By.css("button#disabled"));
linkDebugElement = fixture.debugElement.query(By.css("a"));
}));
});

it("should not be disabled when loading and disabled are false", () => {
testAppComponent.loading = false;
Expand Down Expand Up @@ -85,11 +80,11 @@ describe("Button", () => {

<button id="disabled" type="button" bitButton disabled>Button</button>
`,
standalone: false,
imports: [ButtonModule],
})
class TestApp {
buttonType: string;
block: boolean;
disabled: boolean;
loading: boolean;
buttonType?: string;
block?: boolean;
disabled?: boolean;
loading?: boolean;
}
24 changes: 6 additions & 18 deletions libs/components/src/dialog/dialog.service.stories.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import { DIALOG_DATA, DialogModule, DialogRef } from "@angular/cdk/dialog";
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";

Check warning on line 1 in libs/components/src/dialog/dialog.service.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/dialog/dialog.service.stories.ts#L1

Added line #L1 was not covered by tests
import { Component, Inject } from "@angular/core";
import { provideAnimations } from "@angular/platform-browser/animations";

Check warning on line 3 in libs/components/src/dialog/dialog.service.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/dialog/dialog.service.stories.ts#L3

Added line #L3 was not covered by tests
import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";

import { ButtonModule } from "../button";
import { IconButtonModule } from "../icon-button";
import { SharedModule } from "../shared";
import { I18nMockService } from "../utils/i18n-mock.service";

import { DialogComponent } from "./dialog/dialog.component";
import { DialogModule } from "./dialog.module";

Check warning on line 11 in libs/components/src/dialog/dialog.service.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/dialog/dialog.service.stories.ts#L11

Added line #L11 was not covered by tests
import { DialogService } from "./dialog.service";
import { DialogCloseDirective } from "./directives/dialog-close.directive";
import { DialogTitleContainerDirective } from "./directives/dialog-title-container.directive";

interface Animal {
animal: string;
}

@Component({
template: `<button bitButton type="button" (click)="openDialog()">Open Dialog</button>`,
standalone: false,
imports: [ButtonModule],
})
class StoryDialogComponent {
constructor(public dialogService: DialogService) {}
Expand Down Expand Up @@ -50,7 +47,7 @@
</ng-container>
</bit-dialog>
`,
standalone: false,
imports: [DialogModule, ButtonModule],
})
class StoryDialogContentComponent {
constructor(
Expand All @@ -68,17 +65,8 @@
component: StoryDialogComponent,
decorators: [
moduleMetadata({
declarations: [StoryDialogContentComponent],
imports: [
SharedModule,
ButtonModule,
DialogModule,
IconButtonModule,
DialogCloseDirective,
DialogComponent,
DialogTitleContainerDirective,
],
providers: [
provideAnimations(),
DialogService,
{
provide: I18nService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from "@angular/core";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { Meta, StoryObj, applicationConfig, moduleMetadata } from "@storybook/angular";
import { provideAnimations } from "@angular/platform-browser/animations";
import { Meta, StoryObj, applicationConfig } from "@storybook/angular";

Check warning on line 3 in libs/components/src/dialog/simple-dialog/simple-configurable-dialog/simple-configurable-dialog.service.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/dialog/simple-dialog/simple-configurable-dialog/simple-configurable-dialog.service.stories.ts#L2-L3

Added lines #L2 - L3 were not covered by tests

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";

Expand Down Expand Up @@ -31,7 +31,7 @@
</bit-callout>
}
`,
standalone: false,
imports: [ButtonModule, CalloutModule, DialogModule],
})
class StoryDialogComponent {
protected dialogs: { title: string; dialogs: SimpleDialogOptions[] }[] = [
Expand Down Expand Up @@ -147,11 +147,9 @@
title: "Component Library/Dialogs/Service/SimpleConfigurable",
component: StoryDialogComponent,
decorators: [
moduleMetadata({
imports: [ButtonModule, BrowserAnimationsModule, DialogModule, CalloutModule],
}),
applicationConfig({
providers: [
provideAnimations(),
{
provide: I18nService,
useFactory: () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { DialogRef, DIALOG_DATA } from "@angular/cdk/dialog";
import { Component, Inject } from "@angular/core";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { provideAnimations } from "@angular/platform-browser/animations";

Check warning on line 3 in libs/components/src/dialog/simple-dialog/simple-dialog.service.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/dialog/simple-dialog/simple-dialog.service.stories.ts#L3

Added line #L3 was not covered by tests
import { Meta, StoryObj, moduleMetadata } from "@storybook/angular";

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";

import { ButtonModule } from "../../button";
import { IconButtonModule } from "../../icon-button";
import { SharedModule } from "../../shared/shared.module";
import { I18nMockService } from "../../utils/i18n-mock.service";
import { DialogModule } from "../dialog.module";
import { DialogService } from "../dialog.service";
Expand All @@ -18,7 +16,7 @@

@Component({
template: `<button type="button" bitButton (click)="openDialog()">Open Simple Dialog</button>`,
standalone: false,
imports: [ButtonModule],
})
class StoryDialogComponent {
constructor(public dialogService: DialogService) {}
Expand Down Expand Up @@ -49,7 +47,7 @@
</ng-container>
</bit-simple-dialog>
`,
standalone: false,
imports: [ButtonModule, DialogModule],
})
class StoryDialogContentComponent {
constructor(
Expand All @@ -67,15 +65,8 @@
component: StoryDialogComponent,
decorators: [
moduleMetadata({
declarations: [StoryDialogContentComponent],
imports: [
SharedModule,
IconButtonModule,
ButtonModule,
BrowserAnimationsModule,
DialogModule,
],
providers: [
provideAnimations(),
DialogService,
{
provide: I18nService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic

import { IconButtonModule } from "../icon-button";
import { BitIconButtonComponent } from "../icon-button/icon-button.component";
import { InputModule } from "../input/input.module";
import { I18nMockService } from "../utils/i18n-mock.service";

import { BitFormFieldControl } from "./form-field-control";
Expand All @@ -25,7 +24,7 @@ import { BitPasswordInputToggleDirective } from "./password-input-toggle.directi
</bit-form-field>
</form>
`,
standalone: false,
imports: [FormFieldModule, IconButtonModule],
})
class TestFormFieldComponent {}

Expand All @@ -37,8 +36,7 @@ describe("PasswordInputToggle", () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FormFieldModule, IconButtonModule, InputModule],
declarations: [TestFormFieldComponent],
imports: [TestFormFieldComponent],
providers: [
{
provide: I18nService,
Expand Down
1 change: 0 additions & 1 deletion libs/components/src/input/autofocus.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { FocusableElement } from "../shared/focusable-element";
*/
@Directive({
selector: "[appAutofocus], [bitAutofocus]",
standalone: false,
})
export class AutofocusDirective implements AfterContentChecked {
@Input() set appAutofocus(condition: boolean | string) {
Expand Down
15 changes: 6 additions & 9 deletions libs/components/src/menu/menu.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from "@angular/core";
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";

import { MenuTriggerForDirective } from "./menu-trigger-for.directive";
Expand All @@ -16,19 +16,16 @@ describe("Menu", () => {
// The overlay is created outside the root debugElement, so we need to query its parent
const getBitMenuPanel = () => document.querySelector(".bit-menu-panel");

beforeEach(waitForAsync(() => {
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [MenuModule],
declarations: [TestApp],
imports: [TestApp],
});

// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.compileComponents();
await TestBed.compileComponents();

fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
}));
});

it("should open when the trigger is clicked", async () => {
const buttonDebugElement = fixture.debugElement.query(By.directive(MenuTriggerForDirective));
Expand Down Expand Up @@ -73,6 +70,6 @@ describe("Menu", () => {
<a id="item2" bitMenuItem>Item 2</a>
</bit-menu>
`,
standalone: false,
imports: [MenuModule],
})
class TestApp {}
17 changes: 6 additions & 11 deletions libs/components/src/radio-button/radio-button.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Component } from "@angular/core";
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";

import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
Expand All @@ -17,26 +15,23 @@ describe("RadioButton", () => {
let testAppComponent: TestApp;
let radioButton: HTMLInputElement;

beforeEach(waitForAsync(() => {
beforeEach(async () => {
mockGroupComponent = new MockedButtonGroupComponent();

TestBed.configureTestingModule({
imports: [RadioButtonModule],
declarations: [TestApp],
imports: [TestApp],
providers: [
{ provide: RadioGroupComponent, useValue: mockGroupComponent },
{ provide: I18nService, useValue: new I18nMockService({}) },
],
});

// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.compileComponents();
await TestBed.compileComponents();
fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
testAppComponent = fixture.debugElement.componentInstance;
radioButton = fixture.debugElement.query(By.css("input[type=radio]")).nativeElement;
}));
});

it("should emit value when clicking on radio button", () => {
testAppComponent.value = "value";
Expand Down Expand Up @@ -77,7 +72,7 @@ class MockedButtonGroupComponent implements Partial<RadioGroupComponent> {
@Component({
selector: "test-app",
template: `<bit-radio-button [value]="value"><bit-label>Element</bit-label></bit-radio-button>`,
standalone: false,
imports: [RadioButtonModule],
})
class TestApp {
value?: string;
Expand Down
15 changes: 6 additions & 9 deletions libs/components/src/radio-button/radio-group.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from "@angular/core";
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { FormsModule } from "@angular/forms";
import { By } from "@angular/platform-browser";

Expand All @@ -16,16 +16,13 @@ describe("RadioGroupComponent", () => {
let buttonElements: RadioButtonComponent[];
let radioButtons: HTMLInputElement[];

beforeEach(waitForAsync(() => {
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [FormsModule, RadioButtonModule],
declarations: [TestApp],
imports: [TestApp],
providers: [{ provide: I18nService, useValue: new I18nMockService({}) }],
});

// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
TestBed.compileComponents();
await TestBed.compileComponents();
fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
testAppComponent = fixture.debugElement.componentInstance;
Expand All @@ -37,7 +34,7 @@ describe("RadioGroupComponent", () => {
.map((e) => e.nativeElement);

fixture.detectChanges();
}));
});

it("should select second element when setting selected to second", async () => {
testAppComponent.selected = "second";
Expand Down Expand Up @@ -75,7 +72,7 @@ describe("RadioGroupComponent", () => {
<bit-radio-button value="third">Third</bit-radio-button>
</bit-radio-group>
`,
standalone: false,
imports: [FormsModule, RadioButtonModule],
})
class TestApp {
selected?: string;
Expand Down
Loading
Loading