1
- import { by , ElementFinder , Locator } from 'protractor' ;
1
+ import { by , ElementFinder , Locator , browser } from 'protractor' ;
2
2
import { BaseElement } from './base.element' ;
3
3
import { Input } from './input.element' ;
4
+ import { logger } from '../utils/log.util' ;
4
5
5
6
export class InlineEditor extends BaseElement {
6
7
7
8
constructor ( locatorOrElement : Locator | ElementFinder ) {
8
9
super ( locatorOrElement ) ;
9
10
}
10
11
11
- private inlineForm : ElementFinder = this . element . element ( by . css ( '.inlineEditForm' ) ) ;
12
- private inlineFormSave : ElementFinder = this . element . element ( by . css ( '#inline-editor-button-save' ) ) ;
13
- private inlineInput : Input = new Input ( this . element . element ( by . css ( 'input, textarea' ) ) ) ;
14
- private link : ElementFinder = this . element . element ( by . css ( 'a' ) ) ;
12
+ private inlineForm : ElementFinder = this . element . element ( by . css ( '.ie-value-holder' ) ) ;
13
+ private inlineLinkForm : ElementFinder = this . element . element ( by . css ( '.link-holder' ) ) ;
14
+ private inlineFormPlaceholder : ElementFinder = this . element . element ( by . css ( '.placeholder' ) ) ;
15
+ private editFormOpener : ElementFinder = this . element . element ( by . css ( '.ie-edit' ) ) ;
16
+ private editorFormSave : ElementFinder = this . element . element ( by . css ( '.ie-save' ) ) ;
17
+ private editorFormCancel : ElementFinder = this . element . element ( by . css ( '.ie-cancel' ) ) ;
18
+ private editorInput : Input = new Input ( this . element . element ( by . css ( '.ie-editor' ) ) ) ;
19
+ private error : ElementFinder = this . element . element ( by . css ( '.invalid-feedback' ) ) ;
15
20
16
21
public async openEditor ( ) {
17
- if ( ! ( await this . inlineForm . isDisplayed ( ) ) ) {
18
- return this . element . click ( ) ;
22
+ logger . info ( 'Opening Inline Editor' ) ;
23
+ if ( await this . inlineForm . isDisplayed ( ) ) {
24
+ await browser . actions ( ) . mouseMove ( this . inlineForm ) . perform ( ) ;
25
+ return this . editFormOpener . click ( ) ;
19
26
}
27
+ logger . warn ( 'Inline Editor is not displayed or already opened!' ) ;
20
28
}
21
29
22
30
public async accept ( ) {
23
- if ( await this . inlineForm . isDisplayed ( ) ) {
24
- return this . inlineFormSave . click ( ) ;
31
+ logger . info ( 'Saving Inline Editor' ) ;
32
+ if ( await this . editorInput . isDisplayed ( ) ) {
33
+ return this . editorFormSave . click ( ) ;
25
34
}
35
+ logger . warn ( 'Inline Editor is not displayed or not opened!' ) ;
36
+ }
37
+
38
+ public async cancel ( ) {
39
+ logger . info ( 'Cancel Inline Editor' ) ;
40
+ if ( await this . editorInput . isDisplayed ( ) ) {
41
+ return this . editorFormCancel . click ( ) ;
42
+ }
43
+ logger . warn ( 'Inline Editor is not displayed or not opened!' ) ;
26
44
}
27
45
28
46
public async typeText ( value : string ) {
29
- if ( await this . inlineForm . isDisplayed ( ) ) {
30
- return this . inlineInput . typeText ( value ) ;
47
+ logger . info ( 'Typing into Inline Editor' ) ;
48
+ if ( await this . editorInput . isDisplayed ( ) ) {
49
+ return this . editorInput . typeText ( value ) ;
31
50
}
51
+ logger . warn ( 'Inline Editor is not displayed or not opened!' ) ;
32
52
}
33
53
34
54
public async isEnabled ( ) : Promise < boolean > {
35
- await this . element . click ( ) ;
36
- return this . inlineForm . isDisplayed ( ) ;
55
+ if ( await this . inlineForm . isDisplayed ( ) ) {
56
+ await browser . actions ( ) . mouseMove ( this . inlineForm ) . perform ( ) ;
57
+ return this . editFormOpener . isPresent ( ) ;
58
+ }
59
+ logger . warn ( 'Inline Editor is not displayed or opened!' ) ;
37
60
}
38
61
39
62
public async changeAndSetValue ( value : string ) {
@@ -42,7 +65,23 @@ export class InlineEditor extends BaseElement {
42
65
return this . accept ( ) ;
43
66
}
44
67
68
+ public async getError ( ) {
69
+ return this . error . getText ( ) ;
70
+ }
71
+
45
72
public async getValue ( ) {
46
- return this . link . getText ( ) ;
73
+ logger . warn ( 'Getting Inline Editor value!' ) ;
74
+ if ( await this . inlineFormPlaceholder . isPresent ( ) ) {
75
+ logger . warn ( 'Inline Editor value is empty!' ) ;
76
+ return ''
77
+ }
78
+
79
+ if ( await this . inlineLinkForm . isPresent ( ) ) {
80
+ logger . warn ( 'Inline Editor value is a link!' ) ;
81
+ return this . inlineLinkForm . getAttribute ( 'href' ) ;
82
+ }
83
+
84
+ logger . warn ( 'Inline Editor value is a text!' ) ;
85
+ return this . inlineForm . getText ( ) ;
47
86
}
48
87
}
0 commit comments