]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { $, by, element, protractor } from 'protractor'; |
2 | import { PageHelper } from '../page-helper.po'; | |
11fdf7f2 | 3 | |
9f95a23c TL |
4 | const pages = { |
5 | index: '/#/pool', | |
6 | create: '/#/pool/create' | |
7 | }; | |
8 | ||
9 | export class PoolPageHelper extends PageHelper { | |
10 | pages = pages; | |
11 | ||
12 | private isPowerOf2(n: number): boolean { | |
13 | // tslint:disable-next-line: no-bitwise | |
14 | return (n & (n - 1)) === 0; | |
15 | } | |
16 | ||
17 | @PageHelper.restrictTo(pages.index) | |
18 | async exist(name: string, oughtToBePresent = true) { | |
19 | const tableCell = await this.getTableCellByContent(name); | |
20 | const waitFn = oughtToBePresent ? this.waitVisibility : this.waitInvisibility; | |
21 | try { | |
22 | await waitFn(tableCell); | |
23 | } catch (e) { | |
24 | const visibility = oughtToBePresent ? 'invisible' : 'visible'; | |
25 | const msg = `Pool "${name}" is ${visibility}, but should not be. Waiting for a change timed out`; | |
26 | return Promise.reject(msg); | |
27 | } | |
28 | return Promise.resolve(); | |
29 | } | |
30 | ||
31 | @PageHelper.restrictTo(pages.create) | |
32 | async create(name: string, placement_groups: number, ...apps: string[]): Promise<any> { | |
33 | const nameInput = $('input[name=name]'); | |
34 | await nameInput.clear(); | |
35 | if (!this.isPowerOf2(placement_groups)) { | |
36 | return Promise.reject(`Placement groups ${placement_groups} are not a power of 2`); | |
37 | } | |
38 | await nameInput.sendKeys(name); | |
39 | await this.selectOption('poolType', 'replicated'); | |
40 | ||
41 | await this.expectSelectOption('pgAutoscaleMode', 'on'); | |
42 | await this.selectOption('pgAutoscaleMode', 'off'); // To show pgNum field | |
43 | await $('input[name=pgNum]').sendKeys( | |
44 | protractor.Key.CONTROL, | |
45 | 'a', | |
46 | protractor.Key.NULL, | |
47 | placement_groups | |
48 | ); | |
49 | await this.setApplications(apps); | |
50 | await element(by.css('cd-submit-button')).click(); | |
51 | ||
52 | return Promise.resolve(); | |
53 | } | |
54 | ||
55 | async edit_pool_pg(name: string, new_pg: number, wait = true): Promise<void> { | |
56 | if (!this.isPowerOf2(new_pg)) { | |
57 | return Promise.reject(`Placement groups ${new_pg} are not a power of 2`); | |
58 | } | |
59 | const elem = await this.getTableCellByContent(name); | |
60 | await this.waitClickableAndClick(elem); // select pool from the table | |
61 | await element(by.cssContainingText('button', 'Edit')).click(); // click edit button | |
62 | await this.waitTextToBePresent(this.getBreadcrumb(), 'Edit'); // verify we are now on edit page | |
63 | await $('input[name=pgNum]').sendKeys(protractor.Key.CONTROL, 'a', protractor.Key.NULL, new_pg); | |
64 | await element(by.css('cd-submit-button')).click(); | |
65 | const str = `${new_pg} active+clean`; | |
66 | await this.waitVisibility(this.getTableRow(name), 'Timed out waiting for table row to load'); | |
67 | if (wait) { | |
68 | await this.waitTextToBePresent( | |
69 | this.getTableRow(name), | |
70 | str, | |
71 | 'Timed out waiting for placement group to be updated' | |
72 | ); | |
73 | } | |
74 | } | |
75 | ||
76 | private async setApplications(apps: string[]) { | |
77 | if (!apps || apps.length === 0) { | |
78 | return; | |
79 | } | |
80 | await element(by.css('.float-left.mr-2.select-menu-edit')).click(); | |
81 | await this.waitVisibility(element(by.css('.popover-content.popover-body'))); | |
82 | apps.forEach( | |
83 | async (app) => await element(by.cssContainingText('.select-menu-item-content', app)).click() | |
84 | ); | |
11fdf7f2 TL |
85 | } |
86 | } |