1 import { PageHelper } from '../page-helper.po';
3 export class ImagesPageHelper extends PageHelper {
5 index: { url: '#/block/rbd', id: 'cd-rbd-list' },
6 create: { url: '#/block/rbd/create', id: 'cd-rbd-form' }
9 // Creates a block image and fills in the name, pool, and size fields.
10 // Then checks if the image is present in the Images table.
11 createImage(name: string, pool: string, size: string) {
12 this.navigateTo('create');
14 cy.get('#name').type(name); // Enter in image name
17 cy.contains('Loading...').should('not.exist');
18 this.selectOption('pool', pool);
19 cy.get('#pool').should('have.class', 'ng-valid'); // check if selected
21 // Enter in the size of the image
22 cy.get('#size').type(size);
24 // Click the create button and wait for image to be made
25 cy.contains('button', 'Create RBD').click();
26 this.getFirstTableCell(name).should('exist');
29 editImage(name: string, pool: string, newName: string, newSize: string) {
30 this.navigateEdit(name);
32 // Wait until data is loaded
33 cy.get('#pool').should('contain.value', pool);
35 cy.get('#name').clear().type(newName);
36 cy.get('#size').clear().type(newSize); // click the size box and send new size
38 cy.contains('button', 'Edit RBD').click();
40 this.getExpandCollapseElement(newName).click();
41 cy.get('.table.table-striped.table-bordered').contains('td', newSize);
44 // Selects RBD image and moves it to the trash,
45 // checks that it is present in the trash table
46 moveToTrash(name: string) {
47 // wait for image to be created
48 cy.get('.datatable-body').first().should('not.contain.text', '(Creating...)');
50 this.getFirstTableCell(name).click();
52 // click on the drop down and selects the move to trash option
53 cy.get('.table-actions button.dropdown-toggle').first().click();
54 cy.get('li.move-to-trash').click();
56 cy.contains('button', 'Move Image').should('be.visible').click();
59 cy.contains('.nav-link', 'Trash').click();
60 this.getFirstTableCell(name).should('exist');
63 // Checks trash tab table for image and then restores it to the RBD Images table
64 // (could change name if new name is given)
65 restoreImage(name: string, newName?: string) {
66 // clicks on trash tab
67 cy.contains('.nav-link', 'Trash').click();
69 // wait for table to load
70 this.getFirstTableCell(name).click();
71 cy.contains('button', 'Restore').click();
73 // wait for pop-up to be visible (checks for title of pop-up)
74 cy.get('#name').should('be.visible');
76 // If a new name for the image is passed, it changes the name of the image
77 if (newName !== undefined) {
78 // click name box and send new name
79 cy.get('#name').clear().type(newName);
82 cy.contains('button', 'Restore Image').click();
85 cy.contains('.nav-link', 'Images').click();
87 this.getFirstTableCell(newName).should('exist');
90 // Enters trash tab and purges trash, thus emptying the trash table.
91 // Checks if Image is still in the table.
92 purgeTrash(name: string, pool?: string) {
94 cy.contains('.nav-link', 'Trash').click();
95 cy.contains('button', 'Purge Trash').click();
97 // Check for visibility of modal container
98 cy.get('.modal-header').should('be.visible');
100 // If purgeing a specific pool, selects that pool if given
101 if (pool !== undefined) {
102 this.selectOption('poolName', pool);
103 cy.get('#poolName').should('have.class', 'ng-valid'); // check if pool is selected
105 cy.get('#purgeFormButton').click();
106 // Wait for image to delete and check it is not present
108 this.getFirstTableCell(name).should('not.exist');