Skip to content

Commit

Permalink
Add E2E test case
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Jul 16, 2023
1 parent a24a728 commit e1ca26f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ui-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: cypress-io/github-action@v5
env:
ODO_EXPERIMENTAL_MODE: "true"
ODO_TRACKING_CONSENT: "no"
with:
working-directory: ui
# Run odo against the UI itself
Expand Down
26 changes: 26 additions & 0 deletions ui/cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import {TAB_COMMANDS, TAB_CONTAINERS, TAB_IMAGES, TAB_METADATA, TAB_RESOURCES} f

describe('devfile editor spec', () => {

let originalDevfile: any
before(() => {
cy.readFile('devfile.yaml').then(yaml => originalDevfile = yaml)
})

afterEach(() => {
cy.writeFile('devfile.yaml', originalDevfile)
})

it('displays matadata.name set in YAML', () => {
cy.visit('http://localhost:4200');
cy.clearDevfile();
Expand Down Expand Up @@ -204,4 +213,21 @@ describe('devfile editor spec', () => {
.should('contain.text', 'URI')
.should('contain.text', '/my/manifest.yaml');
});

it('reloads the Devfile upon changes in the filesystem', () => {
cy.visit('http://localhost:4200');
cy.fixture('input/devfile-new-version.yaml').then(yaml => {
cy.writeDevfileFile(yaml);
});

cy.selectTab(TAB_METADATA);
cy.getByDataCy("metadata-name").should('have.value', 'my-component');

cy.selectTab(TAB_CONTAINERS);
cy.getByDataCy('container-info').first()
.should('contain.text', 'my-cont1')
.should('contain.text', 'some-image:latest')
.should('contain.text', 'some command')
.should('contain.text', 'some arg');
});
});
13 changes: 13 additions & 0 deletions ui/cypress/fixtures/input/devfile-new-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
schemaVersion: 2.2.0
metadata:
name: my-component
components:
- container:
args:
- some
- arg
command:
- some
- command
image: some-image:latest
name: my-cont1
12 changes: 12 additions & 0 deletions ui/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,24 @@ Cypress.Commands.add('clearDevfile', () => {
cy.wait(['@clearDevState', '@applyDevState', '@getDevStateChart']);
});

// writeDevfileFile writes the specified content into the local devfile.yaml file on the filesystem.
// Since #6902, doing so sends notification from the server to the client, and makes it reload the Devfile.
Cypress.Commands.add('writeDevfileFile', (content: string) => {
cy.intercept('GET', '/api/v1/devfile').as('fetchDevfile');
cy.intercept('PUT', '/api/v1/devstate/devfile').as('applyDevState');
cy.intercept('GET', '/api/v1/devstate/chart').as('getDevStateChart');
cy.writeFile('devfile.yaml', content)
cy.wait(['@fetchDevfile', '@applyDevState', '@getDevStateChart']);
});

declare namespace Cypress {
interface Chainable {
getByDataCy(value: string): Chainable<void>
selectTab(n: number): Chainable<void>

setDevfile(devfile: string): Chainable<void>
clearDevfile(): Chainable<void>

writeDevfileFile(content: string): Chainable<void>
}
}

0 comments on commit e1ca26f

Please sign in to comment.