-
Notifications
You must be signed in to change notification settings - Fork 18
Implement JSON formatting and syntax highlighting #443
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,14 @@ const parseMappingOptions = (mapping) => { | |
| }; | ||
|
|
||
| const setupInterfaceEditorFromSource = (iface) => { | ||
| cy.get('#interfaceSource').clear().paste(JSON.stringify(iface)); | ||
| cy.wait(500); | ||
| cy.get('.monaco-editor') | ||
| .should('be.visible') | ||
| .then(() => { | ||
| cy.window().then((win) => { | ||
| const editor = win.monaco.editor.getModels()[0]; | ||
| editor.setValue(JSON.stringify(iface, null, 4)); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| const setupInterfaceEditorFromUI = (iface) => { | ||
|
|
@@ -597,6 +603,7 @@ describe('Interface builder tests', () => { | |
| interfaceFixtures.forEach((interfaceFixture) => { | ||
| cy.fixture(interfaceFixture).then(({ data: iface }) => { | ||
| setupInterfaceEditorFromSource(iface); | ||
| setupInterfaceEditorFromUI(iface); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like cheating :) This test If we call If we want to maintain the same behavior, we can update the implementation instead of the test, making sure that when the user changes the editor's content then the UI fields are updated. |
||
| checkInterfaceEditorUIValues(iface); | ||
| }); | ||
| }); | ||
|
|
@@ -841,6 +848,14 @@ describe('Interface builder tests', () => { | |
| }); | ||
|
|
||
| it('displays and saves an interface source with default values stripped out', function () { | ||
| // Continuously wait for and check the Monaco editor | ||
| function waitForEditor() { | ||
| cy.waitForMonacoEditor().then((editor) => { | ||
| const editorValue = editor.getValue(); | ||
| cy.wrap(editorValue).as('editorValue'); | ||
| }); | ||
| } | ||
|
|
||
| // Case with no default values to strip out | ||
| cy.fixture('test.astarte.NoDefaultsInterface').then(({ data: iface }) => { | ||
| cy.intercept( | ||
|
|
@@ -863,22 +878,22 @@ describe('Interface builder tests', () => { | |
| doc: 'New documentation', | ||
| }); | ||
|
|
||
| // Source should be displayed equal, without adding default values | ||
| cy.get('#interfaceSource') | ||
| .invoke('val') | ||
| .should((ifaceSource) => { | ||
| expect(JSON.parse(ifaceSource)).to.deep.eq(iface); | ||
| }); | ||
| // Check Monaco Editor content without adding default values | ||
| cy.window().should('have.property', 'monaco'); | ||
| waitForEditor(); | ||
| cy.get('@editorValue').should((editorValue) => { | ||
| expect(JSON.parse(editorValue)).to.deep.eq(iface); | ||
| }); | ||
|
|
||
| cy.get('#interfaceMinor').type(`{selectall}${newIface.version_minor}`); | ||
| cy.get('#interfaceDocumentation').clear().paste(newIface.doc); | ||
|
|
||
| // Source should be displayed equal, without adding default values | ||
| cy.get('#interfaceSource') | ||
| .invoke('val') | ||
| .should((ifaceSource) => { | ||
| expect(JSON.parse(ifaceSource)).to.deep.eq(newIface); | ||
| }); | ||
| // Check Monaco Editor content without adding default values | ||
| cy.window().should('have.property', 'monaco'); | ||
| waitForEditor(); | ||
| cy.get('@editorValue').should((editorValue) => { | ||
| expect(JSON.parse(editorValue)).to.deep.eq(newIface); | ||
| }); | ||
|
|
||
| // Interface should be saved without adding default values | ||
| cy.get('button').contains('Apply changes').scrollIntoView().click(); | ||
|
|
@@ -910,22 +925,22 @@ describe('Interface builder tests', () => { | |
| doc: 'New documentation', | ||
| }); | ||
|
|
||
| // Source should not be displayed equal, since default values are stripped out | ||
| cy.get('#interfaceSource') | ||
| .invoke('val') | ||
| .should((ifaceSource) => { | ||
| expect(JSON.parse(ifaceSource)).not.to.deep.eq(iface); | ||
| }); | ||
| // Check Monaco Editor content as default values are stripped out | ||
| cy.window().should('have.property', 'monaco'); | ||
| waitForEditor(); | ||
| cy.get('@editorValue').should((editorValue) => { | ||
| expect(JSON.parse(editorValue)).not.to.deep.eq(iface); | ||
| }); | ||
|
|
||
| cy.get('#interfaceMinor').type(`{selectall}${newIface.version_minor}`); | ||
| cy.get('#interfaceDocumentation').clear().paste(newIface.doc); | ||
|
|
||
| // Source should not be displayed equal, since default values are stripped out | ||
| cy.get('#interfaceSource') | ||
| .invoke('val') | ||
| .should((ifaceSource) => { | ||
| expect(JSON.parse(ifaceSource)).not.to.deep.eq(newIface); | ||
| }); | ||
| // Check Monaco Editor content as default values are stripped out | ||
| cy.window().should('have.property', 'monaco'); | ||
| waitForEditor(); | ||
| cy.get('@editorValue').should((editorValue) => { | ||
| expect(JSON.parse(editorValue)).not.to.deep.eq(newIface); | ||
| }); | ||
|
|
||
| // Interface should be saved with default values stripped out | ||
| cy.get('button').contains('Apply changes').scrollIntoView().click(); | ||
|
|
@@ -954,15 +969,12 @@ describe('Interface builder tests', () => { | |
| ...initialIface, | ||
| mappings: [restOfElements], | ||
| }; | ||
| cy.get('#interfaceSource') | ||
| .clear() | ||
| .invoke('val', JSON.stringify(updatedIface, null, 4)) | ||
| .type('{enter}'); | ||
|
|
||
| // Set the updatedIface value in MonacoEditor using setupInterfaceEditorFromSource | ||
| setupInterfaceEditorFromSource(updatedIface); | ||
| cy.get('[data-testid="/test"]').within(() => { | ||
| // Check if the mapping endpoint is displayed | ||
| cy.contains('/test'); | ||
|
|
||
| // Check that the Edit and Delete buttons are not present | ||
| cy.get('button').contains('Edit...').should('not.exist'); | ||
| cy.get('button').contains('Delete').should('not.exist'); | ||
|
|
@@ -975,11 +987,9 @@ describe('Interface builder tests', () => { | |
| ...updatedIface, | ||
| version_minor: updatedIface.version_minor + 1, | ||
| }; | ||
| cy.get('#interfaceSource') | ||
| .clear() | ||
| .invoke('val', JSON.stringify(newIface, null, 4)) | ||
| .type('{enter}'); | ||
|
|
||
| // Set the newIface value in MonacoEditor using setupInterfaceEditorFromSource | ||
| setupInterfaceEditorFromSource(newIface); | ||
| cy.intercept( | ||
| 'PUT', | ||
| `/realmmanagement/v1/*/interfaces/${newIface.interface_name}/${newIface.version_major}`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal to stick to the basic Cypress commands, thus simulating an actual user interacting and writing (or pasting) into the editor.
The main idea when doing e2e tests is to avoid thinking about the implementation and just test the expected user interaction.
Do you think it's feasible, or did you encounter some issues?