@@ -27,7 +27,10 @@ demonstrate some playwright for test developers. This pattern should not be re-u
27
27
*/
28
28
29
29
const { test, expect } = require ( '../../../../pluginFixtures.js' ) ;
30
- const { createDomainObjectWithDefaults } = require ( '../../../../appActions' ) ;
30
+ const {
31
+ createDomainObjectWithDefaults,
32
+ createExampleTelemetryObject
33
+ } = require ( '../../../../appActions' ) ;
31
34
32
35
let conditionSetUrl ;
33
36
let getConditionSetIdentifierFromUrl ;
@@ -205,23 +208,31 @@ test.describe.serial('Condition Set CRUD Operations on @localStorage', () => {
205
208
} ) ;
206
209
207
210
test . describe ( 'Basic Condition Set Use' , ( ) => {
211
+ let conditionSet ;
212
+
208
213
test . beforeEach ( async ( { page } ) => {
209
214
// Open a browser, navigate to the main page, and wait until all network events to resolve
210
215
await page . goto ( './' , { waitUntil : 'domcontentloaded' } ) ;
211
- } ) ;
212
- test ( 'Can add a condition' , async ( { page } ) => {
213
216
// Create a new condition set
214
- await createDomainObjectWithDefaults ( page , {
217
+ conditionSet = await createDomainObjectWithDefaults ( page , {
215
218
type : 'Condition Set' ,
216
219
name : 'Test Condition Set'
217
220
} ) ;
221
+ } ) ;
222
+ test ( 'Creating a condition defaults the condition name to "Unnamed Condition"' , async ( {
223
+ page
224
+ } ) => {
225
+ await page . goto ( conditionSet . url ) ;
226
+
218
227
// Change the object to edit mode
219
228
await page . locator ( '[title="Edit"]' ) . click ( ) ;
220
229
221
230
// Click Add Condition button
222
231
await page . locator ( '#addCondition' ) . click ( ) ;
223
232
// Check that the new Unnamed Condition section appears
224
- const numOfUnnamedConditions = await page . locator ( 'text=Unnamed Condition' ) . count ( ) ;
233
+ const numOfUnnamedConditions = await page
234
+ . locator ( '.c-condition__name' , { hasText : 'Unnamed Condition' } )
235
+ . count ( ) ;
225
236
expect ( numOfUnnamedConditions ) . toEqual ( 1 ) ;
226
237
} ) ;
227
238
test ( 'ConditionSet should display appropriate view options' , async ( { page } ) => {
@@ -238,16 +249,13 @@ test.describe('Basic Condition Set Use', () => {
238
249
type : 'Sine Wave Generator' ,
239
250
name : 'Beta Sine Wave Generator'
240
251
} ) ;
241
- const conditionSet1 = await createDomainObjectWithDefaults ( page , {
242
- type : 'Condition Set' ,
243
- name : 'Test Condition Set'
244
- } ) ;
252
+
253
+ await page . goto ( conditionSet . url ) ;
245
254
246
255
// Change the object to edit mode
247
256
await page . locator ( '[title="Edit"]' ) . click ( ) ;
248
257
249
258
// Expand the 'My Items' folder in the left tree
250
- await page . goto ( conditionSet1 . url ) ;
251
259
page . click ( 'button[title="Show selected item in tree"]' ) ;
252
260
// Add the Alpha & Beta Sine Wave Generator to the Condition Set and save changes
253
261
const treePane = page . getByRole ( 'tree' , {
@@ -264,105 +272,99 @@ test.describe('Basic Condition Set Use', () => {
264
272
await alphaGeneratorTreeItem . dragTo ( conditionCollection ) ;
265
273
await betaGeneratorTreeItem . dragTo ( conditionCollection ) ;
266
274
267
- const saveButtonLocator = page . locator ( 'button[title="Save"]' ) ;
268
- await saveButtonLocator . click ( ) ;
275
+ await page . locator ( 'button[title="Save"]' ) . click ( ) ;
269
276
await page . getByRole ( 'listitem' , { name : 'Save and Finish Editing' } ) . click ( ) ;
277
+
270
278
await page . click ( 'button[title="Change the current view"]' ) ;
271
279
272
280
await expect ( page . getByRole ( 'menuitem' , { name : / L a d T a b l e / } ) ) . toBeHidden ( ) ;
273
281
await expect ( page . getByRole ( 'menuitem' , { name : / C o n d i t i o n s V i e w / } ) ) . toBeVisible ( ) ;
274
282
await expect ( page . getByRole ( 'menuitem' , { name : / P l o t / } ) ) . toBeVisible ( ) ;
275
283
await expect ( page . getByRole ( 'menuitem' , { name : / T e l e m e t r y T a b l e / } ) ) . toBeVisible ( ) ;
276
284
} ) ;
277
- test ( 'ConditionSet should output blank instead of the default value' , async ( { page } ) => {
278
- //Navigate to baseURL
279
- await page . goto ( './' , { waitUntil : 'domcontentloaded' } ) ;
280
-
281
- //Click the Create button
282
- await page . click ( 'button:has-text("Create")' ) ;
283
-
284
- // Click the object specified by 'type'
285
- await page . click ( `li[role='menuitem']:text("Sine Wave Generator")` ) ;
286
- await page . getByRole ( 'spinbutton' , { name : 'Loading Delay (ms)' } ) . fill ( '8000' ) ;
287
- const nameInput = page . locator ( 'form[name="mctForm"] .first input[type="text"]' ) ;
288
- await nameInput . fill ( 'Delayed Sine Wave Generator' ) ;
289
-
290
- // Click OK button and wait for Navigate event
291
- await Promise . all ( [
292
- page . waitForLoadState ( ) ,
293
- page . click ( '[aria-label="Save"]' ) ,
294
- // Wait for Save Banner to appear
295
- page . waitForSelector ( '.c-message-banner__message' )
296
- ] ) ;
285
+ test ( 'ConditionSet has correct outputs when telemetry is and is not available' , async ( {
286
+ page
287
+ } ) => {
288
+ const exampleTelemetry = await createExampleTelemetryObject ( page ) ;
297
289
298
- // Create a new condition set
299
- await createDomainObjectWithDefaults ( page , {
300
- type : 'Condition Set' ,
301
- name : 'Test Blank Output of Condition Set'
302
- } ) ;
290
+ await page . getByTitle ( 'Show selected item in tree' ) . click ( ) ;
291
+ await page . goto ( conditionSet . url ) ;
303
292
// Change the object to edit mode
304
293
await page . locator ( '[title="Edit"]' ) . click ( ) ;
305
294
306
- // Click Add Condition button twice
295
+ // Create two conditions
307
296
await page . locator ( '#addCondition' ) . click ( ) ;
308
297
await page . locator ( '#addCondition' ) . click ( ) ;
309
298
await page . locator ( '#conditionCollection' ) . getByRole ( 'textbox' ) . nth ( 0 ) . fill ( 'First Condition' ) ;
310
299
await page . locator ( '#conditionCollection' ) . getByRole ( 'textbox' ) . nth ( 1 ) . fill ( 'Second Condition' ) ;
311
300
312
- // Expand the 'My Items' folder in the left tree
313
- await page . locator ( '.c-tree__item__view-control.c-disclosure-triangle' ) . first ( ) . click ( ) ;
314
- // Add the Sine Wave Generator to the Condition Set and save changes
315
- const treePane = page . getByRole ( 'tree' , {
316
- name : 'Main Tree'
317
- } ) ;
318
- const sineWaveGeneratorTreeItem = treePane . getByRole ( 'treeitem' , {
319
- name : 'Delayed Sine Wave Generator'
320
- } ) ;
321
- const conditionCollection = await page . locator ( '#conditionCollection' ) ;
322
-
301
+ // Add Telemetry to ConditionSet
302
+ const sineWaveGeneratorTreeItem = page
303
+ . getByRole ( 'tree' , {
304
+ name : 'Main Tree'
305
+ } )
306
+ . getByRole ( 'treeitem' , {
307
+ name : exampleTelemetry . name
308
+ } ) ;
309
+ const conditionCollection = page . locator ( '#conditionCollection' ) ;
323
310
await sineWaveGeneratorTreeItem . dragTo ( conditionCollection ) ;
324
311
325
- const firstCriterionTelemetry = await page . locator (
312
+ // Modify First Criterion
313
+ const firstCriterionTelemetry = page . locator (
326
314
'[aria-label="Criterion Telemetry Selection"] >> nth=0'
327
315
) ;
328
- firstCriterionTelemetry . selectOption ( { label : 'Delayed Sine Wave Generator' } ) ;
329
-
330
- const secondCriterionTelemetry = await page . locator (
331
- '[aria-label="Criterion Telemetry Selection"] >> nth=1'
332
- ) ;
333
- secondCriterionTelemetry . selectOption ( { label : 'Delayed Sine Wave Generator' } ) ;
334
-
335
- const firstCriterionMetadata = await page . locator (
316
+ firstCriterionTelemetry . selectOption ( { label : exampleTelemetry . name } ) ;
317
+ const firstCriterionMetadata = page . locator (
336
318
'[aria-label="Criterion Metadata Selection"] >> nth=0'
337
319
) ;
338
320
firstCriterionMetadata . selectOption ( { label : 'Sine' } ) ;
321
+ const firstCriterionComparison = page . locator (
322
+ '[aria-label="Criterion Comparison Selection"] >> nth=0'
323
+ ) ;
324
+ firstCriterionComparison . selectOption ( { label : 'is greater than or equal to' } ) ;
325
+ const firstCriterionInput = page . locator ( '[aria-label="Criterion Input"] >> nth=0' ) ;
326
+ await firstCriterionInput . fill ( '0' ) ;
339
327
340
- const secondCriterionMetadata = await page . locator (
341
- '[aria-label="Criterion Metadata Selection"] >> nth=1'
328
+ // Modify First Criterion
329
+ const secondCriterionTelemetry = page . locator (
330
+ '[aria-label="Criterion Telemetry Selection"] >> nth=1'
342
331
) ;
343
- secondCriterionMetadata . selectOption ( { label : 'Sine' } ) ;
332
+ secondCriterionTelemetry . selectOption ( { label : exampleTelemetry . name } ) ;
344
333
345
- const firstCriterionComparison = await page . locator (
346
- '[aria-label="Criterion Comparison Selection"] >> nth=0 '
334
+ const secondCriterionMetadata = page . locator (
335
+ '[aria-label="Criterion Metadata Selection"] >> nth=1 '
347
336
) ;
348
- firstCriterionComparison . selectOption ( { label : 'is greater than or equal to ' } ) ;
337
+ secondCriterionMetadata . selectOption ( { label : 'Sine ' } ) ;
349
338
350
- const secondCriterionComparison = await page . locator (
339
+ const secondCriterionComparison = page . locator (
351
340
'[aria-label="Criterion Comparison Selection"] >> nth=1'
352
341
) ;
353
342
secondCriterionComparison . selectOption ( { label : 'is less than' } ) ;
354
343
355
- const firstCriterionInput = await page . locator ( '[aria-label="Criterion Input"] >> nth=0' ) ;
356
- await firstCriterionInput . fill ( '0' ) ;
357
-
358
- const secondCriterionInput = await page . locator ( '[aria-label="Criterion Input"] >> nth=1' ) ;
344
+ const secondCriterionInput = page . locator ( '[aria-label="Criterion Input"] >> nth=1' ) ;
359
345
await secondCriterionInput . fill ( '0' ) ;
360
346
361
- const saveButtonLocator = page . locator ( 'button[title=" Save"]' ) ;
362
- await saveButtonLocator . click ( ) ;
347
+ // Save ConditionSet
348
+ await page . locator ( 'button[title="Save"]' ) . click ( ) ;
363
349
await page . getByRole ( 'listitem' , { name : 'Save and Finish Editing' } ) . click ( ) ;
364
350
365
- const outputValue = await page . locator ( '[aria-label="Current Output Value"]' ) ;
351
+ // Validate that the condition set is evaluating and outputting
352
+ // the correct value when the underlying telemetry subscription is active.
353
+ let outputValue = page . locator ( '[aria-label="Current Output Value"]' ) ;
354
+ await expect ( outputValue ) . toHaveText ( 'false' ) ;
355
+
356
+ await page . goto ( exampleTelemetry . url ) ;
357
+
358
+ // Edit SWG to add 8 second loading delay to simulate the case
359
+ // where telemetry is not available.
360
+ await page . getByTitle ( 'More options' ) . click ( ) ;
361
+ await page . getByRole ( 'menuitem' , { name : 'Edit Properties...' } ) . click ( ) ;
362
+ await page . getByRole ( 'spinbutton' , { name : 'Loading Delay (ms)' } ) . fill ( '8000' ) ;
363
+ await page . getByLabel ( 'Save' ) . click ( ) ;
364
+
365
+ // Expect that the output value is blank or '---' if the
366
+ // underlying telemetry subscription is not active.
367
+ await page . goto ( conditionSet . url ) ;
366
368
await expect ( outputValue ) . toHaveText ( '---' ) ;
367
369
} ) ;
368
370
} ) ;
0 commit comments