|
| 1 | +import { Query } from '@cucumber/query' |
| 2 | +import { userEvent } from '@testing-library/user-event' |
| 3 | +import { expect } from 'chai' |
| 4 | +import React from 'react' |
| 5 | + |
| 6 | +import hooksSample from '../../../acceptance/hooks/hooks.js' |
| 7 | +import hooksConditionalSample from '../../../acceptance/hooks-conditional/hooks-conditional.js' |
| 8 | +import hooksSkippedSample from '../../../acceptance/hooks-skipped/hooks-skipped.js' |
| 9 | +import { render } from '../../../test-utils/index.js' |
| 10 | +import { EnvelopesProvider } from '../app/index.js' |
| 11 | +import { TestCaseOutcome } from './TestCaseOutcome.js' |
| 12 | + |
| 13 | +describe('TestCaseOutcome', () => { |
| 14 | + it('should hide successful hooks by default, then show them on request', async () => { |
| 15 | + const cucumberQuery = new Query() |
| 16 | + hooksSample.forEach((envelope) => cucumberQuery.update(envelope)) |
| 17 | + const [testCaseStarted] = cucumberQuery.findAllTestCaseStarted() |
| 18 | + |
| 19 | + const { getByRole, getAllByRole, getByText, queryByRole, queryByText } = render( |
| 20 | + <EnvelopesProvider envelopes={hooksSample}> |
| 21 | + <TestCaseOutcome testCaseStarted={testCaseStarted} /> |
| 22 | + </EnvelopesProvider> |
| 23 | + ) |
| 24 | + |
| 25 | + expect(getAllByRole('listitem')).to.have.lengthOf(1) |
| 26 | + expect(queryByText('Before')).not.to.exist |
| 27 | + expect(getByText('a step passes')).to.be.visible |
| 28 | + expect(queryByText('After')).not.to.exist |
| 29 | + expect(getByRole('button', { name: '2 hooks' })).to.be.visible |
| 30 | + |
| 31 | + await userEvent.click(getByRole('button', { name: '2 hooks' })) |
| 32 | + |
| 33 | + expect(getAllByRole('listitem')).to.have.lengthOf(3) |
| 34 | + expect(getByText('Before')).to.be.visible |
| 35 | + expect(getByText('a step passes')).to.be.visible |
| 36 | + expect(getByText('After')).to.be.visible |
| 37 | + expect(queryByRole('button', { name: /hooks/ })).not.to.exist |
| 38 | + }) |
| 39 | + |
| 40 | + it('should always show failed hooks', () => { |
| 41 | + const cucumberQuery = new Query() |
| 42 | + hooksConditionalSample.forEach((envelope) => cucumberQuery.update(envelope)) |
| 43 | + const [testCaseStarted] = cucumberQuery.findAllTestCaseStarted() |
| 44 | + |
| 45 | + const { getAllByRole, getByText, queryByRole } = render( |
| 46 | + <EnvelopesProvider envelopes={hooksConditionalSample}> |
| 47 | + <TestCaseOutcome testCaseStarted={testCaseStarted} /> |
| 48 | + </EnvelopesProvider> |
| 49 | + ) |
| 50 | + |
| 51 | + expect(getAllByRole('listitem')).to.have.lengthOf(2) |
| 52 | + expect(getByText('Before')).to.be.visible |
| 53 | + expect(getByText('a step passes')).to.be.visible |
| 54 | + expect(queryByRole('button', { name: /hooks/ })).not.to.exist |
| 55 | + }) |
| 56 | + |
| 57 | + it('should hide skipped hooks by default when they are not the skipper', () => { |
| 58 | + const cucumberQuery = new Query() |
| 59 | + hooksSkippedSample.forEach((envelope) => cucumberQuery.update(envelope)) |
| 60 | + const [skipFromStep] = cucumberQuery.findAllTestCaseStarted() |
| 61 | + |
| 62 | + const { getAllByRole, getByRole, getByText, queryByText } = render( |
| 63 | + <EnvelopesProvider envelopes={hooksSkippedSample}> |
| 64 | + <TestCaseOutcome testCaseStarted={skipFromStep} /> |
| 65 | + </EnvelopesProvider> |
| 66 | + ) |
| 67 | + |
| 68 | + expect(getAllByRole('listitem')).to.have.lengthOf(1) |
| 69 | + expect(queryByText('Before')).not.to.exist |
| 70 | + expect(getByText('a step that skips')).to.be.visible |
| 71 | + expect(queryByText('After')).not.to.exist |
| 72 | + expect(getByRole('button', { name: '4 hooks' })).to.be.visible |
| 73 | + }) |
| 74 | + |
| 75 | + it('should show skipped hooks by default when they are the skipper', () => { |
| 76 | + const cucumberQuery = new Query() |
| 77 | + hooksSkippedSample.forEach((envelope) => cucumberQuery.update(envelope)) |
| 78 | + const [, skipFromBefore] = cucumberQuery.findAllTestCaseStarted() |
| 79 | + |
| 80 | + const { getAllByRole, getAllByText, getByRole, getByText } = render( |
| 81 | + <EnvelopesProvider envelopes={hooksSkippedSample}> |
| 82 | + <TestCaseOutcome testCaseStarted={skipFromBefore} /> |
| 83 | + </EnvelopesProvider> |
| 84 | + ) |
| 85 | + |
| 86 | + expect(getAllByRole('listitem')).to.have.lengthOf(2) |
| 87 | + expect(getAllByText('Before')).to.have.lengthOf(1) |
| 88 | + expect(getByText('a normal step')).to.be.visible |
| 89 | + expect(getByRole('button', { name: '4 hooks' })).to.be.visible |
| 90 | + }) |
| 91 | +}) |
0 commit comments