|
| 1 | +import {ConstantHelper, NotificationConstantHelper, test} from "@umbraco/playwright-testhelpers"; |
| 2 | +import {expect} from "@playwright/test"; |
| 3 | + |
| 4 | +// Document Type |
| 5 | +const documentTypeName = 'DocumentType'; |
| 6 | +const childDocumentTypeName = 'ChildDocumentType'; |
| 7 | +let documentTypeId = null; |
| 8 | +let childDocumentTypeId = null; |
| 9 | + |
| 10 | +// Document |
| 11 | +const firstDocumentName = 'FirstDocumentName'; |
| 12 | +const secondDocumentName = 'SecondDocumentName'; |
| 13 | +const childDocumentName = 'ChildDocumentName'; |
| 14 | +let firstDocumentId = null; |
| 15 | +let secondDocumentId = null; |
| 16 | + |
| 17 | +// Data Type |
| 18 | +const dataTypeName = 'Textstring'; |
| 19 | +let dataTypeId = null; |
| 20 | +const documentText = 'This is test document text'; |
| 21 | + |
| 22 | +// Document Blueprint |
| 23 | +const testDocumentName = 'TestDocument'; |
| 24 | +const documentBlueprintName = 'TestBlueprintName'; |
| 25 | + |
| 26 | +// User |
| 27 | +const testUser = ConstantHelper.testUserCredentials; |
| 28 | +let testUserCookieAndToken = {cookie: "", accessToken: "", refreshToken: ""}; |
| 29 | + |
| 30 | +// User Group |
| 31 | +const userGroupName = 'TestUserGroup'; |
| 32 | +let userGroupId = null; |
| 33 | + |
| 34 | +test.beforeEach(async ({umbracoApi}) => { |
| 35 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 36 | + await umbracoApi.documentType.ensureNameNotExists(childDocumentTypeName); |
| 37 | + await umbracoApi.documentBlueprint.ensureNameNotExists(documentBlueprintName); |
| 38 | + await umbracoApi.user.ensureNameNotExists(testUser.name); |
| 39 | + await umbracoApi.userGroup.ensureNameNotExists(userGroupName); |
| 40 | + const dataType = await umbracoApi.dataType.getByName(dataTypeName); |
| 41 | + dataTypeId = dataType.id; |
| 42 | + childDocumentTypeId = await umbracoApi.documentType.createDefaultDocumentType(childDocumentTypeName); |
| 43 | + documentTypeId = await umbracoApi.documentType.createDocumentTypeWithAllowedChildNodeAndDataType(documentTypeName, childDocumentTypeId, dataTypeName, dataTypeId); |
| 44 | + firstDocumentId = await umbracoApi.document.createDocumentWithTextContent(firstDocumentName, documentTypeId, documentText, dataTypeName); |
| 45 | + secondDocumentId = await umbracoApi.document.createDocumentWithTextContent(secondDocumentName, documentTypeId, documentText, dataTypeName); |
| 46 | +}); |
| 47 | + |
| 48 | +test.afterEach(async ({umbracoApi}) => { |
| 49 | + // Ensure we are logged in to admin |
| 50 | + await umbracoApi.loginToAdminUser(testUserCookieAndToken.cookie, testUserCookieAndToken.accessToken, testUserCookieAndToken.refreshToken); |
| 51 | + await umbracoApi.document.ensureNameNotExists(firstDocumentName); |
| 52 | + await umbracoApi.document.ensureNameNotExists(secondDocumentName); |
| 53 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 54 | + await umbracoApi.documentType.ensureNameNotExists(childDocumentTypeName); |
| 55 | + await umbracoApi.documentBlueprint.ensureNameNotExists(documentBlueprintName); |
| 56 | + await umbracoApi.userGroup.ensureNameNotExists(userGroupName); |
| 57 | +}); |
| 58 | + |
| 59 | +test('can read a specific document with read permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 60 | + // Arrange |
| 61 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithReadPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 62 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 63 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 64 | + await umbracoUi.goToBackOffice(); |
| 65 | + await umbracoUi.userGroup.goToSection(ConstantHelper.sections.content, false); |
| 66 | + |
| 67 | + // Act |
| 68 | + await umbracoUi.content.goToContentWithName(firstDocumentName); |
| 69 | + |
| 70 | + // Assert |
| 71 | + await umbracoUi.content.doesDocumentHaveName(firstDocumentName); |
| 72 | + await umbracoUi.content.goToContentWithName(secondDocumentName); |
| 73 | + await umbracoUi.content.doesDocumentWorkspaceHaveText('Not found'); |
| 74 | +}); |
| 75 | + |
| 76 | +test('can create document blueprint for a specific document with create document blueprint permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 77 | + // Arrange |
| 78 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithCreateDocumentBlueprintPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 79 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 80 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 81 | + await umbracoUi.goToBackOffice(); |
| 82 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 83 | + |
| 84 | + // Act |
| 85 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 86 | + await umbracoUi.content.clickCreateBlueprintActionMenuOption(); |
| 87 | + await umbracoUi.content.enterDocumentBlueprintName(documentBlueprintName); |
| 88 | + await umbracoUi.content.clickSaveDocumentBlueprintButton(); |
| 89 | + |
| 90 | + // Assert |
| 91 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.documentBlueprintCreated); |
| 92 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 93 | +}); |
| 94 | + |
| 95 | +test('can delete a specific content with delete permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 96 | + // Arrange |
| 97 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithDeletePermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 98 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 99 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 100 | + await umbracoUi.goToBackOffice(); |
| 101 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 102 | + |
| 103 | + // Act |
| 104 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 105 | + await umbracoUi.content.clickTrashActionMenuOption(); |
| 106 | + await umbracoUi.content.clickConfirmTrashButton(); |
| 107 | + |
| 108 | + // Assert |
| 109 | + await umbracoUi.content.waitForContentToBeDeleted(); |
| 110 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 111 | +}); |
| 112 | + |
| 113 | +test('can create content from a specific content with create permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 114 | + // Arrange |
| 115 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithCreatePermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 116 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 117 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 118 | + await umbracoUi.goToBackOffice(); |
| 119 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 120 | + |
| 121 | + // Act |
| 122 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 123 | + |
| 124 | + // Assert |
| 125 | + await umbracoUi.content.isPermissionInActionsMenuVisible('Create…'); |
| 126 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 127 | +}); |
| 128 | + |
| 129 | +test('can publish a specific content with publish permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 130 | + // Arrange |
| 131 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithPublishPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 132 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 133 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 134 | + await umbracoUi.goToBackOffice(); |
| 135 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 136 | + |
| 137 | + // Act |
| 138 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 139 | + await umbracoUi.content.clickPublishActionMenuOption(); |
| 140 | + await umbracoUi.content.clickConfirmToPublishButton(); |
| 141 | + |
| 142 | + // Assert |
| 143 | + await umbracoUi.content.waitForContentToBePublished(); |
| 144 | + expect(await umbracoApi.document.isDocumentPublished(firstDocumentId)).toBeTruthy(); |
| 145 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 146 | +}); |
| 147 | + |
| 148 | +test('can unpublish a specific content with unpublish permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 149 | + // Arrange |
| 150 | + await umbracoApi.document.publish(firstDocumentId); |
| 151 | + await umbracoApi.document.publish(secondDocumentId); |
| 152 | + expect(await umbracoApi.document.isDocumentPublished(firstDocumentId)).toBeTruthy(); |
| 153 | + expect(await umbracoApi.document.isDocumentPublished(secondDocumentId)).toBeTruthy(); |
| 154 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithUnpublishPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 155 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 156 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 157 | + await umbracoUi.goToBackOffice(); |
| 158 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 159 | + |
| 160 | + // Act |
| 161 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 162 | + await umbracoUi.content.clickUnpublishActionMenuOption(); |
| 163 | + await umbracoUi.content.clickConfirmToUnpublishButton(); |
| 164 | + |
| 165 | + // Assert |
| 166 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.unpublished); |
| 167 | + expect(await umbracoApi.document.isDocumentPublished(firstDocumentId)).toBeFalsy(); |
| 168 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 169 | +}); |
| 170 | + |
| 171 | +test('can update a specific content with update permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 172 | + // Arrange |
| 173 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithUpdatePermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 174 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 175 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 176 | + await umbracoUi.goToBackOffice(); |
| 177 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 178 | + |
| 179 | + // Act |
| 180 | + await umbracoUi.content.goToContentWithName(firstDocumentName); |
| 181 | + await umbracoUi.content.enterContentName(testDocumentName); |
| 182 | + await umbracoUi.content.clickSaveButton(); |
| 183 | + |
| 184 | + // Assert |
| 185 | + await umbracoUi.content.isSuccessStateVisibleForSaveButton(); |
| 186 | + expect(await umbracoApi.document.doesNameExist(testDocumentName)).toBeTruthy(); |
| 187 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 188 | +}); |
| 189 | + |
| 190 | +test('can duplicate a specific content with duplicate permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 191 | + // Arrange |
| 192 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithDuplicatePermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 193 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 194 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 195 | + await umbracoUi.goToBackOffice(); |
| 196 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 197 | + |
| 198 | + // Act |
| 199 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 200 | + // Duplicate to root |
| 201 | + await umbracoUi.content.clickDuplicateToActionMenuOption(); |
| 202 | + await umbracoUi.content.clickLabelWithName('Content'); |
| 203 | + await umbracoUi.content.clickDuplicateButton(); |
| 204 | + |
| 205 | + // Assert |
| 206 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.duplicated); |
| 207 | + await umbracoUi.content.clickActionsMenuForContent(secondDocumentName); |
| 208 | + await umbracoUi.content.isPermissionInActionsMenuVisible('Duplicate to…', false); |
| 209 | +}); |
| 210 | + |
| 211 | +test('can move a specific content with move to permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 212 | + // Arrange |
| 213 | + const moveToDocumentName = 'MoveToDocument'; |
| 214 | + await umbracoApi.document.createDefaultDocumentWithParent(childDocumentName, childDocumentTypeId, firstDocumentId); |
| 215 | + await umbracoApi.document.createDocumentWithTextContent(moveToDocumentName, documentTypeId, documentText, dataTypeName); |
| 216 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithMoveToPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 217 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 218 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 219 | + await umbracoUi.goToBackOffice(); |
| 220 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 221 | + |
| 222 | + // Act |
| 223 | + await umbracoUi.content.clickCaretButtonForContentName(firstDocumentName); |
| 224 | + await umbracoUi.content.clickActionsMenuForContent(childDocumentName); |
| 225 | + await umbracoUi.content.clickMoveToActionMenuOption(); |
| 226 | + await umbracoUi.content.moveToContentWithName([], moveToDocumentName); |
| 227 | + |
| 228 | + // Assert |
| 229 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.moved); |
| 230 | + await umbracoUi.content.clickActionsMenuForContent(secondDocumentName); |
| 231 | + await umbracoUi.content.isPermissionInActionsMenuVisible('Move to…', false); |
| 232 | +}); |
| 233 | + |
| 234 | +test('can sort children with sort children permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 235 | + // Arrange |
| 236 | + await umbracoApi.document.createDefaultDocumentWithParent(childDocumentName, childDocumentTypeId, firstDocumentId); |
| 237 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithSortChildrenPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 238 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 239 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 240 | + await umbracoUi.goToBackOffice(); |
| 241 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 242 | + |
| 243 | + // Act |
| 244 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 245 | + |
| 246 | + // Assert |
| 247 | + await umbracoUi.content.isPermissionInActionsMenuVisible('Sort children…'); |
| 248 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 249 | +}); |
| 250 | + |
| 251 | +test('can set culture and hostnames for a specific content with culture and hostnames permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 252 | + // Arrange |
| 253 | + const domainName = '/domain'; |
| 254 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithCultureAndHostnamesPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 255 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 256 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 257 | + await umbracoUi.goToBackOffice(); |
| 258 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 259 | + |
| 260 | + // Act |
| 261 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 262 | + await umbracoUi.content.clickCultureAndHostnamesActionMenuOption(); |
| 263 | + await umbracoUi.content.clickAddNewDomainButton(); |
| 264 | + await umbracoUi.content.enterDomain(domainName); |
| 265 | + await umbracoUi.content.clickSaveModalButton(); |
| 266 | + |
| 267 | + // Assert |
| 268 | + await umbracoUi.content.waitForDomainToBeCreated(); |
| 269 | + const document = await umbracoApi.document.getByName(firstDocumentName); |
| 270 | + const domains = await umbracoApi.document.getDomains(document.id); |
| 271 | + expect(domains.domains[0].domainName).toEqual(domainName); |
| 272 | + expect(domains.domains[0].isoCode).toEqual('en-US'); |
| 273 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 274 | +}); |
| 275 | + |
| 276 | +test('can set public access for a specific content with public access permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 277 | + // Arrange |
| 278 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithPublicAccessPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 279 | + const testMemberGroup = 'TestMemberGroup'; |
| 280 | + await umbracoApi.memberGroup.ensureNameNotExists(testMemberGroup); |
| 281 | + await umbracoApi.memberGroup.create(testMemberGroup); |
| 282 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 283 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 284 | + await umbracoUi.goToBackOffice(); |
| 285 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 286 | + |
| 287 | + // Act |
| 288 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 289 | + await umbracoUi.content.clickPublicAccessActionMenuOption(); |
| 290 | + await umbracoUi.content.addGroupBasedPublicAccess(testMemberGroup, firstDocumentName); |
| 291 | + |
| 292 | + // Assert |
| 293 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.publicAccessSettingCreated); |
| 294 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 295 | + |
| 296 | + // Clean |
| 297 | + await umbracoApi.memberGroup.ensureNameNotExists(testMemberGroup); |
| 298 | +}); |
| 299 | + |
| 300 | +test('can rollback a specific content with rollback permission enabled', async ({umbracoApi, umbracoUi}) => { |
| 301 | + // Arrange |
| 302 | + userGroupId = await umbracoApi.userGroup.createUserGroupWithRollbackPermissionForSpecificDocument(userGroupName, firstDocumentId); |
| 303 | + await umbracoApi.document.publish(firstDocumentId); |
| 304 | + const updatedTextStringText = 'This is an updated textString text'; |
| 305 | + const contentData = await umbracoApi.document.get(firstDocumentId); |
| 306 | + contentData.values[0].value = updatedTextStringText; |
| 307 | + await umbracoApi.document.update(firstDocumentId, contentData); |
| 308 | + await umbracoApi.document.publish(firstDocumentId); |
| 309 | + await umbracoApi.user.setUserPermissions(testUser.name, testUser.email, testUser.password, userGroupId); |
| 310 | + testUserCookieAndToken = await umbracoApi.user.loginToUser(testUser.name, testUser.email, testUser.password); |
| 311 | + await umbracoUi.goToBackOffice(); |
| 312 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content, false); |
| 313 | + |
| 314 | + // Act |
| 315 | + await umbracoUi.content.clickActionsMenuForContent(firstDocumentName); |
| 316 | + await umbracoUi.content.clickRollbackActionMenuOption(); |
| 317 | + await umbracoUi.content.clickLatestRollBackItem(); |
| 318 | + await umbracoUi.content.clickRollbackContainerButton(); |
| 319 | + |
| 320 | + // Assert |
| 321 | + await umbracoUi.content.goToContentWithName(firstDocumentName); |
| 322 | + await umbracoUi.content.doesDocumentPropertyHaveValue(dataTypeName, documentText); |
| 323 | + await umbracoUi.content.isActionsMenuForNameVisible(secondDocumentName, false); |
| 324 | +}); |
0 commit comments