-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Account tabs and add group list (#838)
- Uses the existing user profile information obtained in OAuth signin process and updates the profile page. - Downgrades the ESLint version to make it compatible with eslintrc configuration file.
- Loading branch information
1 parent
1431828
commit 9bd4c1b
Showing
5 changed files
with
200 additions
and
101 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,12 +1,111 @@ | ||
import * as React from 'react'; | ||
import Account from 'route/auth/Account'; | ||
import tabs from 'route/auth/AccountTabData'; | ||
import { InitRouteTests, itDisplaysContentOfTabs } from '../testUtils'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { useAuth } from 'react-oidc-context'; | ||
|
||
describe('Account Page', () => { | ||
const tabLabels: string[] = []; | ||
tabs.forEach((tab) => tabLabels.push(tab.label)); | ||
InitRouteTests(<Account />); | ||
jest.mock('react-oidc-context'); | ||
|
||
itDisplaysContentOfTabs(tabs); | ||
describe('AccountTabs', () => { | ||
type Profile = { | ||
preferred_username: string | undefined; | ||
picture: string | undefined; | ||
profile: string | undefined; | ||
groups: string[] | string | undefined; | ||
}; | ||
|
||
const mockProfile: Profile = { | ||
preferred_username: 'user1', | ||
picture: 'pfp.jpg', | ||
profile: 'test.com', | ||
groups: 'group-one', | ||
}; | ||
|
||
function setupTest(groups: string[] | string) { | ||
mockProfile.groups = groups; | ||
const mockuser = { profile: mockProfile }; | ||
(useAuth as jest.Mock).mockReturnValue({ | ||
user: mockuser, | ||
}); | ||
render(<Account />); | ||
} | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
function testStaticElements() { | ||
const profilePicture = screen.getByTestId('profile-picture'); | ||
expect(profilePicture).toBeInTheDocument(); | ||
expect(profilePicture).toHaveAttribute('src', 'pfp.jpg'); | ||
|
||
const username = screen.getAllByText('user1'); | ||
expect(username).not.toBeNull(); | ||
expect(username).toHaveLength(2); | ||
|
||
const profileLink = screen.getByRole('link', { | ||
name: /SSO OAuth Provider/i, | ||
}); | ||
expect(profileLink).toBeInTheDocument(); | ||
expect(profileLink).toHaveAttribute('href', 'test.com'); | ||
} | ||
|
||
test('renders AccountTabs with correct profile information when user is in 0 groups', () => { | ||
setupTest([]); | ||
|
||
testStaticElements(); | ||
|
||
const groupInfo = screen.getByText(/belong to/); | ||
expect(groupInfo).toHaveProperty( | ||
'innerHTML', | ||
'<b>user1</b> does not belong to any groups.', | ||
); | ||
}); | ||
|
||
test('renders AccountTabs with correct profile information when user is in 1 group', () => { | ||
setupTest('group-one'); | ||
|
||
testStaticElements(); | ||
|
||
const groupInfo = screen.getByText(/belongs to/); | ||
expect(groupInfo).toHaveProperty( | ||
'innerHTML', | ||
'<b>user1</b> belongs to <b>group-one</b> group.', | ||
); | ||
}); | ||
|
||
test('renders AccountTabs with correct profile information when user is in 2 groups', () => { | ||
setupTest(['first-group', 'second-group']); | ||
|
||
testStaticElements(); | ||
|
||
const groupInfo = screen.getByText(/belongs to/); | ||
expect(groupInfo).toHaveProperty( | ||
'innerHTML', | ||
'<b>user1</b> belongs to <b>first-group</b> and <b>second-group</b> groups.', | ||
); | ||
}); | ||
|
||
test('renders AccountTabs with correct profile information when user is in 3 groups', () => { | ||
setupTest(['group1', 'group2', 'group3']); | ||
|
||
testStaticElements(); | ||
|
||
const groupInfo = screen.getByText(/belongs to/); | ||
expect(groupInfo).toHaveProperty( | ||
'innerHTML', | ||
'<b>user1</b> belongs to <b>group1</b>, <b>group2</b> and <b>group3</b> groups.', | ||
); | ||
}); | ||
|
||
test('renders AccountTabs with correct profile information when user is in more than 3 groups', () => { | ||
setupTest(['g1', 'g2', 'g3', 'g4', 'g5']); | ||
|
||
testStaticElements(); | ||
|
||
const groupInfo = screen.getByText(/belongs to/); | ||
expect(groupInfo).toHaveProperty( | ||
'innerHTML', | ||
'<b>user1</b> belongs to <b>g1</b>, <b>g2</b>, <b>g3</b>, <b>g4</b> and <b>g5</b> groups.', | ||
); | ||
}); | ||
}); |
Oops, something went wrong.