@serenity-js/core 3.28.0 → 3.29.2
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 +43 -0
- package/lib/screenplay/questions/Numeric.d.ts +534 -0
- package/lib/screenplay/questions/Numeric.d.ts.map +1 -0
- package/lib/screenplay/questions/Numeric.js +646 -0
- package/lib/screenplay/questions/Numeric.js.map +1 -0
- 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 +5 -5
- package/src/screenplay/questions/Numeric.ts +684 -0
- package/src/screenplay/questions/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,49 @@
|
|
|
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.29.2](https://github.com/serenity-js/serenity-js/compare/v3.29.1...v3.29.2) (2024-09-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **core:** added implementation examples to Numeric API docs ([5365ec4](https://github.com/serenity-js/serenity-js/commit/5365ec4f92f17a9b835e8a5de0880c38558de520))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [3.29.1](https://github.com/serenity-js/serenity-js/compare/v3.29.0...v3.29.1) (2024-09-24)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **core:** code clean-up ([c95e32b](https://github.com/serenity-js/serenity-js/commit/c95e32b880949c0dd085d64c6fad46680f14c9f8))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [3.29.0](https://github.com/serenity-js/serenity-js/compare/v3.28.0...v3.29.0) (2024-09-24)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* **core:** improved precision of results calculated by Numeric.sum() ([d82a23d](https://github.com/serenity-js/serenity-js/commit/d82a23d95572fedcca297bd79d555325f96ea460)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* **core:** added Numeric.sum() arithmetic function ([5ed15ec](https://github.com/serenity-js/serenity-js/commit/5ed15ec2ea90655fc45aa54a0b30c2e089265d18)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
39
|
+
* **core:** introduced Numeric.difference() ([97e7f5e](https://github.com/serenity-js/serenity-js/commit/97e7f5e396787b8eb9a51983b60aa191f5bfb8f8)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
40
|
+
* **core:** introduced Numeric.floor() and Numeric.ceiling() functions ([dbe892b](https://github.com/serenity-js/serenity-js/commit/dbe892b8f064a84f907d60bb5594ad900645a631)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
41
|
+
* **core:** introduced Numeric.intValue(), .bigIntValue() and floatValue() meta-questions ([bab710e](https://github.com/serenity-js/serenity-js/commit/bab710e1e6c92045561159a6a89462f6a3b6ee67)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
42
|
+
* **core:** introduced Numeric.max() and Numeric.min() ([f310bb0](https://github.com/serenity-js/serenity-js/commit/f310bb002ca30abb163bdeeff5764b0f4971ad03)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
43
|
+
* **core:** standardised arithmetic function APIs so that they can be used to map collection items ([8817ad4](https://github.com/serenity-js/serenity-js/commit/8817ad4ecfdef411eee0f5af8f1ccd73d6eb0806)), closes [#2420](https://github.com/serenity-js/serenity-js/issues/2420)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
6
49
|
# [3.28.0](https://github.com/serenity-js/serenity-js/compare/v3.27.0...v3.28.0) (2024-09-11)
|
|
7
50
|
|
|
8
51
|
**Note:** Version bump only for package @serenity-js/core
|
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import type { Answerable } from '../Answerable';
|
|
2
|
+
import type { QuestionAdapter } from '../Question';
|
|
3
|
+
import type { MetaQuestion } from './MetaQuestion';
|
|
4
|
+
/**
|
|
5
|
+
* Provides methods to perform calculations on numeric values returned by other [questions](https://serenity-js.org/api/core/class/Question/).
|
|
6
|
+
*
|
|
7
|
+
* ## Example
|
|
8
|
+
*
|
|
9
|
+
* The examples in this section demonstrate interacting with an HTML widget representing a price list.
|
|
10
|
+
*
|
|
11
|
+
* ```html
|
|
12
|
+
* <ul id="price-list">
|
|
13
|
+
* <li class="item">
|
|
14
|
+
* <span class="name">apples</span>
|
|
15
|
+
* <span class="quantity">5</span>
|
|
16
|
+
* <span class="price">£2.25</span>
|
|
17
|
+
* </li>
|
|
18
|
+
* <li class="item">
|
|
19
|
+
* <span class="name">apricots</span>
|
|
20
|
+
* <span class="quantity">4</span>
|
|
21
|
+
* <span class="price">£3.70</span>
|
|
22
|
+
* </li>
|
|
23
|
+
* <li class="item">
|
|
24
|
+
* <span class="name">bananas</span>
|
|
25
|
+
* <span class="quantity">2</span>
|
|
26
|
+
* <span class="price">£1.50</span>
|
|
27
|
+
* </li>
|
|
28
|
+
* </ul>
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* ### Lean Page Objects
|
|
32
|
+
*
|
|
33
|
+
* To represent our example HTML widget,
|
|
34
|
+
* we follow the [Lean Page Objects pattern](https://serenity-js.org/handbook/web-testing/page-objects-pattern/)
|
|
35
|
+
* to define the `PriceList` and `PriceListItem` classes
|
|
36
|
+
* and use the Serenity/JS [Page Element Query Language (PEQL)](https://serenity-js.org/handbook/web-testing/page-element-query-language/)
|
|
37
|
+
* to identify the elements of interest.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* // ui/price-list.ts
|
|
41
|
+
*
|
|
42
|
+
* import { PageElement, PageElements, By } from '@serenity-js/web'
|
|
43
|
+
*
|
|
44
|
+
* export class PriceList {
|
|
45
|
+
* static container = () =>
|
|
46
|
+
* PageElement.located(By.id('price-list'))
|
|
47
|
+
* .describedAs('price list')
|
|
48
|
+
*
|
|
49
|
+
* static items = () =>
|
|
50
|
+
* PageElements.located(PriceListItem.containerSelector())
|
|
51
|
+
* .of(this.container())
|
|
52
|
+
* .describedAs('items')
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* export class PriceListItem {
|
|
56
|
+
* static containerSelector = () =>
|
|
57
|
+
* By.css('.item')
|
|
58
|
+
*
|
|
59
|
+
* static container = () =>
|
|
60
|
+
* PageElement.located(this.containerSelector())
|
|
61
|
+
* .describedAs('item')
|
|
62
|
+
*
|
|
63
|
+
* static name = () =>
|
|
64
|
+
* PageElement.located(By.css('.name'))
|
|
65
|
+
* .of(this.container())
|
|
66
|
+
* .describedAs('name')
|
|
67
|
+
*
|
|
68
|
+
* static quantity = () =>
|
|
69
|
+
* PageElement.located(By.css('.quantity'))
|
|
70
|
+
* .of(this.container())
|
|
71
|
+
* .describedAs('quantity')
|
|
72
|
+
*
|
|
73
|
+
* static price = () =>
|
|
74
|
+
* PageElement.located(By.css('.price'))
|
|
75
|
+
* .of(this.container())
|
|
76
|
+
* .describedAs('price')
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @group Questions
|
|
81
|
+
*/
|
|
82
|
+
export declare class Numeric {
|
|
83
|
+
/**
|
|
84
|
+
* Returns a [`Question`](https://serenity-js.org/api/core/class/Question/) that sums up the values provided
|
|
85
|
+
* and throws if any of the values is not a `number`.
|
|
86
|
+
*
|
|
87
|
+
* #### Adding static numbers
|
|
88
|
+
*
|
|
89
|
+
* The most basic example of using the `Numeric.sum` method is to add up a few numbers.
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
93
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
94
|
+
*
|
|
95
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
96
|
+
* Ensure.that(
|
|
97
|
+
* Numeric.sum(1, 2, 3),
|
|
98
|
+
* equals(6),
|
|
99
|
+
* )
|
|
100
|
+
* )
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The numbers can be provided individually, as an array, or as a combination of both.
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
107
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
108
|
+
*
|
|
109
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
110
|
+
* Ensure.that(
|
|
111
|
+
* Numeric.sum([ 1, 2 ], 3, [ 4, 5 ]),
|
|
112
|
+
* equals(15),
|
|
113
|
+
* )
|
|
114
|
+
* )
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* #### Adding numbers returned by other questions
|
|
118
|
+
*
|
|
119
|
+
* Apart from adding static numbers, you can also add numbers returned by other questions.
|
|
120
|
+
* This is particularly useful when you need to calculate the sum of numbers extracted from a list of UI elements
|
|
121
|
+
* or from an API response.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { actorCalled, Numeric, Question } from '@serenity-js/core'
|
|
125
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
126
|
+
*
|
|
127
|
+
* const myNumber = () =>
|
|
128
|
+
* Question.about('my number', actor => 42)
|
|
129
|
+
*
|
|
130
|
+
* const myArrayOfNumbers = () =>
|
|
131
|
+
* Question.about('my array of numbers', actor => [ 1, 2, 3 ])
|
|
132
|
+
*
|
|
133
|
+
* const myObjectWithNumbers = () =>
|
|
134
|
+
* Question.about('my object with numbers', actor => ({ a: 1, b: 2, c: 3 }))
|
|
135
|
+
*
|
|
136
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
137
|
+
* Ensure.that(
|
|
138
|
+
* Numeric.sum(
|
|
139
|
+
* myNumber(), // a question returning a number
|
|
140
|
+
* myArrayOfNumbers(), // a question returning an array of numbers
|
|
141
|
+
* ),
|
|
142
|
+
* equals(48),
|
|
143
|
+
* ),
|
|
144
|
+
* Ensure.that(
|
|
145
|
+
* Numeric.sum(
|
|
146
|
+
* myObjectWithNumbers() // a question returning an object with numbers
|
|
147
|
+
* .as(Object.values), // from which we extract the numeric values
|
|
148
|
+
* ),
|
|
149
|
+
* equals(6),
|
|
150
|
+
* ),
|
|
151
|
+
* )
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* Of course, you can also mix and match static numbers with numbers returned by questions.
|
|
155
|
+
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* import { actorCalled, Numeric, Question } from '@serenity-js/core'
|
|
158
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
159
|
+
*
|
|
160
|
+
* const myObjectWithNumbers = () =>
|
|
161
|
+
* Question.about('my object with numbers', actor => ({ a: 1, b: 2, c: 3 }))
|
|
162
|
+
*
|
|
163
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
164
|
+
* Ensure.that(
|
|
165
|
+
* Numeric.sum(
|
|
166
|
+
* myObjectWithNumbers().as(Object.values),
|
|
167
|
+
* [ 4, 5 ],
|
|
168
|
+
* 6,
|
|
169
|
+
* ),
|
|
170
|
+
* equals(21),
|
|
171
|
+
* ),
|
|
172
|
+
* )
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* #### Adding numbers extracted from a UI
|
|
176
|
+
*
|
|
177
|
+
* To add numbers extracted from a UI:
|
|
178
|
+
* - use the [`PageElement`](https://serenity-js.org/api/web/class/PageElement) and [`PageElements`](https://serenity-js.org/api/web/class/PageElements) classes to identify the elements of interest,
|
|
179
|
+
* - use the [`Text.of`](https://serenity-js.org/api/web/class/Text/) or [`Text.ofAll`](https://serenity-js.org/api/web/class/Text/) questions to extract the text of the element or elements,
|
|
180
|
+
* - and then interpret this text as number using either the [`.as(Number)`](https://serenity-js.org/api/core/class/Question/#as) mapping function,
|
|
181
|
+
* or the [`Numeric.intValue()`](https://serenity-js.org/api/core/class/Numeric/#intValue) or [`Numeric.floatValue()`](https://serenity-js.org/api/core/class/Numeric/#floatValue) meta-questions.
|
|
182
|
+
*
|
|
183
|
+
* For example, we could calculate the sum of quantities of items in our example price list by specifying each element explicitly
|
|
184
|
+
* and mapping its text to [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number):
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
188
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
189
|
+
* import { Text } from '@serenity-js/web'
|
|
190
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
191
|
+
*
|
|
192
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
193
|
+
* Ensure.that(
|
|
194
|
+
* Numeric.sum(
|
|
195
|
+
* Text.of(PriceListItem.quantity().of(PriceList.items().first())).as(Number),
|
|
196
|
+
* Text.of(PriceListItem.quantity().of(PriceList.items().at(1))).as(Number),
|
|
197
|
+
* Text.of(PriceListItem.quantity().of(PriceList.items().last())).as(Number),
|
|
198
|
+
* ),
|
|
199
|
+
* equals(11),
|
|
200
|
+
* ),
|
|
201
|
+
* )
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* A more elegant approach would be to use the Serenity/JS [Page Element Query Language (PEQL)](https://serenity-js.org/handbook/web-testing/page-element-query-language/#mapping-page-elements-in-a-collection)
|
|
205
|
+
* to map each item in the collection to its quantity and then calculate the sum.
|
|
206
|
+
*
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
209
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
210
|
+
* import { Text } from '@serenity-js/web'
|
|
211
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
212
|
+
*
|
|
213
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
214
|
+
* Ensure.that(
|
|
215
|
+
* Numeric.sum(
|
|
216
|
+
* PriceList.items() // get all the li.item elements
|
|
217
|
+
* .eachMappedTo(
|
|
218
|
+
* Text.of(PriceListItem.quantity()) // extract the text of the .quantity element
|
|
219
|
+
* )
|
|
220
|
+
* .eachMappedTo( // interpret the quantity as an integer value
|
|
221
|
+
* Numeric.intValue(),
|
|
222
|
+
* ),
|
|
223
|
+
* ),
|
|
224
|
+
* equals(11), // 5 apples, 4 apricots, 2 bananas
|
|
225
|
+
* )
|
|
226
|
+
* )
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
229
|
+
* Using PEQL allows us to express the intent more concisely and, for example,
|
|
230
|
+
* introduce helper functions that limit the scope of the operation to a subset of elements.
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* import { actorCalled, Expectation, Numeric, the } from '@serenity-js/core'
|
|
234
|
+
* import { Ensure, equals, startsWith } from '@serenity-js/assertions'
|
|
235
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
236
|
+
*
|
|
237
|
+
* const quantitiesOfItemsWhichName = (expectation: Expectation<string>) =>
|
|
238
|
+
* PriceList.items() // get all the li.item elements
|
|
239
|
+
* .where( // leave only those which name matches the expectation
|
|
240
|
+
* Text.of(PriceListItem.name()),
|
|
241
|
+
* expectation
|
|
242
|
+
* )
|
|
243
|
+
* .eachMappedTo(
|
|
244
|
+
* Text.of(PriceListItem.quantity()) // extract the text of the .quantity element
|
|
245
|
+
* )
|
|
246
|
+
* .eachMappedTo( // interpret the quantity as an integer value
|
|
247
|
+
* Numeric.intValue(),
|
|
248
|
+
* )
|
|
249
|
+
* .describedAs(the`quantities of items which name does ${ expectation }`)
|
|
250
|
+
*
|
|
251
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
252
|
+
* Ensure.that(
|
|
253
|
+
* Numeric.sum(
|
|
254
|
+
* quantitiesOfItemsWhichName(startsWith('ap')), // apples and apricots
|
|
255
|
+
* ),
|
|
256
|
+
* equals(9), // 5 apples, 4 apricots
|
|
257
|
+
* )
|
|
258
|
+
* )
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* #### Learn more
|
|
262
|
+
*
|
|
263
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
264
|
+
* and examples.
|
|
265
|
+
*
|
|
266
|
+
* @param values
|
|
267
|
+
*/
|
|
268
|
+
static sum(...values: Array<Answerable<number | number[]>>): QuestionAdapter<number>;
|
|
269
|
+
/**
|
|
270
|
+
* Returns a [`Question`](https://serenity-js.org/api/core/class/Question/) that calculates the difference between
|
|
271
|
+
* two numbers and throws if any of the values is not a `number`.
|
|
272
|
+
*
|
|
273
|
+
* #### Subtracting numbers
|
|
274
|
+
*
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
277
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
278
|
+
* import { Text } from '@serenity-js/web'
|
|
279
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
280
|
+
*
|
|
281
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
282
|
+
* Ensure.that(
|
|
283
|
+
* Numeric.difference(
|
|
284
|
+
* Text.of(PriceListItem.quantity().of(PriceList.items().first())).as(Number), // 5 (apples)
|
|
285
|
+
* 2, // - 2
|
|
286
|
+
* ),
|
|
287
|
+
* equals(3),
|
|
288
|
+
* ),
|
|
289
|
+
* )
|
|
290
|
+
* ```
|
|
291
|
+
*
|
|
292
|
+
* #### Learn more
|
|
293
|
+
*
|
|
294
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
295
|
+
* and examples.
|
|
296
|
+
*
|
|
297
|
+
* @param minuend
|
|
298
|
+
* @param subtrahend
|
|
299
|
+
*/
|
|
300
|
+
static difference(minuend: Answerable<number>, subtrahend: Answerable<number>): QuestionAdapter<number>;
|
|
301
|
+
/**
|
|
302
|
+
* Returns a [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) that calculates
|
|
303
|
+
* the ceiling of a number and throws if the value is not a `number`.
|
|
304
|
+
*
|
|
305
|
+
* #### Calculating the ceiling of a number
|
|
306
|
+
*
|
|
307
|
+
* ```ts
|
|
308
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
309
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
310
|
+
* import { Text } from '@serenity-js/web'
|
|
311
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
312
|
+
*
|
|
313
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
314
|
+
* Ensure.that(
|
|
315
|
+
* Numeric.ceiling().of(
|
|
316
|
+
* Text.of(PriceListItem.price().of(PriceList.items().first())) // '£2.25' (apples)
|
|
317
|
+
* .replace('£', '') // '2.25'
|
|
318
|
+
* .as(Number.parseFloat), // 2.25
|
|
319
|
+
* ),
|
|
320
|
+
* equals(3),
|
|
321
|
+
* ),
|
|
322
|
+
* )
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* #### Learn more
|
|
326
|
+
*
|
|
327
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
328
|
+
* and examples.
|
|
329
|
+
*/
|
|
330
|
+
static ceiling(): MetaQuestion<number, QuestionAdapter<number>>;
|
|
331
|
+
/**
|
|
332
|
+
* Returns a [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) that calculates
|
|
333
|
+
* the floor of a number and throws if the value is not a `number`.
|
|
334
|
+
*
|
|
335
|
+
* #### Calculating the floor of a number
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
339
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
340
|
+
* import { Text } from '@serenity-js/web'
|
|
341
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
342
|
+
*
|
|
343
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
344
|
+
* Ensure.that(
|
|
345
|
+
* Numeric.floor().of(
|
|
346
|
+
* Text.of(PriceListItem.price().of(PriceList.items().first())) // '£2.25' (apples)
|
|
347
|
+
* .replace('£', '') // '2.25'
|
|
348
|
+
* .as(Number.parseFloat), // 2.25
|
|
349
|
+
* ),
|
|
350
|
+
* equals(2),
|
|
351
|
+
* ),
|
|
352
|
+
* )
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* #### Learn more
|
|
356
|
+
*
|
|
357
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
358
|
+
* and examples.
|
|
359
|
+
*/
|
|
360
|
+
static floor(): MetaQuestion<number, QuestionAdapter<number>>;
|
|
361
|
+
/**
|
|
362
|
+
* Returns a [`Question`](https://serenity-js.org/api/core/class/Question/) that calculates
|
|
363
|
+
* the maximum value in the lists of numbers provided and throws if any of the values is not a `number`.
|
|
364
|
+
*
|
|
365
|
+
* #### Calculating the maximum value
|
|
366
|
+
*
|
|
367
|
+
* ```ts
|
|
368
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
369
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
370
|
+
* import { Text } from '@serenity-js/web'
|
|
371
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
372
|
+
*
|
|
373
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
374
|
+
* Ensure.that(
|
|
375
|
+
* Numeric.max(
|
|
376
|
+
* PriceList.items() // get all the li.item elements
|
|
377
|
+
* .eachMappedTo(
|
|
378
|
+
* Text.of(PriceListItem.quantity()) // extract the text of the .quantity element
|
|
379
|
+
* )
|
|
380
|
+
* .eachMappedTo( // interpret the quantity as an integer value
|
|
381
|
+
* Numeric.intValue(),
|
|
382
|
+
* ),
|
|
383
|
+
* ),
|
|
384
|
+
* equals(5), // 5 (apples)
|
|
385
|
+
* )
|
|
386
|
+
* )
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* #### Learn more
|
|
390
|
+
*
|
|
391
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
392
|
+
* and examples.
|
|
393
|
+
*
|
|
394
|
+
* @param values
|
|
395
|
+
*/
|
|
396
|
+
static max(...values: Array<Answerable<number | number[]>>): QuestionAdapter<number>;
|
|
397
|
+
/**
|
|
398
|
+
* Returns a [`Question`](https://serenity-js.org/api/core/class/Question/) that calculates
|
|
399
|
+
* the minimum value in the lists of numbers provided and throws if any of the values is not a `number`.
|
|
400
|
+
*
|
|
401
|
+
* #### Calculating the minimum value
|
|
402
|
+
*
|
|
403
|
+
* ```ts
|
|
404
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
405
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
406
|
+
* import { Text } from '@serenity-js/web'
|
|
407
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
408
|
+
*
|
|
409
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
410
|
+
* Ensure.that(
|
|
411
|
+
* Numeric.min(
|
|
412
|
+
* PriceList.items() // get all the li.item elements
|
|
413
|
+
* .eachMappedTo(
|
|
414
|
+
* Text.of(PriceListItem.quantity()) // extract the text of the .quantity element
|
|
415
|
+
* )
|
|
416
|
+
* .eachMappedTo( // interpret the quantity as an integer value
|
|
417
|
+
* Numeric.intValue(),
|
|
418
|
+
* ),
|
|
419
|
+
* ),
|
|
420
|
+
* equals(2), // 2 (bananas)
|
|
421
|
+
* )
|
|
422
|
+
* )
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* #### Learn more
|
|
426
|
+
*
|
|
427
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
428
|
+
* and examples.
|
|
429
|
+
*
|
|
430
|
+
* @param values
|
|
431
|
+
*/
|
|
432
|
+
static min(...values: Array<Answerable<number | number[]>>): QuestionAdapter<number>;
|
|
433
|
+
/**
|
|
434
|
+
* Returns a [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) that parses a string `value`
|
|
435
|
+
* and returns an integer of the specified `base`.
|
|
436
|
+
* Leading whitespace in the value to parse argument is ignored.
|
|
437
|
+
*
|
|
438
|
+
* #### Parsing a string as an integer
|
|
439
|
+
*
|
|
440
|
+
* ```ts
|
|
441
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
442
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
443
|
+
* import { Text } from '@serenity-js/web'
|
|
444
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
445
|
+
*
|
|
446
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
447
|
+
* Ensure.that(
|
|
448
|
+
* Numeric.intValue().of(
|
|
449
|
+
* Text.of( // '5' (apples)
|
|
450
|
+
* PriceListItem.quantity().of(
|
|
451
|
+
* PriceList.items().first()
|
|
452
|
+
* )
|
|
453
|
+
* )
|
|
454
|
+
* ),
|
|
455
|
+
* equals(5),
|
|
456
|
+
* ),
|
|
457
|
+
* )
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* #### Learn more
|
|
461
|
+
*
|
|
462
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
463
|
+
* and examples.
|
|
464
|
+
*
|
|
465
|
+
* @param base
|
|
466
|
+
* An integer between 2 and 36 that represents the base in mathematical numeral systems of the string.
|
|
467
|
+
* If base is undefined or 0, it is assumed to be 10 except when the number begins with the code unit pairs 0x or 0X, in which case a radix of 16 is assumed.
|
|
468
|
+
*/
|
|
469
|
+
static intValue(base?: Answerable<number>): MetaQuestion<string, QuestionAdapter<number>>;
|
|
470
|
+
/**
|
|
471
|
+
* Returns a [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) that parses a string `value`
|
|
472
|
+
* and returns a [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt).
|
|
473
|
+
* Leading whitespace in the value to parse argument is ignored.
|
|
474
|
+
*
|
|
475
|
+
* #### Parsing a string as a bigint
|
|
476
|
+
*
|
|
477
|
+
* ```ts
|
|
478
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
479
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
480
|
+
* import { Text } from '@serenity-js/web'
|
|
481
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
482
|
+
*
|
|
483
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
484
|
+
* Ensure.that(
|
|
485
|
+
* Numeric.bigIntValue().of(
|
|
486
|
+
* Text.of( // '5' (apples)
|
|
487
|
+
* PriceListItem.quantity().of(PriceList.items().first())
|
|
488
|
+
* )
|
|
489
|
+
* ),
|
|
490
|
+
* equals(BigInt('5')),
|
|
491
|
+
* ),
|
|
492
|
+
* )
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* #### Learn more
|
|
496
|
+
*
|
|
497
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
498
|
+
* and examples.
|
|
499
|
+
*/
|
|
500
|
+
static bigIntValue(): MetaQuestion<string, QuestionAdapter<bigint>>;
|
|
501
|
+
/**
|
|
502
|
+
* Returns a [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) that parses a string `value`
|
|
503
|
+
* and returns a floating-point number.
|
|
504
|
+
*
|
|
505
|
+
* #### Parsing a string as a floating point number
|
|
506
|
+
*
|
|
507
|
+
* ```ts
|
|
508
|
+
* import { actorCalled, Numeric } from '@serenity-js/core'
|
|
509
|
+
* import { Ensure, equals } from '@serenity-js/assertions'
|
|
510
|
+
* import { Text } from '@serenity-js/web'
|
|
511
|
+
* import { PriceList, PriceListItem } from './ui/price-list'
|
|
512
|
+
*
|
|
513
|
+
* await actorCalled('Zoé').attemptsTo(
|
|
514
|
+
* Ensure.that(
|
|
515
|
+
* Numeric.floatValue().of(
|
|
516
|
+
* Text.of( // '£2.25'
|
|
517
|
+
* PriceListItem.price().of(PriceList.items().first())
|
|
518
|
+
* ).replace('£', '') // '2.25'
|
|
519
|
+
* ),
|
|
520
|
+
* equals(2.25),
|
|
521
|
+
* ),
|
|
522
|
+
* )
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* #### Learn more
|
|
526
|
+
*
|
|
527
|
+
* View the [`Numeric` API documentation](https://serenity-js.org/api/core/class/Numeric) for more details
|
|
528
|
+
* and examples.
|
|
529
|
+
*/
|
|
530
|
+
static floatValue(): MetaQuestion<string, QuestionAdapter<number>>;
|
|
531
|
+
private static flatten;
|
|
532
|
+
private static descriptionOf;
|
|
533
|
+
}
|
|
534
|
+
//# sourceMappingURL=Numeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Numeric.d.ts","sourceRoot":"","sources":["../../../src/screenplay/questions/Numeric.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6EG;AACH,qBAAa,OAAO;IAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwLG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IASpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IAUvG;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAW/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,KAAK,IAAI,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAW7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IAQpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC;IAQpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IA4BzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,WAAW,IAAI,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAqBnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,MAAM,CAAC,UAAU,IAAI,YAAY,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAsBlE,OAAO,CAAC,MAAM,CAAC,OAAO;IAmBtB,OAAO,CAAC,MAAM,CAAC,aAAa;CAO/B"}
|