Skip to content

Commit

Permalink
Improve Frontend Tests (#3795)
Browse files Browse the repository at this point in the history
* update SignInPage tests

* update TopBanner tests

* update FloatingMenu tests

* update SuperAdminUserList tests

* update UserListModal tests

* update removeUser tests in UserListModal

* update TwoFactorAuthenticatePage tests

* unskip AdminPage tests

* unskip UserPage tests

* trigger cloudbuild
  • Loading branch information
lcampbell2 committed Jun 9, 2022
1 parent 7995abb commit 07a8250
Show file tree
Hide file tree
Showing 14 changed files with 1,299 additions and 61 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"webpack": "webpack",
"start": "NODE_OPTIONS=--openssl-legacy-provider node index.js",
"test": "jest",
"test-coverage": "jest --coverage",
"lint": "eslint src",
"dbg": "node --inspect-brk node_modules/.bin/jest --runInBand --no-cache",
"extract": "lingui extract",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/admin/AdminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ export default function AdminPage({ isLoginRequired }) {
)

let adminPanel
if (activeMenu === 'organizations') {
adminPanel = orgPanel
} else if (activeMenu === 'users' && data?.isUserSuperAdmin) {
if (activeMenu === 'users' && data?.isUserSuperAdmin) {
adminPanel = (
<SuperAdminUserList
permission={data?.isUserSuperAdmin ? 'SUPER_ADMIN' : 'ADMIN'}
/>
)
} else {
adminPanel = orgPanel
}

return (
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/admin/SuperAdminUserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export function SuperAdminUserList({ permission }) {
onClick={() => {
setMutation('remove')
onOpen()
console.log(`Removed user from org ${orgName}`)
}}
p="2"
icon={<MinusIcon />}
Expand All @@ -236,7 +235,6 @@ export function SuperAdminUserList({ permission }) {
onClick={() => {
setMutation('update')
onOpen()
console.log(`Edit user in org ${orgName}`)
}}
p="2"
icon={<EditIcon />}
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/admin/UserListModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export function UserListModal({
isClosable: true,
position: 'top-left',
})
console.log('Incorrect inviteUserToOrg.result typename.')
}
},
},
Expand Down Expand Up @@ -134,7 +133,6 @@ export function UserListModal({
isClosable: true,
position: 'top-left',
})
console.log('Incorrect updateUserRole.result typename.')
}
},
})
Expand Down
15 changes: 5 additions & 10 deletions frontend/src/admin/__tests__/AdminPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { I18nProvider } from '@lingui/react'
import { setupI18n } from '@lingui/core'
import { MockedProvider } from '@apollo/client/testing'
import AdminPage from '../AdminPage'
import { waitFor, render, fireEvent } from '@testing-library/react'
import { waitFor, render } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { makeVar } from '@apollo/client'
import { en } from 'make-plural/plurals'
Expand All @@ -29,8 +29,8 @@ const i18n = setupI18n({
})

describe('<AdminPage />', () => {
it.skip('shows a list of the users organizations', async () => {
const { getByText, getByLabelText } = render(
it('shows a list of the users organizations', async () => {
const { getByText } = render(
<MockedProvider mocks={mocks()} addTypename={false}>
<UserVarProvider
userVar={makeVar({ jwt: null, tfaSendMethod: null, userName: null })}
Expand All @@ -49,18 +49,13 @@ describe('<AdminPage />', () => {
</MockedProvider>,
)

await waitFor(() => {
const saMenu = getByLabelText(/Menu/i)
fireEvent.change(saMenu, { target: { value: 'organizations' } })
})

await waitFor(() => {
const welcome = getByText(/Select an organization to view admin options/i)
expect(welcome).toBeInTheDocument()
})
})

it.skip('displays info for admin', async () => {
it('displays info for admin', async () => {
const { getByText, findByRole } = render(
<MockedProvider mocks={mocks()} addTypename={false}>
<UserVarProvider
Expand Down Expand Up @@ -97,7 +92,7 @@ describe('<AdminPage />', () => {
})
})

it.skip('filters organization list', async () => {
it('filters organization list', async () => {
const { getByText, queryByText, findByRole } = render(
<MockedProvider mocks={mocks()} addTypename={false}>
<UserVarProvider
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/admin/__tests__/SuperAdminUserList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ describe('<SuperAdminUserList />', () => {
})

describe('admin abilities', () => {
it.skip("edit user's role in org", async () => {
const { queryByText, getByRole } = render(
it("edit user's role in org", async () => {
const { queryByText, getByRole, queryAllByText } = render(
<MockedProvider mocks={successMocks} cache={createCache()}>
<UserVarProvider
userVar={makeVar({
Expand Down Expand Up @@ -318,10 +318,10 @@ describe('<SuperAdminUserList />', () => {
name: 'Edit Raegan.Ritchie50@yahoo.com in Kreiger - Schamberger',
})
fireEvent.click(editBtn)
await waitFor(() => expect(queryByText(/Edit User/i)))
await waitFor(() => expect(queryAllByText(/Edit User/i)))
})
it.skip('remove user from org', async () => {
const { queryByText, getByRole } = render(
it('remove user from org', async () => {
const { queryByText, getByRole, queryAllByText } = render(
<MockedProvider mocks={successMocks} cache={createCache()}>
<UserVarProvider
userVar={makeVar({
Expand Down Expand Up @@ -356,7 +356,7 @@ describe('<SuperAdminUserList />', () => {
name: 'Remove Raegan.Ritchie50@yahoo.com from Kreiger - Schamberger',
})
fireEvent.click(removeBtn)
await waitFor(() => expect(queryByText(/Remove User/i)))
await waitFor(() => expect(queryAllByText(/Remove User/i)))
})
})
})
Expand Down
Loading

0 comments on commit 07a8250

Please sign in to comment.