@@ -23,6 +23,10 @@ jest.mock('shared/data/resources', () => ({
2323 CommunityLibrarySubmission : {
2424 create : jest . fn ( ( ) => Promise . resolve ( ) ) ,
2525 } ,
26+ Channel : {
27+ fetchModel : jest . fn ( ) ,
28+ getCatalogChannel : jest . fn ( ( ) => Promise . resolve ( ) ) ,
29+ } ,
2630} ) ) ;
2731
2832const store = factory ( ) ;
@@ -33,6 +37,8 @@ const { nonePrimaryInfo$, flaggedPrimaryInfo$, approvedPrimaryInfo$, submittedPr
3337async function makeWrapper ( { channel, publishedData, latestSubmission } ) {
3438 const isLoading = ref ( true ) ;
3539 const isFinished = ref ( false ) ;
40+ const fetchPublishedData = jest . fn ( ( ) => Promise . resolve ( ) ) ;
41+ const fetchLatestSubmission = jest . fn ( ( ) => Promise . resolve ( ) ) ;
3642
3743 store . state . currentChannel . currentChannelId = channel . id ;
3844 store . commit ( 'channel/ADD_CHANNEL' , channel ) ;
@@ -41,12 +47,14 @@ async function makeWrapper({ channel, publishedData, latestSubmission }) {
4147 isLoading,
4248 isFinished,
4349 data : computed ( ( ) => publishedData ) ,
50+ fetchData : fetchPublishedData ,
4451 } ) ;
4552
4653 useLatestCommunityLibrarySubmission . mockReturnValue ( {
4754 isLoading,
4855 isFinished,
4956 data : computed ( ( ) => latestSubmission ) ,
57+ fetchData : fetchLatestSubmission ,
5058 } ) ;
5159
5260 const wrapper = mount ( SubmitToCommunityLibrarySidePanel , {
@@ -265,6 +273,67 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
265273 } ) ;
266274 } ) ;
267275
276+ describe ( 'publishing state' , ( ) => {
277+ beforeEach ( ( ) => {
278+ jest . useFakeTimers ( ) ;
279+ } ) ;
280+ afterEach ( ( ) => {
281+ jest . useRealTimers ( ) ;
282+ } ) ;
283+
284+ it ( 'disables form and shows loader when channel is publishing' , async ( ) => {
285+ const channel = { ...publishedNonPublicChannel , publishing : true } ;
286+ const wrapper = await makeWrapper ( { channel, publishedData, latestSubmission : null } ) ;
287+
288+ // Loader/message container should exist
289+ expect ( wrapper . find ( '.publishing-loader' ) . exists ( ) ) . toBe ( true ) ;
290+
291+ const descriptionTextbox = wrapper . findComponent ( '.description-textbox' ) ;
292+ expect ( descriptionTextbox . exists ( ) ) . toBe ( false ) ;
293+ const submitButton = wrapper . find ( '[data-test="submit-button"]' ) ;
294+ expect ( submitButton . exists ( ) ) . toBe ( false ) ;
295+ } ) ;
296+
297+ it ( 'enables form after publishing flips to false (poll-driven)' , async ( ) => {
298+ const { Channel } = require ( 'shared/data/resources' ) ;
299+ Channel . fetchModel . mockResolvedValue ( {
300+ id : publishedNonPublicChannel . id ,
301+ publishing : false ,
302+ version : 3 ,
303+ } ) ;
304+
305+ const channel = { ...publishedNonPublicChannel , publishing : true } ;
306+ const publishedDataWithVersion3 = {
307+ ...publishedData ,
308+ 3 : {
309+ included_languages : [ 'en' , null ] ,
310+ included_licenses : [ 1 ] ,
311+ included_categories : [ Categories . SCHOOL ] ,
312+ } ,
313+ } ;
314+ const wrapper = await makeWrapper ( {
315+ channel,
316+ publishedData : publishedDataWithVersion3 ,
317+ latestSubmission : null ,
318+ } ) ;
319+
320+ const updatedChannel = { ...channel , publishing : false , version : 3 } ;
321+ await wrapper . setProps ( { channel : updatedChannel } ) ;
322+ store . commit ( 'channel/ADD_CHANNEL' , updatedChannel ) ;
323+
324+ await wrapper . vm . $nextTick ( ) ;
325+ await wrapper . vm . $nextTick ( ) ;
326+
327+ const descriptionTextbox = wrapper . findComponent ( '.description-textbox' ) ;
328+ expect ( descriptionTextbox . props ( 'disabled' ) ) . toBe ( false ) ;
329+
330+ await descriptionTextbox . vm . $emit ( 'input' , 'Some description' ) ;
331+ await wrapper . vm . $nextTick ( ) ;
332+ const submitButton = wrapper . find ( '[data-test="submit-button"]' ) ;
333+ expect ( submitButton . attributes ( 'disabled' ) ) . toBeUndefined ( ) ;
334+ } ) ;
335+ } ) ;
336+
268337 describe ( 'show less button' , ( ) => {
269338 it ( 'is displayed when additional info is shown' , async ( ) => {
270339 const wrapper = await makeWrapper ( {
0 commit comments