Skip to content

Commit ab821a5

Browse files
committed
update logic to disable pinning
1 parent 4d17909 commit ab821a5

File tree

2 files changed

+56
-142
lines changed

2 files changed

+56
-142
lines changed

packages/reporter/src/commands/command.cy.tsx

Lines changed: 9 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -234,48 +234,9 @@ describe('commands', () => {
234234
})
235235
})
236236

237-
describe('studio click message', () => {
237+
describe('studio active state', () => {
238238
beforeEach(() => {
239-
// Reset appState before each test
240239
appState.reset()
241-
appState.isRunning = false
242-
})
243-
244-
it('should show click message when studio is not active', () => {
245-
appState.studioActive = false
246-
247-
cy.mount(
248-
<div>
249-
<Command
250-
model={
251-
new CommandModel({
252-
name: 'get',
253-
message: '.foo',
254-
state: 'passed',
255-
hasConsoleProps: true,
256-
number: 1,
257-
type: 'parent',
258-
hookId: '1',
259-
testId: '1',
260-
id: 1,
261-
numElements: 1,
262-
})
263-
}
264-
scrollIntoView={() => {}}
265-
aliasesWithDuplicates={[]}
266-
/>
267-
</div>,
268-
)
269-
270-
// Click on the command
271-
cy.get('.command-wrapper').click()
272-
273-
// The tooltip message should appear
274-
cy.get('.cy-tooltip').should('contain', 'Printed output to your console')
275-
})
276-
277-
it('should NOT show click message when studio is active', () => {
278-
appState.studioActive = true
279240

280241
cy.mount(
281242
<div>
@@ -299,73 +260,23 @@ describe('commands', () => {
299260
/>
300261
</div>,
301262
)
302-
303-
cy.get('.command-wrapper').click()
304-
305-
cy.get('.cy-tooltip').should('not.exist')
306263
})
307264

308-
it('should NOT show click message when test is running', () => {
265+
it('allows pinning command when studio is not active', () => {
309266
appState.studioActive = false
310-
appState.isRunning = true
311-
312-
cy.mount(
313-
<div>
314-
<Command
315-
model={
316-
new CommandModel({
317-
name: 'get',
318-
message: '.foo',
319-
state: 'passed',
320-
hasConsoleProps: true,
321-
number: 1,
322-
type: 'parent',
323-
hookId: '1',
324-
testId: '1',
325-
id: 1,
326-
numElements: 1,
327-
})
328-
}
329-
scrollIntoView={() => {}}
330-
aliasesWithDuplicates={[]}
331-
/>
332-
</div>,
333-
)
267+
cy.get('.command-pin-target').should('exist')
334268

335-
cy.get('.command-wrapper').click()
269+
cy.get('.command-pin-target').click()
336270

337-
cy.get('.cy-tooltip').should('not.exist')
271+
cy.contains('Printed output to your console').should('be.visible')
338272
})
339273

340-
it('should NOT show click message when command has no console props', () => {
341-
appState.studioActive = false
342-
343-
cy.mount(
344-
<div>
345-
<Command
346-
model={
347-
new CommandModel({
348-
name: 'get',
349-
message: '.foo',
350-
state: 'passed',
351-
hasConsoleProps: false,
352-
number: 1,
353-
type: 'parent',
354-
hookId: '1',
355-
testId: '1',
356-
id: 1,
357-
numElements: 1,
358-
})
359-
}
360-
scrollIntoView={() => {}}
361-
aliasesWithDuplicates={[]}
362-
/>
363-
</div>,
364-
)
274+
it('does not allow pinning when studio is active', () => {
275+
appState.studioActive = true
365276

366-
cy.get('.command-wrapper').click()
277+
cy.get('.command-pin-target').should('not.exist')
367278

368-
cy.get('.cy-tooltip').should('not.exist')
279+
cy.get('.command-wrapper-container').should('exist')
369280
})
370281
})
371282
})

packages/reporter/src/commands/command.tsx

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ const Command: React.FC<CommandProps> = observer(({ model, aliasesWithDuplicates
432432
}
433433

434434
const _shouldShowClickMessage = () => {
435-
return !appState.isRunning && !!model.hasConsoleProps && !appState.studioActive
435+
return !appState.isRunning && !!model.hasConsoleProps
436436
}
437437

438438
const _toggleColumnPin = () => {
@@ -495,6 +495,48 @@ const Command: React.FC<CommandProps> = observer(({ model, aliasesWithDuplicates
495495
return null
496496
}
497497

498+
let commandContent = (<div className='command-wrapper-container'>
499+
<div
500+
className={cs('command-wrapper-text', {
501+
'command-wrapper-text-group': model.hasChildren && groupId,
502+
'command-wrapper-text-group-parent': model.hasChildren && !groupId,
503+
})}
504+
onMouseEnter={() => _snapshot(true)}
505+
onMouseLeave={() => _snapshot(false)}
506+
>
507+
{groupPlaceholder}
508+
509+
{model.hasChildren && groupId && (
510+
<div className={cs('command-expander-column-group', { 'nested-group-expander': model.groupLevel })} onClick={(e) => {
511+
e.stopPropagation()
512+
model.toggleOpen()
513+
}}>
514+
<ChevronIcon className={cs('command-expander', { 'command-expander-is-open': model.hasChildren && !!model.isOpen })} />
515+
</div>
516+
)}
517+
<CommandDetails model={model} groupId={groupId} aliasesWithDuplicates={aliasesWithDuplicates} />
518+
<CommandControls model={model} commandName={commandName} />
519+
</div>
520+
{model.isCyPrompt && model.state === 'passed' && (
521+
<Button
522+
variant="indigo-dark-mode"
523+
size="20"
524+
onClick={(e) => {
525+
e.stopPropagation()
526+
events.emit('prompt:get-code', { testId: model.testId, logId: model.id })
527+
}}
528+
className="command-prompt-get-code mr-1 whitespace-nowrap"
529+
>
530+
<IconTechnologyAngleBrackets
531+
className='command-prompt-get-code-indicator pr-1'
532+
size='16'
533+
strokeColor='white'
534+
/>
535+
<span>Get code</span>
536+
</Button>
537+
)}
538+
</div>)
539+
498540
return (
499541
<>
500542
<li className={cs('command', `command-name-${commandName}`)}>
@@ -511,54 +553,15 @@ const Command: React.FC<CommandProps> = observer(({ model, aliasesWithDuplicates
511553
)}
512554
>
513555
<NavColumns model={model} isPinned={_isPinned()} toggleColumnPin={_toggleColumnPin} />
514-
<FlashOnClick
556+
{appState.studioActive ? commandContent : <FlashOnClick
515557
message='Printed output to your console'
516558
onClick={_toggleColumnPin}
517559
shouldShowMessage={_shouldShowClickMessage}
518560
wrapperClassName={cs('command-pin-target', { 'command-group': !!groupId, 'command-group-no-children': !model.hasChildren && model.group })}
519561
>
520-
<div className='command-wrapper-container'>
521-
<div
522-
className={cs('command-wrapper-text', {
523-
'command-wrapper-text-group': model.hasChildren && groupId,
524-
'command-wrapper-text-group-parent': model.hasChildren && !groupId,
525-
})}
526-
onMouseEnter={() => _snapshot(true)}
527-
onMouseLeave={() => _snapshot(false)}
528-
>
529-
{groupPlaceholder}
530-
531-
{model.hasChildren && groupId && (
532-
<div className={cs('command-expander-column-group', { 'nested-group-expander': model.groupLevel })} onClick={(e) => {
533-
e.stopPropagation()
534-
model.toggleOpen()
535-
}}>
536-
<ChevronIcon className={cs('command-expander', { 'command-expander-is-open': model.hasChildren && !!model.isOpen })} />
537-
</div>
538-
)}
539-
<CommandDetails model={model} groupId={groupId} aliasesWithDuplicates={aliasesWithDuplicates} />
540-
<CommandControls model={model} commandName={commandName} />
541-
</div>
542-
{model.isCyPrompt && model.state === 'passed' && (
543-
<Button
544-
variant="indigo-dark-mode"
545-
size="20"
546-
onClick={(e) => {
547-
e.stopPropagation()
548-
events.emit('prompt:get-code', { testId: model.testId, logId: model.id })
549-
}}
550-
className="command-prompt-get-code mr-1 whitespace-nowrap"
551-
>
552-
<IconTechnologyAngleBrackets
553-
className='command-prompt-get-code-indicator pr-1'
554-
size='16'
555-
strokeColor='white'
556-
/>
557-
<span>Get code</span>
558-
</Button>
559-
)}
560-
</div>
561-
</FlashOnClick>
562+
{commandContent}
563+
</FlashOnClick>}
564+
562565
</div>
563566
<Progress model={model} />
564567
{model.hasChildren && model.isOpen && (

0 commit comments

Comments
 (0)