Skip to content

Commit aa891fc

Browse files
committed
refactor spec file name into its own component
1 parent 82763cd commit aa891fc

File tree

8 files changed

+76
-121
lines changed

8 files changed

+76
-121
lines changed

packages/reporter/src/OpenFileInIDEButton.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/reporter/src/header/header.scss

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -164,43 +164,6 @@ $color-transition: color 150ms ease-out;
164164
align-items: center;
165165
flex: 1;
166166

167-
.runnable-header-file-name {
168-
display: inline-flex;
169-
align-items: center;
170-
flex: 1;
171-
min-width: 0;
172-
overflow: hidden;
173-
text-overflow: ellipsis;
174-
white-space: nowrap;
175-
position: relative;
176-
background: $gray-1100;
177-
178-
&:after {
179-
content: none;
180-
}
181-
182-
.spec-name {
183-
color: $white;
184-
font-weight: 500;
185-
}
186-
187-
.spec-file-extension {
188-
color: $gray-300;
189-
font-weight: 300;
190-
}
191-
192-
&:hover,
193-
&:focus-visible {
194-
.open-in-ide-button {
195-
opacity: 1;
196-
}
197-
198-
.button-hover-shadow {
199-
opacity: 1;
200-
}
201-
}
202-
}
203-
204167
span > span > a > svg {
205168
margin-bottom: -2px;
206169
margin-right: 8px;
@@ -219,7 +182,7 @@ $color-transition: color 150ms ease-out;
219182
}
220183
}
221184
}
222-
185+
223186
.toggle-specs-wrapper {
224187
.toggle-specs-button {
225188
padding: 0;

packages/reporter/src/runnables/runnable-header.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { observer } from 'mobx-react'
22
import React, { ReactElement } from 'react'
33

44
import type { StatsStore } from '../header/stats-store'
5-
import { getFilenameParts } from '../lib/util'
65
import { RunnablesStore } from './runnables-store'
76
import { DebugDismiss } from '../header/DebugDismiss'
8-
import { OpenFileInIDEButton } from '../header/OpenFileInIDEButton'
97
import { Duration } from '../duration/duration'
8+
import { SpecFileName } from '../shared/SpecFileName'
109

1110
const renderRunnableHeader = (children: ReactElement) => <div className="runnable-header" data-cy="runnable-header">{children}</div>
1211

@@ -17,8 +16,6 @@ interface RunnableHeaderProps {
1716
}
1817

1918
const RunnableHeader: React.FC<RunnableHeaderProps> = observer(({ spec, statsStore, runnablesStore }) => {
20-
const relativeSpecPath = spec.relative
21-
2219
if (spec.relative === '__all') {
2320
if (spec.specFilter) {
2421
return renderRunnableHeader(
@@ -31,31 +28,9 @@ const RunnableHeader: React.FC<RunnableHeaderProps> = observer(({ spec, statsSto
3128
)
3229
}
3330

34-
const displayFileName = () => {
35-
const specParts = getFilenameParts(spec.name)
36-
37-
return (
38-
<>
39-
<span className='spec-name'>{specParts[0]}</span><span className='spec-file-extension'>{specParts[1]}</span>
40-
</>
41-
)
42-
}
43-
44-
const fileDetails = {
45-
absoluteFile: spec.absolute,
46-
column: 0,
47-
displayFile: displayFileName(),
48-
line: 0,
49-
originalFile: relativeSpecPath,
50-
relativeFile: relativeSpecPath,
51-
}
52-
5331
return renderRunnableHeader(
5432
<>
55-
<div className='runnable-header-file-name'>
56-
{fileDetails.displayFile || fileDetails.originalFile}{!!fileDetails.line && `:${fileDetails.line}`}{!!fileDetails.column && `:${fileDetails.column}`}
57-
<OpenFileInIDEButton fileDetails={fileDetails} />
58-
</div>
33+
<SpecFileName spec={spec} />
5934
{runnablesStore.testFilter && runnablesStore.totalTests > 0 && <DebugDismiss matched={runnablesStore.totalTests} total={runnablesStore.totalUnfilteredTests} />}
6035
<Duration duration={statsStore.duration} />
6136
</>,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.spec-file-name {
2+
display: inline-flex;
3+
align-items: center;
4+
flex: 1;
5+
min-width: 0;
6+
overflow: hidden;
7+
text-overflow: ellipsis;
8+
white-space: nowrap;
9+
position: relative;
10+
background: $gray-1100;
11+
12+
&:after {
13+
content: none;
14+
}
15+
16+
.spec-name {
17+
color: $white;
18+
font-weight: 500;
19+
}
20+
21+
.spec-file-extension {
22+
color: $gray-500;
23+
font-weight: 400;
24+
}
25+
26+
&:hover,
27+
&:focus-visible {
28+
.open-in-ide-button {
29+
opacity: 1;
30+
}
31+
32+
.button-hover-shadow {
33+
opacity: 1;
34+
}
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import { getFilenameParts } from '../lib/util'
3+
import { OpenFileInIDEButton } from '../header/OpenFileInIDEButton'
4+
5+
const displayFileName = (spec: Cypress.Cypress['spec']) => {
6+
const specParts = getFilenameParts(spec.name)
7+
8+
return (
9+
<>
10+
<span className='spec-name'>{specParts[0]}</span><span className='spec-file-extension'>{specParts[1]}</span>
11+
</>
12+
)
13+
}
14+
15+
export const SpecFileName = ({ spec }: { spec: Cypress.Cypress['spec'] }) => {
16+
const relativeSpecPath = spec.relative
17+
18+
const fileDetails = {
19+
absoluteFile: spec.absolute,
20+
column: 0,
21+
displayFile: displayFileName(spec),
22+
line: 0,
23+
originalFile: relativeSpecPath,
24+
relativeFile: relativeSpecPath,
25+
}
26+
27+
return <div className='spec-file-name'>
28+
{fileDetails.displayFile || fileDetails.originalFile}{!!fileDetails.line && `:${fileDetails.line}`}{!!fileDetails.column && `:${fileDetails.column}`}
29+
<OpenFileInIDEButton fileDetails={fileDetails} />
30+
</div>
31+
}

packages/reporter/src/studio/StudioTestHeader.cy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('StudioTestHeader', () => {
2525

2626
cy.get('.studio-header').should('be.visible')
2727
cy.get('.studio-header__file-section').should('be.visible')
28-
cy.get('.studio-header__file-content').should('be.visible')
29-
cy.get('[data-cy="studio-single-test-file-name"]').should('contain.text', 'example.cy.ts')
28+
cy.get('.spec-file-name').should('be.visible')
29+
cy.get('.spec-file-name').should('contain.text', 'example.cy.ts')
3030
cy.get('[data-cy="studio-back-button"]').should('be.visible')
3131
cy.percySnapshot()
3232
})

packages/reporter/src/studio/StudioTestHeader.scss

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,8 @@
1414
font-size: 14px;
1515
line-height: 20px;
1616
color: $gray-500;
17-
18-
.studio-header__file-content {
19-
position: relative;
20-
width: 100%;
21-
22-
&:hover,
23-
&:focus-visible {
24-
.open-in-ide-button {
25-
opacity: 1;
26-
}
27-
}
28-
}
29-
30-
.studio-header__file-name {
31-
font-weight: 300;
32-
flex-grow: 1;
33-
}
34-
17+
18+
3519
.studio-header__back-button {
3620
padding: 0;
3721
width: 32px;

packages/reporter/src/studio/StudioTestHeader.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
import React, { useCallback } from 'react'
22
import { observer } from 'mobx-react'
3-
import { getFilenameParts } from '../lib/util'
43
import Button from '@cypress-design/react-button'
54
import { IconArrowLeft } from '@cypress-design/react-icon'
6-
import { OpenFileInIDEButton } from '../header/OpenFileInIDEButton'
75
import events from '../lib/events'
6+
import { SpecFileName } from '../shared/SpecFileName'
87

98
interface StudioHeaderProps {
109
spec: Cypress.Cypress['spec']
1110
}
1211

1312
export const StudioTestHeader = observer(({ spec }: StudioHeaderProps) => {
14-
const specParts = getFilenameParts(spec.name)
15-
const relativeSpecPath = spec.relative
16-
17-
const fileDetails = {
18-
absoluteFile: spec.absolute,
19-
column: 0,
20-
line: 0,
21-
originalFile: relativeSpecPath,
22-
relativeFile: relativeSpecPath,
23-
}
24-
2513
const handleBackButton = useCallback((e: React.MouseEvent<HTMLElement>) => {
2614
e.preventDefault()
2715

@@ -35,10 +23,7 @@ export const StudioTestHeader = observer(({ spec }: StudioHeaderProps) => {
3523
<Button data-cy='studio-back-button' size='32' variant='outline-dark' className='studio-header__back-button' onClick={handleBackButton}>
3624
<IconArrowLeft size='16' strokeColor='gray-500' />
3725
</Button>
38-
<div className='studio-header__file-content'>
39-
<span data-cy='studio-single-test-file-name' className='studio-header__file-name'>{specParts[0]}{specParts[1]}</span>
40-
<OpenFileInIDEButton fileDetails={fileDetails} />
41-
</div>
26+
<SpecFileName spec={spec} />
4227
</div>
4328
</header>
4429
</>

0 commit comments

Comments
 (0)