Skip to content

Commit

Permalink
Merge pull request #92 from mitaai/blms/tests
Browse files Browse the repository at this point in the history
#17 More tests
  • Loading branch information
blms authored Nov 19, 2020
2 parents 7582d2f + 74a2df1 commit cabe7e4
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/Admin/User/AdminUserTable/AdminUserTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ const AdminUserTable = ({
size="sm"
variant="light"
style={{ borderCollapse: 'unset' }}
data-testid="admin-user-view"
>
<thead>
<tr>
<td colSpan="2" className="text-center">View User</td>
<div style={{ position: 'absolute', right: '2em' }} id="user-dropdown">
<td style={{ position: 'absolute', right: '2em', border: 'none' }} id="user-dropdown">
<DropdownButton
size="sm"
variant="text"
drop="down"
menuAlign="right"
title="Actions"
>
<Dropdown.Item eventKey="1" href={`/user/${user.slug}/editprofile`}>Modify user</Dropdown.Item>
Expand All @@ -102,7 +102,7 @@ const AdminUserTable = ({
</>
)}
</DropdownButton>
</div>
</td>
</tr>
</thead>
<tbody>
Expand Down
20 changes: 20 additions & 0 deletions src/components/Admin/User/AdminUserTable/AdminUserTable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import AdminUserTable from './AdminUserTable';
import { user } from '../../../../utils/testUtil';

test('renders admin user view', async () => {
const { getByTestId } = render(
<AdminUserTable
user={user}
setAlerts={jest.fn}
alerts={[]}
isSelf
/>,
);
const userTable = getByTestId('admin-user-view');
expect(userTable).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const DashboardAnnotationList = ({
}, [annotations]);

return (
<Card>
<Card data-testid="dash-annotation-list">
<Card.Header>
<Card.Title>
{mode === 'dashboard' && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import DashboardAnnotationList from './DashboardAnnotationList';
import { userSession } from '../../../utils/testUtil';

test('renders dashboard annotation list', async () => {
const { getByTestId } = render(
<DashboardAnnotationList
session={userSession}
alerts={[]}
setAlerts={jest.fn}
mode="dashboard"
/>,
);
const annotationList = getByTestId('dash-annotation-list');
expect(annotationList).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const DashboardDocumentList = ({
}, [documents, documentGroupState]);

return (
<Card>
<Card data-testid="dash-document-list">
<Card.Header>
<Card.Title><Link href="/documents">Documents</Link></Card.Title>
<Tabs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import DashboardDocumentList from './DashboardDocumentList';
import { userSession } from '../../../utils/testUtil';

test('renders dashboard document list', async () => {
const { getByTestId } = render(
<DashboardDocumentList
session={userSession}
alerts={[]}
setAlerts={jest.fn}
/>,
);
const documentList = getByTestId('dash-document-list');
expect(documentList).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DashboardGroupList = ({
}, [session]);

return (
<Card>
<Card data-testid="dash-group-list">
<Card.Header>
<Card.Title><Link href="/groups">Groups</Link></Card.Title>
</Card.Header>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import DashboardGroupList from './DashboardGroupList';
import { userSession } from '../../../utils/testUtil';

test('renders dashboard group list', async () => {
const { getByTestId } = render(
<DashboardGroupList
session={userSession}
/>,
);
const groupList = getByTestId('dash-group-list');
expect(groupList).toBeInTheDocument();
});
2 changes: 1 addition & 1 deletion src/components/SecondNavbar/SecondNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SecondNavbar = ({
docView,
}) => (
<>
<Navbar bg="light" variant="light" className="second-navbar">
<Navbar bg="light" variant="light" className="second-navbar" data-testid="second-navbar">
<Container>
<Row>
<Col sm={8}>
Expand Down
18 changes: 18 additions & 0 deletions src/components/SecondNavbar/SecondNavbar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import SecondNavbar from './SecondNavbar';
import { userSession } from '../../utils/testUtil';

test('renders second navbar with type = dashboard', async () => {
const { getByTestId } = render(
<SecondNavbar
session={userSession}
type="dashboard"
/>,
);
const navbar = getByTestId('second-navbar');
expect(navbar).toBeInTheDocument();
});
1 change: 1 addition & 0 deletions src/components/SlateToolbar/SlateToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const SlateToolbar = () => {
return (
<div
className="slate-toolbar"
data-testid="slate-toolbar"
>
<Dropdown>
<OverlayTrigger overlay={<Tooltip>Styles</Tooltip>}>
Expand Down
56 changes: 56 additions & 0 deletions src/components/SlateToolbar/SlateToolbar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import SlateToolbar from './SlateToolbar';

jest.mock('slate-react', () => ({
useSlate() {
return {};
},
}));

jest.mock('../../utils/slateUtil', () => ({
BlockButton() { return <div />; },
MarkButton() { return <div />; },
videoURLtoEmbedURL: jest.fn,
insertVideoEmbed: jest.fn,
}));

jest.mock('@udecode/slate-plugins', () => ({
ToolbarImage() { return <div />; },
ToolbarAlign() { return <div />; },
ToolbarButton() { return <div />; },
ToolbarList() { return <div />; },
ToolbarLink() { return <div />; },
isNodeTypeIn: jest.fn,
toggleNodeType: jest.fn,
DEFAULTS_ALIGN: {
align_left: { type: 'align_left' },
align_center: { type: 'align_center' },
align_right: { type: 'align_right' },
},
DEFAULTS_BLOCKQUOTE: { blockquote: { type: 'blockquote' } },
DEFAULTS_CODE_BLOCK: { code_block: { type: 'code_block' } },
DEFAULTS_HEADING: {
h1: { type: 'h1' },
h2: { type: 'h2' },
h3: { type: 'h3' },
h4: { type: 'h4' },
h5: { type: 'h5' },
h6: { type: 'h6' },
},
DEFAULTS_IMAGE: {},
DEFAULTS_LINK: {},
DEFAULTS_LIST: { ul: { type: 'ul' }, ol: { type: 'ol' } },
ELEMENT_MEDIA_EMBED: 'media_embed',
}));

test('renders slate toolbar', async () => {
const { getByTestId } = render(
<SlateToolbar />,
);
const toolbar = getByTestId('slate-toolbar');
expect(toolbar).toBeInTheDocument();
});
1 change: 0 additions & 1 deletion src/utils/testUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const userSession = {
expires: '2881-10-05T14:48:00.000',
};


export {
adminUserSession,
annotation,
Expand Down

0 comments on commit cabe7e4

Please sign in to comment.