-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
155 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
import { userSession } from '../../utils/testUtil'; | ||
|
||
const client = jest.genMockFromModule('next-auth/client'); | ||
|
||
const useSession = jest.fn(() => [ | ||
{ | ||
user: { | ||
name: 'Test User', | ||
email: '[email protected]', | ||
groups: [{ | ||
id: 'abcd1234', name: 'Test Group', ownerName: 'Test User', memberCount: 2, role: 'owner', | ||
}], | ||
role: 'user', | ||
}, | ||
expires: '2881-10-05T14:48:00.000', | ||
}, | ||
userSession, | ||
false]); | ||
|
||
client.useSession = useSession; | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import { render, wait } from '@testing-library/react'; | ||
import EditGroup from '../../../pages/groups/[id]/edit'; | ||
import { group } from '../../../utils/testUtil'; | ||
|
||
|
||
jest.mock('next/router', () => ({ | ||
|
@@ -17,18 +18,6 @@ jest.mock('next/router', () => ({ | |
})); | ||
|
||
describe('Group Edit Page', () => { | ||
const group = { | ||
id: 'abcd1234', | ||
name: 'Test Group', | ||
members: [{ | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
role: 'owner', | ||
}], | ||
inviteUrl: '', | ||
}; | ||
|
||
it('renders group card', async () => { | ||
const { getByTestId } = render(<EditGroup group={group} />); | ||
const cardBody = getByTestId('groupedit-card-body'); | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import { render, wait } from '@testing-library/react'; | ||
import ViewGroup from '../../../pages/groups/[id]/index'; | ||
import { group } from '../../../utils/testUtil'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
|
@@ -16,17 +17,6 @@ jest.mock('next/router', () => ({ | |
})); | ||
|
||
describe('Group View Page', () => { | ||
const group = { | ||
id: 'abcd1234', | ||
name: 'Test Group', | ||
members: [{ | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
role: 'owner', | ||
}], | ||
}; | ||
|
||
it('renders group card', async () => { | ||
const { getByTestId } = render(<ViewGroup group={group} />); | ||
const cardBody = getByTestId('groupview-card-body'); | ||
|
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import { render, wait } from '@testing-library/react'; | ||
import EditProfile from '../../pages/user/[slug]/editprofile'; | ||
import { user } from '../../utils/testUtil'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter() { | ||
|
@@ -16,44 +17,23 @@ jest.mock('next/router', () => ({ | |
})); | ||
|
||
test('renders edit profile card', async () => { | ||
const { getAllByText } = render(<EditProfile user={{ | ||
name: 'Test User', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
affiliation: 'Jest Tests', | ||
}} | ||
/>); | ||
const { getAllByText } = render(<EditProfile user={user} />); | ||
const textElements = getAllByText(/Edit Profile/); | ||
await wait(() => { | ||
expect(textElements[1]).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('renders edit profile form', async () => { | ||
const { getAllByRole } = render(<EditProfile user={{ | ||
name: 'Test User', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
affiliation: 'Jest Tests', | ||
}} | ||
/>); | ||
const { getAllByRole } = render(<EditProfile user={user} />); | ||
const textboxElements = getAllByRole('textbox'); | ||
await wait(() => { | ||
expect(textboxElements).toHaveLength(4); | ||
}); | ||
}); | ||
|
||
test('renders submit button', async () => { | ||
const { getByTestId } = render(<EditProfile user={{ | ||
name: 'Test User', | ||
firstName: 'Test', | ||
lastName: 'User', | ||
email: '[email protected]', | ||
affiliation: 'Jest Tests', | ||
}} | ||
/>); | ||
const { getByTestId } = render(<EditProfile user={user} />); | ||
const submitButton = getByTestId('editprofile-submit-button'); | ||
await wait(() => { | ||
expect(submitButton).toBeInTheDocument(); | ||
|
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 |
---|---|---|
|
@@ -4,18 +4,7 @@ | |
|
||
import { render } from '@testing-library/react'; | ||
import AdminPanel from './AdminPanel'; | ||
|
||
const adminUserSession = { | ||
user: { | ||
name: 'Admin User', | ||
email: '[email protected]', | ||
groups: [{ | ||
id: 'abcd1234', name: 'Test Group', ownerName: 'Test User', memberCount: 2, role: 'owner', | ||
}], | ||
role: 'admin', | ||
}, | ||
expires: '2881-10-05T14:48:00.000', | ||
}; | ||
import { adminUserSession } from '../../../utils/testUtil'; | ||
|
||
test('renders admin panel', async () => { | ||
const { getByTestId } = render( | ||
|
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 |
---|---|---|
|
@@ -4,19 +4,7 @@ | |
|
||
import { render } from '@testing-library/react'; | ||
import AdminGroupTable from './AdminGroupTable'; | ||
|
||
const group = { | ||
id: 'abcd1234', | ||
name: 'Test Group', | ||
members: [{ | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
role: 'owner', | ||
}], | ||
createdAt: '2881-10-05T14:48:00.000', | ||
updatedAt: '2881-10-05T14:48:00.000', | ||
}; | ||
import { group } from '../../../../utils/testUtil'; | ||
|
||
test('renders admin group view', async () => { | ||
const { getByTestId } = render( | ||
|
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 |
---|---|---|
|
@@ -4,30 +4,10 @@ | |
|
||
import { render } from '@testing-library/react'; | ||
import DocumentForm from './DocumentForm'; | ||
import { document, userSession } from '../../utils/testUtil'; | ||
|
||
// Mock session | ||
const session = { | ||
user: { | ||
id: 'testestestest', | ||
name: 'Test User', | ||
email: '[email protected]', | ||
groups: [{ | ||
id: 'abcd1234', name: 'Test Group', ownerName: 'Test User', memberCount: 2, role: 'owner', | ||
}], | ||
}, | ||
expires: '2881-10-05T14:48:00.000', | ||
}; | ||
|
||
// Mock document | ||
const document = { | ||
_id: 'documenttestid', | ||
title: 'test', | ||
state: 'draft', | ||
contributors: [], | ||
createdAt: '2881-10-05T14:48:00.000', | ||
owner: 'testestestest', | ||
groups: [], | ||
}; | ||
const session = userSession; | ||
|
||
describe('document form', () => { | ||
test('renders with mode = new', 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
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 |
---|---|---|
|
@@ -5,18 +5,7 @@ | |
import { render } from '@testing-library/react'; | ||
import { Formik } from 'formik'; | ||
import DocumentStatusSelect from './DocumentStatusSelect'; | ||
|
||
// Mock document | ||
const values = { | ||
_id: 'documenttestid', | ||
title: 'test', | ||
contributors: [], | ||
createdAt: '2881-10-05T14:48:00.000', | ||
state: 'draft', | ||
owner: 'testestestest', | ||
groups: [], | ||
}; | ||
|
||
import { document, userSession } from '../../utils/testUtil'; | ||
|
||
describe('document status select', () => { | ||
test('renders with jest context and mocked values', async () => { | ||
|
@@ -25,20 +14,10 @@ describe('document status select', () => { | |
{(props) => ( | ||
<form onSubmit={props.handleSubmit}> | ||
<DocumentStatusSelect | ||
values={values} | ||
values={document} | ||
onChange={props.handleChange} | ||
onBlur={props.handleBlur} | ||
session={{ | ||
user: { | ||
name: 'Test User', | ||
email: '[email protected]', | ||
groups: [{ | ||
id: 'abcd1234', name: 'Test Group', ownerName: 'Test User', memberCount: 2, role: 'owner', | ||
}], | ||
role: 'user', | ||
}, | ||
expires: '2881-10-05T14:48:00.000', | ||
}} | ||
session={userSession} | ||
/> | ||
</form> | ||
)} | ||
|
Oops, something went wrong.