1
0
mirror of https://github.com/bitwarden/jslib synced 2026-01-05 10:03:14 +00:00

Component Library scaffolding (#625)

This commit is contained in:
Oscar Hinton
2022-03-08 11:50:34 +01:00
committed by GitHub
parent fa3a95fed0
commit 67a4fc8591
45 changed files with 62205 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
import { Component } from "@angular/core";
import { TestBed, waitForAsync } from "@angular/core/testing";
import { By } from "@angular/platform-browser";
import { ButtonModule } from "./index";
describe("Button", () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [ButtonModule],
declarations: [TestApp],
});
TestBed.compileComponents();
})
);
it("should apply classes based on type", () => {
const fixture = TestBed.createComponent(TestApp);
const testAppComponent: TestApp = fixture.debugElement.componentInstance;
const buttonDebugElement = fixture.debugElement.query(By.css("button"));
const linkDebugElement = fixture.debugElement.query(By.css("a"));
testAppComponent.buttonType = "primary";
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains("tw-bg-primary-500")).toBe(true);
expect(linkDebugElement.nativeElement.classList.contains("tw-bg-primary-500")).toBe(true);
testAppComponent.buttonType = "secondary";
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains("tw-border-text-muted")).toBe(true);
expect(linkDebugElement.nativeElement.classList.contains("tw-border-text-muted")).toBe(true);
testAppComponent.buttonType = "danger";
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains("tw-border-danger-500")).toBe(true);
expect(linkDebugElement.nativeElement.classList.contains("tw-border-danger-500")).toBe(true);
testAppComponent.buttonType = null;
fixture.detectChanges();
expect(buttonDebugElement.nativeElement.classList.contains("tw-border-text-muted")).toBe(true);
expect(linkDebugElement.nativeElement.classList.contains("tw-border-text-muted")).toBe(true);
});
});
@Component({
selector: "test-app",
template: `
<button type="button" bit-button [buttonType]="buttonType">Button</button>
<a href="#" bit-button [buttonType]="buttonType"> Link </a>
`,
})
class TestApp {
buttonType: string;
}