Skip to content

Commit 0aa198e

Browse files
committed
no cy selectors
1 parent 7c25002 commit 0aa198e

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

.changeset/funny-poets-hang.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ a = b;
2929
a = b;
3030
```
3131

32-
The advantage of `@ts-expect-error` is that if there is no error to ignore, then the comment itself becomes an error whereas `@ts-ignore` sits there quietly whether it has effect or not.
32+
The advantage of `@ts-expect-error` is that if there is no error to ignore, then the comment itself becomes an error whereas `@ts-ignore` sits there quietly whether it has an effect or not.
3333

3434
There is more you can do with TypeScript in JavaScript, such as providing type annotations via JSDoc. Learn more about it all here:
3535

cypress/e2e/laboratory/__cypress__.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export namespace cyLaboratory {
6262
export namespace preflight {
6363
export const selectors = {
6464
buttonGraphiQLPreflight: '[aria-label*="Preflight Script"]',
65-
buttonModalCy: 'preflight-modal-button',
66-
buttonToggleCy: 'toggle-preflight',
65+
buttonModal: '[data-cy="preflight-modal-button"]',
66+
buttonToggle: '[data-cy="toggle-preflight"]',
6767
buttonHeaders: '[data-name="headers"]',
6868
headersEditor: {
6969
textArea: '.graphiql-editor-tool .graphiql-editor:last-child textarea',
@@ -73,23 +73,18 @@ export namespace cyLaboratory {
7373
},
7474

7575
modal: {
76-
buttonSubmitCy: 'preflight-modal-submit',
77-
editorCy: 'preflight-editor',
78-
variablesEditorCy: 'env-editor',
76+
buttonSubmit: '[data-cy="preflight-modal-submit"]',
77+
scriptEditor: '[data-cy="preflight-editor"]',
78+
variablesEditor: '[data-cy="env-editor"]',
7979
},
8080
};
81-
/**
82-
* Sets the content of the preflight editor
83-
*/
81+
8482
export const setScriptEditorContent = (value: string) => {
85-
cyMonaco.setContent(selectors.modal.editorCy, value);
83+
cyMonaco.setContent(selectors.modal.scriptEditor, value);
8684
};
8785

88-
/**
89-
* Sets the content of the variables editor
90-
*/
9186
export const setEnvironmentEditorContent = (value: string) => {
92-
cyMonaco.setContent(selectors.modal.variablesEditorCy, value);
87+
cyMonaco.setContent(selectors.modal.variablesEditor, value);
9388
};
9489
}
9590
}

cypress/e2e/laboratory/preflight.cy.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,21 @@ describe('Preflight Modal', () => {
5353

5454
it('script is validated with TypeScript', () => {
5555
cyPreflight.setScriptEditorContent('let a = 1; a = ""');
56-
cyMonaco.nextProblemContains(selectors.modal.editorCy, "Type 'string' is not assignable to type 'number'."); // prettier-ignore
56+
cyMonaco.nextProblemContains(selectors.modal.scriptEditor, "Type 'string' is not assignable to type 'number'."); // prettier-ignore
5757
});
5858

5959
it('script cannot have TypeScript syntax', () => {
6060
cyPreflight.setScriptEditorContent('let a:number = 1');
61-
cyMonaco.nextProblemContains(selectors.modal.editorCy, 'Type annotations can only be used in TypeScript files.'); // prettier-ignore
61+
cyMonaco.nextProblemContains(selectors.modal.scriptEditor, 'Type annotations can only be used in TypeScript files.'); // prettier-ignore
62+
});
63+
64+
it('regression: saving and re-opening clears previous validation state', () => {
65+
cyPreflight.setScriptEditorContent('const a = 1');
66+
cy.get(selectors.modal.buttonSubmit).click();
67+
cy.get(selectors.buttonModal).click();
68+
cy.wait(1000);
69+
cyMonaco.goToNextProblem(selectors.modal.scriptEditor);
70+
cy.contains('Cannot redeclare block-scoped variable').should('not.exist');
6271
});
6372

6473
it('save script and environment variables when submitting', () => {
@@ -191,12 +200,12 @@ describe('Execution', () => {
191200
const preflightHeaders = {
192201
foo: 'bar',
193202
};
194-
cy.dataCy(selectors.buttonToggleCy).click();
195-
cy.dataCy(selectors.buttonModalCy).click();
203+
cy.get(selectors.buttonToggle).click();
204+
cy.get(selectors.buttonModal).click();
196205
cyPreflight.setScriptEditorContent(
197206
`lab.request.headers.append('foo', '${preflightHeaders.foo}')`,
198207
);
199-
cy.dataCy(selectors.modal.buttonSubmitCy).click();
208+
cy.get(selectors.modal.buttonSubmit).click();
200209
// Run GraphiQL
201210
cy.intercept({ headers: preflightHeaders }).as('request');
202211
cy.get(selectors.graphiql.buttonExecute).click();
@@ -217,12 +226,12 @@ describe('Execution', () => {
217226
const preflightHeaders = {
218227
accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
219228
};
220-
cy.dataCy(selectors.buttonToggleCy).click();
221-
cy.dataCy(selectors.buttonModalCy).click();
229+
cy.get(selectors.buttonToggle).click();
230+
cy.get(selectors.buttonModal).click();
222231
cyPreflight.setScriptEditorContent(
223232
`lab.request.headers.append('accept', '${preflightHeaders.accept}')`,
224233
);
225-
cy.dataCy(selectors.modal.buttonSubmitCy).click();
234+
cy.get(selectors.modal.buttonSubmit).click();
226235
// Run GraphiQL
227236
cy.intercept({ headers: preflightHeaders }).as('request');
228237
cy.get(selectors.graphiql.buttonExecute).click();
@@ -247,13 +256,13 @@ describe('Execution', () => {
247256
const preflightHeaders = {
248257
foo_preflight: barEnVarInterpolation,
249258
};
250-
cy.dataCy(selectors.buttonToggleCy).click();
251-
cy.dataCy(selectors.buttonModalCy).click();
259+
cy.get(selectors.buttonToggle).click();
260+
cy.get(selectors.buttonModal).click();
252261
cyPreflight.setScriptEditorContent(`
253262
lab.environment.set('bar', '${environmentVariables.bar}')
254263
lab.request.headers.append('foo_preflight', '${preflightHeaders.foo_preflight}')
255264
`);
256-
cy.dataCy(selectors.modal.buttonSubmitCy).click();
265+
cy.get(selectors.modal.buttonSubmit).click();
257266
// Run GraphiQL
258267
cy.intercept({
259268
headers: {

cypress/support/monaco.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import type * as Monaco from 'monaco-editor';
22

33
export namespace cyMonaco {
44
/** Helper function for setting the text within a monaco editor as typing manually results in flaky tests */
5-
export function setContent(editorCyName: string, text: string) {
5+
export function setContent(editorSelector: string, text: string) {
66
// wait for textarea appearing which indicates monaco is loaded
7-
cy.dataCy(editorCyName).find('textarea');
7+
cy.get(editorSelector).find('textarea');
88
cy.window().then((win: Window & typeof globalThis & { monaco: typeof Monaco }) => {
99
// First, check if monaco is available on the main window
1010
const editor = win.monaco.editor
1111
.getEditors()
12-
.find(e => e.getContainerDomNode().parentElement.getAttribute('data-cy') === editorCyName);
12+
.find(
13+
e => e.getContainerDomNode().parentElement.getAttribute('data-cy') === editorSelector,
14+
);
1315

1416
// If Monaco instance is found
1517
if (editor) {
@@ -20,14 +22,14 @@ export namespace cyMonaco {
2022
});
2123
}
2224

23-
export function goToNextProblem(editorCyName: string) {
24-
cy.dataCy(editorCyName).find('textarea').focus().realPress(['Alt', 'F8']);
25+
export function goToNextProblem(editorSelector: string) {
26+
cy.get(editorSelector).find('textarea').focus().realPress(['Alt', 'F8']);
2527
}
2628

27-
export function nextProblemContains(editorCyName: string, problem: string, waitMs = 1000) {
29+
export function nextProblemContains(editorSelector: string, problem: string, waitMs = 1000) {
2830
// Hack: Seemingly only way to reliably interact with the monaco text area from Cypress.
2931
if (waitMs) cy.wait(waitMs);
30-
goToNextProblem(editorCyName);
32+
goToNextProblem(editorSelector);
3133
cy.contains(problem);
3234
}
3335
}

0 commit comments

Comments
 (0)