|
| 1 | +const DELAY_FOR_LAZY_LOAD_EDITOR = 30000 |
| 2 | + |
| 3 | +describe('Script Builder -- scripts crud on cloud', () => { |
| 4 | + const writeData: string[] = [] |
| 5 | + for (let i = 0; i < 30; i++) { |
| 6 | + writeData.push(`ndbc,air_temp_degc=70_degrees station_id_${i}=${i}`) |
| 7 | + writeData.push(`ndbc2,air_temp_degc=70_degrees station_id_${i}=${i}`) |
| 8 | + } |
| 9 | + |
| 10 | + const scriptName = 'foo' |
| 11 | + |
| 12 | + const attemptSaveScript = (scriptText: string, name = scriptName) => { |
| 13 | + cy.getByTestID('flux-editor') |
| 14 | + .monacoType(`{selectall}{del}{selectall}{rightArrow}{enter} |
| 15 | + ${scriptText} |
| 16 | + |> yield(name: "${name}") |
| 17 | + `) |
| 18 | + cy.getByTestID('flux-editor').contains(`|> yield(name: "${name}")`) |
| 19 | + cy.getByTestID('script-query-builder--save-script') |
| 20 | + .should('be.visible') |
| 21 | + .click() |
| 22 | + cy.getByTestID('overlay--container').within(() => { |
| 23 | + cy.getByTestID('save-script-name__input').should('be.visible').type(name) |
| 24 | + cy.getByTestID('script-query-builder--save').should('be.visible').click() |
| 25 | + }) |
| 26 | + } |
| 27 | + |
| 28 | + const saveScript = (scriptText: string, name = scriptName) => { |
| 29 | + cy.intercept('POST', '/api/v2/scripts*').as('scripts') |
| 30 | + attemptSaveScript(scriptText, name) |
| 31 | + cy.wait('@scripts') |
| 32 | + cy.getByTestID('notification-success').should('be.visible').contains(name) |
| 33 | + } |
| 34 | + |
| 35 | + before(() => { |
| 36 | + cy.flush().then(() => { |
| 37 | + return cy.signin().then(() => { |
| 38 | + return cy.writeData(writeData, 'defbuck') |
| 39 | + }) |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | + describe('saveAsScript', () => { |
| 44 | + beforeEach(() => { |
| 45 | + cy.scriptsLoginWithFlags({}).then(() => { |
| 46 | + cy.switchToDataExplorer('new') |
| 47 | + cy.clearFluxScriptSession() |
| 48 | + cy.getByTestID('flux-editor', {timeout: DELAY_FOR_LAZY_LOAD_EDITOR}) |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + it('will not save an invalid flux query', () => { |
| 53 | + attemptSaveScript('invalid query') |
| 54 | + cy.log('should notify user of an error') |
| 55 | + cy.getByTestID('notification-error--dismiss').should('be.visible') |
| 56 | + cy.log('modal will stay open') |
| 57 | + cy.getByTestID('overlay--container').within(() => { |
| 58 | + cy.getByTestID('script-query-builder--cancel').should('be.visible') |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + it('will save a valid flux query', () => { |
| 63 | + saveScript( |
| 64 | + 'from(bucket: "defbuck") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)' |
| 65 | + ) |
| 66 | + cy.log('should notify user of a success') |
| 67 | + cy.getByTestID('notification-success--dismiss').should('be.visible') |
| 68 | + cy.getByTestID('overlay--container').should('not.exist') |
| 69 | + }) |
| 70 | + }) |
| 71 | + |
| 72 | + describe('handling of existing scripts', () => { |
| 73 | + const DELAY_FOR_UPDATE = 1000 |
| 74 | + const scriptName = 'bar' |
| 75 | + const anotherScriptName = 'baz' |
| 76 | + const scriptToDelete = 'toDelete' |
| 77 | + |
| 78 | + before(() => { |
| 79 | + cy.scriptsLoginWithFlags({}).then(() => { |
| 80 | + cy.switchToDataExplorer('new') |
| 81 | + cy.getByTestID('flux-editor', {timeout: DELAY_FOR_LAZY_LOAD_EDITOR}) |
| 82 | + cy.clearFluxScriptSession() |
| 83 | + saveScript( |
| 84 | + `from(bucket: "defbuck") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)`, |
| 85 | + scriptName |
| 86 | + ) |
| 87 | + cy.clearFluxScriptSession() |
| 88 | + cy.wait(DELAY_FOR_UPDATE) |
| 89 | + saveScript( |
| 90 | + `from(bucket: "defbuck") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)`, |
| 91 | + anotherScriptName |
| 92 | + ) |
| 93 | + cy.clearFluxScriptSession() |
| 94 | + cy.wait(DELAY_FOR_UPDATE) |
| 95 | + saveScript( |
| 96 | + `from(bucket: "defbuck") |> range(start: v.timeRangeStart, stop: v.timeRangeStop)`, |
| 97 | + scriptToDelete |
| 98 | + ) |
| 99 | + }) |
| 100 | + }) |
| 101 | + |
| 102 | + beforeEach(() => { |
| 103 | + cy.scriptsLoginWithFlags({}).then(() => { |
| 104 | + cy.switchToDataExplorer('new') |
| 105 | + cy.clearFluxScriptSession() |
| 106 | + cy.getByTestID('flux-editor', {timeout: DELAY_FOR_LAZY_LOAD_EDITOR}) |
| 107 | + }) |
| 108 | + }) |
| 109 | + |
| 110 | + it('can search existing scripts, and open new one', () => { |
| 111 | + cy.getByTestID('script-query-builder--open-script') |
| 112 | + .should('be.visible') |
| 113 | + .click() |
| 114 | + cy.getByTestID('overlay--container').within(() => { |
| 115 | + cy.log('should see both scripts') |
| 116 | + // may have other script from previous test, since we don't flush btwn each |
| 117 | + cy.get('.cf-dropdown-item').should('have.length.at.least', 2) |
| 118 | + |
| 119 | + cy.getByTestID('open-script__search') |
| 120 | + .should('be.visible') |
| 121 | + .type(anotherScriptName) |
| 122 | + cy.get('.cf-dropdown-item').should('have.length', 1).click() |
| 123 | + |
| 124 | + cy.getByTestID('open-script__open').should('be.visible').click() |
| 125 | + }) |
| 126 | + |
| 127 | + cy.log('confirm is open') |
| 128 | + cy.wait(DELAY_FOR_UPDATE) |
| 129 | + cy.getByTestID('page-title').contains(anotherScriptName) |
| 130 | + cy.getByTestID('flux-editor').contains( |
| 131 | + `|> yield(name: "${anotherScriptName}")` |
| 132 | + ) |
| 133 | + }) |
| 134 | + |
| 135 | + // TODO: this fails only in cypress, not in manual QA |
| 136 | + it.skip('can delete a script', () => { |
| 137 | + cy.getByTestID('script-query-builder--open-script') |
| 138 | + .should('be.visible') |
| 139 | + .click() |
| 140 | + cy.getByTestID('overlay--container').within(() => { |
| 141 | + cy.getByTestID('open-script__search') |
| 142 | + .should('be.visible') |
| 143 | + .type(scriptToDelete) |
| 144 | + cy.get('.cf-dropdown-item').should('have.length', 1).click() |
| 145 | + cy.getByTestID('open-script__open').should('be.visible').click() |
| 146 | + }) |
| 147 | + |
| 148 | + cy.log('confirm is open') |
| 149 | + cy.wait(DELAY_FOR_UPDATE) |
| 150 | + cy.getByTestID('page-title').contains(scriptToDelete) |
| 151 | + cy.getByTestID('flux-editor').contains( |
| 152 | + `|> yield(name: "${scriptToDelete}")` |
| 153 | + ) |
| 154 | + |
| 155 | + cy.log('delete') |
| 156 | + cy.intercept('DELETE', '/api/v2/scripts/*').as('delete-script') |
| 157 | + cy.getByTestID('script-query-builder--edit-script') |
| 158 | + .should('be.visible') |
| 159 | + .click() |
| 160 | + cy.getByTestID('overlay--container').within(() => { |
| 161 | + cy.getByTestID('script-query-builder--delete-script') |
| 162 | + .should('be.visible') |
| 163 | + .click() |
| 164 | + }) |
| 165 | + cy.getByTestID('overlay--container').within(() => { |
| 166 | + cy.getByTestID('script-query-builder--confirm-delete') |
| 167 | + .should('be.visible') |
| 168 | + .click() |
| 169 | + }) |
| 170 | + cy.wait('@delete-script') |
| 171 | + cy.wait(DELAY_FOR_UPDATE) |
| 172 | + |
| 173 | + cy.log('confirm no longer in list') |
| 174 | + cy.getByTestID('script-query-builder--open-script') |
| 175 | + .should('be.visible') |
| 176 | + .click() |
| 177 | + cy.getByTestID('overlay--container').within(() => { |
| 178 | + cy.getByTestID('open-script__search') |
| 179 | + .should('be.visible') |
| 180 | + .type(scriptToDelete) |
| 181 | + cy.get('.cf-dropdown-item').should('have.length', 0) |
| 182 | + }) |
| 183 | + }) |
| 184 | + |
| 185 | + // TODO: test for editing a script. And editing the script metadata. |
| 186 | + }) |
| 187 | +}) |
0 commit comments