-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Added error message when user can't approve membership (#1200)
- Loading branch information
Showing
13 changed files
with
267 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
*/ | ||
import { render, screen } from 'tests/utils'; | ||
import React from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import { useNavigate, useSearchParams } from 'react-router-dom'; | ||
import * as accountService from 'terraso-client-shared/account/accountService'; | ||
|
||
import AccountLogin from 'account/components/AccountLogin'; | ||
|
@@ -26,10 +26,12 @@ jest.mock('terraso-client-shared/account/accountService'); | |
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useSearchParams: jest.fn(), | ||
useNavigate: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
useSearchParams.mockReturnValue([new URLSearchParams(), () => {}]); | ||
useNavigate.mockReturnValue(jest.fn()); | ||
}); | ||
|
||
test('AccountLogin: Display error', async () => { | ||
|
@@ -50,36 +52,100 @@ test('AccountLogin: Display loader', async () => { | |
test('AccountLogin: Display buttons', async () => { | ||
accountService.getAuthURLs.mockReturnValue( | ||
Promise.resolve({ | ||
google: 'google.url', | ||
apple: 'apple.url', | ||
google: 'google.url?param=value', | ||
apple: 'apple.url?param=value', | ||
}) | ||
); | ||
await render(<AccountLogin />); | ||
expect(screen.getByText('Continue with Google')).toBeInTheDocument(); | ||
expect(screen.getByText('Continue with Google')).toHaveAttribute( | ||
'href', | ||
`google.url?param=value` | ||
); | ||
expect(screen.getByText('Continue with Apple')).toBeInTheDocument(); | ||
}); | ||
|
||
test('AccountLogin: Add referrer', async () => { | ||
const searchParams = new URLSearchParams(); | ||
searchParams.set('referrer', 'groups?sort=-name'); | ||
const referrer = encodeURIComponent('groups?sort=-name&other=1'); | ||
searchParams.set('referrer', referrer); | ||
useSearchParams.mockReturnValue([searchParams]); | ||
accountService.getAuthURLs.mockReturnValue( | ||
Promise.resolve({ | ||
google: 'google.url', | ||
apple: 'apple.url', | ||
google: 'google.url?param=value', | ||
apple: 'apple.url?param=value', | ||
}) | ||
); | ||
await render(<AccountLogin />); | ||
expect(screen.getByText('Continue with Google')).toBeInTheDocument(); | ||
const state = `account%3FreferrerBase64%3D${btoa(referrer)}`; | ||
expect(screen.getByText('Continue with Google')).toHaveAttribute( | ||
'href', | ||
'google.url&state=groups?sort=-name' | ||
`google.url?param=value&state=${state}` | ||
); | ||
expect(screen.getByText('Continue with Apple')).toBeInTheDocument(); | ||
expect(screen.getByText('Continue with Apple')).toHaveAttribute( | ||
'href', | ||
'apple.url&state=groups?sort=-name' | ||
`apple.url?param=value&state=${state}` | ||
); | ||
}); | ||
|
||
test('AccountLogin: Navigate to referrer if logged in', async () => { | ||
accountService.getAuthURLs.mockReturnValue( | ||
Promise.resolve({ | ||
google: 'google.url', | ||
apple: 'apple.url', | ||
}) | ||
); | ||
const navigate = jest.fn(); | ||
useNavigate.mockReturnValue(navigate); | ||
const searchParams = new URLSearchParams(); | ||
const referrer = encodeURIComponent('groups?sort=-name&other=1'); | ||
searchParams.set('referrer', referrer); | ||
useSearchParams.mockReturnValue([searchParams]); | ||
await render(<AccountLogin />, { | ||
account: { | ||
hasToken: true, | ||
login: {}, | ||
currentUser: { | ||
data: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(navigate).toHaveBeenCalledWith('groups?sort=-name&other=1', { | ||
replace: true, | ||
}); | ||
}); | ||
|
||
test('AccountLogin: Navigate to referrer base 64 if logged in', async () => { | ||
accountService.getAuthURLs.mockReturnValue( | ||
Promise.resolve({ | ||
google: 'google.url', | ||
apple: 'apple.url', | ||
}) | ||
); | ||
const navigate = jest.fn(); | ||
useNavigate.mockReturnValue(navigate); | ||
const searchParams = new URLSearchParams(); | ||
const referrer = encodeURIComponent('groups?sort=-name&other=1'); | ||
searchParams.set('referrerBase64', btoa(referrer)); | ||
useSearchParams.mockReturnValue([searchParams]); | ||
await render(<AccountLogin />, { | ||
account: { | ||
hasToken: true, | ||
login: {}, | ||
currentUser: { | ||
data: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(navigate).toHaveBeenCalledWith('groups?sort=-name&other=1', { | ||
replace: true, | ||
}); | ||
}); | ||
|
||
test('AccountLogin: Display locale picker', async () => { | ||
|
This file contains 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.