Skip to content

Commit 5896795

Browse files
authored
internal: Clear AUT Url and prompt for new url when removing a visit command from the test via Studio (#32131)
* internal: remove default url when setting the url so that the url can be properly cleared * clear urlInProgress after we set the studio url * add test * add more tests * clear test editor text using invoke instead
1 parent 6e2a60e commit 5896795

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

packages/app/cypress/e2e/studio/studio.cy.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { launchStudio, loadProjectAndRunSpec, assertClosingPanelWithoutChanges } from './helper'
22

3+
const urlPrompt = '// Visit a page by entering a url in the address bar or typing a cy.visit command here'
4+
35
describe('Cypress Studio', () => {
46
function incrementCounter (initialCount: number) {
57
cy.getAutIframe().within(() => {
@@ -751,4 +753,61 @@ describe('studio functionality', () => {
751753

752754
cy.location().its('hash').and('not.contain', 'suiteId=').and('not.contain', 'studio=')
753755
})
756+
757+
describe('prompt for a new url', () => {
758+
const autUrl = 'http://localhost:4455/cypress/e2e/index.html'
759+
const visitUrl = 'cypress/e2e/index.html'
760+
761+
const clearUrl = () => {
762+
cy.findByTestId('aut-url-input').should('have.value', autUrl)
763+
764+
cy.get('.cm-content').invoke('text', '')
765+
766+
cy.findByTestId('studio-save-button').click()
767+
768+
cy.findByTestId('aut-url-input').should('have.value', '')
769+
770+
cy.findByTestId('aut-url-input').should('have.focus')
771+
772+
cy.get('.cm-line').should('contain.text', urlPrompt)
773+
}
774+
775+
const assertAutUrlInput = () => {
776+
cy.findByTestId('aut-url-input').should('have.value', autUrl)
777+
778+
cy.get('.cm-line').should('not.contain.text', urlPrompt)
779+
780+
cy.get('.cm-line').should('contain.text', `cy.visit('${visitUrl}')`)
781+
}
782+
783+
const clearAndAddAutUrl = () => {
784+
clearUrl()
785+
cy.findByTestId('aut-url-input').type(`${visitUrl}{enter}`)
786+
assertAutUrlInput()
787+
}
788+
789+
const clearAndAddTestBlockEditorUrl = () => {
790+
clearUrl()
791+
cy.get('.cm-content').invoke('text', 'cy.visit(\'cypress/e2e/index.html\')')
792+
cy.findByTestId('studio-save-button').click()
793+
assertAutUrlInput()
794+
}
795+
796+
beforeEach(() => {
797+
launchStudio()
798+
})
799+
800+
it('when an existing visit command is cleared and adds a new url via the aut url input', () => {
801+
clearAndAddAutUrl()
802+
})
803+
804+
it('when an existing visit command is cleared and adds a new url via test block editor', () => {
805+
clearAndAddTestBlockEditorUrl()
806+
})
807+
808+
it('ensures we clear the aut url input properly in between adding and clearing urls', () => {
809+
clearAndAddAutUrl()
810+
clearAndAddTestBlockEditorUrl()
811+
})
812+
})
754813
})

packages/app/src/runner/SpecRunnerHeaderOpenMode.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ function setStudioUrl (event: Event) {
225225
}
226226
227227
function visitUrl () {
228-
studioStore.visitUrl(urlInProgress.value)
228+
studioStore.setUrl(urlInProgress.value)
229+
// once we set the url in studio, we can clear the urlInProgress
230+
// since we'll rerun the test which will set the url in the autStore
231+
urlInProgress.value = ''
229232
}
230233
231234
function openExternally () {

packages/app/src/store/studio-store.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export const useStudioStore = defineStore('studioRecorder', {
271271
const autStore = useAutStore()
272272

273273
if (this._initialUrl || this.url) {
274-
this.visitUrl(this._initialUrl)
274+
this.setUrl(this._initialUrl)
275275
}
276276

277277
if (!this.url && autStore.url) {
@@ -331,20 +331,6 @@ export const useStudioStore = defineStore('studioRecorder', {
331331
getEventManager().emit('studio:save', payload)
332332
},
333333

334-
visitUrl (url?: string) {
335-
this.setUrl(url ?? this.url)
336-
337-
// if we're visiting a new url, add the visit log
338-
if (url) {
339-
this.logs.push({
340-
id: this._getId(),
341-
selector: undefined,
342-
name: 'visit',
343-
message: this.url,
344-
})
345-
}
346-
},
347-
348334
_removeLastLogIfType (selector?: string) {
349335
const lastLog = this.logs[this.logs.length - 1]
350336

0 commit comments

Comments
 (0)