-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
ffb345b
commit 037ad53
Showing
6 changed files
with
83 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import DraftPageRedux from '.'; | ||
import { renderWithRouterRedux } from '../../testUtils/reduxRender'; | ||
|
||
describe('<DraftsPage />', () => { | ||
it('renders without crashing', () => { | ||
renderWithRouterRedux(<DraftPageRedux />); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* eslint-disable no-return-assign */ | ||
/* eslint-disable no-console */ | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { RootState } from '../../reducers'; | ||
import { blankNotes, blankReview } from '../../templates'; | ||
import { getBlankInitialState, renderWithRouterRedux } from '../../testUtils/reduxRender'; | ||
import DraftsRedux from './Drafts-redux'; | ||
|
||
const mockGoBack = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
...(jest.requireActual('react-router-dom') as any), | ||
useHistory: () => ({ | ||
goBack: mockGoBack, | ||
}), | ||
})); | ||
|
||
const initialStateWithDrafts: RootState = { | ||
...getBlankInitialState(), | ||
drafts: [{ ...blankReview, _id: 'id', notes: { ...blankNotes, tldr: 'it was nice' } }], | ||
}; | ||
|
||
describe('<Drafts />', () => { | ||
describe('on back', () => { | ||
it('goes back to the previous page', () => { | ||
renderWithRouterRedux(<DraftsRedux />); | ||
const backButton = screen.getByLabelText('Back'); | ||
userEvent.click(backButton); | ||
expect(mockGoBack).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('drafts table', () => { | ||
// This is silly, but the react-katex library throws an ugly warning: https://github.com/talyssonoc/react-katex/issues/59 | ||
// so we'll just suppress it :) | ||
const originalConsoleWarn = console.warn; | ||
beforeAll(() => (console.warn = jest.fn())); | ||
afterAll(() => (console.warn = originalConsoleWarn)); | ||
|
||
it('renders without crashing', () => { | ||
// eslint-disable-next-line react/react-in-jsx-scope | ||
renderWithRouterRedux(<DraftsRedux />); | ||
}); | ||
|
||
it('renders the draft information in the table', () => { | ||
renderWithRouterRedux(<DraftsRedux />, { initialState: initialStateWithDrafts }); | ||
expect(screen.getByText(/it was nice/)).toBeDefined(); | ||
}); | ||
|
||
it('displays more options and actions when user clicks on a draft', () => { | ||
renderWithRouterRedux(<DraftsRedux />, { initialState: initialStateWithDrafts }); | ||
const draftRow = screen.getByText(/it was nice/); | ||
userEvent.click(draftRow); | ||
expect(screen.getByText(/Delete this Draft/)).toBeDefined(); | ||
}); | ||
}); | ||
}); |
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