|
| 1 | +import { launchStudio, loadProjectAndRunSpec, assertClosingPanelWithoutChanges } from './helper' |
| 2 | +import pDefer from 'p-defer' |
| 3 | + |
| 4 | +describe('Studio Cloud', () => { |
| 5 | + it('enables protocol for cloud studio', () => { |
| 6 | + launchStudio({ enableCloudStudio: true }) |
| 7 | + |
| 8 | + cy.window().then((win) => { |
| 9 | + expect(win.Cypress.config('isDefaultProtocolEnabled')).to.be.false |
| 10 | + expect(win.Cypress.state('isProtocolEnabled')).to.be.true |
| 11 | + }) |
| 12 | + }) |
| 13 | + |
| 14 | + it('loads the studio UI correctly when studio bundle is taking too long to load', () => { |
| 15 | + loadProjectAndRunSpec({ enableCloudStudio: false }) |
| 16 | + |
| 17 | + cy.window().then(() => { |
| 18 | + cy.withCtx((ctx) => { |
| 19 | + // Mock the studioLifecycleManager.getStudio method to return a hanging promise |
| 20 | + if (ctx.coreData.studioLifecycleManager) { |
| 21 | + const neverResolvingPromise = new Promise<null>(() => {}) |
| 22 | + |
| 23 | + ctx.coreData.studioLifecycleManager.getStudio = () => neverResolvingPromise |
| 24 | + ctx.coreData.studioLifecycleManager.isStudioReady = () => false |
| 25 | + } |
| 26 | + }) |
| 27 | + }) |
| 28 | + |
| 29 | + cy.contains('visits a basic html page') |
| 30 | + .closest('.runnable-wrapper') |
| 31 | + .findByTestId('launch-studio') |
| 32 | + .click() |
| 33 | + |
| 34 | + cy.waitForSpecToFinish() |
| 35 | + |
| 36 | + // Verify the cloud studio panel is not present |
| 37 | + cy.findByTestId('studio-panel').should('not.exist') |
| 38 | + |
| 39 | + cy.get('[data-cy="loading-studio-panel"]').should('not.exist') |
| 40 | + |
| 41 | + cy.get('[data-cy="hook-name-studio commands"]').should('exist') |
| 42 | + |
| 43 | + cy.getAutIframe().within(() => { |
| 44 | + cy.get('#increment').realClick() |
| 45 | + }) |
| 46 | + |
| 47 | + cy.findByTestId('hook-name-studio commands').closest('.hook-studio').within(() => { |
| 48 | + cy.get('.command').should('have.length', 2) |
| 49 | + cy.get('.command-name-get').should('contain.text', '#increment') |
| 50 | + cy.get('.command-name-click').should('contain.text', 'click') |
| 51 | + }) |
| 52 | + |
| 53 | + cy.get('button').contains('Save Commands').should('not.be.disabled') |
| 54 | + }) |
| 55 | + |
| 56 | + it('immediately loads the studio panel', () => { |
| 57 | + const deferred = pDefer() |
| 58 | + |
| 59 | + loadProjectAndRunSpec({ enableCloudStudio: true }) |
| 60 | + |
| 61 | + cy.findByTestId('studio-panel').should('not.exist') |
| 62 | + |
| 63 | + cy.intercept('/cypress/e2e/index.html', () => { |
| 64 | + // wait for the promise to resolve before responding |
| 65 | + // this will ensure the studio panel is loaded before the test finishes |
| 66 | + return deferred.promise |
| 67 | + }).as('indexHtml') |
| 68 | + |
| 69 | + cy.contains('visits a basic html page') |
| 70 | + .closest('.runnable-wrapper') |
| 71 | + .findByTestId('launch-studio') |
| 72 | + .click() |
| 73 | + |
| 74 | + // regular studio is not loaded until after the test finishes |
| 75 | + cy.get('[data-cy="hook-name-studio commands"]').should('not.exist') |
| 76 | + // cloud studio is loaded immediately |
| 77 | + cy.findByTestId('studio-panel').then(() => { |
| 78 | + // check for the loading panel from the app first |
| 79 | + cy.get('[data-cy="loading-studio-panel"]').should('be.visible') |
| 80 | + // we've verified the studio panel is loaded, now resolve the promise so the test can finish |
| 81 | + deferred.resolve() |
| 82 | + }) |
| 83 | + |
| 84 | + cy.wait('@indexHtml') |
| 85 | + |
| 86 | + // Studio re-executes spec before waiting for commands - wait for the spec to finish executing. |
| 87 | + cy.waitForSpecToFinish() |
| 88 | + |
| 89 | + // Verify the studio panel is still open |
| 90 | + cy.findByTestId('studio-panel') |
| 91 | + cy.get('[data-cy="hook-name-studio commands"]') |
| 92 | + }) |
| 93 | + |
| 94 | + it('hides selector playground and studio controls when studio beta is available', () => { |
| 95 | + launchStudio({ enableCloudStudio: true }) |
| 96 | + cy.get('[data-cy="studio-header-studio-button"]').click() |
| 97 | + |
| 98 | + cy.get('[data-cy="playground-activator"]').should('not.exist') |
| 99 | + cy.get('[data-cy="studio-toolbar"]').should('not.exist') |
| 100 | + }) |
| 101 | + |
| 102 | + it('closes studio panel when clicking studio button (from the cloud)', () => { |
| 103 | + launchStudio({ enableCloudStudio: true }) |
| 104 | + |
| 105 | + cy.get('[data-cy="studio-header-studio-button"]').click() |
| 106 | + |
| 107 | + assertClosingPanelWithoutChanges() |
| 108 | + }) |
| 109 | + |
| 110 | + it('opens studio panel to new test when clicking on studio button (from the app) next to url', () => { |
| 111 | + cy.viewport(1500, 1000) |
| 112 | + loadProjectAndRunSpec({ enableCloudStudio: true }) |
| 113 | + // studio button should be visible when using cloud studio |
| 114 | + cy.get('[data-cy="studio-button"]').should('be.visible').click() |
| 115 | + cy.get('[data-cy="studio-panel"]').should('be.visible') |
| 116 | + |
| 117 | + cy.contains('New Test') |
| 118 | + |
| 119 | + cy.get('[data-cy="studio-url-prompt"]').should('not.exist') |
| 120 | + |
| 121 | + cy.percySnapshot() |
| 122 | + }) |
| 123 | + |
| 124 | + it('opens a cloud studio session with AI enabled', () => { |
| 125 | + cy.mockNodeCloudRequest({ |
| 126 | + url: '/studio/testgen/n69px6/enabled', |
| 127 | + method: 'get', |
| 128 | + body: { enabled: true }, |
| 129 | + }) |
| 130 | + |
| 131 | + const aiOutput = 'cy.get(\'button\').should(\'have.text\', \'Increment\')' |
| 132 | + |
| 133 | + cy.mockNodeCloudStreamingRequest({ |
| 134 | + url: '/studio/testgen/n69px6/generate', |
| 135 | + method: 'post', |
| 136 | + body: { recommendations: [{ content: aiOutput }] }, |
| 137 | + }) |
| 138 | + |
| 139 | + cy.mockStudioFullSnapshot({ |
| 140 | + id: 1, |
| 141 | + nodeType: 1, |
| 142 | + nodeName: 'div', |
| 143 | + localName: 'div', |
| 144 | + nodeValue: 'div', |
| 145 | + children: [], |
| 146 | + shadowRoots: [], |
| 147 | + }) |
| 148 | + |
| 149 | + const deferred = pDefer() |
| 150 | + |
| 151 | + loadProjectAndRunSpec({ enableCloudStudio: true }) |
| 152 | + |
| 153 | + cy.findByTestId('studio-panel').should('not.exist') |
| 154 | + |
| 155 | + cy.intercept('/cypress/e2e/index.html', () => { |
| 156 | + // wait for the promise to resolve before responding |
| 157 | + // this will ensure the studio panel is loaded before the test finishes |
| 158 | + return deferred.promise |
| 159 | + }).as('indexHtml') |
| 160 | + |
| 161 | + cy.contains('visits a basic html page') |
| 162 | + .closest('.runnable-wrapper') |
| 163 | + .findByTestId('launch-studio') |
| 164 | + .click() |
| 165 | + |
| 166 | + // regular studio is not loaded until after the test finishes |
| 167 | + cy.get('[data-cy="hook-name-studio commands"]').should('not.exist') |
| 168 | + // cloud studio is loaded immediately |
| 169 | + cy.findByTestId('studio-panel').then(() => { |
| 170 | + // check for the loading panel from the app first |
| 171 | + cy.get('[data-cy="loading-studio-panel"]').should('be.visible') |
| 172 | + // we've verified the studio panel is loaded, now resolve the promise so the test can finish |
| 173 | + deferred.resolve() |
| 174 | + }) |
| 175 | + |
| 176 | + cy.wait('@indexHtml') |
| 177 | + |
| 178 | + // Studio re-executes spec before waiting for commands - wait for the spec to finish executing. |
| 179 | + cy.waitForSpecToFinish() |
| 180 | + |
| 181 | + // Verify the studio panel is still open |
| 182 | + cy.findByTestId('studio-panel') |
| 183 | + cy.get('[data-cy="hook-name-studio commands"]') |
| 184 | + |
| 185 | + // Verify that AI is enabled |
| 186 | + cy.get('[data-cy="ai-status-text"]').should('contain.text', 'Enabled') |
| 187 | + |
| 188 | + // Verify that the AI output is correct |
| 189 | + cy.get('[data-cy="recommendation-editor"]').should('contain', aiOutput) |
| 190 | + }) |
| 191 | +}) |
0 commit comments