@cepharum/contextual-gherkin 3.0.0-beta.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +33 -2
- package/index.js +2 -0
- package/lib/api.js +6 -4
- package/lib/step-helper.js +579 -0
- package/package.json +2 -2
- package/steps/global-action.js +19 -169
- package/steps/global-find.js +8 -104
- package/steps/local-action.js +1 -42
- package/steps/local-find.js +8 -117
- package/steps/local-state.js +7 -110
package/steps/local-state.js
CHANGED
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { Then } from "@cucumber/cucumber";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
localStateByAttribute,
|
|
4
|
+
localStateByClass,
|
|
5
|
+
localStateByLabel,
|
|
6
|
+
localStateByProperty,
|
|
7
|
+
localStateByTextContent, localStateExists
|
|
8
|
+
} from "../lib/step-helper.js";
|
|
3
9
|
|
|
4
10
|
Then( "{contextual-word} has/have (the )ID/id {text-or-regexp}", ( context, text ) => localStateByAttribute( context, true, "id", text ) );
|
|
5
11
|
Then( "{contextual-word} has/have (the )name {text-or-regexp}", ( context, text ) => localStateByAttribute( context, true, "name", text ) );
|
|
6
12
|
Then( "{contextual-word} is/are named {text-or-regexp}", ( context, text ) => localStateByAttribute( context, true, "name", text ) );
|
|
7
13
|
|
|
8
|
-
/**
|
|
9
|
-
* Checks if some or all elements of an addressed match have a named attribute
|
|
10
|
-
* matching some expected value.
|
|
11
|
-
*
|
|
12
|
-
* @param {ContextualWord} phrase description of previous match to check
|
|
13
|
-
* @param {boolean} all if true, all matching elements have to match named attribute's expected value
|
|
14
|
-
* @param {string} name name of attribute to check with either matching element
|
|
15
|
-
* @param {string} value expected value of named attribute per matching element
|
|
16
|
-
* @returns {Promise<void>} promises check passed
|
|
17
|
-
*/
|
|
18
|
-
export async function localStateByAttribute( phrase, all, name, value ) {
|
|
19
|
-
const api = Api.access();
|
|
20
|
-
const context = api.getContextFor( phrase );
|
|
21
|
-
const filtered = context.withAttribute( name, value );
|
|
22
|
-
|
|
23
|
-
await context.checkFilteredInContext( filtered, phrase, all );
|
|
24
|
-
}
|
|
25
14
|
|
|
26
15
|
Then( "{contextual-word} has/have (the )value {text-or-regexp}", ( context, text ) => localStateByProperty( context, true, "value", text ) );
|
|
27
16
|
Then( "{contextual-word} is/are enabled", context => localStateByProperty( context, true, "disabled", false ) );
|
|
@@ -33,67 +22,16 @@ Then( "{contextual-word} is/are selected", context => localStateByProperty( cont
|
|
|
33
22
|
Then( "{contextual-word} is/are unselected", context => localStateByProperty( context, true, "selected", false ) );
|
|
34
23
|
Then( "{contextual-word} is/are not selected", context => localStateByProperty( context, true, "selected", false ) );
|
|
35
24
|
|
|
36
|
-
/**
|
|
37
|
-
* Checks if all elements of an addressed match have a named property matching
|
|
38
|
-
* some expected value.
|
|
39
|
-
*
|
|
40
|
-
* @param {ContextualWord} phrase description of previous match to check
|
|
41
|
-
* @param {boolean} all if true, all matching elements have to match named attribute's expected value
|
|
42
|
-
* @param {string} name name of DOM property to check on either matching element
|
|
43
|
-
* @param {string|RegExp|boolean} value expected value of named property per matching element
|
|
44
|
-
* @returns {Promise<void>} promises check passed
|
|
45
|
-
*/
|
|
46
|
-
export async function localStateByProperty( phrase, all, name, value ) {
|
|
47
|
-
const api = Api.access();
|
|
48
|
-
const context = api.getContextFor( phrase );
|
|
49
|
-
const filtered = context.withProperty( name, value );
|
|
50
|
-
|
|
51
|
-
await context.checkFilteredInContext( filtered, phrase, all );
|
|
52
|
-
}
|
|
53
25
|
|
|
54
26
|
Then( "{contextual-word} is/are marked/tagged as {word}", ( context, className ) => localStateByClass( context, true, className, false ) );
|
|
55
27
|
Then( "{contextual-word} is/are not marked/tagged as {word}", ( context, className ) => localStateByClass( context, true, className, true ) );
|
|
56
28
|
|
|
57
|
-
/**
|
|
58
|
-
* Asserts if selected element(s) has/have given class or not.
|
|
59
|
-
*
|
|
60
|
-
* @param {ContextualWord} phrase describes context of search
|
|
61
|
-
* @param {boolean} all if true, all matching elements have to match named attribute's expected value
|
|
62
|
-
* @param {string} className name of class to check
|
|
63
|
-
* @param {boolean} negated inverts the assertion by means of requiring one or all elements of context not to have selected class
|
|
64
|
-
* @return {Promise<void>} promises step passed
|
|
65
|
-
*/
|
|
66
|
-
export async function localStateByClass( phrase, all, className, negated ) {
|
|
67
|
-
const api = Api.access();
|
|
68
|
-
const context = api.getContextFor( phrase );
|
|
69
|
-
const filtered = context.withListProperty( "classList", className, negated );
|
|
70
|
-
|
|
71
|
-
await context.checkFilteredInContext( filtered, phrase, all );
|
|
72
|
-
}
|
|
73
29
|
|
|
74
30
|
Then( "{contextual-word} is/are labelled with {text-or-regexp}", ( context, text ) => localStateByLabel( context, text, false ) );
|
|
75
31
|
Then( "{contextual-word} has/have (the )label {text-or-regexp}", ( context, text ) => localStateByLabel( context, text, false ) );
|
|
76
32
|
Then( "{contextual-word} is/are partially labelled with {text-or-regexp}", ( context, text ) => localStateByLabel( context, text, true ) );
|
|
77
33
|
Then( "{contextual-word} has/have (the )partial label {text-or-regexp}", ( context, text ) => localStateByLabel( context, text, true ) );
|
|
78
34
|
|
|
79
|
-
/**
|
|
80
|
-
* Checks if an addressed match of a previously tracked search contains a given
|
|
81
|
-
* text.
|
|
82
|
-
*
|
|
83
|
-
* @param {ContextualWord} phrase description of previous match to check
|
|
84
|
-
* @param {string} text expected text found in elements of selected match
|
|
85
|
-
* @param {boolean} partially if true, provided text does not have to match whole content of matching subs
|
|
86
|
-
* @returns {Promise<void>} promises check passed
|
|
87
|
-
*/
|
|
88
|
-
export async function localStateByLabel( phrase, text, partially ) {
|
|
89
|
-
const api = Api.access();
|
|
90
|
-
const context = api.getContextFor( phrase );
|
|
91
|
-
const cardinal = phrase.asCardinalWord( await context.matchCount() );
|
|
92
|
-
|
|
93
|
-
await context
|
|
94
|
-
.filterBySubsWithText( "$label", "label", text, partially )
|
|
95
|
-
.checkCardinalWord( cardinal, phrase.isRefining, `expected %amount labelled with "${text}"` );
|
|
96
|
-
}
|
|
97
35
|
|
|
98
36
|
Then( "{contextual-word} read/reads {text-or-regexp}", ( context, text ) => localStateByTextContent( context, text, false ) );
|
|
99
37
|
Then( "{contextual-word} is reading {text-or-regexp}", ( context, text ) => localStateByTextContent( context, text, false ) );
|
|
@@ -102,49 +40,8 @@ Then( "{contextual-word} partially read/reads {text-or-regexp}", ( context, text
|
|
|
102
40
|
Then( "{contextual-word} is partially reading {text-or-regexp}", ( context, text ) => localStateByTextContent( context, text, true ) );
|
|
103
41
|
Then( "{contextual-word} has/have partial text {text-or-regexp}", ( context, text ) => localStateByTextContent( context, text, true ) );
|
|
104
42
|
|
|
105
|
-
/**
|
|
106
|
-
* Checks if an addressed match of a previously tracked search contains a given
|
|
107
|
-
* text.
|
|
108
|
-
*
|
|
109
|
-
* @param {ContextualWord} phrase description of previous match to check
|
|
110
|
-
* @param {string} text expected text found in elements of selected match
|
|
111
|
-
* @param {boolean} partially if true searched elements may partially contain provided text to be considered a match
|
|
112
|
-
* @returns {Promise<void>} promises check passed
|
|
113
|
-
*/
|
|
114
|
-
export async function localStateByTextContent( phrase, text, partially ) {
|
|
115
|
-
const api = Api.access();
|
|
116
|
-
const context = api.getContextFor( phrase );
|
|
117
|
-
const cardinal = phrase.asCardinalWord( await context.matchCount() );
|
|
118
|
-
|
|
119
|
-
await context
|
|
120
|
-
.filterBySubsWithText( "$text", false, text, partially )
|
|
121
|
-
.checkCardinalWord( cardinal, phrase.isRefining, `expected %amount ${partially ? "partially " : ""}reading "${text}"` );
|
|
122
|
-
}
|
|
123
43
|
|
|
124
44
|
Then( "{contextual-word} (still )exists/exist", context => localStateExists( context, true ) );
|
|
125
45
|
Then( "{contextual-word} doesn't/don't exist( anymore)", context => localStateExists( context, false ) );
|
|
126
46
|
Then( "{contextual-word} does/do not exist( anymore)", context => localStateExists( context, false ) );
|
|
127
47
|
Then( "{contextual-word} is/are missing/gone", context => localStateExists( context, false ) );
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Checks if some contextual elements exist or are missing explicitly.
|
|
131
|
-
*
|
|
132
|
-
* @param {ContextualWord} phrase description of previous match to check
|
|
133
|
-
* @param {boolean} mustExist if true, described contextual element has to exist to pass, otherwise it has to be missing
|
|
134
|
-
* @returns {Promise<void>} promises check passed
|
|
135
|
-
*/
|
|
136
|
-
export async function localStateExists( phrase, mustExist ) {
|
|
137
|
-
const api = Api.access();
|
|
138
|
-
const context = api.getContextFor( phrase );
|
|
139
|
-
|
|
140
|
-
if ( mustExist ) {
|
|
141
|
-
// FIXME might pass unintentionally if just one of several elements to be tested exists
|
|
142
|
-
await api.expect( context.locator ).not.toHaveCount( 0 );
|
|
143
|
-
|
|
144
|
-
if ( phrase.isRefining ) {
|
|
145
|
-
await context.track( phrase.word, phrase.targetCardinality );
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
await api.expect( context.locator ).toHaveCount( 0 );
|
|
149
|
-
}
|
|
150
|
-
}
|