|
1 |
| -import { TestStepResultStatus, TimeConversion } from '@cucumber/messages' |
| 1 | +import { Meta } from '@cucumber/messages' |
2 | 2 | import { render } from '@testing-library/react'
|
3 | 3 | import { expect } from 'chai'
|
4 |
| -import { add, addMilliseconds } from 'date-fns' |
5 | 4 | import React from 'react'
|
6 | 5 |
|
7 |
| -import { makeEmptyScenarioCountsByStatus } from '../../countScenariosByStatuses.js' |
8 |
| -import { ExecutionSummary, IExecutionSummaryProps } from './ExecutionSummary.js' |
9 |
| - |
10 |
| -const startDate = new Date(1639753096000) |
11 |
| -const finishDate = new Date(1639753197000) |
12 |
| - |
13 |
| -const scenarioCountByStatus = { |
14 |
| - ...makeEmptyScenarioCountsByStatus(), |
15 |
| - ...{ |
16 |
| - [TestStepResultStatus.PASSED]: 100, |
17 |
| - [TestStepResultStatus.FAILED]: 3, |
18 |
| - [TestStepResultStatus.UNDEFINED]: 1, |
19 |
| - }, |
20 |
| -} |
21 |
| - |
22 |
| -const DEFAULT_PROPS: IExecutionSummaryProps = { |
23 |
| - scenarioCountByStatus, |
24 |
| - totalScenarioCount: 104, |
25 |
| - testRunStarted: { |
26 |
| - timestamp: TimeConversion.millisecondsSinceEpochToTimestamp(startDate.getTime()), |
27 |
| - }, |
28 |
| - testRunFinished: { |
29 |
| - timestamp: TimeConversion.millisecondsSinceEpochToTimestamp(finishDate.getTime()), |
30 |
| - success: false, |
31 |
| - }, |
32 |
| - meta: { |
33 |
| - protocolVersion: '17.1.1', |
34 |
| - implementation: { version: '8.0.0-rc.1', name: 'cucumber-js' }, |
35 |
| - cpu: { name: 'x64' }, |
36 |
| - os: { name: 'linux', version: '5.11.0-1022-azure' }, |
37 |
| - runtime: { name: 'node.js', version: '16.13.1' }, |
38 |
| - ci: { |
39 |
| - name: 'GitHub Actions', |
40 |
| - url: 'https://github.com/cucumber/cucumber-js/actions/runs/1592557391', |
41 |
| - buildNumber: '1592557391', |
42 |
| - git: { |
43 |
| - revision: 'b53d820504b31c8e4d44234dc5eaa58d6b7fdd4c', |
44 |
| - remote: 'https://github.com/cucumber/cucumber-js.git', |
45 |
| - branch: 'main', |
46 |
| - }, |
| 6 | +import examplesTablesFeature from '../../../acceptance/examples-tables/examples-tables.feature.js' |
| 7 | +import { EnvelopesWrapper } from './EnvelopesWrapper.js' |
| 8 | +import { ExecutionSummary } from './ExecutionSummary.js' |
| 9 | + |
| 10 | +const meta: Meta = { |
| 11 | + protocolVersion: '17.1.1', |
| 12 | + implementation: { version: '8.0.0-rc.1', name: 'cucumber-js' }, |
| 13 | + cpu: { name: 'x64' }, |
| 14 | + os: { name: 'linux', version: '5.11.0-1022-azure' }, |
| 15 | + runtime: { name: 'node.js', version: '16.13.1' }, |
| 16 | + ci: { |
| 17 | + name: 'GitHub Actions', |
| 18 | + url: 'https://github.com/cucumber/cucumber-js/actions/runs/1592557391', |
| 19 | + buildNumber: '1592557391', |
| 20 | + git: { |
| 21 | + revision: 'b53d820504b31c8e4d44234dc5eaa58d6b7fdd4c', |
| 22 | + remote: 'https://github.com/cucumber/cucumber-js.git', |
| 23 | + branch: 'main', |
47 | 24 | },
|
48 | 25 | },
|
49 | 26 | }
|
50 | 27 |
|
51 | 28 | describe('ExecutionSummary', () => {
|
52 |
| - describe('last run date/time', () => { |
53 |
| - const examples: [text: string, referenceDate: Date][] = [ |
54 |
| - ['1 hour ago', add(startDate, { hours: 1 })], |
55 |
| - ['3 hours ago', add(startDate, { hours: 3, minutes: 24, seconds: 18 })], |
56 |
| - ['1 day ago', add(startDate, { days: 1, hours: 3, minutes: 24, seconds: 18 })], |
57 |
| - ['15 days ago', add(startDate, { weeks: 2, days: 1 })], |
58 |
| - ] |
59 |
| - |
60 |
| - for (const [text, referenceDate] of examples) { |
61 |
| - it(`should render correctly for ${text}`, () => { |
62 |
| - const { getByText } = render( |
63 |
| - <ExecutionSummary {...DEFAULT_PROPS} referenceDate={referenceDate} /> |
64 |
| - ) |
65 |
| - |
66 |
| - expect(getByText(text)).to.be.visible |
67 |
| - expect(getByText('last run')).to.be.visible |
68 |
| - }) |
69 |
| - } |
70 |
| - }) |
71 |
| - |
72 |
| - describe('run duration', () => { |
73 |
| - const examples: [text: string, finishDate: Date][] = [ |
74 |
| - ['1 hour 45 minutes 23 seconds', add(startDate, { hours: 1, minutes: 45, seconds: 23 })], |
75 |
| - ['12 minutes 15 seconds', add(startDate, { minutes: 12, seconds: 15 })], |
76 |
| - ['10 seconds', add(startDate, { seconds: 10.01 })], |
77 |
| - ['9.88 seconds', addMilliseconds(startDate, 9876)], |
78 |
| - ['6.54 seconds', addMilliseconds(startDate, 6543)], |
79 |
| - ] |
80 |
| - |
81 |
| - for (const [text, finishDate] of examples) { |
82 |
| - it(`should render correctly for ${text}`, () => { |
83 |
| - const { getByText } = render( |
84 |
| - <ExecutionSummary |
85 |
| - {...DEFAULT_PROPS} |
86 |
| - testRunFinished={{ |
87 |
| - timestamp: TimeConversion.millisecondsSinceEpochToTimestamp(finishDate.getTime()), |
88 |
| - success: false, |
89 |
| - }} |
90 |
| - /> |
91 |
| - ) |
92 |
| - |
93 |
| - expect(getByText(text)).to.be.visible |
94 |
| - expect(getByText('duration')).to.be.visible |
95 |
| - }) |
96 |
| - } |
97 |
| - }) |
98 |
| - |
99 |
| - describe('passed rate', () => { |
100 |
| - const examples: [passed: number, total: number, percentage: string][] = [ |
101 |
| - [13, 45, '29%'], |
102 |
| - [5, 45, '11%'], |
103 |
| - [45, 45, '100%'], |
104 |
| - [0, 45, '0%'], |
105 |
| - [0, 0, '0%'], |
106 |
| - ] |
107 |
| - |
108 |
| - for (const [passed, total, percentage] of examples) { |
109 |
| - it(`should render correctly for ${percentage} passed`, () => { |
110 |
| - const { getByText } = render( |
111 |
| - <ExecutionSummary |
112 |
| - {...DEFAULT_PROPS} |
113 |
| - scenarioCountByStatus={{ |
114 |
| - ...makeEmptyScenarioCountsByStatus(), |
115 |
| - [TestStepResultStatus.PASSED]: passed, |
116 |
| - }} |
117 |
| - totalScenarioCount={total} |
118 |
| - /> |
119 |
| - ) |
120 |
| - |
121 |
| - expect(getByText(`${percentage} passed`)).to.be.visible |
122 |
| - expect(getByText(`${total} executed`)).to.be.visible |
123 |
| - }) |
124 |
| - } |
125 |
| - }) |
| 29 | + const envelopes = [...examplesTablesFeature, { meta }] |
126 | 30 |
|
127 | 31 | describe('meta', () => {
|
128 | 32 | it('should include the implementation name and version', () => {
|
129 |
| - const { getByText } = render(<ExecutionSummary {...DEFAULT_PROPS} />) |
| 33 | + const { getByText } = render( |
| 34 | + <EnvelopesWrapper envelopes={envelopes}> |
| 35 | + <ExecutionSummary /> |
| 36 | + </EnvelopesWrapper> |
| 37 | + ) |
130 | 38 |
|
131 | 39 | expect(getByText('cucumber-js 8.0.0-rc.1')).to.be.visible
|
132 | 40 | })
|
| 41 | + |
133 | 42 | it('should include the job link', () => {
|
134 |
| - const { getByText } = render(<ExecutionSummary {...DEFAULT_PROPS} />) |
135 |
| - const jobLinkElement = getByText(DEFAULT_PROPS.meta?.ci?.buildNumber as string) |
| 43 | + const { getByText } = render( |
| 44 | + <EnvelopesWrapper envelopes={envelopes}> |
| 45 | + <ExecutionSummary /> |
| 46 | + </EnvelopesWrapper> |
| 47 | + ) |
| 48 | + |
| 49 | + const jobLinkElement = getByText(meta?.ci?.buildNumber as string) |
136 | 50 | expect(jobLinkElement).to.be.visible
|
137 |
| - expect(jobLinkElement.getAttribute('href')).to.eq(DEFAULT_PROPS.meta?.ci?.url) |
| 51 | + expect(jobLinkElement.getAttribute('href')).to.eq(meta?.ci?.url) |
138 | 52 | })
|
139 | 53 | })
|
140 | 54 | })
|
0 commit comments