Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(laboratory): preflight editor components #6498

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions cypress/e2e/laboratory/_cy.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this file cypress.ts? I don't understand why we need to use an abbreviation, let alone why we need to prefix it with a underscore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh happy to explain:

  1. The directory contains test files. I would like to keep this file from being interleaved in them since its not a test file. That is what _ achieves. It could also be nested directory or $ prefix, whereas cypress.ts would not achieve this. Can you propose something that would? Alternatively clarify that you don't care about about my goal here.
  2. The abbreviation is consistent with APIs from Cypress. Cypress uses a global cy namespace and what this module does is provide a kind of cy dedicated for laboratory. If that is not logical to you that's fine, but I think its not as random as your reaction to my change might suggest.

Please let me know how the above changes, if at all, your feedback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #6476 I have tried to appease the feedback with a name of __cypress__.ts which utilizes a file name pattern that is used elsewhere.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .cy.ts extension does this though right? If this is a utility library for testing rather than a test file, it can have a different extension which is excluded from the test file matching.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can have a different extension which is excluded from the test file matching.

@jdolle I think we are talking about different things. At issue in my mind was keeping the utility file in the directory tree in a prefix or suffix position in the directory. In other words it is purely about the visual parsing in the file explorer. In regards to test file execution, as you said, that works fine. Does that clear up for you what I was trying to do?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.
I'm not very concerned with this visual distinction. Unless the directory gets very large, it's still easy enough to distinguish

Copy link
Member Author

@jasonkuhrt jasonkuhrt Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should mention that I struggle parsing visuals and navigating inconsistency more than the average person. It could be that our thresholds significantly differ on some things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If co-locating at the edges of the directory are hurting others' usability of the project, which is the sense I'm getting but not sure, then I will try to find another way, perhaps just back into the catch all directory.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { setMonacoEditorContents } from '../../support/monaco';

export namespace cyLaboratory {
/**
* Updates the value of the graphiql editor
*/
export function updateEditorValue(value: string) {
cy.get('.graphiql-query-editor .cm-s-graphiql').then($editor => {
const editor = ($editor[0] as any).CodeMirror; // Access the CodeMirror instance
editor.setValue(value);
});
}
jasonkuhrt marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the value of the graphiql editor as Chainable<string>
*/
export function getEditorValue() {
return cy.get('.graphiql-query-editor .cm-s-graphiql').then<string>($editor => {
const editor = ($editor[0] as any).CodeMirror; // Access the CodeMirror instance
return editor.getValue();
});
}

/**
* Opens a new tab
*/
export function openNewTab() {
cy.get('button[aria-label="New tab"]').click();
// tab's title should be "untitled" as it's a default name
cy.contains('button[aria-controls="graphiql-session"]', 'untitled').should('exist');
}

/**
* Asserts that the tab with the given name is active
*/
export function assertActiveTab(name: string) {
cy.contains('li.graphiql-tab-active > button[aria-controls="graphiql-session"]', name).should(
'exist',
);
}

/**
* Closes the active tab
*/
export function closeActiveTab() {
cy.get('li.graphiql-tab-active > button.graphiql-tab-close').click();
}

/**
* Closes all tabs until one is left
*/
export function closeTabsUntilOneLeft() {
cy.get('li.graphiql-tab').then($tabs => {
if ($tabs.length > 1) {
closeActiveTab();
// Recurse until there's only one tab left
return closeTabsUntilOneLeft();
}
});
}

export namespace preflight {
export const selectors = {
buttonGraphiQLPreflight: '[aria-label*="Preflight Script"]',
buttonModalCy: 'preflight-modal-button',
buttonToggleCy: 'toggle-preflight',
buttonHeaders: '[data-name="headers"]',
headersEditor: {
textArea: '.graphiql-editor-tool .graphiql-editor:last-child textarea',
},
graphiql: {
buttonExecute: '.graphiql-execute-button',
},

modal: {
buttonSubmitCy: 'preflight-modal-submit',
editorCy: 'preflight-editor',
variablesEditorCy: 'env-editor',
},
};
/**
* Sets the content of the preflight editor
*/
export const setEditorContent = (value: string) => {
setMonacoEditorContents(selectors.modal.editorCy, value);
};

/**
* Sets the content of the variables editor
*/
export const setEnvironmentEditorContent = (value: string) => {
setMonacoEditorContents(selectors.modal.variablesEditorCy, value);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { laboratory } from '../support/testkit';
import { cyLaboratory } from './_cy';

beforeEach(() => {
cy.clearAllLocalStorage().then(() => {
Expand All @@ -16,7 +16,7 @@ beforeEach(() => {
.first()
.click();
cy.get('[aria-label="Show Operation Collections"]').click();
laboratory.closeTabsUntilOneLeft();
cyLaboratory.closeTabsUntilOneLeft();
});
});
});
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('Laboratory > Collections', () => {
name: 'collection-1',
description: 'Description 1',
});
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
Expand All @@ -103,7 +103,7 @@ describe('Laboratory > Collections', () => {
name: 'collection-1',
description: 'Description 1',
});
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
Expand All @@ -127,7 +127,7 @@ describe('Laboratory > Collections', () => {
name: 'collection-1',
description: 'Description 1',
});
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
Expand All @@ -151,7 +151,7 @@ describe('Laboratory > Collections', () => {
name: 'collection-1',
description: 'Description 1',
});
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
Expand All @@ -173,14 +173,14 @@ describe('Laboratory > Collections', () => {
name: 'collection-1',
description: 'Description 1',
});
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
});

laboratory.openNewTab();
laboratory.updateEditorValue(`query op2 { test }`);
cyLaboratory.openNewTab();
cyLaboratory.updateEditorValue(`query op2 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-2',
collectionName: 'collection-1',
Expand All @@ -206,14 +206,14 @@ describe('Laboratory > Collections', () => {
description: 'Description 2',
});
collections.clickCollectionButton('collection-1');
laboratory.updateEditorValue(`query op1 { test }`);
cyLaboratory.updateEditorValue(`query op1 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-1',
collectionName: 'collection-1',
});

laboratory.openNewTab();
laboratory.updateEditorValue(`query op2 { test }`);
cyLaboratory.openNewTab();
cyLaboratory.updateEditorValue(`query op2 { test }`);
collections.saveCurrentOperationAs({
name: 'operation-2',
collectionName: 'collection-2',
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('Laboratory > Collections', () => {
return cy.visit(copiedUrl);
});

laboratory.assertActiveTab('operation-1');
laboratory.getEditorValue().should('contain', 'op1');
cyLaboratory.assertActiveTab('operation-1');
cyLaboratory.getEditorValue().should('contain', 'op1');
});
});
Loading
Loading