Skip to content
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

feat: add back and cancel btns to TOS and Org select pages #3007

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/pages/DefaultOrgSelector/DefaultOrgSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function DefaultOrgSelector() {
return (
<div className="mx-auto w-full max-w-[38rem]">
<h1 className="pb-3 pt-20 text-2xl font-semibold">
Which organization are you using today?
Which organization are you working with today?
</h1>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="my-4 flex flex-col gap-4 border-y border-ds-gray-tertiary py-6">
Expand Down Expand Up @@ -164,9 +164,17 @@ function DefaultOrgSelector() {
/>
<GitHubHelpBanner />
</div>
<div className="flex justify-end">
<div className="flex justify-end gap-2">
<Button
to={{ pageName: 'login' }}
variant="plain"
disabled={false}
hook="org-select-cancel-button"
>
Cancel
</Button>
<Button hook="user selects org, continues to app" type="submit">
Continue
Continue to Codecov
</Button>
</div>
</form>
Expand Down
59 changes: 48 additions & 11 deletions src/pages/DefaultOrgSelector/DefaultOrgSelector.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

let selectLabel = screen.queryByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).not.toBeInTheDocument()

selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()
})
Expand Down Expand Up @@ -391,6 +391,43 @@ describe('DefaultOrgSelector', () => {
})
})

describe('on cancel', () => {
it('sends user back to the login page', async () => {
setup({
useUserData: mockUserData,
myOrganizationsData: {
me: {
myOrganizations: {
edges: [
{
node: {
avatarUrl:
'https://avatars0.githubusercontent.com/u/8226205?v=3&s=55',
username: 'criticalRole',
ownerid: 1,
},
},
],
pageInfo: { hasNextPage: false, endCursor: 'MTI=' },
},
},
},
})

render(<DefaultOrgSelector />, { wrapper: wrapper() })

const header = await screen.findByText(
/Which organization are you working with today?/
)
expect(header).toBeInTheDocument()

const cancel = await screen.findByRole('link', { name: /Cancel/ })
await userEvent.click(cancel)

expect(testLocation.pathname).toBe('/login')
})
})

describe('on submit', () => {
beforeEach(() => jest.resetAllMocks())
it('fires update default org mutation', async () => {
Expand Down Expand Up @@ -418,7 +455,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand All @@ -431,7 +468,7 @@ describe('DefaultOrgSelector', () => {
await user.click(orgInList)

const submit = await screen.findByRole('button', {
name: /Continue/,
name: /Continue to Codecov/,
})

await user.click(submit)
Expand Down Expand Up @@ -474,7 +511,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -612,7 +649,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -671,7 +708,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -887,7 +924,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -951,7 +988,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -1054,7 +1091,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down Expand Up @@ -1168,7 +1205,7 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })

const selectLabel = await screen.findByText(
/Which organization are you using today?/
/Which organization are you working with today?/
)
expect(selectLabel).toBeInTheDocument()

Expand Down
14 changes: 14 additions & 0 deletions src/pages/TermsOfService/TermsOfService.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ describe('TermsOfService', () => {
})
})

describe('on back', () => {
it('sends user back to the login page', async () => {
render(<TermsOfService />, { wrapper })

const welcome = await screen.findByText(/Welcome to Codecov/i)
expect(welcome).toBeInTheDocument()

const back = await screen.findByRole('link', { name: /Back/ })
await userEvent.click(back)

expect(testLocation.pathname).toBe('/login')
})
})

/*
* This is to test the various form validation edge cases case with different data.
* The describe.each function takes an array of arrays, each array is a test case.
Expand Down
10 changes: 9 additions & 1 deletion src/pages/TermsOfService/TermsOfService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@ export default function TermsOfService() {
.
</p>
)}
<div className="mt-3 flex justify-end">
<div className="mt-3 flex justify-end gap-2">
<Button
to={{ pageName: 'login' }}
variant="plain"
disabled={false}
hook="tos-back-button"
>
Back
</Button>
<Button
disabled={isDisabled({
isValid: formState.isValid,
Expand Down
6 changes: 6 additions & 0 deletions src/ui/Button/Button.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ PlainButton.args = {
variant: 'plain',
}

export const ListboxButton = Template.bind({})
ListboxButton.args = {
children: 'Listbox button',
variant: 'listbox',
}

export const GitHubButton = Template.bind({})
GitHubButton.args = {
children: 'GitHub Button',
Expand Down
Loading