-
Notifications
You must be signed in to change notification settings - Fork 291
MNTOR-5162 - Fix Monitor logo breaking version on dashboard #6436
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
+222
−31
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0e298d8
fix breaking version on dashboard
codemist cca49a3
usePathname to avoid undefined pathname crash
codemist b6ec441
align route handling between Storybook and Jest for MonitorLogo
codemist 81dc725
remove unused path
codemist bdf4d5a
Merge branch 'main' into mntor-5162-fix
codemist 1441282
Merge branch 'main' into mntor-5162-fix
codemist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/app/(proper_react)/(redesign)/Shell/MonitorLogo.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| @use "../../../tokens"; | ||
|
|
||
| .homeLink { | ||
| display: none; | ||
|
|
||
| @media screen and (min-width: tokens.$screen-md) { | ||
| align-items: center; | ||
| display: flex; | ||
| height: tokens.$tab-bar-height; | ||
| padding: 0 tokens.$spacing-lg; | ||
|
|
||
| img { | ||
| display: block; | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| &:focus { | ||
| outline-offset: calc(-1 * tokens.$border-focus-width); | ||
| outline: tokens.$border-focus-width solid tokens.$color-purple-10; | ||
| } | ||
|
|
||
| &.isOnDashboard { | ||
| background: tokens.$color-white; | ||
| border-bottom: 1px solid tokens.$color-grey-20; | ||
| box-shadow: tokens.$box-shadow-xs; | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/app/(proper_react)/(redesign)/Shell/MonitorLogo.stories.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import type { Meta, StoryObj } from "@storybook/nextjs"; | ||
| import { MonitorLogo } from "./MonitorLogo"; | ||
|
|
||
| const meta: Meta<typeof MonitorLogo> = { | ||
| title: "Layout/Navigation/Monitor Logo", | ||
| component: MonitorLogo, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof MonitorLogo>; | ||
|
|
||
| export const MonitorLogoFixFlow: Story = { | ||
| args: {}, | ||
| parameters: { | ||
| nextjs: { | ||
| navigation: { | ||
| pathname: "/fix/leaked-passwords/passwords", | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const MonitorLogoActionNeeded: Story = { | ||
| args: {}, | ||
| parameters: { | ||
| nextjs: { | ||
| navigation: { | ||
| pathname: "/action-needed", | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
41 changes: 41 additions & 0 deletions
41
src/app/(proper_react)/(redesign)/Shell/MonitorLogo.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import { render, screen } from "@testing-library/react"; | ||
| import { composeStory } from "@storybook/react"; | ||
| import Meta, { | ||
| MonitorLogoActionNeeded, | ||
| MonitorLogoFixFlow, | ||
| } from "./MonitorLogo.stories"; | ||
| import * as navigation from "next/navigation"; | ||
|
|
||
| jest.mock("next/navigation", () => ({ | ||
| usePathname: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedUsePathname = navigation.usePathname as unknown as jest.Mock; | ||
|
|
||
| describe("MonitorLogo", () => { | ||
| beforeEach(() => mockedUsePathname.mockReset()); | ||
|
|
||
| it("has white background on dashboard", () => { | ||
| mockedUsePathname.mockReturnValue("/"); | ||
|
|
||
| const Composed = composeStory(MonitorLogoActionNeeded, Meta); | ||
| render(<Composed />); | ||
|
|
||
| const homeLink = screen.getByRole("link", { name: "Home" }); | ||
| expect(homeLink).toHaveClass("isOnDashboard"); | ||
| }); | ||
|
|
||
| it("does not have white background on /fix", () => { | ||
| mockedUsePathname.mockReturnValue("/fix/leaked-passwords/passwords"); | ||
|
|
||
| const Composed = composeStory(MonitorLogoFixFlow, Meta); | ||
| render(<Composed />); | ||
|
|
||
| const homeLink = screen.getByRole("link", { name: "Home" }); | ||
| expect(homeLink).not.toHaveClass("isOnDashboard"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| "use client"; | ||
|
|
||
| import Image from "next/image"; | ||
| import MonitorLogoImg from "../../images/monitor-logo.svg"; | ||
| import { useL10n } from "../../../hooks/l10n"; | ||
| import { usePathname } from "next/navigation"; | ||
| import styles from "./MonitorLogo.module.scss"; | ||
| import Link from "next/link"; | ||
|
|
||
| export const MonitorLogo = () => { | ||
| const l10n = useL10n(); | ||
| const pathname = usePathname(); | ||
| const isResolutionFlow = | ||
| typeof pathname === "string" && pathname.includes("/fix/"); | ||
| return ( | ||
| <Link | ||
| href="/user/dashboard" | ||
| className={`${styles.homeLink} ${!isResolutionFlow ? styles.isOnDashboard : ""}`} | ||
| > | ||
| <Image | ||
| src={MonitorLogoImg} | ||
| alt={l10n.getString("main-nav-link-home-label")} | ||
| width={170} | ||
| /> | ||
| </Link> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
MonitorLogorelies onusePathnameand isn’t rendered with a real router context in the Storybook environment by default, thepathnameis mocked at the story level (for all stories in the fix flow).