Skip to content

Commit

Permalink
Cypress: Refactor Images & Volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYuzeng committed Jun 6, 2022
1 parent 32ddc46 commit 28db2c7
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 371 deletions.
1 change: 1 addition & 0 deletions cypress/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export const HCI = {
};

export const NETWORK_ATTACHMENT = 'k8s.cni.cncf.io.networkattachmentdefinition';
export const PVC = 'persistentvolumeclaim';
9 changes: 6 additions & 3 deletions cypress/cypress.env.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
}
]
},
"image":
{
"largeImage": {
"name": "openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso",
"url": "https://mirrors.bfsu.edu.cn/opensuse/distribution/leap/15.3/iso/openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso"
}
},
"image": {
"name": "cirros-0.5.2-aarch64-disk.img",
"url": "https://github.com/cirros-dev/cirros/releases/download/0.5.2/cirros-0.5.2-aarch64-disk.img"
},
}
6 changes: 5 additions & 1 deletion cypress/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
"devPath": ""
}]
},
"image": {
"largeImage": {
"name": "openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso",
"url": "https://mirrors.bfsu.edu.cn/opensuse/distribution/leap/15.3/iso/openSUSE-Leap-15.3-3-DVD-x86_64-Build38.1-Media.iso"
},
"image": {
"name": "cirros-0.5.2-aarch64-disk.img",
"url": "https://github.com/cirros-dev/cirros/releases/download/0.5.2/cirros-0.5.2-aarch64-disk.img"
},
"nfsEndPoint": "nfs://ip"
},
"retries": {
Expand Down
73 changes: 16 additions & 57 deletions cypress/pageobjects/image.po.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Constants } from "@/constants/constants";
import { HCI } from '@/constants/types'
import CruResourcePo from '@/utils/components/cru-resource.po';
import LabeledInputPo from '@/utils/components/labeled-input.po';
import { VolumePage } from "@/pageobjects/volume.po";

Expand All @@ -15,41 +17,29 @@ interface ValueInterface {
labels?: any,
}

export class ImagePage {
private actionMenu: string = '.list-unstyled.menu';
export class ImagePage extends CruResourcePo {
private downloadOrUploadRadios: string = '.radio-group';
private fileButton: string = '#file';
private search: string = '.search';
private deleteButton: string = '.card-container.prompt-remove';
private pageHead = 'main .outlet header h1';

name() {
return new LabeledInputPo('.namespace-select > .labeled-input', `:contains("Name")`)
constructor() {
super({
type: HCI.IMAGE
});
}

url() {
return new LabeledInputPo('.labeled-input', `:contains("URL")`);
}

description() {
return new LabeledInputPo('.labeled-input', `:contains("Description")`)
}

public goToList() {
cy.visit(constants.imagePage);
cy.get(this.pageHead).then($el => {
cy.url().should('exist', constants.imagePage);
})
}

public goToCreate() {
this.goToList();
cy.contains('Create').click();
}

public goToEdit(name: string) {
this.goToList();
cy.get(this.search).type(name);
cy.get(this.searchInput).type(name);
const image = cy.contains(name);

image.should('be.visible')
Expand Down Expand Up @@ -106,7 +96,7 @@ export class ImagePage {

public exportImage(vmName: string, imageName: string) {
volumes.goToList();
cy.get(this.search).type(vmName);
cy.get(this.searchInput).type(vmName);

const volume = cy.contains(vmName);

Expand All @@ -119,7 +109,7 @@ export class ImagePage {
}

public checkState(value: ValueInterface, valid: boolean = true) {
cy.get(this.search).type(value.name);
cy.get(this.searchInput).type(value.name);

// state indicator for image upload progress percentage bar
cy.contains(value.name).parentsUntil('tbody', 'tr').find('td.col-image-percentage-bar').contains(valid ? 'Completed' : '0%', { timeout: constants.timeout.uploadTimeout }).should('be.visible');
Expand All @@ -131,34 +121,6 @@ export class ImagePage {
}
}

// public checkImageInLH(imageName: string) {
// let imageId: any = null;

// cy.intercept('GET', '/v1/harvester/harvesterhci.io.virtualmachineimages').as('getImageList');
// this.goToList();

// cy.wait('@getImageList').then(res => {
// expect(res.response?.statusCode).to.equal(200);

// const images = res.response?.body?.data || [];

// imageId = images.find((image: any) => image.spec.displayName === imageName)?.id;
// expect(!!imageId).to.be.true;
// });

// cy.request({ method: 'GET', url: 'v1/longhorn.io.backingimages', headers: {
// 'Content-Type': 'application/json; charset=utf-8',
// 'accept': 'json'
// }}).as('getBackingImageList');

// cy.get('@getBackingImageList').should((response) => {
// const found = response.body.data.find((image: any) => imageId.replace('/', '-') === image.metadata.name);

// expect(found?.metadata?.state?.error).to.be.false;
// expect(found?.metadata?.state?.name).to.equal('active');
// });
// }

public save( { upload, edit }: { upload?: boolean; edit?: boolean } = {} ) {
cy.intercept(edit? 'PUT' : 'POST', `/v1/harvester/harvesterhci.io.virtualmachineimages${ upload ? '/*' : edit ? '/*/*' : '' }`).as('createImage');
cy.get('.cru-resource-footer').contains(!edit ? 'Create' : 'Save').click();
Expand All @@ -168,24 +130,21 @@ export class ImagePage {
}

public setValue(value: ValueInterface) {
this.namespace().select(value?.namespace)
this.name().input(value?.name);
this.url().input(value?.url);
this.description().input(value?.description);
}

public delete(name: string) {
this.goToList();
cy.get(this.search).type(name);
const image = cy.contains(name);
cy.visit(`/c/local/harvester/${this.type}`)

image.should('be.visible')
image.parentsUntil('tbody', 'tr').click();
cy.contains('Delete').click();
this.clickAction(name, 'Delete')

cy.intercept('DELETE', '/v1/harvester/harvesterhci.io.virtualmachineimages/*/*').as('delete');
cy.get(this.deleteButton).contains('Delete').click();
cy.get(this.confirmRemove).contains('Delete').click();
cy.wait('@delete').then(res => {
expect(res.response?.statusCode).to.equal(200);
});
expect(res.response?.statusCode, `Delete ${this.type}`).to.be.oneOf([200, 204]);
})
}
}
14 changes: 5 additions & 9 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,12 @@ export class VmsPage {
}

public init() {
cy.intercept('GET', `v1/harvester/${HCI.IMAGE}s`).as('imageList');
image.goToList();
cy.request({
url: `v1/harvester/${HCI.IMAGE}s`,
headers: {
accept: 'application/json'
}
}).as('imageList')

cy.get('@imageList').should((res: any) => {
expect(res?.status, 'Check Image list').to.equal(200);
const images = res?.body?.data || []
cy.wait('@imageList').should((res: any) => {
expect(res.response?.statusCode, 'Check Image list').to.equal(200);
const images = res?.response?.body?.data || []

const imageEnv = Cypress.env('image');

Expand All @@ -179,6 +174,7 @@ export class VmsPage {
url,
})
image.save()
image.checkState({ name, size: '16 MB' });
}
})
}
Expand Down
Loading

0 comments on commit 28db2c7

Please sign in to comment.