-
Notifications
You must be signed in to change notification settings - Fork 943
feat: Add user menu #887
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
Merged
feat: Add user menu #887
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36026f1
feat: Add user menu
BrunoQuaresma 901da69
fix: Arrow icons
BrunoQuaresma 73ed5cd
fix: styles
BrunoQuaresma 5ed8232
test: Add tests and storybook
BrunoQuaresma 5dae508
chore: merge main
BrunoQuaresma 9748e39
chore: Merge branch 'main' of github.com:coder/coder into bq/usermenu
BrunoQuaresma 0455e54
refactor: use Language object
BrunoQuaresma d17a808
refactor: Use Language in tests
BrunoQuaresma 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import SvgIcon, { SvgIconProps } from "@material-ui/core/SvgIcon" | ||
import React from "react" | ||
|
||
export const DocsIcon = (props: SvgIconProps): JSX.Element => ( | ||
<SvgIcon {...props} viewBox="0 0 24 24"> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M6.53846 3.75C4.67698 3.75 2.86058 4.50721 2.86058 4.50721L2.5 4.66947V16.4423H9.00841C9.20898 16.7871 9.57407 17.0192 10 17.0192C10.4259 17.0192 10.791 16.7871 10.9916 16.4423H17.5V4.66947L17.1394 4.50721C17.1394 4.50721 15.323 3.75 13.4615 3.75C11.7781 3.75 10.2997 4.31566 10 4.4351C9.70027 4.31566 8.22191 3.75 6.53846 3.75ZM6.53846 4.90385C7.654 4.90385 8.84615 5.26442 9.42308 5.46274V14.7656C8.7808 14.5538 7.72611 14.2608 6.53846 14.2608C5.32602 14.2608 4.33894 14.5403 3.65385 14.7656V5.46274C4.09781 5.30273 5.26968 4.90385 6.53846 4.90385ZM13.4615 4.90385C14.7303 4.90385 15.9022 5.30273 16.3462 5.46274V14.7656C15.6611 14.5403 14.674 14.2608 13.4615 14.2608C12.2739 14.2608 11.2192 14.5538 10.5769 14.7656V5.46274C11.1538 5.26442 12.346 4.90385 13.4615 4.90385Z" | ||
fill="currentColor" | ||
/> | ||
</SvgIcon> | ||
) |
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,26 @@ | ||
import Box from "@material-ui/core/Box" | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { UserDropdown, UserDropdownProps } from "./UserDropdown" | ||
|
||
export default { | ||
title: "Page/UserDropdown", | ||
component: UserDropdown, | ||
argTypes: { | ||
onSignOut: { action: "Sign Out" }, | ||
}, | ||
} | ||
|
||
const Template: Story<UserDropdownProps> = (args: UserDropdownProps) => ( | ||
<Box style={{ backgroundColor: "#000", width: 88 }}> | ||
<UserDropdown {...args} /> | ||
</Box> | ||
) | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
user: { id: "1", username: "CathyCoder", email: "cathy@coder.com", created_at: "dawn" }, | ||
onSignOut: () => { | ||
return Promise.resolve() | ||
}, | ||
} |
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,55 @@ | ||
import { screen } from "@testing-library/react" | ||
import React from "react" | ||
import { render } from "../../test_helpers" | ||
import { MockUser } from "../../test_helpers/entities" | ||
import { UserDropdown, UserDropdownProps } from "./UserDropdown" | ||
|
||
const renderAndClick = async (props: Partial<UserDropdownProps> = {}) => { | ||
render(<UserDropdown user={props.user ?? MockUser} onSignOut={props.onSignOut ?? jest.fn()} />) | ||
const trigger = await screen.findByTestId("user-dropdown-trigger") | ||
trigger.click() | ||
} | ||
|
||
describe("UserDropdown", () => { | ||
describe("when the trigger is clicked", () => { | ||
it("opens the menu", async () => { | ||
await renderAndClick() | ||
expect(screen.getByText(/account/i)).toBeDefined() | ||
expect(screen.getByText(/documentation/i)).toBeDefined() | ||
expect(screen.getByText(/sign out/i)).toBeDefined() | ||
}) | ||
}) | ||
|
||
describe("when the menu is open", () => { | ||
describe("and sign out is clicked", () => { | ||
it("calls the onSignOut function", async () => { | ||
const onSignOut = jest.fn() | ||
await renderAndClick({ onSignOut }) | ||
screen.getByText(/sign out/i).click() | ||
expect(onSignOut).toBeCalledTimes(1) | ||
}) | ||
}) | ||
}) | ||
|
||
it("has the correct link for the documentation item", async () => { | ||
await renderAndClick() | ||
|
||
const link = screen.getByText(/documentation/i).closest("a") | ||
if (!link) { | ||
throw new Error("Anchor tag not found for the documentation menu item") | ||
} | ||
|
||
expect(link.getAttribute("href")).toBe("https://coder.com/docs") | ||
}) | ||
|
||
it("has the correct link for the account item", async () => { | ||
await renderAndClick() | ||
|
||
const link = screen.getByText(/account/i).closest("a") | ||
if (!link) { | ||
throw new Error("Anchor tag not found for the account menu item") | ||
} | ||
|
||
expect(link.getAttribute("href")).toBe("/preferences") | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Box from "@material-ui/core/Box" | ||
import Paper from "@material-ui/core/Paper" | ||
import React from "react" | ||
import { Header } from "../../components/Header" | ||
import { Footer } from "../../components/Page" | ||
|
||
export const PreferencesPage: React.FC = () => { | ||
return ( | ||
<Box display="flex" flexDirection="column"> | ||
<Header title="Preferences" /> | ||
<Paper style={{ maxWidth: "1380px", margin: "1em auto", width: "100%" }}>Preferences here!</Paper> | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Footer /> | ||
</Box> | ||
) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.