-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement JSON formatting and syntax highlighting #443
Open
AmerMesanovic
wants to merge
2
commits into
astarte-platform:master
Choose a base branch
from
AmerMesanovic:json-editor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { | ||
|
@@ -42,14 +48,8 @@ const setupInterfaceEditorFromUI = (iface) => { | |
} | ||
} | ||
if (iface.aggregation === 'object') { | ||
const { | ||
reliability, | ||
explicitTimestamp, | ||
retention, | ||
expiry, | ||
databaseRetention, | ||
databaseTTL, | ||
} = parseMappingOptions(_.get(iface.mappings, '0')); | ||
const { reliability, explicitTimestamp, retention, expiry, databaseRetention, databaseTTL } = | ||
parseMappingOptions(_.get(iface.mappings, '0')); | ||
cy.get('#objectMappingReliability').scrollIntoView().select(reliability); | ||
if (explicitTimestamp) { | ||
cy.get('#objectMappingExplicitTimestamp').scrollIntoView().check(); | ||
|
@@ -128,7 +128,7 @@ const checkMappingEditorUIValues = ({ mapping, type, aggregation = 'individual' | |
.should('be.visible') | ||
.within(() => { | ||
cy.contains(mapping.endpoint); | ||
cy.get('button').contains('Edit...').click(); | ||
cy.get('button').contains('Edit...').should('have.length', 1).click({ force: true }); | ||
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. we could possible have more that one edit button? There is a necessity to check that? |
||
}); | ||
cy.get('.modal.show').within(() => { | ||
cy.get('#mappingEndpoint') | ||
|
@@ -232,14 +232,8 @@ const checkInterfaceEditorUIValues = (iface) => { | |
} | ||
} | ||
if (iface.aggregation === 'object') { | ||
const { | ||
reliability, | ||
explicitTimestamp, | ||
retention, | ||
expiry, | ||
databaseRetention, | ||
databaseTTL, | ||
} = parseMappingOptions(_.get(iface.mappings, '0')); | ||
const { reliability, explicitTimestamp, retention, expiry, databaseRetention, databaseTTL } = | ||
parseMappingOptions(_.get(iface.mappings, '0')); | ||
cy.get('#objectMappingReliability') | ||
.scrollIntoView() | ||
.should('be.visible') | ||
|
@@ -569,10 +563,7 @@ describe('Interface builder tests', () => { | |
// Valid name | ||
cy.get('#interfaceName').clear().paste('com.sample.Name'); | ||
cy.get('#interfaceName').should('not.have.class', 'is-invalid'); | ||
cy.get('#interfaceName') | ||
.parents() | ||
.get('.warning-feedback') | ||
.should('not.exist'); | ||
cy.get('#interfaceName').parents().get('.warning-feedback').should('not.exist'); | ||
}); | ||
|
||
it('correctly reports errors in mapping editor for the endpoint field', () => { | ||
|
@@ -596,6 +587,9 @@ describe('Interface builder tests', () => { | |
]; | ||
interfaceFixtures.forEach((interfaceFixture) => { | ||
cy.fixture(interfaceFixture).then(({ data: iface }) => { | ||
if (!iface) { | ||
throw new Error(`Fixture ${interfaceFixture} did not load correctly`); | ||
} | ||
setupInterfaceEditorFromSource(iface); | ||
checkInterfaceEditorUIValues(iface); | ||
}); | ||
|
@@ -609,10 +603,12 @@ describe('Interface builder tests', () => { | |
'test.astarte.IndividualObjectInterface', | ||
'test.astarte.AggregatedObjectInterface', | ||
]; | ||
|
||
interfaceFixtures.forEach((interfaceFixture) => { | ||
cy.fixture(interfaceFixture).then(({ data: iface }) => { | ||
setupInterfaceEditorFromUI(iface); | ||
checkInterfaceEditorUIValues(iface); | ||
|
||
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. as above, avoid newlines if not necessary |
||
(iface.mappings || []).forEach((mapping) => { | ||
checkMappingEditorUIValues({ | ||
mapping, | ||
|
@@ -773,6 +769,7 @@ describe('Interface builder tests', () => { | |
cy.visit( | ||
`/interfaces/${majorInterface.interface_name}/${majorInterface.version_major}/edit`, | ||
); | ||
cy.wait(1500); | ||
cy.wait('@getInterfaceRequest'); | ||
cy.contains('Delete interface').should('not.exist'); | ||
|
||
|
@@ -792,7 +789,7 @@ describe('Interface builder tests', () => { | |
cy.visit( | ||
`/interfaces/${draftInterface.interface_name}/${draftInterface.version_major}/edit`, | ||
); | ||
cy.wait('@getInterfaceRequest2'); | ||
cy.wait('@getInterfaceRequest2', { timeout: 1500 }); | ||
cy.contains('Delete interface').scrollIntoView().click(); | ||
cy.get('.modal.show').within(() => { | ||
cy.contains( | ||
|
@@ -857,28 +854,33 @@ describe('Interface builder tests', () => { | |
}, | ||
).as('saveNoDefaultsInterfaceRequest'); | ||
cy.visit(`/interfaces/${iface.interface_name}/${iface.version_major}/edit`); | ||
cy.wait('@getInterfaceRequest'); | ||
cy.wait('@getInterfaceRequest', { timeout: 1500 }); | ||
cy.wait(2000); | ||
cy.window().then((win) => { | ||
cy.wrap(win.monaco).should('exist'); | ||
cy.wrap(win.monaco.editor).should('exist'); | ||
}); | ||
|
||
cy.window().then((win) => { | ||
const editor = win.monaco.editor.getModels()[0]; | ||
cy.wrap(editor).should('exist'); | ||
const ifaceSource = editor.getValue(); | ||
expect(JSON.parse(ifaceSource)).to.deep.eq(iface); | ||
}); | ||
|
||
const newIface = _.merge({}, iface, { | ||
version_minor: iface.version_minor + 1, | ||
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); | ||
}); | ||
|
||
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); | ||
}); | ||
cy.window().then((win) => { | ||
const editor = win.monaco.editor.getModels()[0]; | ||
cy.wrap(editor).should('exist'); | ||
const ifaceSource = editor.getValue(); | ||
expect(JSON.parse(ifaceSource)).to.deep.eq(newIface); | ||
}); | ||
|
||
// Interface should be saved without adding default values | ||
cy.get('button').contains('Apply changes').scrollIntoView().click(); | ||
|
@@ -905,27 +907,32 @@ describe('Interface builder tests', () => { | |
).as('saveSpecifiedDefaultsInterfaceRequest'); | ||
cy.visit(`/interfaces/${iface.interface_name}/${iface.version_major}/edit`); | ||
cy.wait('@getInterfaceRequest2'); | ||
cy.wait(2000); | ||
cy.window().then((win) => { | ||
cy.wrap(win.monaco).should('exist'); | ||
cy.wrap(win.monaco.editor).should('exist'); | ||
}); | ||
|
||
cy.window().then((win) => { | ||
const editor = win.monaco.editor.getModels()[0]; | ||
cy.wrap(editor).should('exist'); | ||
const ifaceSource = editor.getValue(); | ||
expect(JSON.parse(ifaceSource)).not.to.deep.eq(iface); | ||
}); | ||
const newIface = _.merge({}, iface, { | ||
version_minor: iface.version_minor + 1, | ||
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); | ||
}); | ||
|
||
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); | ||
}); | ||
cy.window().then((win) => { | ||
const editor = win.monaco.editor.getModels()[0]; | ||
cy.wrap(editor).should('exist'); | ||
const ifaceSource = editor.getValue(); | ||
expect(JSON.parse(ifaceSource)).not.to.deep.eq(newIface); | ||
}); | ||
|
||
// Interface should be saved with default values stripped out | ||
cy.get('button').contains('Apply changes').scrollIntoView().click(); | ||
|
@@ -954,11 +961,9 @@ 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'); | ||
|
@@ -975,11 +980,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}`, | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
if there are no changes, please avoid to change code format as this will introduce undesired noise to the pr.
Same goes for unnecessary ; at the end of a line
there are multiple occurrences in this PR that only changes how the code is styled but add nothing, it's better to move a restyling in another PR