@@ -33,6 +33,26 @@ describe("SegmentSelectorEditorTest", function () {
3333 await ( await page . jQuery ( prefixSelector + ' .metricListBlock .expandableList .secondLevel li:contains(' + name + ')' , { waitFor : true } ) ) . click ( ) ;
3434 }
3535
36+ async function switchToAnonymousUser ( ) {
37+ await testEnvironment . callApi ( 'UsersManager.setUserAccess' , {
38+ userLogin : 'anonymous' ,
39+ access : 'view' ,
40+ idSites : [ 1 ] ,
41+ } ) ;
42+ testEnvironment . testUseMockAuth = 0 ;
43+ testEnvironment . save ( ) ;
44+ }
45+
46+ async function switchToConnectedUser ( ) {
47+ testEnvironment . testUseMockAuth = 1 ;
48+ testEnvironment . save ( ) ;
49+ await testEnvironment . callApi ( 'UsersManager.setUserAccess' , {
50+ userLogin : 'anonymous' ,
51+ access : 'noaccess' ,
52+ idSites : [ 1 ] ,
53+ } ) ;
54+ }
55+
3656 it ( "should load correctly" , async function ( ) {
3757 await page . goto ( url ) ;
3858 expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '0_initial' ) ;
@@ -43,21 +63,39 @@ describe("SegmentSelectorEditorTest", function () {
4363 expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '1_selector_open' ) ;
4464 } ) ;
4565
46- it ( "should unstar all segments" , async function ( ) {
47- await page . click ( '.segmentList li:nth-child(2) .starSegment' ) ;
48- await page . click ( '.segmentList li:nth-child(3) .starSegment' ) ;
49- await page . click ( '.segmentList li:nth-child(4) .starSegment' ) ;
50- expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '1_selector_unstarred' ) ;
66+ it ( "should star all segments" , async function ( ) {
67+ await page . click ( '.segmentList li:nth-child(2) .starSegment' ) ;
68+ await page . click ( '.segmentList li:nth-child(3) .starSegment' ) ;
69+ await page . click ( '.segmentList li:nth-child(4) .starSegment' ) ;
70+ const firstSegment = await page . $ ( '.segmentList li:nth-child(2)' ) ;
71+ expect ( firstSegment . className ) . to . contain ( 'segmentStarred' ) ;
72+ expect ( firstSegment . find ( '.starSegment' ) . attr ( 'data-state' ) ) . to . equal ( '' ) ;
73+ expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '1_selector_starred' ) ;
5174 } ) ;
5275
53- it ( "should star last segment" , async function ( ) {
54- await page . click ( '.segmentList li:last-child .starSegment' ) ;
55- expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '1_selector_starred' ) ;
76+ it ( "should unstar first segment" , async function ( ) {
77+ await page . click ( '.segmentList li:nth-child(2) .starSegment' ) ;
78+ const firstSegment = await page . $ ( '.segmentList li:nth-child(2)' ) ;
79+ expect ( firstSegment . className ) . to . not . contain ( 'segmentStarred' ) ;
80+ expect ( firstSegment . find ( '.starSegment' ) . attr ( 'data-state' ) ) . to . equal ( '' ) ;
81+ expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '1b_selector_unstarred' ) ;
82+ } ) ;
83+
84+ it ( "should have disabled star for anonymous users" , async function ( ) {
85+ await switchToAnonymousUser ( ) ;
86+ await page . goto ( url ) ;
87+ await page . click ( '.segmentationContainer .title' ) ;
88+ const firstSegment = await page . $ ( '.segmentList li:nth-child(2)' ) ;
89+ expect ( firstSegment . className ) . to . contain ( 'segmentStarred' ) ;
90+ expect ( firstSegment . find ( '.starSegment' ) . attr ( 'data-state' ) ) . to . equal ( '' ) ;
5691 } ) ;
5792
5893 it ( "should open segment editor when edit link clicked for existing segment" , async function ( ) {
94+ await switchToConnectedUser ( ) ;
95+ await page . goto ( url ) ;
96+ await page . click ( '.segmentationContainer .title' ) ;
5997 await page . evaluate ( function ( ) {
60- $ ( '.segmentList .editSegment:first' ) . click ( )
98+ $ ( '.segmentList .editSegment:first' ) . click ( ) ;
6199 } ) ;
62100 await page . waitForNetworkIdle ( ) ;
63101 expect ( await page . screenshotSelector ( selectorsToCapture ) ) . to . matchImage ( '2_segment_editor_update' ) ;
@@ -127,10 +165,10 @@ describe("SegmentSelectorEditorTest", function () {
127165
128166 it ( "should save a new segment and add it to the segment list when the form is filled out and the save button is clicked" , async function ( ) {
129167 for ( let i = 0 ; i < 3 ; i += 1 ) {
130- await page . evaluate ( function ( i ) {
131- $ ( `.metricValueBlock input:eq(${ i } )` ) . val ( 'value ' + i ) . change ( ) ;
132- } , i ) ;
133- await page . waitForTimeout ( 250 ) ;
168+ await page . evaluate ( function ( i ) {
169+ $ ( `.metricValueBlock input:eq(${ i } )` ) . val ( 'value ' + i ) . change ( ) ;
170+ } , i ) ;
171+ await page . waitForTimeout ( 250 ) ;
134172 }
135173
136174 await page . type ( 'input.edit_segment_name' , 'new segment' ) ;
0 commit comments