@@ -10,7 +10,9 @@ import { store as preferencesStore } from '@wordpress/preferences';
1010import {
1111 getDefaultRenderingMode ,
1212 getPostBlocksByName ,
13+ isCollaborationEnabledForCurrentPost ,
1314} from '../private-selectors' ;
15+ import { lock } from '../../lock-unlock' ;
1416
1517describe ( 'getPostBlocksByName' , ( ) => {
1618 const state = {
@@ -86,6 +88,73 @@ describe( 'getPostBlocksByName', () => {
8688 } ) ;
8789} ) ;
8890
91+ describe ( 'isCollaborationEnabledForCurrentPost' , ( ) => {
92+ let originalCollaborationEnabled ;
93+
94+ beforeEach ( ( ) => {
95+ originalCollaborationEnabled = window . _wpCollaborationEnabled ;
96+ window . _wpCollaborationEnabled = true ;
97+ } ) ;
98+
99+ afterEach ( ( ) => {
100+ window . _wpCollaborationEnabled = originalCollaborationEnabled ;
101+ } ) ;
102+
103+ function setupRegistry ( {
104+ collaborationSupported = true ,
105+ syncConfig = { } ,
106+ } = { } ) {
107+ isCollaborationEnabledForCurrentPost . registry = {
108+ select : ( store ) => {
109+ if ( store === coreStore ) {
110+ const selectors = {
111+ getEntityConfig : ( ) => ( { syncConfig } ) ,
112+ } ;
113+ lock ( selectors , {
114+ isCollaborationSupported : ( ) => collaborationSupported ,
115+ } ) ;
116+ return selectors ;
117+ }
118+ } ,
119+ } ;
120+ }
121+
122+ it ( 'returns true when the current post type sync config should sync' , ( ) => {
123+ const shouldSync = jest . fn ( ( ) => true ) ;
124+ setupRegistry ( {
125+ syncConfig : { shouldSync, supportsPersistence : true } ,
126+ } ) ;
127+
128+ const state = { postType : 'book' , postId : 123 } ;
129+
130+ expect ( isCollaborationEnabledForCurrentPost ( state ) ) . toBe ( true ) ;
131+ expect ( shouldSync ) . toHaveBeenCalledWith ( 'postType/book' , 123 ) ;
132+ } ) ;
133+
134+ it ( 'returns false when the current post type sync config does not support persistence' , ( ) => {
135+ const shouldSync = jest . fn ( ( ) => true ) ;
136+ setupRegistry ( { syncConfig : { shouldSync } } ) ;
137+
138+ const state = { postType : 'book' , postId : 123 } ;
139+
140+ expect ( isCollaborationEnabledForCurrentPost ( state ) ) . toBe ( false ) ;
141+ expect ( shouldSync ) . not . toHaveBeenCalled ( ) ;
142+ } ) ;
143+
144+ it ( 'returns false when the current post type sync config should not sync' , ( ) => {
145+ setupRegistry ( {
146+ syncConfig : {
147+ shouldSync : ( ) => false ,
148+ supportsPersistence : true ,
149+ } ,
150+ } ) ;
151+
152+ const state = { postType : 'book' , postId : 123 } ;
153+
154+ expect ( isCollaborationEnabledForCurrentPost ( state ) ) . toBe ( false ) ;
155+ } ) ;
156+ } ) ;
157+
89158describe ( 'getDefaultRenderingMode' , ( ) => {
90159 function setupRegistry ( {
91160 supportsEditor = true ,
0 commit comments