mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
[CL-890] fix flakey tests (#17160)
* remove animations to try and fix flakey tests * allow some diff in tootltip story * dedicated collapsed nav story * remove viewports and add delay * add back animations * add input to disable responsive behavior * remove responsive input. open nav on lg viewports * create story to capture collapsed nav * remove unused import * more explicit user preference logic
This commit is contained in:
@@ -4,6 +4,7 @@ import { componentWrapperDecorator } from "@storybook/angular";
|
|||||||
import type { Preview } from "@storybook/angular";
|
import type { Preview } from "@storybook/angular";
|
||||||
|
|
||||||
import docJson from "../documentation.json";
|
import docJson from "../documentation.json";
|
||||||
|
|
||||||
setCompodocJson(docJson);
|
setCompodocJson(docJson);
|
||||||
|
|
||||||
const wrapperDecorator = componentWrapperDecorator((story) => {
|
const wrapperDecorator = componentWrapperDecorator((story) => {
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ export default {
|
|||||||
type: "figma",
|
type: "figma",
|
||||||
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=16329-40145&t=b5tDKylm5sWm2yKo-4",
|
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=16329-40145&t=b5tDKylm5sWm2yKo-4",
|
||||||
},
|
},
|
||||||
// remove disableSnapshots in CL-890
|
|
||||||
chromatic: { viewports: [640, 1280], disableSnapshot: true },
|
|
||||||
},
|
},
|
||||||
} as Meta;
|
} as Meta;
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ export default {
|
|||||||
type: "figma",
|
type: "figma",
|
||||||
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=16329-40145&t=b5tDKylm5sWm2yKo-4",
|
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=16329-40145&t=b5tDKylm5sWm2yKo-4",
|
||||||
},
|
},
|
||||||
// remove disableSnapshots in CL-890
|
chromatic: { delay: 1000 },
|
||||||
chromatic: { viewports: [640, 1280], disableSnapshot: true },
|
|
||||||
},
|
},
|
||||||
} as Meta;
|
} as Meta;
|
||||||
|
|
||||||
@@ -136,3 +135,28 @@ export const ForceActiveStyles: Story = {
|
|||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CollapsedNavItems: Story = {
|
||||||
|
render: (args) => ({
|
||||||
|
props: args,
|
||||||
|
template: `
|
||||||
|
<bit-nav-item text="First Nav" icon="bwi-collection-shared"></bit-nav-item>
|
||||||
|
<bit-nav-item text="Active Nav" icon="bwi-collection-shared" [forceActiveStyles]="true"></bit-nav-item>
|
||||||
|
<bit-nav-item text="Third Nav" icon="bwi-collection-shared"></bit-nav-item>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
play: async () => {
|
||||||
|
const toggleButton = document.querySelector(
|
||||||
|
"[aria-label='Toggle side navigation']",
|
||||||
|
) as HTMLButtonElement;
|
||||||
|
|
||||||
|
if (toggleButton) {
|
||||||
|
toggleButton.click();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
parameters: {
|
||||||
|
chromatic: {
|
||||||
|
delay: 1000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CdkTrapFocus } from "@angular/cdk/a11y";
|
import { CdkTrapFocus } from "@angular/cdk/a11y";
|
||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, ElementRef, input, viewChild } from "@angular/core";
|
import { Component, ElementRef, inject, input, viewChild } from "@angular/core";
|
||||||
|
|
||||||
import { I18nPipe } from "@bitwarden/ui-common";
|
import { I18nPipe } from "@bitwarden/ui-common";
|
||||||
|
|
||||||
@@ -22,8 +22,7 @@ export class SideNavComponent {
|
|||||||
readonly variant = input<SideNavVariant>("primary");
|
readonly variant = input<SideNavVariant>("primary");
|
||||||
|
|
||||||
private readonly toggleButton = viewChild("toggleButton", { read: ElementRef });
|
private readonly toggleButton = viewChild("toggleButton", { read: ElementRef });
|
||||||
|
protected sideNavService = inject(SideNavService);
|
||||||
constructor(protected sideNavService: SideNavService) {}
|
|
||||||
|
|
||||||
protected handleKeyDown = (event: KeyboardEvent) => {
|
protected handleKeyDown = (event: KeyboardEvent) => {
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
|
|||||||
@@ -2,23 +2,36 @@ import { Injectable } from "@angular/core";
|
|||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { BehaviorSubject, Observable, combineLatest, fromEvent, map, startWith } from "rxjs";
|
import { BehaviorSubject, Observable, combineLatest, fromEvent, map, startWith } from "rxjs";
|
||||||
|
|
||||||
|
type CollapsePreference = "open" | "closed" | null;
|
||||||
|
|
||||||
|
const SMALL_SCREEN_BREAKPOINT_PX = 768;
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root",
|
providedIn: "root",
|
||||||
})
|
})
|
||||||
export class SideNavService {
|
export class SideNavService {
|
||||||
private _open$ = new BehaviorSubject<boolean>(!window.matchMedia("(max-width: 768px)").matches);
|
private _open$ = new BehaviorSubject<boolean>(
|
||||||
|
!window.matchMedia(`(max-width: ${SMALL_SCREEN_BREAKPOINT_PX}px)`).matches,
|
||||||
|
);
|
||||||
open$ = this._open$.asObservable();
|
open$ = this._open$.asObservable();
|
||||||
|
|
||||||
private isSmallScreen$ = media("(max-width: 768px)");
|
private isSmallScreen$ = media(`(max-width: ${SMALL_SCREEN_BREAKPOINT_PX}px)`);
|
||||||
|
private _userCollapsePreference$ = new BehaviorSubject<CollapsePreference>(null);
|
||||||
|
userCollapsePreference$ = this._userCollapsePreference$.asObservable();
|
||||||
|
|
||||||
isOverlay$ = combineLatest([this.open$, this.isSmallScreen$]).pipe(
|
isOverlay$ = combineLatest([this.open$, this.isSmallScreen$]).pipe(
|
||||||
map(([open, isSmallScreen]) => open && isSmallScreen),
|
map(([open, isSmallScreen]) => open && isSmallScreen),
|
||||||
);
|
);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.isSmallScreen$.pipe(takeUntilDestroyed()).subscribe((isSmallScreen) => {
|
combineLatest([this.isSmallScreen$, this.userCollapsePreference$])
|
||||||
|
.pipe(takeUntilDestroyed())
|
||||||
|
.subscribe(([isSmallScreen, userCollapsePreference]) => {
|
||||||
if (isSmallScreen) {
|
if (isSmallScreen) {
|
||||||
this.setClose();
|
this.setClose();
|
||||||
|
} else if (userCollapsePreference !== "closed") {
|
||||||
|
// Auto-open when user hasn't set preference (null) or prefers open
|
||||||
|
this.setOpen();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -37,6 +50,9 @@ export class SideNavService {
|
|||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
const curr = this._open$.getValue();
|
const curr = this._open$.getValue();
|
||||||
|
// Store user's preference based on what state they're toggling TO
|
||||||
|
this._userCollapsePreference$.next(curr ? "closed" : "open");
|
||||||
|
|
||||||
if (curr) {
|
if (curr) {
|
||||||
this.setClose();
|
this.setClose();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -200,3 +200,12 @@ export const VirtualScrollBlockingDialog: Story = {
|
|||||||
await userEvent.click(dialogButton);
|
await userEvent.click(dialogButton);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ResponsiveSidebar: Story = {
|
||||||
|
render: Default.render,
|
||||||
|
parameters: {
|
||||||
|
chromatic: {
|
||||||
|
viewports: [640, 1280],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ export default {
|
|||||||
type: "figma",
|
type: "figma",
|
||||||
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?m=auto&node-id=30558-13730&t=4k23PtzCwqDekAZW-1",
|
url: "https://www.figma.com/design/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?m=auto&node-id=30558-13730&t=4k23PtzCwqDekAZW-1",
|
||||||
},
|
},
|
||||||
|
chromatic: {
|
||||||
|
// Allows 30% difference for the tooltip stories since they are rendered in a portal and may be affected by the environment.
|
||||||
|
diffThreshold: 0.3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
argTypes: {
|
argTypes: {
|
||||||
bitTooltip: {
|
bitTooltip: {
|
||||||
|
|||||||
Reference in New Issue
Block a user