1+ import { expect } from '@playwright/test' ;
2+ import { ConstantHelper , test } from '@umbraco/playwright-testhelpers' ;
3+
4+ const testUser = ConstantHelper . testUserCredentials ;
5+ let testUserCookieAndToken = { cookie : "" , accessToken : "" , refreshToken : "" } ;
6+
7+ const userGroupName = 'TestPropertyValuePermission' ;
8+ let userGroupId = null ;
9+
10+ const documentName = 'TestContent' ;
11+ const documentTypeName = 'TestDocumentTypeForContent' ;
12+ const customDataTypeName = 'Custom Block List' ;
13+ const elementTypeName = 'BlockListElement' ;
14+ const propertyInBlock = 'Textstring' ;
15+ const groupName = 'testGroup' ;
16+ let elementTypeId = '' ;
17+
18+ test . beforeEach ( async ( { umbracoApi} ) => {
19+ await umbracoApi . documentType . ensureNameNotExists ( documentTypeName ) ;
20+ await umbracoApi . document . ensureNameNotExists ( documentName ) ;
21+ const textStringData = await umbracoApi . dataType . getByName ( propertyInBlock ) ;
22+ elementTypeId = await umbracoApi . documentType . createDefaultElementType ( elementTypeName , groupName , propertyInBlock , textStringData . id ) ;
23+ } ) ;
24+
25+ test . afterEach ( async ( { umbracoApi} ) => {
26+ // Ensure we are logged in to admin
27+ await umbracoApi . loginToAdminUser ( testUserCookieAndToken . cookie , testUserCookieAndToken . accessToken , testUserCookieAndToken . refreshToken ) ;
28+ await umbracoApi . document . ensureNameNotExists ( documentName ) ;
29+ await umbracoApi . documentType . ensureNameNotExists ( documentTypeName ) ;
30+ await umbracoApi . documentType . ensureNameNotExists ( elementTypeName ) ;
31+ await umbracoApi . dataType . ensureNameNotExists ( customDataTypeName ) ;
32+ } ) ;
33+
34+ test ( 'can see property values in block list with UI read but not UI write permission' , async ( { umbracoApi, umbracoUi} ) => {
35+ // Arrange
36+ await umbracoApi . document . createDefaultDocumentWithABlockListEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
37+ userGroupId = await umbracoApi . userGroup . createUserGroupWithReadPermissionAndReadPropertyValuePermission ( userGroupName , true , true ) ;
38+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
39+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
40+ await umbracoUi . goToBackOffice ( ) ;
41+
42+ // Act
43+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
44+ await umbracoUi . content . goToContentWithName ( documentName ) ;
45+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-list' , true ) ;
46+ await umbracoUi . content . clickEditBlockListBlockButton ( ) ;
47+
48+ // Assert
49+ await umbracoUi . content . isPropertyEditorUiWithNameReadOnly ( 'text-box' ) ;
50+ } ) ;
51+
52+ // Remove .skip when the front-end is ready.
53+ // Issue link: https://github.com/umbraco/Umbraco-CMS/issues/19395
54+ test . skip ( 'can edit property values in block list with UI write permission' , async ( { umbracoApi, umbracoUi} ) => {
55+ // Arrange
56+ const updatedText = 'Updated test text' ;
57+ await umbracoApi . document . createDefaultDocumentWithABlockListEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
58+ userGroupId = await umbracoApi . userGroup . createUserGroupWithUpdatePermissionAndWritePropertyValuePermission ( userGroupName , true , false ) ;
59+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
60+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
61+ await umbracoUi . goToBackOffice ( ) ;
62+
63+ // Act
64+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
65+ await umbracoUi . content . goToContentWithName ( documentName ) ;
66+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-list' , true ) ;
67+ await umbracoUi . content . clickEditBlockListBlockButton ( ) ;
68+ await umbracoUi . content . enterTextstring ( updatedText ) ;
69+ await umbracoUi . content . clickUpdateButton ( ) ;
70+ await umbracoUi . content . clickSaveButton ( ) ;
71+
72+ // Assert
73+ const documentData = await umbracoApi . document . getByName ( documentName ) ;
74+ expect ( documentData . values [ 0 ] . value . contentData [ 0 ] . values [ 0 ] . value ) . toEqual ( updatedText ) ;
75+ } ) ;
76+
77+ test ( 'cannot see property values in block list with only UI write but no UI read permission' , async ( { umbracoApi, umbracoUi} ) => {
78+ // Arrange
79+ await umbracoApi . document . createDefaultDocumentWithABlockListEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
80+ userGroupId = await umbracoApi . userGroup . createUserGroupWithUpdatePermissionAndWritePropertyValuePermission ( userGroupName , true , true , false ) ;
81+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
82+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
83+ await umbracoUi . goToBackOffice ( ) ;
84+
85+ // Act
86+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
87+ await umbracoUi . content . goToContentWithName ( documentName ) ;
88+
89+ // Assert
90+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-list' , false ) ;
91+ } ) ;
92+
93+ test ( 'can see property values in block grid with UI read but not UI write permission' , async ( { umbracoApi, umbracoUi} ) => {
94+ // Arrange
95+ await umbracoApi . document . createDefaultDocumentWithABlockGridEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
96+ userGroupId = await umbracoApi . userGroup . createUserGroupWithReadPermissionAndReadPropertyValuePermission ( userGroupName , true , true ) ;
97+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
98+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
99+ await umbracoUi . goToBackOffice ( ) ;
100+
101+ // Act
102+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
103+ await umbracoUi . content . goToContentWithName ( documentName ) ;
104+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-grid' , true ) ;
105+ await umbracoUi . content . clickEditBlockGridBlockButton ( ) ;
106+
107+ // Assert
108+ await umbracoUi . content . isPropertyEditorUiWithNameReadOnly ( 'text-box' ) ;
109+ } ) ;
110+
111+ // Remove .skip when the front-end is ready.
112+ // Issue link: https://github.com/umbraco/Umbraco-CMS/issues/19395
113+ test . skip ( 'can edit property values in block grid with UI write permission' , async ( { umbracoApi, umbracoUi} ) => {
114+ // Arrange
115+ const updatedText = 'Updated test text' ;
116+ await umbracoApi . document . createDefaultDocumentWithABlockGridEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
117+ userGroupId = await umbracoApi . userGroup . createUserGroupWithUpdatePermissionAndWritePropertyValuePermission ( userGroupName , true , false ) ;
118+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
119+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
120+ await umbracoUi . goToBackOffice ( ) ;
121+
122+ // Act
123+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
124+ await umbracoUi . content . goToContentWithName ( documentName ) ;
125+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-grid' , true ) ;
126+ await umbracoUi . content . clickEditBlockGridBlockButton ( ) ;
127+ await umbracoUi . content . enterTextstring ( updatedText ) ;
128+ await umbracoUi . content . clickUpdateButton ( ) ;
129+ await umbracoUi . content . clickSaveButton ( ) ;
130+
131+ // Assert
132+ const documentData = await umbracoApi . document . getByName ( documentName ) ;
133+ expect ( documentData . values [ 0 ] . value . contentData [ 0 ] . values [ 0 ] . value ) . toEqual ( updatedText ) ;
134+ } ) ;
135+
136+ test ( 'cannot see property values in block grid with only UI write but no UI read permission' , async ( { umbracoApi, umbracoUi} ) => {
137+ // Arrange
138+ await umbracoApi . document . createDefaultDocumentWithABlockGridEditor ( documentName , elementTypeId , documentTypeName , customDataTypeName ) ;
139+ userGroupId = await umbracoApi . userGroup . createUserGroupWithUpdatePermissionAndWritePropertyValuePermission ( userGroupName , true , true , false ) ;
140+ await umbracoApi . user . setUserPermissions ( testUser . name , testUser . email , testUser . password , userGroupId ) ;
141+ testUserCookieAndToken = await umbracoApi . user . loginToUser ( testUser . name , testUser . email , testUser . password ) ;
142+ await umbracoUi . goToBackOffice ( ) ;
143+
144+ // Act
145+ await umbracoUi . content . goToSection ( ConstantHelper . sections . content , false ) ;
146+ await umbracoUi . content . goToContentWithName ( documentName ) ;
147+
148+ // Assert
149+ await umbracoUi . content . isPropertyEditorUiWithNameVisible ( 'block-grid' , false ) ;
150+ } ) ;
0 commit comments