]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/e2e/block/images.po.ts
d/control: depend on python3-yaml for ceph-mgr
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / e2e / block / images.po.ts
1 import { $, $$, browser, by, element } from 'protractor';
2 import { PageHelper } from '../page-helper.po';
3
4 export class ImagesPageHelper extends PageHelper {
5 pages = {
6 index: '/#/block/rbd',
7 create: '/#/block/rbd/create'
8 };
9
10 // Creates a block image and fills in the name, pool, and size fields. Then checks
11 // if the image is present in the Images table.
12 async createImage(name: string, pool: string, size: string) {
13 await this.navigateTo('create');
14
15 // Need the string '[value="<pool>"]' to find the pool in the dropdown menu
16 const getPoolName = `[value="${pool}"]`;
17
18 await element(by.id('name')).sendKeys(name); // Enter in image name
19
20 // Select image pool
21 await this.selectOption('pool', pool);
22 await $(getPoolName).click();
23 await expect(element(by.id('pool')).getAttribute('class')).toContain('ng-valid'); // check if selected
24
25 // Enter in the size of the image
26 await element(by.id('size')).click();
27 await element(by.id('size')).sendKeys(size);
28
29 // Click the create button and wait for image to be made
30 await element(by.cssContainingText('button', 'Create RBD')).click();
31 return this.waitPresence(this.getFirstTableCellWithText(name));
32 }
33
34 async editImage(name: string, pool: string, newName: string, newSize: string) {
35 const base_url = '/#/block/rbd/edit/';
36 const editURL = base_url
37 .concat(encodeURIComponent(pool))
38 .concat('%2F')
39 .concat(encodeURIComponent(name));
40 await browser.get(editURL);
41
42 await element(by.id('name')).click(); // click name box and send new name
43 await element(by.id('name')).clear();
44 await element(by.id('name')).sendKeys(newName);
45 await element(by.id('size')).click();
46 await element(by.id('size')).clear();
47 await element(by.id('size')).sendKeys(newSize); // click the size box and send new size
48
49 await element(by.cssContainingText('button', 'Edit RBD')).click();
50 await this.navigateTo();
51 await this.waitClickableAndClick(this.getFirstTableCellWithText(newName));
52 await expect(
53 element
54 .all(by.css('.table.table-striped.table-bordered'))
55 .first()
56 .getText()
57 ).toMatch(newSize);
58 }
59
60 // Selects RBD image and moves it to the trash, checks that it is present in the
61 // trash table
62 async moveToTrash(name: string) {
63 await this.navigateTo();
64 // wait for image to be created
65 await this.waitTextNotPresent($$('.datatable-body').first(), '(Creating...)');
66 await this.waitClickableAndClick(this.getFirstTableCellWithText(name));
67 // click on the drop down and selects the move to trash option
68 await $$('.table-actions button.dropdown-toggle')
69 .first()
70 .click();
71 await $('li.move-to-trash').click();
72 await this.waitVisibility(element(by.cssContainingText('button', 'Move Image')));
73 await element(by.cssContainingText('button', 'Move Image')).click();
74 await this.navigateTo();
75 // Clicks trash tab
76 await this.waitClickableAndClick(element(by.cssContainingText('.nav-link', 'Trash')));
77 await this.waitPresence(this.getFirstTableCellWithText(name));
78 }
79
80 // Checks trash tab table for image and then restores it to the RBD Images table
81 // (could change name if new name is given)
82 async restoreImage(name: string, newName?: string) {
83 await this.navigateTo();
84 // clicks on trash tab
85 await element(by.cssContainingText('.nav-link', 'Trash')).click();
86 // wait for table to load
87 await this.waitClickableAndClick(this.getFirstTableCellWithText(name));
88 await element(by.cssContainingText('button', 'Restore')).click();
89 // wait for pop-up to be visible (checks for title of pop-up)
90 await this.waitVisibility(element(by.id('name')));
91 // If a new name for the image is passed, it changes the name of the image
92 if (newName !== undefined) {
93 await element(by.id('name')).click(); // click name box and send new name
94 await element(by.id('name')).clear();
95 await element(by.id('name')).sendKeys(newName);
96 }
97 await element(by.cssContainingText('button', 'Restore Image')).click();
98 await this.navigateTo();
99 // clicks images tab
100 await element(by.cssContainingText('.nav-link', 'Images')).click();
101 await this.navigateTo();
102 await this.waitPresence(this.getFirstTableCellWithText(newName));
103 }
104
105 // Enters trash tab and purges trash, thus emptying the trash table. Checks if
106 // Image is still in the table.
107 async purgeTrash(name: string, pool?: string) {
108 await this.navigateTo();
109 // clicks trash tab
110 await element(by.cssContainingText('.nav-link', 'Trash')).click();
111 await element(by.cssContainingText('button', 'Purge Trash')).click();
112 // Check for visibility of modal container
113 await this.waitVisibility(element(by.id('poolName')));
114 // If purgeing a specific pool, selects that pool if given
115 if (pool !== undefined) {
116 const getPoolName = `[value="${pool}"]`;
117 await element(by.id('poolName')).click();
118 await element(by.cssContainingText('select[name=poolName] option', pool)).click();
119 await $(getPoolName).click();
120 await expect(element(by.id('poolName')).getAttribute('class')).toContain('ng-valid'); // check if pool is selected
121 }
122 await this.waitClickableAndClick(element(by.id('purgeFormButton')));
123 // Wait for image to delete and check it is not present
124 await this.waitStaleness(
125 this.getFirstTableCellWithText(name),
126 'Timed out waiting for image to be purged'
127 );
128 await expect(this.getFirstTableCellWithText(name).isPresent()).toBe(false);
129 }
130 }