mirror of
https://github.com/bitwarden/browser
synced 2026-02-09 05:00:10 +00:00
* Use aria-disabled for button disabled state * remove import from testing story * use aria-disabled attr on bitLink button * remove unnecessary story attrs * remove disabled attr if on button element * create caprture click util * use caprture click util and fix tests * fix lint errors * fix event type * combine click capture and attr modification * fix lint error. Commit spec changes left out of last commit in error * inject element ref * move aria-disabled styles to common * move disabled logic into util * fix broken async actions stories * fix broken tests asserting disabled attr * have test check for string true vlalue * fix Signal type * fix form-field story import * remove injector left in error * aria-disable icon buttons * update form component css selector to look for aria-disabled buttons * use correct types. pass nativeElement directly * add JSDoc comment for util function * WIP * WIP * inject service in directive * remove console log * remove disabled attr left in error * update comments * remove unnecessary logic * remove :disabled psuedo selector as its apparently not needed * fix event type * coerce disabled attr to boolean * remove duplicate style concat left by conflict resolution * add back buttonStyles default * move reactive logic back to helper * add test to ensure menu button doesn't open when trigger is disabled * remove menu toggle to fix tests * remove disabled menu story * Fix usage of bitLink in verify email component * Update varaible name * no longer pass destroyRef
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { Component } from "@angular/core";
|
|
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
|
import { By } from "@angular/platform-browser";
|
|
|
|
import { MenuTriggerForDirective } from "./menu-trigger-for.directive";
|
|
|
|
import { MenuModule } from "./index";
|
|
|
|
describe("Menu", () => {
|
|
let fixture: ComponentFixture<TestApp>;
|
|
const getMenuTriggerDirective = () => {
|
|
const buttonDebugElement = fixture.debugElement.query(By.directive(MenuTriggerForDirective));
|
|
return buttonDebugElement.injector.get(MenuTriggerForDirective);
|
|
};
|
|
|
|
// The overlay is created outside the root debugElement, so we need to query its parent
|
|
const getBitMenuPanel = () => document.querySelector(".bit-menu-panel");
|
|
|
|
beforeEach(async () => {
|
|
TestBed.configureTestingModule({
|
|
imports: [TestApp],
|
|
});
|
|
|
|
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));
|
|
(buttonDebugElement.nativeElement as HTMLButtonElement).click();
|
|
|
|
expect(getBitMenuPanel()).toBeTruthy();
|
|
});
|
|
|
|
it("should close when the trigger is clicked", () => {
|
|
getMenuTriggerDirective().toggleMenu();
|
|
|
|
const buttonDebugElement = fixture.debugElement.query(By.directive(MenuTriggerForDirective));
|
|
(buttonDebugElement.nativeElement as HTMLButtonElement).click();
|
|
|
|
expect(getBitMenuPanel()).toBeFalsy();
|
|
});
|
|
|
|
it("should close when a menu item is clicked", () => {
|
|
getMenuTriggerDirective().toggleMenu();
|
|
|
|
(document.querySelector("#item1") as HTMLAnchorElement).click();
|
|
|
|
expect(getBitMenuPanel()).toBeFalsy();
|
|
});
|
|
|
|
it("should close when the backdrop is clicked", () => {
|
|
getMenuTriggerDirective().toggleMenu();
|
|
|
|
(document.querySelector(".cdk-overlay-backdrop") as HTMLAnchorElement).click();
|
|
|
|
expect(getBitMenuPanel()).toBeFalsy();
|
|
});
|
|
|
|
it("should not open when the trigger button is disabled", () => {
|
|
const buttonDebugElement = fixture.debugElement.query(By.directive(MenuTriggerForDirective));
|
|
buttonDebugElement.nativeElement.setAttribute("disabled", "true");
|
|
(buttonDebugElement.nativeElement as HTMLButtonElement).click();
|
|
|
|
expect(getBitMenuPanel()).toBeFalsy();
|
|
});
|
|
});
|
|
|
|
@Component({
|
|
selector: "test-app",
|
|
template: `
|
|
<button type="button" [bitMenuTriggerFor]="testMenu">Open menu</button>
|
|
|
|
<bit-menu #testMenu>
|
|
<a id="item1" bitMenuItem>Item 1</a>
|
|
<a id="item2" bitMenuItem>Item 2</a>
|
|
</bit-menu>
|
|
`,
|
|
imports: [MenuModule],
|
|
})
|
|
class TestApp {}
|