Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor progress bar tests #451

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 32 additions & 20 deletions src/Components/IssuesControl.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,39 @@ describe('IssueControl', () => {
})

// XXX: Should this be split into two different tests?
it('test Loader is present if issues are null, and removed when issues set', async () => {
// Set up handler to return an empty set of issues
server.use(
rest.get('https://api.github.com/repos/:org/:repo/issues', (req, res, ctx) => {
return res(
ctx.json(MOCK_ISSUES_EMPTY),
)
}),
)

const {getByRole, queryByRole} = render(<ShareMock><Issues/></ShareMock>)
expect(getByRole('progressbar')).toBeInTheDocument()

// Restore the original set of HTTP handlers that return issues
server.restoreHandlers()
const {result} = renderHook(() => useStore((state) => state))
await act(() => {
result.current.setIssues(MOCK_ISSUES)
describe('when issues are null', () => {
beforeEach(() => {
// Set up handler to return an empty set of issues
server.use(
rest.get('https://api.github.com/repos/:org/:repo/issues', (req, res, ctx) => {
return res(
ctx.json(MOCK_ISSUES_EMPTY),
)
}),
)
})

afterEach(() => {
// Restore the original set of HTTP handlers that return issues
server.restoreHandlers()
})

it('progress bar is present during loading of issues', () => {
const {getByRole} = render(<ShareMock><Issues/></ShareMock>)
expect(getByRole('progressbar')).toBeInTheDocument()
})

it('progress bar is no longer visible when issues are not-null', async () => {
const {queryByRole} = render(<ShareMock><Issues/></ShareMock>)

const {result} = renderHook(() => useStore((state) => state))
await act(() => {
result.current.setIssues(MOCK_ISSUES)
})

// queryByRole is used to not throw an error is the element is missing.
expect(queryByRole('progressbar')).not.toBeInTheDocument()
})
// queryByRole is used to not throw an error is the element is missing.
expect(queryByRole('progressbar')).not.toBeInTheDocument()
})
})

Expand Down