-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDomainFieldRow.java
More file actions
1882 lines (1615 loc) · 64.6 KB
/
DomainFieldRow.java
File metadata and controls
1882 lines (1615 loc) · 64.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.labkey.test.components.domain;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.labkey.api.exp.query.ExpSchema;
import org.labkey.test.BootstrapLocators;
import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.components.bootstrap.ModalDialog;
import org.labkey.test.components.html.Checkbox;
import org.labkey.test.components.html.Input;
import org.labkey.test.components.html.RadioButton;
import org.labkey.test.components.html.SelectWrapper;
import org.labkey.test.components.react.FilteringReactSelect;
import org.labkey.test.components.ui.ontology.ConceptPickerDialog;
import org.labkey.test.pages.core.admin.BaseSettingsPage.DATE_FORMAT;
import org.labkey.test.pages.core.admin.BaseSettingsPage.TIME_FORMAT;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.util.LabKeyExpectedConditions;
import org.labkey.test.util.selenium.WebElementUtils;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static org.junit.Assert.assertTrue;
import static org.labkey.test.WebDriverWrapper.WAIT_FOR_JAVASCRIPT;
import static org.labkey.test.WebDriverWrapper.waitFor;
public class DomainFieldRow extends WebDriverComponent<DomainFieldRow.ElementCache>
{
public static final String ALL_SAMPLES_OPTION_TEXT = "All Samples";
final WebElement _el;
final WebDriver _driver;
final DomainFormPanel _formPanel;
public DomainFieldRow(DomainFormPanel panel, WebElement element, WebDriver driver)
{
_el = element;
_driver = driver;
_formPanel = panel;
}
@Override
public WebElement getComponentElement()
{
return _el;
}
@Override
public WebDriver getDriver()
{
return _driver;
}
// basic field properties
public String getName()
{
return elementCache().fieldNameInput.getValue();
}
public DomainFieldRow setName(String name)
{
elementCache().fieldNameInput.setValue(name);
return this;
}
public Input nameInput()
{
return elementCache().fieldNameInput;
}
public WebElement typeInput()
{
return elementCache().fieldTypeSelectInput.getWrappedElement();
}
public FieldDefinition.ColumnType getType()
{
// The previous code doesn't work:
// String typeString = getWrapper().getFormElement(elementCache().fieldTypeSelectInput);
// return Enum.valueOf(FieldDefinition.ColumnType.class, typeString);
// getFormElement get's the value attribute which is not the same as the text shown and not the
// same as the Enum.valueOf. To get a match get the text shown in the control and compare it
// to the enum's label attribute.
String typeString = getWrapper().getSelectedOptionText(elementCache().fieldTypeSelectInput.getWrappedElement());
for (FieldDefinition.ColumnType ct : FieldDefinition.ColumnType.values())
{
if (ct.getLabel().equalsIgnoreCase(typeString))
return ct;
}
throw new IllegalStateException("Unknown column type: " + typeString);
}
public List<String> getTypeOptions()
{
List<String> typeOptions = new ArrayList<>();
for (WebElement option : elementCache().fieldTypeSelectInput.getOptions())
{
typeOptions.add(option.getText());
}
return typeOptions;
}
/**
* Selects the field data type.
*/
public DomainFieldRow setType(FieldDefinition.ColumnType columnType)
{
return setType(columnType, false);
}
/**
* Selects the field data type.
* @param confirmDialogExpected boolean indicating if this field data type change expects a confirm dialog
*/
public DomainFieldRow setType(FieldDefinition.ColumnType columnType, boolean confirmDialogExpected)
{
elementCache().fieldTypeSelectInput.selectByVisibleText(columnType.getLabel());
if (confirmDialogExpected)
{
ModalDialog confirmDialog = new ModalDialog.ModalDialogFinder(getDriver())
.withTitle("Confirm Data Type Change").timeout(1000).waitFor();
confirmDialog.dismiss("Yes, Change Data Type");
}
return this;
}
/**
* Selects the field data type and returns the 'are you sure' dialog.
*/
public ModalDialog setTypeWithDialog(FieldDefinition.ColumnType columnType)
{
elementCache().fieldTypeSelectInput.selectByVisibleText(columnType.getLabel());
return new ModalDialog.ModalDialogFinder(getDriver())
.withTitle("Confirm Data Type Change").timeout(1000).waitFor();
}
public boolean getRequiredField()
{
return elementCache().fieldRequiredCheckbox.get();
}
public DomainFieldRow setRequiredField(boolean checked)
{
elementCache().fieldRequiredCheckbox.set(checked);
return this;
}
public boolean hasRequiredField()
{
return elementCache().fieldRequiredCheckbox.isDisplayed();
}
public DomainFieldRow setSelectRowField(boolean checked)
{
elementCache().fieldSelectCheckbox.set(checked);
return this;
}
public String detailsMessage()
{
return elementCache().fieldDetailsMessage.getText().trim();
}
public int getIndex()
{
String itemIndexAttribute = getComponentElement().getAttribute("tabindex");
return Integer.parseInt(itemIndexAttribute);
}
public boolean isExpanded()
{
return elementCache().collapseToggleLoc.existsIn(this);
}
/**
* Remove the field from the domain designer.
*
* @param confirmDialogExpected boolean indicating if this field removal expects a confirm dialog
*/
public void clickRemoveField(boolean confirmDialogExpected)
{
getWrapper().mouseOver(elementCache().removeField);
elementCache().removeField.click();
if (confirmDialogExpected)
{
ModalDialog confirmDialog = new ModalDialog.ModalDialogFinder(getDriver())
.withTitle("Confirm Remove Field").timeout(1000).waitFor();
confirmDialog.dismiss("Yes, Remove Field");
}
}
public boolean isRemoveFieldBtnPresent()
{
return elementCache().removeFieldLoc.existsIn(this);
}
public DomainFieldRow setAdvancedSettings(List<AdvancedFieldSetting> settings)
{
if (!settings.isEmpty())
{
AdvancedSettingsDialog advancedSettingsDialog = clickAdvancedSettings();
for (AdvancedFieldSetting setting : settings)
{
setting.accept(advancedSettingsDialog);
}
advancedSettingsDialog.apply();
}
return this;
}
public AdvancedSettingsDialog clickAdvancedSettings()
{
expand();
WebDriverWrapper.waitFor(() -> elementCache().advancedSettingsBtn.isEnabled(),
"the Advanced Settings button did not become enabled", 5000);
int trycount = 0;
do
{
getWrapper().log("clicking advanced settings button try=[" + trycount + "]");
elementCache().advancedSettingsBtn.click();
getWrapper().shortWait().until(LabKeyExpectedConditions.animationIsDone(getComponentElement()));
trycount++;
assertTrue("advanced settings dialog did not appear in time", trycount < 4);
}
while (!Locator.tagWithClass("div", "modal-backdrop").existsIn(getDriver()));
return new AdvancedSettingsDialog(this);
}
public DomainFieldRow expand()
{
if (!isExpanded())
{
getWrapper().shortWait().until(ExpectedConditions.elementToBeClickable(elementCache().expandToggle));
for (int i = 0; i < 3; i++)
{
elementCache().expandToggle.click();
getWrapper().shortWait().until(LabKeyExpectedConditions.animationIsDone(getComponentElement())); // wait for transition to happen
if (WebDriverWrapper.waitFor(this::isExpanded, 1000))
break;
}
WebDriverWrapper.waitFor(this::isExpanded,
"the field row did not become expanded", 1500);
}
return this;
}
public DomainFieldRow collapse()
{
if (isExpanded())
{
elementCache().collapseToggle.click();
getWrapper().shortWait().until(LabKeyExpectedConditions.animationIsDone(getComponentElement())); // wait for transition to happen
WebDriverWrapper.waitFor(() -> elementCache().expandToggleLoc.existsIn(this),
"the field row did not collapse", 1500);
}
return this;
}
/**
* indicates that the field has been added, the user will need to save changes to persist.
* New fields can have their type changed
*/
public boolean isNewField()
{
return Locator.tagWithAttributeContaining("span", "id", "domainpropertiesrow-details")
.withText("New Field").existsIn(this);
}
/**
* indicates that the field has been edited (but is not new). The user will need to save changes to persist
*/
public boolean isEditedField()
{
return Locator.tagWithAttributeContaining("span", "id", "domainpropertiesrow-details")
.withText("Updated").existsIn(this);
}
//
// common field options
public String getDescription()
{
expand();
return getWrapper().getFormElement(elementCache().descriptionTextArea);
}
public DomainFieldRow setDescription(String description)
{
expand();
getWrapper().shortWait().until(ExpectedConditions.elementToBeClickable(elementCache().descriptionTextArea));
try
{
getWrapper().setFormElement(elementCache().descriptionTextArea, description);
}
catch (ElementNotInteractableException retry)
{
WebDriverWrapper.sleep(500);
getWrapper().setFormElement(elementCache().descriptionTextArea, description);
}
return this;
}
public String getAttachmentBehavior()
{
expand();
return elementCache().attachmentBehavior.getFirstSelectedOption().getText();
}
public DomainFieldRow setAttachmentBehavior(String value)
{
expand();
elementCache().attachmentBehavior.selectByVisibleText(value);
return this;
}
public String getLabel()
{
expand();
return elementCache().labelInput.getValue();
}
public DomainFieldRow setLabel(String label)
{
expand();
elementCache().labelInput.setValue(label);
return this;
}
public String getImportAliases()
{
expand();
return elementCache().importAliasesInput.getValue();
}
public DomainFieldRow setImportAliases(String aliases)
{
expand();
elementCache().importAliasesInput.setValue(aliases);
return this;
}
public String getUrl()
{
expand();
return elementCache().urlInput.getValue();
}
public DomainFieldRow setUrl(String url)
{
expand();
elementCache().urlInput.setValue(url);
return this;
}
public boolean isUrlOpenNewTab()
{
expand();
return elementCache().urlTargetCheckbox.get();
}
public DomainFieldRow setUrlOpenNewTab(boolean checked)
{
expand();
elementCache().urlTargetCheckbox.set(checked);
return this;
}
//
// numeric field options.
public String getNumberFormat()
{
return getFormat();
}
public DomainFieldRow setNumberFormat(String formatString)
{
return setFormat(formatString);
}
public FieldDefinition.ScaleType getScaleType()
{
expand();
String scaleTypeString = getWrapper().getFormElement(elementCache().defaultScaleTypeSelect.getWrappedElement());
return Enum.valueOf(FieldDefinition.ScaleType.class, scaleTypeString.toUpperCase());
}
public DomainFieldRow setScaleType(FieldDefinition.ScaleType scaleType)
{
expand();
elementCache().defaultScaleTypeSelect.selectByVisibleText(scaleType.getText());
return this;
}
// generic set format.
public DomainFieldRow setFormat(String formatString)
{
return setFormat(formatString, null);
}
public DomainFieldRow setFormat(String formatString, @Nullable String dataType)
{
expand();
if (FieldDefinition.ColumnType.DateAndTime.getRangeURI().equals(dataType) ||
FieldDefinition.ColumnType.Date.getRangeURI().equals(dataType) ||
(FieldDefinition.ColumnType.Time.getRangeURI().equals(dataType)))
{
throw new UnsupportedOperationException("Setting the format for Date, Time or DateTime fields not supported in this method.");
}
if (elementCache().formatInput.getComponentElement().isDisplayed())
{
elementCache().formatInput.setValue(formatString);
}
else if (elementCache().charScaleInput.getComponentElement().isDisplayed())
{
// Formatting of Boolean types use the scale input.
elementCache().charScaleInput.setValue(formatString);
}
else
{
throw new NullPointerException("No 'Format' input present to set.");
}
return this;
}
public String getFormat()
{
expand();
if(elementCache().formatInput.getComponentElement().isDisplayed())
{
return elementCache().formatInput.getValue();
}
else if(elementCache().charScaleInput.getComponentElement().isDisplayed())
{
// Formatting of Boolean types use the scale input.
return elementCache().charScaleInput.getValue();
}
else
{
throw new NullPointerException("No 'Format' input present to get.");
}
}
public WebElement getFormatControl()
{
if(elementCache().formatInput.getComponentElement().isDisplayed())
{
return elementCache().formatInput.getComponentElement();
}
else if(elementCache().charScaleInput.getComponentElement().isDisplayed())
{
// Formatting of Boolean types use the scale input.
return elementCache().charScaleInput.getComponentElement();
}
else
{
return null;
}
}
//
// string field options.
public DomainFieldRow allowMaxChar()
{
expand();
elementCache().allowMaxCharCountRadio.set(true);
return this;
}
public boolean isMaxCharDefault()
{
expand();
return elementCache().allowMaxCharCountRadio.isChecked();
}
public DomainFieldRow setCharCount(int maxCharCount)
{
expand();
String strCharCount = Integer.toString(maxCharCount);
elementCache().setCharCountRadio.set(true);
WebDriverWrapper.waitFor(() -> !isCharCountDisabled(),
"character count input did not become enabled in time", 1000);
elementCache().charScaleInput.setValue(strCharCount);
return this;
}
public boolean isCharCountDisabled()
{
return elementCache().charScaleInput.getComponentElement().getAttribute("disabled") != null;
}
public boolean isFieldProtected()
{
return elementCache().fieldNameInput.getComponentElement().getAttribute("disabled") != null;
}
public boolean isCustomCharSelected()
{
expand();
return elementCache().setCharCountRadio.isChecked();
}
public Integer getCustomCharCount()
{
expand();
return Integer.parseInt(elementCache().charScaleInput.getValue());
}
public boolean isMaxTextLengthPresent(int rowIndex)
{
return getWrapper().isElementPresent(elementCache().getCharScaleInputLocForRow(rowIndex));
}
// barcode- scannable options
/**
* Indicates that the field should be searched when
*/
public boolean isFieldScannable()
{
expand();
return elementCache().scannableCheckbox.get();
}
public DomainFieldRow setFieldScannable(boolean checked)
{
expand();
elementCache().scannableCheckbox.set(checked);
return this;
}
public boolean isScannableCheckboxPresent()
{
expand();
return elementCache().scannableCheckboxLoc.existsIn(this);
}
// lookup options.
public DomainFieldRow setLookup(FieldDefinition.LookupInfo lookupInfo)
{
setType(FieldDefinition.ColumnType.Lookup);
setFromFolder(lookupInfo.getFolder());
setFromSchema(lookupInfo.getSchema());
String tableType;
if (lookupInfo.getTableType() == FieldDefinition.ColumnType.Integer)
tableType = "Integer";
else if (lookupInfo.getTableType() == FieldDefinition.ColumnType.String)
tableType = "String";
else
throw new IllegalArgumentException("Invalid lookup type specified for " + lookupInfo.getTable() + ": " + lookupInfo.getTableType());
setFromTargetTable(lookupInfo.getTable() + " (" + tableType + ")");
return this;
}
public String getFromFolder()
{
expand();
return elementCache().lookupContainerSelect.getFirstSelectedOption().getText();
}
public DomainFieldRow setFromFolder(String containerPath)
{
expand();
if (StringUtils.isBlank(containerPath) || containerPath.equals("Current Folder") || containerPath.equals("Current Project"))
{
containerPath = "";
}
WebDriverWrapper.waitFor(() -> Locator.tagContainingText("option","Current Project")
.findOptionalElement(elementCache().lookupContainerSelect.getWrappedElement()).isPresent(), 2000);
String initialValue = elementCache().lookupContainerSelect.getFirstSelectedOption().getAttribute("value");
if (!containerPath.equals(initialValue))
{
getWrapper().scrollIntoView(elementCache().lookupContainerSelect.getWrappedElement(), true);
elementCache().lookupContainerSelect.selectByValue(containerPath);
getWrapper().shortWait().withMessage("Schema select didn't clear after selecting lookup container")
.until(ExpectedConditions.domPropertyToBe(elementCache().getLookupSchemaSelect().getWrappedElement(), "value", ""));
}
return this;
}
public String getFromSchema()
{
expand();
return elementCache().getLookupSchemaSelect().getFirstSelectedOption().getText();
}
public DomainFieldRow setFromSchema(String schemaName)
{
expand();
WebDriverWrapper.waitFor(() -> Locator.tagContainingText("option","core")
.findOptionalElement(elementCache().getLookupSchemaSelect().getWrappedElement()).isPresent(), 2000);
String initialValue = elementCache().getLookupSchemaSelect().getFirstSelectedOption().getText();
if (!schemaName.equals(initialValue))
{
getWrapper().scrollIntoView(elementCache().getLookupSchemaSelect().getWrappedElement(), true);
elementCache().getLookupSchemaSelect().selectByVisibleText(schemaName);
getWrapper().shortWait().withMessage("Query select didn't update after selecting lookup schema")
.until(ExpectedConditions.domPropertyToBe(elementCache().getLookupQuerySelect().getWrappedElement(), "value", ""));
}
return this;
}
public String getFromTargetTable()
{
expand();
return elementCache().getLookupQuerySelect().getFirstSelectedOption().getText();
}
public DomainFieldRow setFromTargetTable(String targetTable)
{
expand();
elementCache().getLookupQuerySelect().selectByVisibleText(targetTable);
return this;
}
public boolean getLookupValidatorEnabled()
{
expand();
return elementCache().getLookupValidatorEnabledCheckbox().get();
}
public DomainFieldRow setLookupValidatorEnabled(boolean checked)
{
expand();
elementCache().getLookupValidatorEnabledCheckbox().set(checked);
return this;
}
// ontology lookup settings
public DomainFieldRow setOntology(String ontology, String importField, String labelField)
{
setType(FieldDefinition.ColumnType.OntologyLookup);
setSelectedOntology(ontology)
.setConceptImportField(importField)
.setConceptLabelField(labelField);
return this;
}
public String getSelectedOntology()
{
expand();
return elementCache().getOntologySelect().getFirstSelectedOption().getAttribute("value");
}
public DomainFieldRow setSelectedOntology(String ontology)
{
expand();
elementCache().getOntologySelect().selectByValue(ontology);
return this;
}
public DomainFieldRow setConceptImportField(String importField)
{
expand();
elementCache().getConceptImportFieldSelect().selectByVisibleText(importField);
return this;
}
public String getConceptImportField()
{
expand();
return elementCache().getConceptImportFieldSelect().getFirstSelectedOption().getText();
}
/**
* Allows test code to get which ontologies are available for selection
*
* @return a list of the full text shown in the options
*/
public List<String> getConceptImportSelectOptions()
{
expand();
return getWrapper().getTexts(elementCache().getOntologySelect().getOptions());
}
public DomainFieldRow setConceptLabelField(String labelField)
{
expand();
elementCache().getConceptLabelFieldSelect().selectByVisibleText(labelField);
return this;
}
public String getConceptLabelField()
{
expand();
return elementCache().getConceptLabelFieldSelect().getFirstSelectedOption().getText();
}
public ConceptPickerDialog clickExpectedVocabulary()
{
expand();
elementCache().expectedVocabularyButton().click();
return new ConceptPickerDialog(new ModalDialog.ModalDialogFinder(getDriver()).withTitle("Expected Vocabulary"));
}
public ConceptPickerDialog clickSelectConcept()
{
expand();
elementCache().selectConceptButton().click();
return new ConceptPickerDialog(new ModalDialog.ModalDialogFinder(getDriver()).withTitle("Select Concept"));
}
public Optional<WebElement> optionalExpectedVocabularyLink()
{
expand();
return elementCache().selectedVocabularyLink();
}
public DomainFieldRow clickRemoveExpectedVocabulary()
{
expand();
WebDriverWrapper.waitFor(() -> elementCache().removeSelectedVocabularyLink().isPresent(),
"the expected vocabulary link is not present", 2000);
elementCache().removeSelectedVocabularyLink().get().click();
return this;
}
public Optional<WebElement> optionalOntologyConceptLink()
{
expand();
return elementCache().selectedConceptLink();
}
public DomainFieldRow clickRemoveOntologyConcept()
{
expand();
WebDriverWrapper.waitFor(() -> elementCache().selectedConceptLink().isPresent(),
"the expected ontology link is not present", 2000);
elementCache().removeSelectedConceptLink().get().click();
return this;
}
// TextChoice Field settings
//
// To a user a TextChoice field looks and behaves a lot like a lookup, even though it is implemented using a validator
// behind the scenes. Because of that the validator aspect of the TextChoice field is hidden from the user (just like
// it is in the product).
public void setAllowMultipleSelections(Boolean allowMultipleSelections)
{
elementCache().allowMultipleSelectionsCheckbox.set(allowMultipleSelections);
}
/**
* Set the list of allowed values for a TextChoice field.
*
* @param values List of values (Strings).
* @return A reference to this field row.
*/
public DomainFieldRow setTextChoiceValues(List<String> values)
{
WebElement button = Locator.tagWithClass("span", "container--action-button").withText("Add Values").findElement(this);
button.click();
TextChoiceValueDialog addValuesDialog = new TextChoiceValueDialog(this);
addValuesDialog.addValues(values);
return addValuesDialog.clickApply();
}
/**
* Get the displayed list of allowed values a TextChoice field.
*
* @return Values shown in the list for the TextChoice field.
*/
public List<String> getTextChoiceValues()
{
// Intentionally using '.collect(Collectors.toList())' so the returned list is mutable (e.g. can sort it when
// comparing against expected).
return Locator.tagWithClass("button", "list-group-item").findElements(this)
.stream().map(WebElement::getText).collect(Collectors.toList());
}
/**
* Get a list of the values that are 'locked' for a TextChoice field. A locked value is one that has been applied and cannot be deleted.
*
* @return List of locked values.
*/
public List<String> getLockedTextChoiceValues()
{
// Intentionally using '.collect(Collectors.toList())' so the returned list is mutable (e.g. can sort it when
// comparing against expected).
return Locator.tagWithClass("button", "list-group-item")
.withDescendant(Locator.tagWithClass("span", "choices-list__locked"))
.findElements(this)
.stream().map(WebElement::getText).collect(Collectors.toList());
}
/**
* Get a list of the values that are 'unlocked' for a TextChoice field. An unlocked value is one that has not been used.
*
* @return List of unlocked values.
*/
public List<String> getUnlockedTextChoiceValues()
{
List<String> allChoices = getTextChoiceValues();
allChoices.removeAll(getLockedTextChoiceValues());
return allChoices;
}
/**
* Enter a value into the search field for TextChoice values. If no values have been this will error with a
* no-such-element exception.
*
* @param searchValue Value to search for.
* @return List of values matching the search value.
*/
public List<String> searchForTextChoiceValue(String searchValue)
{
WebElement searchTxtBox = Locator.tagWithClass("input", "domain-text-choices-search").findElement(this);
getWrapper().setFormElement(searchTxtBox, searchValue);
return getTextChoiceValues();
}
/**
* Click on a value in the list of values for a TextChoice field. If the value is already selected this will have
* no effect.
*
* @param value The value to click on.
* @return This field row.
*/
public DomainFieldRow selectTextChoiceValue(String value)
{
WebElement element = Locator.tagWithClass("button", "list-group-item").withText(value).findElement(this);
element.click();
return this;
}
/**
* Check if the 'Apply' button is enabled for a TextChoice field. I will not be enabled if the value has not been
* changed, or if it conflicts with an existing value. Note: The button is only visible if a value is selected.
*
* @return True if the button is enabled, false otherwise.
*/
public boolean isTextChoiceApplyButtonEnabled()
{
WebElement button = Locator.button("Apply").findElement(this);
return button.isEnabled();
}
/**
* Enter text into the update textbox for a value. Note: The field is only visible if a value is selected.
*
* @param updatedValue Value to enter into the update textbox.
* @return This field row.
*/
public DomainFieldRow setUpdateTextChoiceValue(String updatedValue)
{
WebDriverWrapper.waitFor(this::isTextChoiceUpdateFieldEnabled,
"The edit field for the TextChoice value did not become enabled in time.", 1_000);
getWrapper().setFormElement(Locator.tagWithName("input", "value").findElement(this), updatedValue);
return this;
}
private void updateValue(String originalValue, String newValue, boolean clickApply)
{
selectTextChoiceValue(originalValue);
setUpdateTextChoiceValue(newValue);
if(clickApply)
{
WebDriverWrapper.waitFor(this::isTextChoiceApplyButtonEnabled, "'Apply' button is not enabled.", 1_000);
Locator.button("Apply").findElement(this).click();
}
}
/**
* Update the selected value in the TextChoice field. This will select the given field.
*
* @param originalValue The original value to select and change.
* @param newValue The new value to replace it.
* @return This field row.
*/
public DomainFieldRow updateTextChoiceValue(String originalValue, String newValue)
{
WebElement alert = Locator.tagWithClass("div", "alert").findWhenNeeded(this);
updateValue(originalValue, newValue, true);
Assert.assertFalse("An unexpected alert was present after applying the change.",
alert.isDisplayed());
return this;
}
/**
* Update a TextChoice value and expect an error. Can happen if the new value already exists in the list of values.
*
* @param originalValue The original value to select and change.
* @param newValue The new value to replace it.
* @return The error message.
*/
public String updateTextChoiceValueExpectError(String originalValue, String newValue)
{
updateValue(originalValue, newValue, false);
WebElement alert = BootstrapLocators.errorBanner.waitForElement(this, 1_000);
return alert.getText();
}
/**
* Update a TextChoice value that is currently being used and expect an info message with the number updated.
*
* @param originalValue The original value to select and change.
* @param newValue The new value to replace it.
* @return The info message indicating the number of entites updated.
*/
public String updateLockedTextChoiceValue(String originalValue, String newValue)
{
updateValue(originalValue, newValue, true);
WebElement alert = BootstrapLocators.infoBanner.waitForElement(this, 1_000);
return alert.getText();
}
/**
* Select a TextChoice value and check if the edit field is enabled.
*
* @param value The TextChoice value to select.
* @return True if enabled, false otherwise.
*/
public boolean isTextChoiceUpdateFieldEnabled(String value)
{
selectTextChoiceValue(value);
return isTextChoiceUpdateFieldEnabled();
}
/**
* Check if the edit field is enabled for the selected TextChoice value. A value must be selected.
*
* @return True if enabled, false otherwise.
*/
public boolean isTextChoiceUpdateFieldEnabled()
{
WebElement updateField = Locator.tagWithName("input", "value").findWhenNeeded(this);
Assert.assertTrue("Update field is not visible, make sure a TextChoice value is selected.",
updateField.isDisplayed());
return updateField.isEnabled();
}
/**
* Check to see if the 'Delete' button is enabled for a TextChoice field. Note: The button is only visible if a
* value is selected.
*
* @return True if the button is enabled, false otherwise.
*/
public boolean isTextChoiceDeleteButtonEnabled()
{
WebElement button = Locator.buttonContainingText("Delete").findElement(this);
return button.isEnabled();
}
/**
* Delete a value from the list of values for a TextChoice field. This will select the value before deleting it.
*
* @param value The value to delete.
* @return This field row.
*/
public DomainFieldRow deleteTextChoiceValue(String value)
{
selectTextChoiceValue(value);
WebElement button = Locator.buttonContainingText("Delete").refindWhenNeeded(this);
WebDriverWrapper.waitFor(button::isEnabled, "'Delete' button is not enabled.", 1_000);
button.click();
WebDriverWrapper.waitFor(()->!button.isDisplayed(), "Deleting TextChoice value did not complete.", 1_000);
return this;
}
// Calculations field settings
public DomainFieldRow setValueExpression(String expression)