Skip to content

Commit 42732eb

Browse files
authored
MNTOR-5162 - Fix Monitor logo breaking version on dashboard (#6436)
* fix breaking version on dashboard * usePathname to avoid undefined pathname crash * align route handling between Storybook and Jest for MonitorLogo * remove unused path
1 parent 3f3e8f8 commit 42732eb

File tree

9 files changed

+222
-31
lines changed

9 files changed

+222
-31
lines changed

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/high-risk-data-breaches/[type]/HighRiskDataBreach.stories.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,55 @@ export const SsnStory: Story = {
135135
args: {
136136
type: "social-security-number",
137137
},
138+
parameters: {
139+
nextjs: {
140+
navigation: {
141+
pathname: "/fix/high-risk-data-breaches/social-security-number",
142+
},
143+
},
144+
},
138145
};
139146

140147
export const CreditCardStory: Story = {
141148
name: "2b. Credit card",
142149
args: {
143150
type: "credit-card",
144151
},
152+
parameters: {
153+
nextjs: {
154+
navigation: {
155+
pathname: "/fix/high-risk-data-breaches/credit-card",
156+
},
157+
},
158+
},
145159
};
146160

147161
export const BankAccountStory: Story = {
148162
name: "2c. Bank account",
149163
args: {
150164
type: "bank-account",
151165
},
166+
parameters: {
167+
nextjs: {
168+
navigation: {
169+
pathname: "/fix/high-risk-data-breaches/bank-account",
170+
},
171+
},
172+
},
152173
};
153174

154175
export const PinStory: Story = {
155176
name: "2d. PIN",
156177
args: {
157178
type: "pin",
158179
},
180+
parameters: {
181+
nextjs: {
182+
navigation: {
183+
pathname: "/fix/high-risk-data-breaches/pin",
184+
},
185+
},
186+
},
159187
};
160188

161189
export const HighRiskBreachDoneStory: Story = {
@@ -164,4 +192,11 @@ export const HighRiskBreachDoneStory: Story = {
164192
type: "done",
165193
nextUnresolvedBreachType: "None",
166194
},
195+
parameters: {
196+
nextjs: {
197+
navigation: {
198+
pathname: "/fix/high-risk-data-breaches/done",
199+
},
200+
},
201+
},
167202
};

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/leaked-passwords/[type]/LeakedPasswords.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,27 @@ export const PasswordsStory: Story = {
122122
args: {
123123
type: "passwords",
124124
},
125+
parameters: {
126+
nextjs: {
127+
navigation: {
128+
pathname: "/fix/leaked-passwords/passwords",
129+
},
130+
},
131+
},
125132
};
126133

127134
export const SecurityQuestionsStory: Story = {
128135
name: "3b. Security questions",
129136
args: {
130137
type: "security-questions",
131138
},
139+
parameters: {
140+
nextjs: {
141+
navigation: {
142+
pathname: "/fix/leaked-passwords/security-questions",
143+
},
144+
},
145+
},
132146
};
133147

134148
export const LeakedPasswordsDoneStory: Story = {
@@ -137,4 +151,11 @@ export const LeakedPasswordsDoneStory: Story = {
137151
type: "passwords-done",
138152
nextUnresolvedBreachType: "None",
139153
},
154+
parameters: {
155+
nextjs: {
156+
navigation: {
157+
pathname: "/fix/leaked-passwords/done",
158+
},
159+
},
160+
},
140161
};

src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/dashboard/fix/security-recommendations/[type]/SecurityRecommendations.stories.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,53 @@ export const PhoneStory: Story = {
9393
args: {
9494
type: "phone",
9595
},
96+
parameters: {
97+
nextjs: {
98+
navigation: {
99+
pathname: "/fix/security-recommendations/phone",
100+
},
101+
},
102+
},
96103
};
97104

98105
export const EmailStory: Story = {
99106
name: "4b. Email address",
100107
args: {
101108
type: "email",
102109
},
110+
parameters: {
111+
nextjs: {
112+
navigation: {
113+
pathname: "/fix/security-recommendations/email",
114+
},
115+
},
116+
},
103117
};
104118

105119
export const IpStory: Story = {
106120
name: "4c. IP address",
107121
args: {
108122
type: "ip",
109123
},
124+
parameters: {
125+
nextjs: {
126+
navigation: {
127+
pathname: "/fix/security-recommendations/ip",
128+
},
129+
},
130+
},
110131
};
111132

112133
export const DoneStory: Story = {
113134
name: "4d. Done",
114135
args: {
115136
type: "done",
116137
},
138+
parameters: {
139+
nextjs: {
140+
navigation: {
141+
pathname: "/fix/security-recommendations/done",
142+
},
143+
},
144+
},
117145
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@use "../../../tokens";
2+
3+
.homeLink {
4+
display: none;
5+
6+
@media screen and (min-width: tokens.$screen-md) {
7+
align-items: center;
8+
display: flex;
9+
height: tokens.$tab-bar-height;
10+
padding: 0 tokens.$spacing-lg;
11+
12+
img {
13+
display: block;
14+
max-width: 100%;
15+
}
16+
17+
&:focus {
18+
outline-offset: calc(-1 * tokens.$border-focus-width);
19+
outline: tokens.$border-focus-width solid tokens.$color-purple-10;
20+
}
21+
22+
&.isOnDashboard {
23+
background: tokens.$color-white;
24+
border-bottom: 1px solid tokens.$color-grey-20;
25+
box-shadow: tokens.$box-shadow-xs;
26+
}
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import type { Meta, StoryObj } from "@storybook/nextjs";
6+
import { MonitorLogo } from "./MonitorLogo";
7+
8+
const meta: Meta<typeof MonitorLogo> = {
9+
title: "Layout/Navigation/Monitor Logo",
10+
component: MonitorLogo,
11+
};
12+
13+
export default meta;
14+
type Story = StoryObj<typeof MonitorLogo>;
15+
16+
export const MonitorLogoFixFlow: Story = {
17+
args: {},
18+
parameters: {
19+
nextjs: {
20+
navigation: {
21+
pathname: "/fix/leaked-passwords/passwords",
22+
},
23+
},
24+
},
25+
};
26+
27+
export const MonitorLogoActionNeeded: Story = {
28+
args: {},
29+
parameters: {
30+
nextjs: {
31+
navigation: {
32+
pathname: "/action-needed",
33+
},
34+
},
35+
},
36+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
import { render, screen } from "@testing-library/react";
6+
import { composeStory } from "@storybook/react";
7+
import Meta, {
8+
MonitorLogoActionNeeded,
9+
MonitorLogoFixFlow,
10+
} from "./MonitorLogo.stories";
11+
import * as navigation from "next/navigation";
12+
13+
jest.mock("next/navigation", () => ({
14+
usePathname: jest.fn(),
15+
}));
16+
17+
const mockedUsePathname = navigation.usePathname as unknown as jest.Mock;
18+
19+
describe("MonitorLogo", () => {
20+
beforeEach(() => mockedUsePathname.mockReset());
21+
22+
it("has white background on dashboard", () => {
23+
mockedUsePathname.mockReturnValue("/");
24+
25+
const Composed = composeStory(MonitorLogoActionNeeded, Meta);
26+
render(<Composed />);
27+
28+
const homeLink = screen.getByRole("link", { name: "Home" });
29+
expect(homeLink).toHaveClass("isOnDashboard");
30+
});
31+
32+
it("does not have white background on /fix", () => {
33+
mockedUsePathname.mockReturnValue("/fix/leaked-passwords/passwords");
34+
35+
const Composed = composeStory(MonitorLogoFixFlow, Meta);
36+
render(<Composed />);
37+
38+
const homeLink = screen.getByRole("link", { name: "Home" });
39+
expect(homeLink).not.toHaveClass("isOnDashboard");
40+
});
41+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use client";
6+
7+
import Image from "next/image";
8+
import MonitorLogoImg from "../../images/monitor-logo.svg";
9+
import { useL10n } from "../../../hooks/l10n";
10+
import { usePathname } from "next/navigation";
11+
import styles from "./MonitorLogo.module.scss";
12+
import Link from "next/link";
13+
14+
export const MonitorLogo = () => {
15+
const l10n = useL10n();
16+
const pathname = usePathname();
17+
const isResolutionFlow =
18+
typeof pathname === "string" && pathname.includes("/fix/");
19+
return (
20+
<Link
21+
href="/user/dashboard"
22+
className={`${styles.homeLink} ${!isResolutionFlow ? styles.isOnDashboard : ""}`}
23+
>
24+
<Image
25+
src={MonitorLogoImg}
26+
alt={l10n.getString("main-nav-link-home-label")}
27+
width={170}
28+
/>
29+
</Link>
30+
);
31+
};

src/app/(proper_react)/(redesign)/Shell/ShellRedesign.module.scss

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,6 @@
1919
}
2020
}
2121

22-
.homeLink {
23-
display: none;
24-
25-
@media screen and (min-width: tokens.$screen-md) {
26-
align-items: center;
27-
display: flex;
28-
height: tokens.$tab-bar-height;
29-
padding: 0 tokens.$spacing-lg;
30-
31-
img {
32-
display: block;
33-
max-width: 100%;
34-
}
35-
36-
&:focus {
37-
outline-offset: calc(-1 * tokens.$border-focus-width);
38-
outline: tokens.$border-focus-width solid tokens.$color-purple-10;
39-
}
40-
}
41-
}
42-
4322
.content {
4423
background-color: tokens.$color-grey-05;
4524
display: flex;

src/app/(proper_react)/(redesign)/Shell/ShellRedesign.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { ReactNode } from "react";
6-
import Link from "next/link";
7-
import Image from "next/image";
86
import { Session } from "next-auth";
97
import { MobileShell } from "../MobileShell";
108
import { Footer } from "../Footer";
119
import { ExtendedReactLocalization } from "../../../functions/l10n";
1210
import { FeatureFlagName } from "../../../../db/tables/featureFlags";
13-
import MonitorLogo from "../../images/monitor-logo.svg";
1411
import styles from "./ShellRedesign.module.scss";
1512
import { NavbarList } from "./ShellNavbarList";
1613
import { UserAnnouncementWithDetails } from "../../../../db/tables/user_announcements";
14+
import { MonitorLogo } from "./MonitorLogo";
1715

1816
export type Props = {
1917
l10n: ExtendedReactLocalization;
@@ -41,13 +39,7 @@ export const ShellRedesign = (props: Props) => {
4139
className={styles.mainMenu}
4240
aria-label={props.l10n.getString("main-nav-label")}
4341
>
44-
<Link href="/user/dashboard" className={styles.homeLink}>
45-
<Image
46-
src={MonitorLogo}
47-
alt={props.l10n.getString("main-nav-link-home-label")}
48-
width={170}
49-
/>
50-
</Link>
42+
<MonitorLogo />
5143
{!props.hideSidebar && (
5244
<NavbarList
5345
countryCode={props.countryCode}

0 commit comments

Comments
 (0)