@serenity-js/core 3.9.1 → 3.10.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/CHANGELOG.md +11 -0
- package/lib/screenplay/Question.d.ts +12 -4
- package/lib/screenplay/Question.d.ts.map +1 -1
- package/lib/screenplay/Question.js +16 -4
- package/lib/screenplay/Question.js.map +1 -1
- package/lib/screenplay/questions/ChainableMetaQuestion.d.ts +26 -0
- package/lib/screenplay/questions/ChainableMetaQuestion.d.ts.map +1 -0
- package/lib/screenplay/questions/ChainableMetaQuestion.js +3 -0
- package/lib/screenplay/questions/ChainableMetaQuestion.js.map +1 -0
- package/lib/screenplay/questions/List.d.ts +58 -11
- package/lib/screenplay/questions/List.d.ts.map +1 -1
- package/lib/screenplay/questions/List.js +145 -42
- package/lib/screenplay/questions/List.js.map +1 -1
- package/lib/screenplay/questions/MetaQuestion.d.ts +2 -2
- package/lib/screenplay/questions/MetaQuestion.d.ts.map +1 -1
- package/lib/screenplay/questions/index.d.ts +1 -0
- package/lib/screenplay/questions/index.d.ts.map +1 -1
- package/lib/screenplay/questions/index.js +1 -0
- package/lib/screenplay/questions/index.js.map +1 -1
- package/package.json +2 -2
- package/src/screenplay/Question.ts +20 -7
- package/src/screenplay/questions/ChainableMetaQuestion.ts +30 -0
- package/src/screenplay/questions/List.ts +246 -69
- package/src/screenplay/questions/MetaQuestion.ts +2 -2
- package/src/screenplay/questions/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.10.0](https://github.com/serenity-js/serenity-js/compare/v3.9.1...v3.10.0) (2023-08-23)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **web:** chainable `PageElements` ([#1864](https://github.com/serenity-js/serenity-js/issues/1864)) ([4d0c7eb](https://github.com/serenity-js/serenity-js/commit/4d0c7eb97c24fe3ae1eed702773cf3b80f104947))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [3.9.1](https://github.com/serenity-js/serenity-js/compare/v3.9.0...v3.9.1) (2023-08-18)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -176,14 +176,15 @@ export declare abstract class Question<T> {
|
|
|
176
176
|
* )
|
|
177
177
|
* )
|
|
178
178
|
* );
|
|
179
|
-
*
|
|
180
|
-
* @param source
|
|
181
|
-
* @param overrides
|
|
179
|
+
* ```
|
|
182
180
|
*
|
|
183
181
|
* #### Learn more
|
|
184
182
|
* - {@apilink WithAnswerableProperties}
|
|
185
183
|
* - {@apilink RecursivelyAnswered}
|
|
186
184
|
* - {@apilink Answerable}
|
|
185
|
+
*
|
|
186
|
+
* @param source
|
|
187
|
+
* @param overrides
|
|
187
188
|
*/
|
|
188
189
|
static fromObject<Source_Type extends object>(source: Answerable<WithAnswerableProperties<Source_Type>>, ...overrides: Array<Answerable<Partial<WithAnswerableProperties<Source_Type>>>>): QuestionAdapter<RecursivelyAnswered<Source_Type>>;
|
|
189
190
|
/**
|
|
@@ -193,6 +194,13 @@ export declare abstract class Question<T> {
|
|
|
193
194
|
* The value to check
|
|
194
195
|
*/
|
|
195
196
|
static isAQuestion<T>(maybeQuestion: unknown): maybeQuestion is Question<T>;
|
|
197
|
+
/**
|
|
198
|
+
* Checks if the value is a {@apilink MetaQuestion}.
|
|
199
|
+
*
|
|
200
|
+
* @param maybeMetaQuestion
|
|
201
|
+
* The value to check
|
|
202
|
+
*/
|
|
203
|
+
static isAMetaQuestion<CT, RQT extends Question<unknown>>(maybeMetaQuestion: unknown): maybeMetaQuestion is MetaQuestion<CT, RQT>;
|
|
196
204
|
protected static createAdapter<AT>(statement: Question<AT>): QuestionAdapter<Awaited<AT>>;
|
|
197
205
|
private static fieldDescription;
|
|
198
206
|
private static methodDescription;
|
|
@@ -257,7 +265,7 @@ export type QuestionAdapter<Answer_Type> = Question<Promise<Answer_Type>> & Inte
|
|
|
257
265
|
*
|
|
258
266
|
* @group Questions
|
|
259
267
|
*/
|
|
260
|
-
export type MetaQuestionAdapter<Context_Type, Answer_Type> = QuestionAdapter<Answer_Type> & MetaQuestion<Context_Type, Answer_Type
|
|
268
|
+
export type MetaQuestionAdapter<Context_Type, Answer_Type> = QuestionAdapter<Answer_Type> & MetaQuestion<Context_Type, QuestionAdapter<Answer_Type>>;
|
|
261
269
|
/**
|
|
262
270
|
* @package
|
|
263
271
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Question.d.ts","sourceRoot":"","sources":["../../src/screenplay/Question.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,8BAAsB,QAAQ,CAAC,CAAC;IAE5B;;;;;;;;;;;;;;;OAeG;IACH,MA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AE,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,EAAE,GAAG,UAAU,OAAA,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,EACrH,QAAQ,GAAE,kBAAwD;IAKtE;;;OAGG;IACH,SAAS,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAIjC,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC;IAKzE,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,EAAE,OAAO,IAAI,CAAC,OAAO,GAAG,MAAM;IAIhH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAKzB,QAAQ,IAAI,MAAM;IAI3B,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;CAWzF"}
|
|
@@ -185,14 +185,15 @@ class Question {
|
|
|
185
185
|
* )
|
|
186
186
|
* )
|
|
187
187
|
* );
|
|
188
|
-
*
|
|
189
|
-
* @param source
|
|
190
|
-
* @param overrides
|
|
188
|
+
* ```
|
|
191
189
|
*
|
|
192
190
|
* #### Learn more
|
|
193
191
|
* - {@apilink WithAnswerableProperties}
|
|
194
192
|
* - {@apilink RecursivelyAnswered}
|
|
195
193
|
* - {@apilink Answerable}
|
|
194
|
+
*
|
|
195
|
+
* @param source
|
|
196
|
+
* @param overrides
|
|
196
197
|
*/
|
|
197
198
|
static fromObject(source, ...overrides) {
|
|
198
199
|
return Question.about('value', async (actor) => {
|
|
@@ -216,6 +217,17 @@ class Question {
|
|
|
216
217
|
return !!maybeQuestion
|
|
217
218
|
&& typeof maybeQuestion.answeredBy === 'function';
|
|
218
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Checks if the value is a {@apilink MetaQuestion}.
|
|
222
|
+
*
|
|
223
|
+
* @param maybeMetaQuestion
|
|
224
|
+
* The value to check
|
|
225
|
+
*/
|
|
226
|
+
static isAMetaQuestion(maybeMetaQuestion) {
|
|
227
|
+
return !!maybeMetaQuestion
|
|
228
|
+
&& typeof maybeMetaQuestion['of'] === 'function'
|
|
229
|
+
&& maybeMetaQuestion['of'].length === 1; // arity of 1
|
|
230
|
+
}
|
|
219
231
|
static createAdapter(statement) {
|
|
220
232
|
function getStatement() {
|
|
221
233
|
return statement;
|
|
@@ -383,7 +395,7 @@ class MetaQuestionStatement extends QuestionStatement {
|
|
|
383
395
|
this.metaQuestionBody = metaQuestionBody;
|
|
384
396
|
}
|
|
385
397
|
of(answerable) {
|
|
386
|
-
return Question.about((0, io_1.d)
|
|
398
|
+
return Question.about(this.toString() + (0, io_1.d) ` of ${answerable}`, actor => actor.answer(this.metaQuestionBody(answerable)));
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
401
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Question.js","sourceRoot":"","sources":["../../src/screenplay/Question.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAkD;AAClD,2CAA6B,CAAC,2CAA2C;AAEzE,sCAAuC;AAEvC,8BAA8C;AAG9C,+CAA4C;AAI5C,uDAAoD;AAIpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,MAAsB,QAAQ;IA6B1B,MAAM,CAAC,KAAK,CACR,WAAmB,EACnB,IAAqF,EACrF,gBAAuF;QAGvF,MAAM,SAAS,GAAG,OAAO,gBAAg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M,eAAe,GAAG,EAAE,CAAC;QAE3B,KAAK,MAAM,CAAE,GAAG,EAAE,KAAK,CAAE,IAAI,OAAO,EAAE;YAClC,eAAe,CAAC,IAAI,CAAC,CAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC,KAAK,EAAE,KAAY,EAAE,WAAW,EAAE,gBAAgB,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC;SAClH;QAED,OAAO,MAAM,CAAC,WAAW,CAAC,eAAe,CAAiB,CAAC;KAC9D;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,eAAe,GAAa,EAAE,CAAC;QAErC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;YACvB,eAAe,CAAC,IAAI,CAAC,MAAM,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,gBAAgB,GAAG,CAAC,CAAM,CAAC,CAAC;SACtG;QAED,OAAO,eAA0C,CAAC;KACrD;IAED,OAAO,MAAsB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Answerable } from '../Answerable';
|
|
2
|
+
import type { Question } from '../Question';
|
|
3
|
+
import type { MetaQuestion } from './MetaQuestion';
|
|
4
|
+
/**
|
|
5
|
+
* A chainable meta-question is a {@apilink MetaQuestion} that can be answered
|
|
6
|
+
* in the context of another {@apilink Answerable},
|
|
7
|
+
* and form a chain of transformations.
|
|
8
|
+
*
|
|
9
|
+
* {@apilink MetaQuestion|Meta questions} are typically used when filtering a {@apilink List}.
|
|
10
|
+
*
|
|
11
|
+
* ## Learn more
|
|
12
|
+
* - {@apilink List}
|
|
13
|
+
*
|
|
14
|
+
* @group Questions
|
|
15
|
+
*/
|
|
16
|
+
export interface ChainableMetaQuestion<Supported_Context_Type, Returned_Question_Type extends Question<unknown>> extends MetaQuestion<Supported_Context_Type, Returned_Question_Type & ChainableMetaQuestion<Supported_Context_Type, Returned_Question_Type>> {
|
|
17
|
+
/**
|
|
18
|
+
* Answers the given `ChainableMetaQuestion` in the context of another {@apilink Answerable}
|
|
19
|
+
* and returns another `ChainableMetaQuestion` ready for further chaining.
|
|
20
|
+
*
|
|
21
|
+
* #### Learn more
|
|
22
|
+
* - {@apilink List}
|
|
23
|
+
*/
|
|
24
|
+
of(context: Answerable<Supported_Context_Type>): Returned_Question_Type & ChainableMetaQuestion<Supported_Context_Type, Returned_Question_Type>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ChainableMetaQuestion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChainableMetaQuestion.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/ChainableMetaQuestion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,qBAAqB,CAClC,sBAAsB,EACtB,sBAAsB,SAAS,QAAQ,CAAC,OAAO,CAAC,CAClD,SAAQ,YAAY,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,qBAAqB,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;IAE1I;;;;;;OAMG;IACH,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,GAAG,qBAAqB,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;CACnJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChainableMetaQuestion.js","sourceRoot":"","sources":["../../../src/screenplay/questions/ChainableMetaQuestion.ts"],"names":[],"mappings":""}
|
|
@@ -1,33 +1,80 @@
|
|
|
1
1
|
import type { UsesAbilities } from '../abilities';
|
|
2
2
|
import type { Actor } from '../Actor';
|
|
3
3
|
import type { Answerable } from '../Answerable';
|
|
4
|
-
import type { QuestionAdapter } from '../Question';
|
|
4
|
+
import type { MetaQuestionAdapter, QuestionAdapter } from '../Question';
|
|
5
5
|
import { Question } from '../Question';
|
|
6
|
-
import type { AnswersQuestions } from '../questions';
|
|
6
|
+
import type { AnswersQuestions, ChainableMetaQuestion, MetaQuestion } from '../questions';
|
|
7
7
|
import { Task } from '../Task';
|
|
8
8
|
import type { Expectation } from './Expectation';
|
|
9
|
-
import type { MetaQuestion } from './MetaQuestion';
|
|
10
9
|
/**
|
|
11
10
|
* Serenity/JS Screenplay Pattern-style wrapper around {@apilink Array}
|
|
12
11
|
* and array-like structures - see {@apilink PageElements}.
|
|
13
12
|
*
|
|
14
13
|
* @group Questions
|
|
15
14
|
*/
|
|
16
|
-
export declare class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
15
|
+
export declare abstract class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
17
16
|
protected readonly collection: Answerable<Array<Item_Type>>;
|
|
18
|
-
|
|
17
|
+
protected subject?: string;
|
|
18
|
+
static of<IT, CT, RQT extends (Question<Promise<Array<IT>>> | Question<Array<IT>>)>(collection: Answerable<Array<IT>> & ChainableMetaQuestion<CT, RQT>): MetaList<CT, IT>;
|
|
19
19
|
static of<IT>(collection: Answerable<Array<IT>>): List<IT>;
|
|
20
20
|
constructor(collection: Answerable<Array<Item_Type>>);
|
|
21
|
-
eachMappedTo<Mapped_Item_Type>(question: MetaQuestion<Item_Type, Promise<Mapped_Item_Type> | Mapped_Item_Type>): List<Mapped_Item_Type>;
|
|
22
21
|
forEach(callback: (current: CurrentItem<Item_Type>, index: number, items: Array<Item_Type>) => Promise<void> | void): Task;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
abstract eachMappedTo<Mapped_Item_Type>(question: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>): List<Mapped_Item_Type>;
|
|
23
|
+
abstract where<Answer_Type>(question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>, expectation: Expectation<Answer_Type>): List<Item_Type>;
|
|
24
|
+
abstract count(): QuestionAdapter<number>;
|
|
25
|
+
abstract first(): QuestionAdapter<Item_Type>;
|
|
26
|
+
abstract last(): QuestionAdapter<Item_Type>;
|
|
27
|
+
abstract nth(index: number): QuestionAdapter<Item_Type>;
|
|
28
28
|
answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<Array<Item_Type>>;
|
|
29
29
|
describedAs(subject: string): this;
|
|
30
30
|
toString(): string;
|
|
31
|
+
/**
|
|
32
|
+
* @param {number} index
|
|
33
|
+
*/
|
|
34
|
+
protected ordinal(index: number): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Serenity/JS Screenplay Pattern-style wrapper around
|
|
38
|
+
* a {@apilink ChainableMetaQuestion} representing a collection
|
|
39
|
+
* that can be resolved in `Supported_Context_Type` of another {@apilink Question}.
|
|
40
|
+
*
|
|
41
|
+
* For example, {@apilink PageElements.located} returns `MetaList<PageElement>`,
|
|
42
|
+
* which allows for the collection of page elements to be resolved in the context
|
|
43
|
+
* of dynamically-provided root element.
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { By, PageElements, PageElement } from '@serenity-js/web'
|
|
47
|
+
*
|
|
48
|
+
* const firstLabel = () =>
|
|
49
|
+
* PageElements.located(By.css('label'))
|
|
50
|
+
* .first()
|
|
51
|
+
* .describedAs('first label')
|
|
52
|
+
*
|
|
53
|
+
* const exampleForm = () =>
|
|
54
|
+
* PageElement.located(By.css('form#example1'))
|
|
55
|
+
* .describedAs('example form')
|
|
56
|
+
*
|
|
57
|
+
* const anotherExampleForm = () =>
|
|
58
|
+
* PageElement.located(By.css('form#example2'))
|
|
59
|
+
* .describedAs('another example form')
|
|
60
|
+
*
|
|
61
|
+
* // Next, you can compose the above questions dynamically with various "contexts":
|
|
62
|
+
* // firstLabel().of(exampleForm())
|
|
63
|
+
* // firstLabel().of(anotherExampleForm())
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @group Questions
|
|
67
|
+
*/
|
|
68
|
+
export declare class MetaList<Supported_Context_Type, Item_Type> extends List<Item_Type> implements ChainableMetaQuestion<Supported_Context_Type, MetaList<Supported_Context_Type, Item_Type>> {
|
|
69
|
+
protected readonly collection: Answerable<Array<Item_Type>> & ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>;
|
|
70
|
+
constructor(collection: Answerable<Array<Item_Type>> & ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>);
|
|
71
|
+
of(context: Answerable<Supported_Context_Type>): MetaList<Supported_Context_Type, Item_Type>;
|
|
72
|
+
eachMappedTo<Mapped_Item_Type>(question: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>): MetaList<Supported_Context_Type, Mapped_Item_Type>;
|
|
73
|
+
where<Answer_Type>(question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>, expectation: Expectation<Answer_Type>): MetaList<Supported_Context_Type, Item_Type>;
|
|
74
|
+
count(): MetaQuestionAdapter<Supported_Context_Type, number>;
|
|
75
|
+
first(): MetaQuestionAdapter<Supported_Context_Type, Item_Type>;
|
|
76
|
+
last(): MetaQuestionAdapter<Supported_Context_Type, Item_Type>;
|
|
77
|
+
nth(index: number): MetaQuestionAdapter<Supported_Context_Type, Item_Type>;
|
|
31
78
|
}
|
|
32
79
|
/**
|
|
33
80
|
* @group Questions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/List.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACtC,OAA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I,mBAAmB,CAAC,sBAAsB,EAAE,MAAM,CAAC;IAU5D,KAAK,IAAI,mBAAmB,CAAC,sBAAsB,EAAE,SAAS,CAAC;IAe/D,IAAI,IAAI,mBAAmB,CAAC,sBAAsB,EAAE,SAAS,CAAC;IAe9D,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB,CAAC,sBAAsB,EAAE,SAAS,CAAC;CActF;AAoJD;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,SAAS;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;CAChB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.List = void 0;
|
|
3
|
+
exports.MetaList = exports.List = void 0;
|
|
4
4
|
const errors_1 = require("../../errors");
|
|
5
5
|
const io_1 = require("../../io");
|
|
6
6
|
const Question_1 = require("../Question");
|
|
@@ -14,30 +14,68 @@ const expectations_1 = require("./expectations");
|
|
|
14
14
|
*/
|
|
15
15
|
class List extends Question_1.Question {
|
|
16
16
|
static of(collection) {
|
|
17
|
-
|
|
17
|
+
if (Question_1.Question.isAMetaQuestion(collection)) {
|
|
18
|
+
return new MetaList(collection);
|
|
19
|
+
}
|
|
20
|
+
return new ArrayList(collection);
|
|
18
21
|
}
|
|
19
22
|
constructor(collection) {
|
|
20
23
|
super();
|
|
21
24
|
this.collection = collection;
|
|
22
|
-
this.subject = (0, io_1.d) `${collection}`;
|
|
23
|
-
}
|
|
24
|
-
eachMappedTo(question) {
|
|
25
|
-
return new List(new EachMappedTo(this.collection, question, this.subject));
|
|
26
25
|
}
|
|
27
26
|
forEach(callback) {
|
|
28
|
-
return new ForEachLoop(this.collection, this.
|
|
27
|
+
return new ForEachLoop(this.collection, this.toString(), callback);
|
|
28
|
+
}
|
|
29
|
+
async answeredBy(actor) {
|
|
30
|
+
const collection = await actor.answer(this.collection);
|
|
31
|
+
if (!Array.isArray(collection)) {
|
|
32
|
+
throw new errors_1.LogicError((0, io_1.d) `A List has to wrap an Array-compatible object. ${collection} given.`);
|
|
33
|
+
}
|
|
34
|
+
return collection;
|
|
35
|
+
}
|
|
36
|
+
describedAs(subject) {
|
|
37
|
+
this.subject = subject;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
return this.subject ?? (0, io_1.d) `${this.collection}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @param {number} index
|
|
45
|
+
*/
|
|
46
|
+
ordinal(index) {
|
|
47
|
+
const lastDigit = Math.abs(index) % 10, lastTwoDigits = Math.abs(index) % 100;
|
|
48
|
+
switch (true) {
|
|
49
|
+
case (lastDigit === 1 && lastTwoDigits !== 11):
|
|
50
|
+
return index + 'st';
|
|
51
|
+
case (lastDigit === 2 && lastTwoDigits !== 12):
|
|
52
|
+
return index + 'nd';
|
|
53
|
+
case (lastDigit === 3 && lastTwoDigits !== 13):
|
|
54
|
+
return index + 'rd';
|
|
55
|
+
default:
|
|
56
|
+
return index + 'th';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.List = List;
|
|
61
|
+
/**
|
|
62
|
+
* @package
|
|
63
|
+
*/
|
|
64
|
+
class ArrayList extends List {
|
|
65
|
+
eachMappedTo(question) {
|
|
66
|
+
return new ArrayList(new EachMappedTo(this.collection, question, this.toString()));
|
|
29
67
|
}
|
|
30
68
|
where(question, expectation) {
|
|
31
|
-
return new
|
|
69
|
+
return new ArrayList(new Where(this.collection, question, expectation, this.toString()));
|
|
32
70
|
}
|
|
33
71
|
count() {
|
|
34
|
-
return Question_1.Question.about(`the number of ${this.
|
|
72
|
+
return Question_1.Question.about(`the number of ${this.toString()}`, async (actor) => {
|
|
35
73
|
const items = await this.answeredBy(actor);
|
|
36
74
|
return items.length;
|
|
37
75
|
});
|
|
38
76
|
}
|
|
39
77
|
first() {
|
|
40
|
-
return Question_1.Question.about(`the first of ${this.
|
|
78
|
+
return Question_1.Question.about(`the first of ${this.toString()}`, async (actor) => {
|
|
41
79
|
const items = await this.answeredBy(actor);
|
|
42
80
|
if (items.length === 0) {
|
|
43
81
|
throw new errors_1.ListItemNotFoundError((0, io_1.d) `Can't retrieve the first item from a list with 0 items: ${items}`);
|
|
@@ -46,7 +84,7 @@ class List extends Question_1.Question {
|
|
|
46
84
|
});
|
|
47
85
|
}
|
|
48
86
|
last() {
|
|
49
|
-
return Question_1.Question.about(`the last of ${this.
|
|
87
|
+
return Question_1.Question.about(`the last of ${this.toString()}`, async (actor) => {
|
|
50
88
|
const items = await this.answeredBy(actor);
|
|
51
89
|
if (items.length === 0) {
|
|
52
90
|
throw new errors_1.ListItemNotFoundError((0, io_1.d) `Can't retrieve the last item from a list with 0 items: ${items}`);
|
|
@@ -55,47 +93,96 @@ class List extends Question_1.Question {
|
|
|
55
93
|
});
|
|
56
94
|
}
|
|
57
95
|
nth(index) {
|
|
58
|
-
return Question_1.Question.about(`the ${ordinal(index + 1)} of ${this.
|
|
96
|
+
return Question_1.Question.about(`the ${this.ordinal(index + 1)} of ${this.toString()}`, async (actor) => {
|
|
59
97
|
const items = await this.answeredBy(actor);
|
|
60
98
|
if (index < 0 || items.length <= index) {
|
|
61
|
-
throw new errors_1.ListItemNotFoundError(`Can't retrieve the ${ordinal(index)} item from a list with ${items.length} items: ` + (0, io_1.d) `${items}`);
|
|
99
|
+
throw new errors_1.ListItemNotFoundError(`Can't retrieve the ${this.ordinal(index)} item from a list with ${items.length} items: ` + (0, io_1.d) `${items}`);
|
|
62
100
|
}
|
|
63
101
|
return items[index];
|
|
64
102
|
});
|
|
65
103
|
}
|
|
66
|
-
async answeredBy(actor) {
|
|
67
|
-
const collection = await actor.answer(this.collection);
|
|
68
|
-
if (!Array.isArray(collection)) {
|
|
69
|
-
throw new errors_1.LogicError((0, io_1.d) `A List has to wrap an Array-compatible object. ${collection} given.`);
|
|
70
|
-
}
|
|
71
|
-
return collection;
|
|
72
|
-
}
|
|
73
|
-
describedAs(subject) {
|
|
74
|
-
this.subject = subject;
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
toString() {
|
|
78
|
-
return this.subject;
|
|
79
|
-
}
|
|
80
104
|
}
|
|
81
|
-
exports.List = List;
|
|
82
105
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @
|
|
106
|
+
* Serenity/JS Screenplay Pattern-style wrapper around
|
|
107
|
+
* a {@apilink ChainableMetaQuestion} representing a collection
|
|
108
|
+
* that can be resolved in `Supported_Context_Type` of another {@apilink Question}.
|
|
109
|
+
*
|
|
110
|
+
* For example, {@apilink PageElements.located} returns `MetaList<PageElement>`,
|
|
111
|
+
* which allows for the collection of page elements to be resolved in the context
|
|
112
|
+
* of dynamically-provided root element.
|
|
113
|
+
*
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import { By, PageElements, PageElement } from '@serenity-js/web'
|
|
116
|
+
*
|
|
117
|
+
* const firstLabel = () =>
|
|
118
|
+
* PageElements.located(By.css('label'))
|
|
119
|
+
* .first()
|
|
120
|
+
* .describedAs('first label')
|
|
121
|
+
*
|
|
122
|
+
* const exampleForm = () =>
|
|
123
|
+
* PageElement.located(By.css('form#example1'))
|
|
124
|
+
* .describedAs('example form')
|
|
125
|
+
*
|
|
126
|
+
* const anotherExampleForm = () =>
|
|
127
|
+
* PageElement.located(By.css('form#example2'))
|
|
128
|
+
* .describedAs('another example form')
|
|
129
|
+
*
|
|
130
|
+
* // Next, you can compose the above questions dynamically with various "contexts":
|
|
131
|
+
* // firstLabel().of(exampleForm())
|
|
132
|
+
* // firstLabel().of(anotherExampleForm())
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @group Questions
|
|
85
136
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
class MetaList extends List {
|
|
138
|
+
constructor(collection) {
|
|
139
|
+
super(collection);
|
|
140
|
+
this.collection = collection;
|
|
141
|
+
}
|
|
142
|
+
of(context) {
|
|
143
|
+
return new MetaList(this.collection.of(context)).describedAs(this.toString() + (0, io_1.d) ` of ${context}`);
|
|
144
|
+
}
|
|
145
|
+
eachMappedTo(question) {
|
|
146
|
+
return new MetaList(new MetaEachMappedTo(this.collection, question, this.toString()));
|
|
147
|
+
}
|
|
148
|
+
where(question, expectation) {
|
|
149
|
+
return new MetaList(new MetaWhere(this.collection, question, expectation, this.toString()));
|
|
150
|
+
}
|
|
151
|
+
count() {
|
|
152
|
+
return Question_1.Question.about(`the number of ${this.toString()}`, async (actor) => {
|
|
153
|
+
const items = await this.answeredBy(actor);
|
|
154
|
+
return items.length;
|
|
155
|
+
}, (parent) => this.of(parent).count());
|
|
156
|
+
}
|
|
157
|
+
first() {
|
|
158
|
+
return Question_1.Question.about(`the first of ${this.toString()}`, async (actor) => {
|
|
159
|
+
const items = await this.answeredBy(actor);
|
|
160
|
+
if (items.length === 0) {
|
|
161
|
+
throw new errors_1.ListItemNotFoundError((0, io_1.d) `Can't retrieve the first item from a list with 0 items: ${items}`);
|
|
162
|
+
}
|
|
163
|
+
return items[0];
|
|
164
|
+
}, (parent) => this.of(parent).first());
|
|
165
|
+
}
|
|
166
|
+
last() {
|
|
167
|
+
return Question_1.Question.about(`the last of ${this.toString()}`, async (actor) => {
|
|
168
|
+
const items = await this.answeredBy(actor);
|
|
169
|
+
if (items.length === 0) {
|
|
170
|
+
throw new errors_1.ListItemNotFoundError((0, io_1.d) `Can't retrieve the last item from a list with 0 items: ${items}`);
|
|
171
|
+
}
|
|
172
|
+
return items.at(-1);
|
|
173
|
+
}, (parent) => this.of(parent).last());
|
|
174
|
+
}
|
|
175
|
+
nth(index) {
|
|
176
|
+
return Question_1.Question.about(`the ${this.ordinal(index + 1)} of ${this.toString()}`, async (actor) => {
|
|
177
|
+
const items = await this.answeredBy(actor);
|
|
178
|
+
if (index < 0 || items.length <= index) {
|
|
179
|
+
throw new errors_1.ListItemNotFoundError(`Can't retrieve the ${this.ordinal(index)} item from a list with ${items.length} items: ` + (0, io_1.d) `${items}`);
|
|
180
|
+
}
|
|
181
|
+
return items[index];
|
|
182
|
+
}, (parent) => this.of(parent).nth(index));
|
|
97
183
|
}
|
|
98
184
|
}
|
|
185
|
+
exports.MetaList = MetaList;
|
|
99
186
|
/**
|
|
100
187
|
* @package
|
|
101
188
|
*/
|
|
@@ -124,7 +211,7 @@ class Where extends Question_1.Question {
|
|
|
124
211
|
return results;
|
|
125
212
|
}
|
|
126
213
|
catch (error) {
|
|
127
|
-
throw new errors_1.LogicError((0, io_1.d) `Couldn't check if ${this.question} of an item of ${this.collection} does ${this.expectation}
|
|
214
|
+
throw new errors_1.LogicError((0, io_1.d) `Couldn't check if ${this.question} of an item of ${this.collection} does ${this.expectation}: ` + error.message, error);
|
|
128
215
|
}
|
|
129
216
|
}
|
|
130
217
|
describedAs(subject) {
|
|
@@ -135,6 +222,14 @@ class Where extends Question_1.Question {
|
|
|
135
222
|
return this.subject;
|
|
136
223
|
}
|
|
137
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* @package
|
|
227
|
+
*/
|
|
228
|
+
class MetaWhere extends Where {
|
|
229
|
+
of(context) {
|
|
230
|
+
return new MetaWhere(this.collection.of(context), this.question, this.expectation, this.toString());
|
|
231
|
+
}
|
|
232
|
+
}
|
|
138
233
|
/**
|
|
139
234
|
* @package
|
|
140
235
|
*/
|
|
@@ -161,6 +256,14 @@ class EachMappedTo extends Question_1.Question {
|
|
|
161
256
|
return this.subject;
|
|
162
257
|
}
|
|
163
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* @package
|
|
261
|
+
*/
|
|
262
|
+
class MetaEachMappedTo extends EachMappedTo {
|
|
263
|
+
of(context) {
|
|
264
|
+
return new MetaEachMappedTo(this.collection.of(context), this.mapping, this.toString());
|
|
265
|
+
}
|
|
266
|
+
}
|
|
164
267
|
/**
|
|
165
268
|
* @package
|
|
166
269
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../src/screenplay/questions/List.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,iCAA6B;AAK7B,0CAAuC;AAEvC,kCAA+B;AAE/B,iDAAgD;
|
|
1
|
+
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../src/screenplay/questions/List.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AACjE,iCAA6B;AAK7B,0CAAuC;AAEvC,kCAA+B;AAE/B,iDAAgD;AAEhD;;;;;GAKG;AACH,MAAsB,IAAgB,SAAQ,mBAA8B;IAKxE,MAAM,CAAC,EAAE,CAAK,UAAmB;QAC7B,IAAI,mBAAQ,CAAC,eAAe,CAA+B,UAAU,CAAC,EAAE;YACpE,OAAO,IAAI,QAAQ,CAAC,UAAyF,CAAC,CAAC;SAClH;QAED,OAAO,IAAI,SAAS,CAAK,UAAmC,CAAC,CAAC;IAClE,CAAC;IAED,YAA+B,UAAwC;QACnE,KAAK,EAAE,CAAC;QADmB,eAAU,GAAV,UAAU,CAA8B;IAEvE,CAAC;IAED,OAAO,CAAC,QAA2G;QAC/G,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC;IAmBD,KAAK,CAAC,UAAU,CAAC,KAAuC;QACpD,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEvD,IAAI,CAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC7B,MAAM,IAAI,mBAAU,CAAC,IAAA,MAAC,EAAA,kDAAmD,UAAW,SAAS,CAAC,CAAC;SAClG;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,WAAW,CAAC,OAAe;QACvB,IAAI,CAA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,eAAU,GAAV,UAAU,CAA8B;QACxC,YAAO,GAAP,OAAO,CAAQ;QACf,OAAE,GAAF,EAAE,CAAmG;IAG1H,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAY;QACxB,MAAM,UAAU,GAAqB,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEzE,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE;YAC9C,MAAM,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;SACrD;IACL,CAAC;CACJ"}
|
|
@@ -15,14 +15,14 @@ import type { Question } from '../Question';
|
|
|
15
15
|
*
|
|
16
16
|
* @group Questions
|
|
17
17
|
*/
|
|
18
|
-
export interface MetaQuestion<Supported_Context_Type,
|
|
18
|
+
export interface MetaQuestion<Supported_Context_Type, Returned_Question_Type extends Question<unknown>> {
|
|
19
19
|
/**
|
|
20
20
|
* Answers the given `MetaQuestion` in the context of another {@apilink Answerable}.
|
|
21
21
|
*
|
|
22
22
|
* #### Learn more
|
|
23
23
|
* - {@apilink List}
|
|
24
24
|
*/
|
|
25
|
-
of(context: Answerable<Supported_Context_Type>):
|
|
25
|
+
of(context: Answerable<Supported_Context_Type>): Returned_Question_Type;
|
|
26
26
|
/**
|
|
27
27
|
* Human-readable description of this {@apilink MetaQuestion},
|
|
28
28
|
* typically involving the description of the subject.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetaQuestion.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/MetaQuestion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY,CAAC,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"MetaQuestion.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/MetaQuestion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY,CAAC,sBAAsB,EAAE,sBAAsB,SAAS,QAAQ,CAAC,OAAO,CAAC;IAElG;;;;;OAKG;IACH,EAAE,CAAC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;IAExE;;;;;;OAMG;IACH,QAAQ,IAAI,MAAM,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,KAAK,CAAC;AACpB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,KAAK,CAAC;AACpB,cAAc,cAAc,CAAC"}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./AnswersQuestions"), exports);
|
|
18
|
+
__exportStar(require("./ChainableMetaQuestion"), exports);
|
|
18
19
|
__exportStar(require("./Check"), exports);
|
|
19
20
|
__exportStar(require("./Expectation"), exports);
|
|
20
21
|
__exportStar(require("./expectations"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,0CAAwB;AACxB,gDAA8B;AAC9B,iDAA+B;AAC/B,yCAAuB;AACvB,iDAA+B;AAC/B,sCAAoB;AACpB,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,0DAAwC;AACxC,0CAAwB;AACxB,gDAA8B;AAC9B,iDAA+B;AAC/B,yCAAuB;AACvB,iDAA+B;AAC/B,sCAAoB;AACpB,+CAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Serenity/JS Screenplay, reporting engine and core interfaces.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": "^16.13 || ^18.12 || ^20"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "06ae5d8a702be0be2890e989c120715c32f6578a"
|
|
75
75
|
}
|
|
@@ -204,14 +204,15 @@ export abstract class Question<T> {
|
|
|
204
204
|
* )
|
|
205
205
|
* )
|
|
206
206
|
* );
|
|
207
|
-
*
|
|
208
|
-
* @param source
|
|
209
|
-
* @param overrides
|
|
207
|
+
* ```
|
|
210
208
|
*
|
|
211
209
|
* #### Learn more
|
|
212
210
|
* - {@apilink WithAnswerableProperties}
|
|
213
211
|
* - {@apilink RecursivelyAnswered}
|
|
214
212
|
* - {@apilink Answerable}
|
|
213
|
+
*
|
|
214
|
+
* @param source
|
|
215
|
+
* @param overrides
|
|
215
216
|
*/
|
|
216
217
|
static fromObject<Source_Type extends object>(
|
|
217
218
|
source: Answerable<WithAnswerableProperties<Source_Type>>,
|
|
@@ -245,6 +246,18 @@ export abstract class Question<T> {
|
|
|
245
246
|
&& typeof (maybeQuestion as any).answeredBy === 'function';
|
|
246
247
|
}
|
|
247
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Checks if the value is a {@apilink MetaQuestion}.
|
|
251
|
+
*
|
|
252
|
+
* @param maybeMetaQuestion
|
|
253
|
+
* The value to check
|
|
254
|
+
*/
|
|
255
|
+
static isAMetaQuestion<CT, RQT extends Question<unknown>>(maybeMetaQuestion: unknown): maybeMetaQuestion is MetaQuestion<CT, RQT> {
|
|
256
|
+
return !! maybeMetaQuestion
|
|
257
|
+
&& typeof maybeMetaQuestion['of'] === 'function'
|
|
258
|
+
&& maybeMetaQuestion['of'].length === 1; // arity of 1
|
|
259
|
+
}
|
|
260
|
+
|
|
248
261
|
protected static createAdapter<AT>(statement: Question<AT>): QuestionAdapter<Awaited<AT>> {
|
|
249
262
|
function getStatement() {
|
|
250
263
|
return statement;
|
|
@@ -466,7 +479,7 @@ export type QuestionAdapter<Answer_Type> =
|
|
|
466
479
|
*/
|
|
467
480
|
export type MetaQuestionAdapter<Context_Type, Answer_Type> =
|
|
468
481
|
& QuestionAdapter<Answer_Type>
|
|
469
|
-
& MetaQuestion<Context_Type, Answer_Type
|
|
482
|
+
& MetaQuestion<Context_Type, QuestionAdapter<Answer_Type>>
|
|
470
483
|
|
|
471
484
|
/**
|
|
472
485
|
* @package
|
|
@@ -531,7 +544,7 @@ class QuestionStatement<Answer_Type> extends Interaction implements Question<Pro
|
|
|
531
544
|
*/
|
|
532
545
|
class MetaQuestionStatement<Answer_Type, Supported_Context_Type extends Answerable<any>>
|
|
533
546
|
extends QuestionStatement<Answer_Type>
|
|
534
|
-
implements MetaQuestion<Supported_Context_Type, Answer_Type
|
|
547
|
+
implements MetaQuestion<Supported_Context_Type, QuestionAdapter<Answer_Type>>
|
|
535
548
|
{
|
|
536
549
|
constructor(
|
|
537
550
|
subject: string,
|
|
@@ -541,9 +554,9 @@ class MetaQuestionStatement<Answer_Type, Supported_Context_Type extends Answerab
|
|
|
541
554
|
super(subject, body);
|
|
542
555
|
}
|
|
543
556
|
|
|
544
|
-
of(answerable: Answerable<Supported_Context_Type>):
|
|
557
|
+
of(answerable: Answerable<Supported_Context_Type>): QuestionAdapter<Answer_Type> {
|
|
545
558
|
return Question.about(
|
|
546
|
-
|
|
559
|
+
this.toString() + d` of ${ answerable }`,
|
|
547
560
|
actor => actor.answer(this.metaQuestionBody(answerable))
|
|
548
561
|
);
|
|
549
562
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Answerable } from '../Answerable';
|
|
2
|
+
import type { Question } from '../Question';
|
|
3
|
+
import type { MetaQuestion } from './MetaQuestion';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A chainable meta-question is a {@apilink MetaQuestion} that can be answered
|
|
7
|
+
* in the context of another {@apilink Answerable},
|
|
8
|
+
* and form a chain of transformations.
|
|
9
|
+
*
|
|
10
|
+
* {@apilink MetaQuestion|Meta questions} are typically used when filtering a {@apilink List}.
|
|
11
|
+
*
|
|
12
|
+
* ## Learn more
|
|
13
|
+
* - {@apilink List}
|
|
14
|
+
*
|
|
15
|
+
* @group Questions
|
|
16
|
+
*/
|
|
17
|
+
export interface ChainableMetaQuestion<
|
|
18
|
+
Supported_Context_Type,
|
|
19
|
+
Returned_Question_Type extends Question<unknown>
|
|
20
|
+
> extends MetaQuestion<Supported_Context_Type, Returned_Question_Type & ChainableMetaQuestion<Supported_Context_Type, Returned_Question_Type>> {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Answers the given `ChainableMetaQuestion` in the context of another {@apilink Answerable}
|
|
24
|
+
* and returns another `ChainableMetaQuestion` ready for further chaining.
|
|
25
|
+
*
|
|
26
|
+
* #### Learn more
|
|
27
|
+
* - {@apilink List}
|
|
28
|
+
*/
|
|
29
|
+
of(context: Answerable<Supported_Context_Type>): Returned_Question_Type & ChainableMetaQuestion<Supported_Context_Type, Returned_Question_Type>;
|
|
30
|
+
}
|
|
@@ -3,13 +3,12 @@ import { d } from '../../io';
|
|
|
3
3
|
import type { UsesAbilities } from '../abilities';
|
|
4
4
|
import type { Actor } from '../Actor';
|
|
5
5
|
import type { Answerable } from '../Answerable';
|
|
6
|
-
import type { QuestionAdapter } from '../Question';
|
|
6
|
+
import type { MetaQuestionAdapter, QuestionAdapter } from '../Question';
|
|
7
7
|
import { Question } from '../Question';
|
|
8
|
-
import type { AnswersQuestions } from '../questions';
|
|
8
|
+
import type { AnswersQuestions, ChainableMetaQuestion, MetaQuestion } from '../questions';
|
|
9
9
|
import { Task } from '../Task';
|
|
10
10
|
import type { Expectation } from './Expectation';
|
|
11
11
|
import { ExpectationMet } from './expectations';
|
|
12
|
-
import type { MetaQuestion } from './MetaQuestion';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Serenity/JS Screenplay Pattern-style wrapper around {@apilink Array}
|
|
@@ -17,50 +16,115 @@ import type { MetaQuestion } from './MetaQuestion';
|
|
|
17
16
|
*
|
|
18
17
|
* @group Questions
|
|
19
18
|
*/
|
|
20
|
-
export class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
21
|
-
|
|
19
|
+
export abstract class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
20
|
+
protected subject?: string;
|
|
21
|
+
|
|
22
|
+
static of<IT, CT, RQT extends (Question<Promise<Array<IT>>> | Question<Array<IT>>)>(collection: Answerable<Array<IT>> & ChainableMetaQuestion<CT, RQT>): MetaList<CT, IT>;
|
|
23
|
+
static of<IT>(collection: Answerable<Array<IT>>): List<IT>;
|
|
24
|
+
static of<IT>(collection: unknown): unknown {
|
|
25
|
+
if (Question.isAMetaQuestion<unknown, Question<Array<IT>>>(collection)) {
|
|
26
|
+
return new MetaList(collection as Answerable<Array<IT>> & ChainableMetaQuestion<unknown, Question<Array<IT>>>);
|
|
27
|
+
}
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
return new List<IT>(collection);
|
|
29
|
+
return new ArrayList<IT>(collection as Answerable<Array<IT>>);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
constructor(
|
|
28
|
-
protected readonly collection: Answerable<Array<Item_Type>>,
|
|
29
|
-
) {
|
|
32
|
+
constructor(protected readonly collection: Answerable<Array<Item_Type>>) {
|
|
30
33
|
super();
|
|
31
|
-
this.subject = d`${ collection }`;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
): List<Mapped_Item_Type> {
|
|
37
|
-
return new List(
|
|
38
|
-
new EachMappedTo(this.collection, question, this.subject)
|
|
39
|
-
);
|
|
36
|
+
forEach(callback: (current: CurrentItem<Item_Type>, index: number, items: Array<Item_Type>) => Promise<void> | void): Task {
|
|
37
|
+
return new ForEachLoop(this.collection, this.toString(), callback);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
abstract eachMappedTo<Mapped_Item_Type>(
|
|
41
|
+
question: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>
|
|
42
|
+
): List<Mapped_Item_Type>;
|
|
43
|
+
|
|
44
|
+
abstract where<Answer_Type>(
|
|
45
|
+
question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>,
|
|
46
|
+
expectation: Expectation<Answer_Type>
|
|
47
|
+
): List<Item_Type>;
|
|
48
|
+
|
|
49
|
+
abstract count(): QuestionAdapter<number>;
|
|
50
|
+
|
|
51
|
+
abstract first(): QuestionAdapter<Item_Type>;
|
|
52
|
+
|
|
53
|
+
abstract last(): QuestionAdapter<Item_Type>;
|
|
54
|
+
|
|
55
|
+
abstract nth(index: number): QuestionAdapter<Item_Type>;
|
|
56
|
+
|
|
57
|
+
async answeredBy(actor: AnswersQuestions & UsesAbilities): Promise<Array<Item_Type>> {
|
|
58
|
+
const collection = await actor.answer(this.collection);
|
|
59
|
+
|
|
60
|
+
if (! Array.isArray(collection)) {
|
|
61
|
+
throw new LogicError(d`A List has to wrap an Array-compatible object. ${ collection } given.`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return collection;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describedAs(subject: string): this {
|
|
68
|
+
this.subject = subject;
|
|
69
|
+
return this;
|
|
44
70
|
}
|
|
45
71
|
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
toString(): string {
|
|
73
|
+
return this.subject ?? d`${ this.collection }`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @param {number} index
|
|
78
|
+
*/
|
|
79
|
+
protected ordinal(index: number): string {
|
|
80
|
+
const
|
|
81
|
+
lastDigit = Math.abs(index) % 10,
|
|
82
|
+
lastTwoDigits = Math.abs(index) % 100;
|
|
83
|
+
|
|
84
|
+
switch (true) {
|
|
85
|
+
case (lastDigit === 1 && lastTwoDigits !== 11):
|
|
86
|
+
return index + 'st';
|
|
87
|
+
case (lastDigit === 2 && lastTwoDigits !== 12):
|
|
88
|
+
return index + 'nd';
|
|
89
|
+
case (lastDigit === 3 && lastTwoDigits !== 13):
|
|
90
|
+
return index + 'rd';
|
|
91
|
+
default:
|
|
92
|
+
return index + 'th';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @package
|
|
99
|
+
*/
|
|
100
|
+
class ArrayList<Item_Type> extends List<Item_Type> {
|
|
101
|
+
|
|
102
|
+
override eachMappedTo<Mapped_Item_Type>(
|
|
103
|
+
question: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>,
|
|
104
|
+
): List<Mapped_Item_Type> {
|
|
105
|
+
return new ArrayList(
|
|
106
|
+
new EachMappedTo(this.collection, question, this.toString())
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
override where<Answer_Type>(
|
|
111
|
+
question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>,
|
|
48
112
|
expectation: Expectation<Answer_Type>
|
|
49
|
-
):
|
|
50
|
-
return new
|
|
51
|
-
new Where(this.collection, question, expectation, this.
|
|
113
|
+
): List<Item_Type> {
|
|
114
|
+
return new ArrayList<Item_Type>(
|
|
115
|
+
new Where(this.collection, question, expectation, this.toString())
|
|
52
116
|
) as this;
|
|
53
117
|
}
|
|
54
118
|
|
|
55
|
-
count(): QuestionAdapter<number> {
|
|
56
|
-
return Question.about(`the number of ${ this.
|
|
119
|
+
override count(): QuestionAdapter<number> {
|
|
120
|
+
return Question.about(`the number of ${ this.toString() }`, async actor => {
|
|
57
121
|
const items = await this.answeredBy(actor);
|
|
58
122
|
return items.length;
|
|
59
123
|
});
|
|
60
124
|
}
|
|
61
125
|
|
|
62
|
-
first(): QuestionAdapter<Item_Type> {
|
|
63
|
-
return Question.about(`the first of ${ this.
|
|
126
|
+
override first(): QuestionAdapter<Item_Type> {
|
|
127
|
+
return Question.about(`the first of ${ this.toString() }`, async actor => {
|
|
64
128
|
const items = await this.answeredBy(actor);
|
|
65
129
|
|
|
66
130
|
if (items.length === 0) {
|
|
@@ -71,8 +135,8 @@ export class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
|
71
135
|
});
|
|
72
136
|
}
|
|
73
137
|
|
|
74
|
-
last(): QuestionAdapter<Item_Type> {
|
|
75
|
-
return Question.about(`the last of ${ this.
|
|
138
|
+
override last(): QuestionAdapter<Item_Type> {
|
|
139
|
+
return Question.about(`the last of ${ this.toString() }`, async actor => {
|
|
76
140
|
const items = await this.answeredBy(actor);
|
|
77
141
|
|
|
78
142
|
if (items.length === 0) {
|
|
@@ -83,56 +147,137 @@ export class List<Item_Type> extends Question<Promise<Item_Type[]>> {
|
|
|
83
147
|
});
|
|
84
148
|
}
|
|
85
149
|
|
|
86
|
-
nth(index: number): QuestionAdapter<Item_Type> {
|
|
87
|
-
return Question.about(`the ${ ordinal(index + 1) } of ${ this.
|
|
150
|
+
override nth(index: number): QuestionAdapter<Item_Type> {
|
|
151
|
+
return Question.about(`the ${ this.ordinal(index + 1) } of ${ this.toString() }`, async actor => {
|
|
88
152
|
const items = await this.answeredBy(actor);
|
|
89
153
|
|
|
90
154
|
if (index < 0 || items.length <= index) {
|
|
91
|
-
throw new ListItemNotFoundError(`Can't retrieve the ${ ordinal(index) } item from a list with ${ items.length } items: ` + d`${ items }`)
|
|
155
|
+
throw new ListItemNotFoundError(`Can't retrieve the ${ this.ordinal(index) } item from a list with ${ items.length } items: ` + d`${ items }`)
|
|
92
156
|
}
|
|
93
157
|
|
|
94
158
|
return items[index];
|
|
95
159
|
});
|
|
96
160
|
}
|
|
161
|
+
}
|
|
97
162
|
|
|
98
|
-
|
|
99
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Serenity/JS Screenplay Pattern-style wrapper around
|
|
165
|
+
* a {@apilink ChainableMetaQuestion} representing a collection
|
|
166
|
+
* that can be resolved in `Supported_Context_Type` of another {@apilink Question}.
|
|
167
|
+
*
|
|
168
|
+
* For example, {@apilink PageElements.located} returns `MetaList<PageElement>`,
|
|
169
|
+
* which allows for the collection of page elements to be resolved in the context
|
|
170
|
+
* of dynamically-provided root element.
|
|
171
|
+
*
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { By, PageElements, PageElement } from '@serenity-js/web'
|
|
174
|
+
*
|
|
175
|
+
* const firstLabel = () =>
|
|
176
|
+
* PageElements.located(By.css('label'))
|
|
177
|
+
* .first()
|
|
178
|
+
* .describedAs('first label')
|
|
179
|
+
*
|
|
180
|
+
* const exampleForm = () =>
|
|
181
|
+
* PageElement.located(By.css('form#example1'))
|
|
182
|
+
* .describedAs('example form')
|
|
183
|
+
*
|
|
184
|
+
* const anotherExampleForm = () =>
|
|
185
|
+
* PageElement.located(By.css('form#example2'))
|
|
186
|
+
* .describedAs('another example form')
|
|
187
|
+
*
|
|
188
|
+
* // Next, you can compose the above questions dynamically with various "contexts":
|
|
189
|
+
* // firstLabel().of(exampleForm())
|
|
190
|
+
* // firstLabel().of(anotherExampleForm())
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @group Questions
|
|
194
|
+
*/
|
|
195
|
+
export class MetaList<Supported_Context_Type, Item_Type>
|
|
196
|
+
extends List<Item_Type>
|
|
197
|
+
implements ChainableMetaQuestion<Supported_Context_Type, MetaList<Supported_Context_Type, Item_Type>>
|
|
198
|
+
{
|
|
199
|
+
constructor(
|
|
200
|
+
protected override readonly collection: Answerable<Array<Item_Type>> & ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>
|
|
201
|
+
) {
|
|
202
|
+
super(collection);
|
|
203
|
+
}
|
|
100
204
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
205
|
+
of(context: Answerable<Supported_Context_Type>): MetaList<Supported_Context_Type, Item_Type> {
|
|
206
|
+
return new MetaList<Supported_Context_Type, Item_Type>(
|
|
207
|
+
this.collection.of(context)
|
|
208
|
+
).describedAs(this.toString() + d` of ${ context }`)
|
|
209
|
+
}
|
|
104
210
|
|
|
105
|
-
|
|
211
|
+
override eachMappedTo<Mapped_Item_Type>(
|
|
212
|
+
question: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>,
|
|
213
|
+
): MetaList<Supported_Context_Type, Mapped_Item_Type> {
|
|
214
|
+
return new MetaList(
|
|
215
|
+
new MetaEachMappedTo(this.collection, question, this.toString()),
|
|
216
|
+
);
|
|
106
217
|
}
|
|
107
218
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
219
|
+
override where<Answer_Type>(
|
|
220
|
+
question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>,
|
|
221
|
+
expectation: Expectation<Answer_Type>
|
|
222
|
+
): MetaList<Supported_Context_Type, Item_Type> {
|
|
223
|
+
return new MetaList<Supported_Context_Type, Item_Type>(
|
|
224
|
+
new MetaWhere(this.collection, question, expectation, this.toString())
|
|
225
|
+
) as this;
|
|
111
226
|
}
|
|
112
227
|
|
|
113
|
-
|
|
114
|
-
return this.
|
|
228
|
+
override count(): MetaQuestionAdapter<Supported_Context_Type, number> {
|
|
229
|
+
return Question.about(`the number of ${ this.toString() }`,
|
|
230
|
+
async actor => {
|
|
231
|
+
const items = await this.answeredBy(actor);
|
|
232
|
+
return items.length;
|
|
233
|
+
},
|
|
234
|
+
(parent: Answerable<Supported_Context_Type>) => this.of(parent).count()
|
|
235
|
+
);
|
|
115
236
|
}
|
|
116
|
-
}
|
|
117
237
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
238
|
+
override first(): MetaQuestionAdapter<Supported_Context_Type, Item_Type> {
|
|
239
|
+
return Question.about(`the first of ${ this.toString() }`,
|
|
240
|
+
async actor => {
|
|
241
|
+
const items = await this.answeredBy(actor);
|
|
242
|
+
|
|
243
|
+
if (items.length === 0) {
|
|
244
|
+
throw new ListItemNotFoundError(d`Can't retrieve the first item from a list with 0 items: ${ items }`)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return items[0];
|
|
248
|
+
},
|
|
249
|
+
(parent: Answerable<Supported_Context_Type>) => this.of(parent).first()
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
override last(): MetaQuestionAdapter<Supported_Context_Type, Item_Type> {
|
|
254
|
+
return Question.about(`the last of ${ this.toString() }`,
|
|
255
|
+
async actor => {
|
|
256
|
+
const items = await this.answeredBy(actor);
|
|
257
|
+
|
|
258
|
+
if (items.length === 0) {
|
|
259
|
+
throw new ListItemNotFoundError(d`Can't retrieve the last item from a list with 0 items: ${ items }`)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return items.at(-1);
|
|
263
|
+
},
|
|
264
|
+
(parent: Answerable<Supported_Context_Type>) => this.of(parent).last()
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
override nth(index: number): MetaQuestionAdapter<Supported_Context_Type, Item_Type> {
|
|
269
|
+
return Question.about(`the ${ this.ordinal(index + 1) } of ${ this.toString() }`,
|
|
270
|
+
async actor => {
|
|
271
|
+
const items = await this.answeredBy(actor);
|
|
272
|
+
|
|
273
|
+
if (index < 0 || items.length <= index) {
|
|
274
|
+
throw new ListItemNotFoundError(`Can't retrieve the ${ this.ordinal(index) } item from a list with ${ items.length } items: ` + d`${ items }`)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return items[index];
|
|
278
|
+
},
|
|
279
|
+
(parent: Answerable<Supported_Context_Type>) => this.of(parent).nth(index)
|
|
280
|
+
);
|
|
136
281
|
}
|
|
137
282
|
}
|
|
138
283
|
|
|
@@ -145,9 +290,9 @@ class Where<Item_Type, Answer_Type>
|
|
|
145
290
|
private subject: string;
|
|
146
291
|
|
|
147
292
|
constructor(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
293
|
+
protected readonly collection: Answerable<Array<Item_Type>>,
|
|
294
|
+
protected readonly question: MetaQuestion<Item_Type, Question<Promise<Answer_Type> | Answer_Type>>,
|
|
295
|
+
protected readonly expectation: Expectation<Answer_Type>,
|
|
151
296
|
originalSubject: string,
|
|
152
297
|
) {
|
|
153
298
|
super();
|
|
@@ -175,7 +320,7 @@ class Where<Item_Type, Answer_Type>
|
|
|
175
320
|
|
|
176
321
|
return results;
|
|
177
322
|
} catch (error) {
|
|
178
|
-
throw new LogicError(d`Couldn't check if ${ this.question } of an item of ${ this.collection } does ${ this.expectation }
|
|
323
|
+
throw new LogicError(d`Couldn't check if ${ this.question } of an item of ${ this.collection } does ${ this.expectation }: ` + error.message, error);
|
|
179
324
|
}
|
|
180
325
|
}
|
|
181
326
|
|
|
@@ -189,6 +334,25 @@ class Where<Item_Type, Answer_Type>
|
|
|
189
334
|
}
|
|
190
335
|
}
|
|
191
336
|
|
|
337
|
+
/**
|
|
338
|
+
* @package
|
|
339
|
+
*/
|
|
340
|
+
class MetaWhere<Supported_Context_Type, Item_Type, Answer_Type>
|
|
341
|
+
extends Where<Item_Type, Answer_Type>
|
|
342
|
+
implements ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>
|
|
343
|
+
{
|
|
344
|
+
protected override readonly collection: Answerable<Array<Item_Type>> & ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>;
|
|
345
|
+
|
|
346
|
+
of(context: Answerable<Supported_Context_Type>): MetaWhere<Supported_Context_Type, Item_Type, Answer_Type> {
|
|
347
|
+
return new MetaWhere<Supported_Context_Type, Item_Type, Answer_Type>(
|
|
348
|
+
this.collection.of(context),
|
|
349
|
+
this.question,
|
|
350
|
+
this.expectation,
|
|
351
|
+
this.toString()
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
192
356
|
/**
|
|
193
357
|
* @package
|
|
194
358
|
*/
|
|
@@ -197,8 +361,8 @@ class EachMappedTo<Item_Type, Mapped_Item_Type> extends Question<Promise<Array<M
|
|
|
197
361
|
private subject: string;
|
|
198
362
|
|
|
199
363
|
constructor(
|
|
200
|
-
|
|
201
|
-
|
|
364
|
+
protected readonly collection: Answerable<Array<Item_Type>>,
|
|
365
|
+
protected readonly mapping: MetaQuestion<Item_Type, Question<Promise<Mapped_Item_Type> | Mapped_Item_Type>>,
|
|
202
366
|
originalSubject: string,
|
|
203
367
|
) {
|
|
204
368
|
super();
|
|
@@ -228,6 +392,19 @@ class EachMappedTo<Item_Type, Mapped_Item_Type> extends Question<Promise<Array<M
|
|
|
228
392
|
}
|
|
229
393
|
}
|
|
230
394
|
|
|
395
|
+
/**
|
|
396
|
+
* @package
|
|
397
|
+
*/
|
|
398
|
+
class MetaEachMappedTo<Supported_Context_Type, Item_Type, Mapped_Item_Type>
|
|
399
|
+
extends EachMappedTo<Item_Type, Mapped_Item_Type>
|
|
400
|
+
{
|
|
401
|
+
protected override readonly collection: Answerable<Array<Item_Type>> & ChainableMetaQuestion<Supported_Context_Type, Question<Promise<Array<Item_Type>>> | Question<Array<Item_Type>>>;
|
|
402
|
+
|
|
403
|
+
of(context: Answerable<Supported_Context_Type>): MetaEachMappedTo<Supported_Context_Type, Item_Type, Mapped_Item_Type> {
|
|
404
|
+
return new MetaEachMappedTo<Supported_Context_Type, Item_Type, Mapped_Item_Type>(this.collection.of(context), this.mapping, this.toString());
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
231
408
|
/**
|
|
232
409
|
* @package
|
|
233
410
|
*/
|
|
@@ -16,7 +16,7 @@ import type { Question } from '../Question';
|
|
|
16
16
|
*
|
|
17
17
|
* @group Questions
|
|
18
18
|
*/
|
|
19
|
-
export interface MetaQuestion<Supported_Context_Type,
|
|
19
|
+
export interface MetaQuestion<Supported_Context_Type, Returned_Question_Type extends Question<unknown>> {
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Answers the given `MetaQuestion` in the context of another {@apilink Answerable}.
|
|
@@ -24,7 +24,7 @@ export interface MetaQuestion<Supported_Context_Type, Answer_Type> {
|
|
|
24
24
|
* #### Learn more
|
|
25
25
|
* - {@apilink List}
|
|
26
26
|
*/
|
|
27
|
-
of(context: Answerable<Supported_Context_Type>):
|
|
27
|
+
of(context: Answerable<Supported_Context_Type>): Returned_Question_Type;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Human-readable description of this {@apilink MetaQuestion},
|