Skip to content

Commit

Permalink
Update AfterLogin.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
FeimeiChen committed Apr 17, 2024
1 parent 6f1e89e commit 883c142
Showing 1 changed file with 30 additions and 41 deletions.
71 changes: 30 additions & 41 deletions ui/tests/app/(index)/_components/AfterLogin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,30 @@ import { render, screen } from '@testing-library/react';
import AfterLogin from '@/app/(index)/_components/AfterLogin';
import User from '@/access/User';

const testUser: User = JSON.parse(process.env.TEST_USER_A as string);
describe('AfterLogin', () => {
const numberOfGroupings = 18
const numberOfMemberships = 17
const Admin: User = {
name: '',
firstName: 'John',
lastName: '',
uid: '',
uhUuid: '',
roles: [Role.UH, Role.OWNER, Role.ADMIN] as const

const admin: User = {
...testUser,
roles:[Role.UH, Role.OWNER,Role.ADMIN] as const

}

const Owner: User = {
name: '',
firstName: 'John',
lastName: '',
uid: '',
uhUuid: '',
const owner: User = {
...testUser,
roles: [Role.UH, Role.OWNER] as const
}

const UHUser: User = {
name: '',
firstName: 'John',
lastName: '',
uid: '',
uhUuid: '',
const uhUser: User = {
...testUser,
roles: [Role.UH] as const
}

const getHighestRole = (user: User) => {
const isAdmin = user.roles.includes(Role.ADMIN);
const isOwner = user.roles.includes(Role.OWNER);
if (isAdmin) return 'Admin';
else if (isOwner) return 'Owner';
if (user.roles.includes(Role.ADMIN)) return 'Admin';
else if (user.roles.includes(Role.OWNER)) return 'Owner';
else return 'Member';
}

Expand All @@ -58,13 +47,13 @@ describe('AfterLogin', () => {
expect(screen.getByRole('link', {name: 'Admin'})).toHaveAttribute('href', '/admin')
expect(screen.getByRole('button', {name: 'Admin'})).toBeInTheDocument()
} else {
expect(screen.queryByRole('img', {name: 'key-solid'})).toBeNull()
expect(screen.queryByText('0')).toBeNull()
expect(screen.queryByRole('heading', {name: 'Admin'})).toBeNull()
expect(screen.queryByRole('img', {name: 'key-solid'})).not.toBeInTheDocument()
expect(screen.queryByText('0')).not.toBeInTheDocument()
expect(screen.queryByRole('heading', {name: 'Admin'})).not.toBeInTheDocument()
expect(screen.queryByText('Manage the list of Administrators for this service. ' +
'Search for and manage any grouping on behalf of the owner.')).toBeNull()
expect(screen.queryByRole('link', {name: 'Admin'})).toBeNull()
expect(screen.queryByRole('button', {name: 'Admin'})).toBeNull()
'Search for and manage any grouping on behalf of the owner.')).not.toBeInTheDocument()
expect(screen.queryByRole('link', {name: 'Admin'})).not.toBeInTheDocument()
expect(screen.queryByRole('button', {name: 'Admin'})).not.toBeInTheDocument()


}
Expand All @@ -91,48 +80,48 @@ describe('AfterLogin', () => {
expect(screen.getByRole('link', {name: 'Groupings'})).toHaveAttribute('href', '/groupings')
expect(screen.getByRole('button', {name: 'Groupings'})).toBeInTheDocument()
} else {
expect(screen.queryByRole('img', {name: 'wrench-solid'})).toBeNull()
expect(screen.queryByText(numberOfGroupings)).toBeNull()
expect(screen.queryByRole('heading', {name: 'Groupings'})).toBeNull()
expect(screen.queryByRole('img', {name: 'wrench-solid'})).not.toBeInTheDocument()
expect(screen.queryByText(numberOfGroupings)).not.toBeInTheDocument()
expect(screen.queryByRole('heading', {name: 'Groupings'})).not.toBeInTheDocument()
expect(screen.queryByText('Review members, manage Include and Exclude lists, ' +
'configure preferences, and export members.')).toBeNull()
expect(screen.queryByRole('link', {name: 'Groupings'})).toBeNull()
expect(screen.queryByRole('button', {name: 'Groupings'})).toBeNull()
'configure preferences, and export members.')).not.toBeInTheDocument()
expect(screen.queryByRole('link', {name: 'Groupings'})).not.toBeInTheDocument()
expect(screen.queryByRole('button', {name: 'Groupings'})).not.toBeInTheDocument()
}

}

it('Should render correctly when logged in as an admin', () => {
render(
<AfterLogin
currentUser={Admin}
currentUser={admin}
numberOfGroupings={numberOfGroupings}
numberOfMemberships={numberOfMemberships}
/>
);
Welcome(Admin);
Welcome(admin);
Administration(true)
Memberships();
Groupings(true);
});

it('Should render correctly when logged in as Owner', () => {
render(<AfterLogin
currentUser={Owner}
currentUser={owner}
numberOfGroupings={numberOfGroupings}
numberOfMemberships={numberOfMemberships}/>)
Welcome(Owner)
Welcome(owner)
Administration(false)
Memberships();
Groupings(true);
})

it('Should render correctly when logged in as a user with a UH account', () => {
render(<AfterLogin
currentUser={UHUser}
currentUser={uhUser}
numberOfGroupings={0}
numberOfMemberships={numberOfMemberships}/>)
Welcome(UHUser);
Welcome(uhUser);
Administration(false)
Memberships()
Groupings(false)
Expand Down

0 comments on commit 883c142

Please sign in to comment.