-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEN-1924]: add CRUD E2E tests for UI sources (#1958)
This pull request includes several changes to improve the functionality and user experience of the frontend web application. The most important changes include adjustments to the notification toast positioning, enhancements to the multi-source control component, updates to the source body form, new end-to-end tests for source CRUD operations, and improvements to the `useSourceCRUD` hook. ### UI/UX Improvements: * [`frontend/webapp/components/notification/toast-list.tsx`](diffhunk://#diff-c6ead7587d1e5c52295c921dde2a1a5b9b06977ab3900c7dbf475c47cc1c664cL10-R10): Changed the position of the notification toast from the bottom to the top of the screen. * [`frontend/webapp/containers/main/overview/multi-source-control/index.tsx`](diffhunk://#diff-cdd99a8fcd0484b24586f22b1f7b1bcf8d964bead53eeb0b2c07646c7301af70L60-R60): Added a `data-id` attribute to the `Transition` component for better identification. * [`frontend/webapp/containers/main/sources/update-source-body/index.tsx`](diffhunk://#diff-c5285ffb349464d72b44f6c535fbe1a02959ef2213441d34027c3fa579207565R25): Added a `name` attribute to the input element for the source name to improve form handling. ### Testing Enhancements: * [`frontend/webapp/cypress/e2e/03-sources.cy.ts`](diffhunk://#diff-981488421b684f7ca98e7e8b147b14c23fe2c57e876d88ca981c563c8ba003cdR1-R105): Added new Cypress end-to-end tests for creating, updating, and deleting CRDs in the cluster. ### Codebase Improvements: * [`frontend/webapp/hooks/sources/useSourceCRUD.ts`](diffhunk://#diff-1be86445dc0ed6bfdc08f7525c5800ef39bdcd70318a3c130f83f36f1ae9f5c8L43-R50): Improved error handling and variable access by adding optional chaining to the `sources` array.
- Loading branch information
1 parent
6ec613c
commit cde5e8f
Showing
7 changed files
with
112 additions
and
6 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { ROUTES } from '../../utils/constants/routes'; | ||
|
||
// The number of CRDs that exist in the cluster before running any tests should be 0. | ||
// Tests will fail if you have existing CRDs in the cluster. | ||
// If you have to run tests locally, make sure to clean up the cluster before running the tests. | ||
|
||
describe('Sources CRUD', () => { | ||
const namespace = 'default'; | ||
const crdName = 'instrumentationconfigs.odigos.io'; | ||
const noResourcesFound = `No resources found in ${namespace} namespace.`; | ||
|
||
beforeEach(() => { | ||
cy.intercept('/graphql').as('gql'); | ||
}); | ||
|
||
it('Should create a CRD in the cluster', () => { | ||
cy.visit(ROUTES.OVERVIEW); | ||
|
||
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdListBefore) => { | ||
expect(crdListBefore.stderr).to.eq(noResourcesFound); | ||
expect(crdListBefore.stdout).to.eq(''); | ||
|
||
const crdIdsBefore = crdListBefore.stdout.split('\n').filter((str) => !!str); | ||
expect(crdIdsBefore.length).to.eq(0); | ||
|
||
cy.get('[data-id=add-entity]').click(); | ||
cy.get('[data-id=add-source]').click(); | ||
cy.get('[data-id=modal-Add-Source]').should('exist'); | ||
cy.get('[data-id=namespace-default]').find('[data-id=checkbox]').click(); | ||
|
||
// Wait for 3 seconds to allow the namespace & it's resources to be loaded into the UI | ||
cy.wait(3000).then(() => { | ||
cy.get('button').contains('DONE').click(); | ||
|
||
cy.wait('@gql').then(() => { | ||
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdListAfter) => { | ||
expect(crdListAfter.stderr).to.eq(''); | ||
expect(crdListAfter.stdout).to.not.be.empty; | ||
|
||
const crdIdsAfter = crdListAfter.stdout.split('\n').filter((str) => !!str); | ||
expect(crdIdsAfter.length).to.eq(5); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('Should update the CRD in the cluster', () => { | ||
cy.visit(ROUTES.OVERVIEW); | ||
|
||
const node = cy.contains('[data-id=source-1]', 'frontend'); | ||
expect(node).to.exist; | ||
node.click(); | ||
|
||
cy.get('[data-id=drawer]').should('exist'); | ||
cy.get('button[data-id=drawer-edit]').click(); | ||
cy.get('input[data-id=sourceName]').clear().type('Cypress Test'); | ||
cy.get('button[data-id=drawer-save]').click(); | ||
cy.get('button[data-id=drawer-close]').click(); | ||
|
||
cy.wait('@gql').then(() => { | ||
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdList) => { | ||
expect(crdList.stderr).to.eq(''); | ||
expect(crdList.stdout).to.not.be.empty; | ||
|
||
const crdIds = crdList.stdout.split('\n').filter((str) => !!str); | ||
const crdId = 'deployment-frontend'; | ||
expect(crdIds.length).to.eq(5); | ||
expect(crdIds).includes(crdId); | ||
|
||
cy.exec(`kubectl get ${crdName} ${crdId} -n ${namespace} -o json`).then((crd) => { | ||
expect(crd.stderr).to.eq(''); | ||
expect(crd.stdout).to.not.be.empty; | ||
|
||
const parsed = JSON.parse(crd.stdout); | ||
const { spec } = parsed?.items?.[0] || parsed || {}; | ||
|
||
expect(spec).to.not.be.empty; | ||
expect(spec.serviceName).to.eq('Cypress Test'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('Should delete the CRD from the cluster', () => { | ||
cy.visit(ROUTES.OVERVIEW); | ||
|
||
cy.get('[data-id=source-header]').find('[data-id=checkbox]').click(); | ||
cy.get('[data-id=multi-source-control]').should('exist'); | ||
cy.get('[data-id=multi-source-control]').find('button').contains('Uninstrument').click(); | ||
cy.get('[data-id=modal]').contains('Uninstrument 5 sources').should('exist'); | ||
cy.get('[data-id=modal]').contains("You're about to uninstrument the last source").should('exist'); | ||
cy.get('button[data-id=approve]').click(); | ||
|
||
cy.wait('@gql').then(() => { | ||
cy.exec(`kubectl get ${crdName} -n ${namespace} | awk 'NR>1 {print $1}'`).then((crdList) => { | ||
expect(crdList.stderr).to.eq(noResourcesFound); | ||
expect(crdList.stdout).to.eq(''); | ||
|
||
const crdIds = crdList.stdout.split('\n').filter((str) => !!str); | ||
expect(crdIds.length).to.eq(0); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
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