Skip to content

Commit 6eac7d8

Browse files
chore: display get code button on prompt failure (#33480)
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
1 parent 6dfecda commit 6eac7d8

2 files changed

Lines changed: 109 additions & 2 deletions

File tree

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

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import Command from './command'
33
import CommandModel from './command-model'
4+
import type { ErrProps } from '../errors/err-model'
45
import type { SessionStatus } from '../sessions/utils'
56
import type { TestState } from '@packages/types'
67
import events from '../lib/events'
@@ -151,7 +152,7 @@ describe('commands', () => {
151152
cy.percySnapshot()
152153
})
153154

154-
it('should not render prompt get code button when state is failed', () => {
155+
it('should not render prompt get code button when state is failed with no error', () => {
155156
config.withArgs('experimentalPromptCommand').returns(true)
156157
cy.mount(
157158
<div>
@@ -178,6 +179,110 @@ describe('commands', () => {
178179
cy.percySnapshot()
179180
})
180181

182+
it('should render prompt get code button when state is failed with non-excluded error', () => {
183+
config.withArgs('experimentalPromptCommand').returns(true)
184+
cy.mount(
185+
<div>
186+
<Command
187+
model={
188+
new CommandModel({
189+
name: 'prompt',
190+
state: 'failed',
191+
err: { name: 'SomeOtherError' } as ErrProps,
192+
numElements: 1,
193+
hookId: '1',
194+
id: 1,
195+
testId: '1',
196+
})
197+
}
198+
scrollIntoView={() => {}}
199+
aliasesWithDuplicates={[]}
200+
/>
201+
</div>,
202+
)
203+
204+
cy.get('.command-prompt-get-code').should('be.visible').should('have.text', 'Code')
205+
cy.get('.command-prompt-get-code-indicator').should('be.visible')
206+
})
207+
208+
it('should not render prompt get code button when state is failed with PromptDisabledError', () => {
209+
config.withArgs('experimentalPromptCommand').returns(true)
210+
cy.mount(
211+
<div>
212+
<Command
213+
model={
214+
new CommandModel({
215+
name: 'prompt',
216+
state: 'failed',
217+
err: { name: 'PromptDisabledError' } as ErrProps,
218+
numElements: 1,
219+
hookId: '1',
220+
id: 1,
221+
testId: '1',
222+
})
223+
}
224+
scrollIntoView={() => {}}
225+
aliasesWithDuplicates={[]}
226+
/>
227+
</div>,
228+
)
229+
230+
cy.get('.command-prompt-get-code').should('not.exist')
231+
cy.get('.command-prompt-get-code-indicator').should('not.exist')
232+
})
233+
234+
it('should not render prompt get code button when state is failed with PromptAuthenticationError', () => {
235+
config.withArgs('experimentalPromptCommand').returns(true)
236+
cy.mount(
237+
<div>
238+
<Command
239+
model={
240+
new CommandModel({
241+
name: 'prompt',
242+
state: 'failed',
243+
err: { name: 'PromptAuthenticationError' } as ErrProps,
244+
numElements: 1,
245+
hookId: '1',
246+
id: 1,
247+
testId: '1',
248+
})
249+
}
250+
scrollIntoView={() => {}}
251+
aliasesWithDuplicates={[]}
252+
/>
253+
</div>,
254+
)
255+
256+
cy.get('.command-prompt-get-code').should('not.exist')
257+
cy.get('.command-prompt-get-code-indicator').should('not.exist')
258+
})
259+
260+
it('should not render prompt get code button when state is failed with PromptUsageLimitError', () => {
261+
config.withArgs('experimentalPromptCommand').returns(true)
262+
cy.mount(
263+
<div>
264+
<Command
265+
model={
266+
new CommandModel({
267+
name: 'prompt',
268+
state: 'failed',
269+
err: { name: 'PromptUsageLimitError' } as ErrProps,
270+
numElements: 1,
271+
hookId: '1',
272+
id: 1,
273+
testId: '1',
274+
})
275+
}
276+
scrollIntoView={() => {}}
277+
aliasesWithDuplicates={[]}
278+
/>
279+
</div>,
280+
)
281+
282+
cy.get('.command-prompt-get-code').should('not.exist')
283+
cy.get('.command-prompt-get-code-indicator').should('not.exist')
284+
})
285+
181286
it('should not render prompt get code button when state is not passed', () => {
182287
config.withArgs('experimentalPromptCommand').returns(true)
183288
cy.mount(

packages/reporter/src/commands/command.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ const Command: React.FC<CommandProps> = observer(({ model, aliasesWithDuplicates
521521
return null
522522
}
523523

524+
const shouldShowCodeButton = model.state === 'passed' || (model.state === 'failed' && model.err?.name && !['PromptDisabledError', 'PromptAuthenticationError', 'PromptUsageLimitError'].includes(model.err.name))
525+
524526
return (
525527
<>
526528
<li className={cs('command', `command-name-${commandName}`)}>
@@ -589,7 +591,7 @@ const Command: React.FC<CommandProps> = observer(({ model, aliasesWithDuplicates
589591
/>
590592
<span>Feedback</span>
591593
</Button>
592-
{model.state === 'passed' && (
594+
{shouldShowCodeButton && (
593595
<Button
594596
variant="indigo-dark-mode"
595597
size="20"

0 commit comments

Comments
 (0)