Skip to content

Commit 0163499

Browse files
fix(6537): script crud should not be enabled for non-cloud. Scripts e2es cleanup. (#6540)
* chore: fix typo * fix(6537): scripts crud actions should be entirely disabled for non-cloud, therefore remove from toolbar. Add dataIds for testing. * fix(6537): handle session resetting in oss, now that crud script buttons are no longer (errorenous) provided --------- Co-authored-by: Chunchun <14298407+appletreeisyellow@users.noreply.github.com>
1 parent 44fa895 commit 0163499

File tree

8 files changed

+301
-67
lines changed

8 files changed

+301
-67
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
describe('Script Builder -- scripts crud on cloud', () => {
2+
before(() => {
3+
cy.flush().then(() => cy.signin())
4+
})
5+
6+
beforeEach(() => {
7+
cy.scriptsLoginWithFlags({}).then(() => {
8+
cy.switchToDataExplorer('new')
9+
})
10+
})
11+
12+
it('should not have the scripts crud options', () => {
13+
cy.getByTestID('script-query-builder--open-script').should('not.exist')
14+
cy.getByTestID('script-query-builder--save-script').should('not.exist')
15+
cy.getByTestID('script-query-builder--edit-script').should('not.exist')
16+
})
17+
})

cypress/support/commands.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,35 @@ export const createNotebook = (
765765
}
766766

767767
export const newScriptWithoutLanguageSelection = () => {
768+
const CLOUD = Cypress.env('dexUrl') === 'OSS' ? false : true
769+
if (!CLOUD) {
770+
return cy
771+
.getByTestID('script-query-builder--new-script')
772+
.should('be.visible')
773+
.click()
774+
}
775+
768776
cy.getByTestID('script-query-builder--save-script').then($saveButton => {
769-
if (!$saveButton.is(':disabled')) {
770-
cy.getByTestID('script-query-builder--new-script')
771-
.should('be.visible')
772-
.click()
773-
cy.getByTestID('overlay--container').within(() => {
774-
cy.getByTestID('script-query-builder--delete-script')
775-
.should('be.visible')
776-
.click()
777+
cy.getByTestID('page-title')
778+
.invoke('text')
779+
.then(title => {
780+
if (!$saveButton.is(':disabled')) {
781+
// unsaved existing script
782+
cy.getByTestID('script-query-builder--new-script')
783+
.should('be.visible')
784+
.click()
785+
cy.getByTestID('overlay--container').within(() => {
786+
cy.getByTestID('script-query-builder--delete-script')
787+
.should('be.visible')
788+
.click()
789+
})
790+
} else if (!title.includes('Data Explorer')) {
791+
// saved existing script
792+
cy.getByTestID('script-query-builder--new-script')
793+
.should('be.visible')
794+
.click()
795+
}
777796
})
778-
}
779797
})
780798
}
781799

@@ -886,7 +904,7 @@ export const selectScriptFieldOrTag = (name: string, beActive: boolean) => {
886904
}
887905

888906
export const switchToDataExplorer = (typ: 'new' | 'old') => {
889-
cy.getByTestID('page-title').contains('Data Explorer')
907+
cy.getByTestID('data-explorer-page').should('exist')
890908
cy.get('[data-testid="data-explorer--header"]').then($body => {
891909
if (
892910
$body.has('button[data-testid="script-query-builder-toggle"]').length > 0
@@ -920,7 +938,8 @@ export const scriptsLoginWithFlags = (flags): Cypress.Chainable<any> => {
920938
})
921939
.then(() =>
922940
cy.reload().then(() => {
923-
cy.getByTestID('page-title').contains('Data Explorer')
941+
cy.getByTestID('tree-nav')
942+
cy.getByTestID('data-explorer-page').should('exist')
924943
cy.switchToDataExplorer('new')
925944
})
926945
)

src/dataExplorer/components/DataExplorerPage.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ const DataExplorerPage: FC = () => {
222222
</Page.ControlBarRight>
223223
</Page.ControlBar>
224224
)}
225-
<Page.Contents fullWidth={true} scrollable={false}>
225+
<Page.Contents
226+
fullWidth={true}
227+
scrollable={false}
228+
testID="data-explorer-page"
229+
>
226230
{!shouldShowNewExplorer && <DataExplorer />}
227231
{shouldShowNewExplorer && <ScriptQueryBuilder />}
228232
</Page.Contents>

src/dataExplorer/components/DeleteScript.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const DeleteScript: FC<Props> = ({onBack, onClose}) => {
7878
onClick={handleDeleteScript}
7979
text="delete"
8080
icon={IconFont.Trash_New}
81+
testID="script-query-builder--confirm-delete"
8182
/>
8283
</Overlay.Footer>
8384
</Overlay.Container>

src/dataExplorer/components/OpenScript.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
5555
setScripts(resp.data.scripts)
5656
setLoading(RemoteDataState.Done)
5757
} else {
58-
alert('you are in an supported environment')
58+
alert('you are in an unsupported environment')
5959
}
6060
} catch (error) {
6161
setLoading(RemoteDataState.Error)
@@ -151,6 +151,7 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
151151
value={searchTerm}
152152
placeholder="Search Scripts"
153153
onChange={evt => handleSearchTerm(evt.target.value)}
154+
testID="open-script__search"
154155
/>
155156
<Dropdown.Menu className="open-script__menu-items" maxHeight={300}>
156157
{list}
@@ -162,18 +163,17 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
162163
onClick={onCancel}
163164
text="Cancel"
164165
/>
165-
{CLOUD && (
166-
<Button
167-
color={ComponentColor.Primary}
168-
status={
169-
scripts.length === 0 || Object.keys(selectedScript).length === 0
170-
? ComponentStatus.Disabled
171-
: ComponentStatus.Default
172-
}
173-
onClick={handleOpenScript}
174-
text="Open"
175-
/>
176-
)}
166+
<Button
167+
color={ComponentColor.Primary}
168+
status={
169+
scripts.length === 0 || Object.keys(selectedScript).length === 0
170+
? ComponentStatus.Disabled
171+
: ComponentStatus.Default
172+
}
173+
onClick={handleOpenScript}
174+
text="Open"
175+
testID="open-script__open"
176+
/>
177177
</Overlay.Footer>
178178
</Overlay.Container>
179179
)

src/dataExplorer/components/SaveAsScript.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {ResultsContext} from 'src/dataExplorer/context/results'
1919
import {PersistanceContext} from 'src/dataExplorer/context/persistance'
2020
import {RemoteDataState} from 'src/types'
2121
import './SaveAsScript.scss'
22-
import {CLOUD} from 'src/shared/constants'
2322
import {OverlayType} from './ScriptQueryBuilder'
2423
import {useDispatch, useSelector} from 'react-redux'
2524
import {notify} from 'src/shared/actions/notifications'
@@ -278,19 +277,17 @@ const SaveAsScript: FC<Props> = ({language, onClose, setOverlayType, type}) => {
278277
testID="script-query-builder--delete-script"
279278
/>
280279
)}
281-
{CLOUD && (
282-
<Button
283-
color={ComponentColor.Primary}
284-
status={
285-
(newName?.length ?? 0) === 0
286-
? ComponentStatus.Disabled
287-
: ComponentStatus.Default
288-
}
289-
onClick={handleSaveScript}
290-
text={saveText}
291-
testID="script-query-builder--save"
292-
/>
293-
)}
280+
<Button
281+
color={ComponentColor.Primary}
282+
status={
283+
(newName?.length ?? 0) === 0
284+
? ComponentStatus.Disabled
285+
: ComponentStatus.Default
286+
}
287+
onClick={handleSaveScript}
288+
text={saveText}
289+
testID="script-query-builder--save"
290+
/>
294291
</Overlay.Footer>
295292
</Overlay.Container>
296293
)

0 commit comments

Comments
 (0)