|
38 | 38 | import org.labkey.test.categories.Data; |
39 | 39 | import org.labkey.test.categories.Hosting; |
40 | 40 | import org.labkey.test.components.CustomizeView; |
| 41 | +import org.labkey.test.components.domain.AdvancedSettingsDialog; |
41 | 42 | import org.labkey.test.components.domain.BaseDomainDesigner; |
42 | 43 | import org.labkey.test.components.domain.ConditionalFormatDialog; |
43 | 44 | import org.labkey.test.components.domain.DomainFieldRow; |
@@ -101,6 +102,7 @@ public class ListTest extends BaseWebDriverTest |
101 | 102 | protected final static String LIST_NAME_HTML_KEY = "A_HtmlKey_" + DOMAIN_TRICKY_CHARACTERS; |
102 | 103 | protected final static ColumnType LIST_KEY_TYPE = ColumnType.String; |
103 | 104 | protected final static String LIST_KEY_NAME = "Key"; |
| 105 | + boolean IS_POSTGRES = WebTestHelper.getDatabaseType() == WebTestHelper.DatabaseType.PostgreSQL; |
104 | 106 |
|
105 | 107 | protected final static String LIST_KEY_NAME2 = "Color \"`~!@#$%^&*()_-+={}[]|\\:;<>,.?/"; |
106 | 108 | protected final static String LIST_KEY_NAME2_BULK = "\"Color \"\"`~!@#$%^&*()_-+={}[]|\\:;<>,.?/\""; |
@@ -1589,45 +1591,58 @@ public void testFieldUniqueConstraint() |
1589 | 1591 | viewRawTableMetadata(listName); |
1590 | 1592 | verifyTableIndices("unique_constraint_list_", Collections.emptyList()); |
1591 | 1593 |
|
1592 | | - // set two fields to have unique constraints |
| 1594 | + // set fields to have constraints |
1593 | 1595 | EditListDefinitionPage listDefinitionPage = _listHelper.goToEditDesign(listName); |
1594 | 1596 | listDefinitionPage.getFieldsPanel() |
1595 | | - .getField(fieldName1).expand().clickAdvancedSettings().setUniqueConstraint(true) |
| 1597 | + .getField(fieldName1).expand().clickAdvancedSettings().setSingleFieldIndex(AdvancedSettingsDialog.SingleFieldIndexType.UNIQUE_INDEX) |
1596 | 1598 | .apply(); |
1597 | 1599 | listDefinitionPage.getFieldsPanel() |
1598 | | - .getField(fieldName2).expand().clickAdvancedSettings().setUniqueConstraint(true) |
| 1600 | + .getField(fieldName2).expand().clickAdvancedSettings().setSingleFieldIndex(AdvancedSettingsDialog.SingleFieldIndexType.UNIQUE_INDEX) |
| 1601 | + .apply(); |
| 1602 | + // set one field to have non-unique constraint |
| 1603 | + listDefinitionPage.getFieldsPanel() |
| 1604 | + .getField(fieldName3).expand().clickAdvancedSettings().setSingleFieldIndex(AdvancedSettingsDialog.SingleFieldIndexType.INDEX) |
1599 | 1605 | .apply(); |
1600 | 1606 | listDefinitionPage.clickSave(); |
1601 | 1607 |
|
1602 | 1608 | AuditLogHelper.DetailedAuditEventRow expectedDomainEvent = new AuditLogHelper.DetailedAuditEventRow(null, listName, null, |
1603 | 1609 | "The descriptor of domain " + listName + " was updated.", |
1604 | | - "", null, null, "Indices: > [field Name1, unique: true, fieldName_2, unique: true]"); |
| 1610 | + "", null, null, "Indices: > [FieldName@3, unique: false, field Name1, unique: true, fieldName_2, unique: true]"); |
1605 | 1611 | boolean pass = _auditLogHelper.validateLastDomainAuditEvents(listName, getProjectName(), expectedDomainEvent, Collections.emptyMap()); |
1606 | 1612 | checker().verifyTrue("Domain audit comment not as expected after updating field unique constraint", pass); |
1607 | 1613 |
|
1608 | 1614 | viewRawTableMetadata(listName); |
1609 | | - verifyTableIndices("unique_constraint_list_", List.of("field_name1", "fieldname_2")); |
1610 | | - assertTextNotPresent("unique_constraint_list_fieldname_3"); |
| 1615 | + verifyTableIndices("unique_constraint_list_", List.of("field_Name1", "fieldName_2", "FieldName_3")); |
| 1616 | + verifyTableIndexNonUnique("unique_constraint_list_", "field_Name1", true); |
| 1617 | + verifyTableIndexNonUnique("unique_constraint_list_", "fieldName_2", true); |
| 1618 | + verifyTableIndexNonUnique("unique_constraint_list_", "FieldName_3", false); |
1611 | 1619 |
|
1612 | | - // remove a field unique constraint and add a new one |
| 1620 | + // remove a field unique constraint, change a field from unique -> non-unique, and change one from non-unique -> unique |
1613 | 1621 | listDefinitionPage = _listHelper.goToEditDesign(listName); |
1614 | 1622 | listDefinitionPage.getFieldsPanel() |
1615 | | - .getField(fieldName2).expand().clickAdvancedSettings().setUniqueConstraint(false) |
| 1623 | + .getField(fieldName1).expand().clickAdvancedSettings().setSingleFieldIndex(null) |
| 1624 | + .apply(); |
| 1625 | + listDefinitionPage.getFieldsPanel() |
| 1626 | + .getField(fieldName2).expand().clickAdvancedSettings().setSingleFieldIndex(AdvancedSettingsDialog.SingleFieldIndexType.INDEX) |
1616 | 1627 | .apply(); |
1617 | 1628 | listDefinitionPage.getFieldsPanel() |
1618 | | - .getField(fieldName3).expand().clickAdvancedSettings().setUniqueConstraint(true) |
| 1629 | + .getField(fieldName3).expand().clickAdvancedSettings().setSingleFieldIndex(AdvancedSettingsDialog.SingleFieldIndexType.UNIQUE_INDEX) |
1619 | 1630 | .apply(); |
1620 | 1631 | listDefinitionPage.clickSave(); |
1621 | 1632 |
|
| 1633 | + String expectedDataChanges = "Indices: [field name1, unique: true, fieldname@3, unique: false, fieldname_2, unique: true] > [FieldName@3, unique: true, fieldName_2, unique: false]"; |
| 1634 | + if (!IS_POSTGRES) expectedDataChanges = "Indices: [FieldName@3, unique: false, field Name1, unique: true, fieldName_2, unique: true] > [FieldName@3, unique: true, fieldName_2, unique: false]"; |
1622 | 1635 | expectedDomainEvent = new AuditLogHelper.DetailedAuditEventRow(null, listName, null, |
1623 | 1636 | "The descriptor of domain " + listName + " was updated.", |
1624 | | - "", null, null, "Indices: [field name1, unique: true, fieldname_2, unique: true] > [FieldName@3, unique: true, field Name1, unique: true]"); |
| 1637 | + "", null, null, expectedDataChanges); |
1625 | 1638 | pass = _auditLogHelper.validateLastDomainAuditEvents(listName, getProjectName(), expectedDomainEvent, Collections.emptyMap()); |
1626 | 1639 | checker().verifyTrue("Domain audit comment not as expected after updating field unique constraint", pass); |
1627 | 1640 |
|
1628 | 1641 | viewRawTableMetadata(listName); |
1629 | | - verifyTableIndices("unique_constraint_list_", List.of("field_name1", "fieldname_3")); |
1630 | | - assertTextNotPresent("unique_constraint_list_fieldname_2"); |
| 1642 | + verifyTableIndices("unique_constraint_list_", List.of("fieldName_2", "FieldName_3")); |
| 1643 | + assertTextNotPresent("unique_constraint_list_field_name1"); |
| 1644 | + verifyTableIndexNonUnique("unique_constraint_list_", "fieldName_2", false); |
| 1645 | + verifyTableIndexNonUnique("unique_constraint_list_", "FieldName_3", true); |
1631 | 1646 | } |
1632 | 1647 |
|
1633 | 1648 | @Test // Issue 52247 |
@@ -1698,6 +1713,16 @@ private void verifyTableIndices(String prefix, List<String> indexSuffixes) |
1698 | 1713 | assertTextPresentCaseInsensitive(prefix + suffix); |
1699 | 1714 | } |
1700 | 1715 |
|
| 1716 | + private void verifyTableIndexNonUnique(String prefix, String suffix, boolean isUnique) |
| 1717 | + { |
| 1718 | + String boolDisplay = isUnique ? "0" : "1"; |
| 1719 | + if (IS_POSTGRES) boolDisplay = isUnique ? "false" : "true"; |
| 1720 | + String fieldKey = prefix + suffix; |
| 1721 | + if (IS_POSTGRES) fieldKey = fieldKey.toLowerCase(); |
| 1722 | + Locator locator = Locator.xpath("//td[contains(text(), '" + fieldKey + "')]/preceding-sibling::td[2][text()='" + boolDisplay + "']"); |
| 1723 | + checker().verifyTrue("Non_Unique value not as expected in metadata for locator: " + locator, locator.existsIn(getDriver())); |
| 1724 | + } |
| 1725 | + |
1701 | 1726 | /** |
1702 | 1727 | * Test "tricky characters" in field names, including key field. This will test CrUD operation for list items in |
1703 | 1728 | * lists with an auto-key and user defined key. This will also use file import for validation. |
|
0 commit comments