@@ -27,18 +27,16 @@ jest.mock('shared/data/resources', () => ({
2727
2828const store = factory ( ) ;
2929
30- const {
31- nonePrimaryInfo$,
32- flaggedPrimaryInfo$,
33- approvedPrimaryInfo$,
34- submittedPrimaryInfo$,
35- reviewersWillSeeLatestFirst$,
36- } = communityChannelsStrings ;
30+ const { nonePrimaryInfo$, flaggedPrimaryInfo$, approvedPrimaryInfo$, submittedPrimaryInfo$ } =
31+ communityChannelsStrings ;
3732
3833async function makeWrapper ( { channel, publishedData, latestSubmission } ) {
3934 const isLoading = ref ( true ) ;
4035 const isFinished = ref ( false ) ;
4136
37+ store . state . currentChannel . currentChannelId = channel . id ;
38+ store . commit ( 'channel/ADD_CHANNEL' , channel ) ;
39+
4240 usePublishedData . mockReturnValue ( {
4341 isLoading,
4442 isFinished,
@@ -79,9 +77,9 @@ const publishedNonPublicChannel = {
7977} ;
8078
8179const publicChannel = {
82- id : 'published-non- public-channel' ,
80+ id : 'public-channel' ,
8381 version : 2 ,
84- name : 'Published Non- Public Channel' ,
82+ name : 'Public Channel' ,
8583 published : true ,
8684 public : true ,
8785} ;
@@ -110,6 +108,10 @@ const publishedData = {
110108const submittedLatestSubmission = { channel_version : 2 , status : CommunityLibraryStatus . PENDING } ;
111109
112110describe ( 'SubmitToCommunityLibrarySidePanel' , ( ) => {
111+ beforeEach ( ( ) => {
112+ store . state . currentChannel . currentChannelId = null ;
113+ store . state . channel . channelsMap = { } ;
114+ } ) ;
113115 describe ( 'correct warnings are shown' , ( ) => {
114116 it ( 'when channel is published, not public and not submitted' , async ( ) => {
115117 const wrapper = await makeWrapper ( {
@@ -178,10 +180,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
178180 latestSubmission : null ,
179181 } ) ;
180182
181- const infoBoxes = wrapper . findAllComponents ( Box ) . filter ( box => box . props ( 'kind' ) === 'info' ) ;
182- expect ( infoBoxes . length ) . toBe ( 1 ) ;
183- const infoBox = infoBoxes . wrappers [ 0 ] ;
184- expect ( infoBox . text ( ) ) . toContain ( nonePrimaryInfo$ ( ) ) ;
183+ const infoSection = wrapper . find ( '.info-section' ) ;
184+ expect ( infoSection . exists ( ) ) . toBe ( true ) ;
185+ expect ( infoSection . text ( ) ) . toContain ( nonePrimaryInfo$ ( ) ) ;
185186 } ) ;
186187
187188 it ( 'when the previous submission was rejected' , async ( ) => {
@@ -191,10 +192,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
191192 latestSubmission : { channel_version : 1 , status : CommunityLibraryStatus . REJECTED } ,
192193 } ) ;
193194
194- const infoBoxes = wrapper . findAllComponents ( Box ) . filter ( box => box . props ( 'kind' ) === 'info' ) ;
195- expect ( infoBoxes . length ) . toBe ( 1 ) ;
196- const infoBox = infoBoxes . wrappers [ 0 ] ;
197- expect ( infoBox . text ( ) ) . toContain ( flaggedPrimaryInfo$ ( ) ) ;
195+ const infoSection = wrapper . find ( '.info-section' ) ;
196+ expect ( infoSection . exists ( ) ) . toBe ( true ) ;
197+ expect ( infoSection . text ( ) ) . toContain ( flaggedPrimaryInfo$ ( ) ) ;
198198 } ) ;
199199
200200 it ( 'when the previous submission was approved' , async ( ) => {
@@ -204,11 +204,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
204204 latestSubmission : { channel_version : 1 , status : CommunityLibraryStatus . APPROVED } ,
205205 } ) ;
206206
207- const infoBoxes = wrapper . findAllComponents ( Box ) . filter ( box => box . props ( 'kind' ) === 'info' ) ;
208- expect ( infoBoxes . length ) . toBe ( 1 ) ;
209- const infoBox = infoBoxes . wrappers [ 0 ] ;
210- expect ( infoBox . text ( ) ) . toContain ( approvedPrimaryInfo$ ( ) ) ;
211- expect ( infoBox . text ( ) ) . toContain ( reviewersWillSeeLatestFirst$ ( ) ) ;
207+ const infoSection = wrapper . find ( '.info-section' ) ;
208+ expect ( infoSection . exists ( ) ) . toBe ( true ) ;
209+ expect ( infoSection . text ( ) ) . toContain ( approvedPrimaryInfo$ ( ) ) ;
212210 } ) ;
213211
214212 it ( 'when the previous submission is pending' , async ( ) => {
@@ -218,11 +216,9 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
218216 latestSubmission : { channel_version : 1 , status : CommunityLibraryStatus . PENDING } ,
219217 } ) ;
220218
221- const infoBoxes = wrapper . findAllComponents ( Box ) . filter ( box => box . props ( 'kind' ) === 'info' ) ;
222- expect ( infoBoxes . length ) . toBe ( 1 ) ;
223- const infoBox = infoBoxes . wrappers [ 0 ] ;
224- expect ( infoBox . text ( ) ) . toContain ( submittedPrimaryInfo$ ( ) ) ;
225- expect ( infoBox . text ( ) ) . toContain ( reviewersWillSeeLatestFirst$ ( ) ) ;
219+ const infoSection = wrapper . find ( '.info-section' ) ;
220+ expect ( infoSection . exists ( ) ) . toBe ( true ) ;
221+ expect ( infoSection . text ( ) ) . toContain ( submittedPrimaryInfo$ ( ) ) ;
226222 } ) ;
227223 } ) ;
228224
@@ -256,17 +252,16 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
256252 latestSubmission : null ,
257253 } ) ;
258254
259- let moreDetails = wrapper . find ( '[data-test="more-details"] ' ) ;
260- expect ( moreDetails . exists ( ) ) . toBe ( false ) ;
255+ const infoText = wrapper . find ( '.info-text ' ) ;
256+ expect ( infoText . text ( ) ) . not . toContain ( 'The Kolibri Community Library features channels' ) ;
261257
262- let moreDetailsButton = wrapper . find ( '[data-test="more-details-button"]' ) ;
258+ const moreDetailsButton = wrapper . find ( '[data-test="more-details-button"]' ) ;
263259 await moreDetailsButton . trigger ( 'click' ) ;
264260
265- moreDetails = wrapper . find ( '.more-details-text' ) ;
266- expect ( moreDetails . exists ( ) ) . toBe ( true ) ;
261+ expect ( infoText . text ( ) ) . toContain ( 'The Kolibri Community Library features channels' ) ;
267262
268- moreDetailsButton = wrapper . find ( '[data-test="more -details-button"]' ) ;
269- expect ( moreDetailsButton . exists ( ) ) . toBe ( false ) ;
263+ const lessDetailsButton = wrapper . find ( '[data-test="less -details-button"]' ) ;
264+ expect ( lessDetailsButton . exists ( ) ) . toBe ( true ) ;
270265 } ) ;
271266 } ) ;
272267
@@ -478,6 +473,7 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
478473 } ) ;
479474
480475 it ( 'the panel closes' , async ( ) => {
476+ jest . useFakeTimers ( ) ;
481477 const wrapper = await makeWrapper ( {
482478 channel : publishedNonPublicChannel ,
483479 publishedData,
@@ -491,9 +487,11 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
491487 await submitButton . trigger ( 'click' ) ;
492488
493489 expect ( wrapper . emitted ( 'close' ) ) . toBeTruthy ( ) ;
490+ jest . useRealTimers ( ) ;
494491 } ) ;
495492
496493 it ( 'a submission snackbar is shown' , async ( ) => {
494+ jest . useFakeTimers ( ) ;
497495 const wrapper = await makeWrapper ( {
498496 channel : publishedNonPublicChannel ,
499497 publishedData,
@@ -505,14 +503,15 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
505503
506504 const submitButton = wrapper . find ( '[data-test="submit-button"]' ) ;
507505 await submitButton . trigger ( 'click' ) ;
508-
509- jest . useFakeTimers ( ) ;
506+ await wrapper . vm . $nextTick ( ) ;
510507
511508 expect ( store . getters [ 'snackbarIsVisible' ] ) . toBe ( true ) ;
512509 expect ( CommunityLibrarySubmission . create ) . not . toHaveBeenCalled ( ) ;
510+ jest . useRealTimers ( ) ;
513511 } ) ;
514512
515513 it ( 'the submission is created after a timeout' , async ( ) => {
514+ jest . useFakeTimers ( ) ;
516515 const wrapper = await makeWrapper ( {
517516 channel : publishedNonPublicChannel ,
518517 publishedData,
@@ -524,20 +523,22 @@ describe('SubmitToCommunityLibrarySidePanel', () => {
524523
525524 const countryField = wrapper . findComponent ( CountryField ) ;
526525 await countryField . vm . $emit ( 'input' , [ 'Czech Republic' ] ) ;
527-
528- jest . useFakeTimers ( ) ;
526+ await wrapper . vm . $nextTick ( ) ;
529527
530528 const submitButton = wrapper . find ( '[data-test="submit-button"]' ) ;
531529 await submitButton . trigger ( 'click' ) ;
530+ await wrapper . vm . $nextTick ( ) ;
532531
533532 jest . runAllTimers ( ) ;
533+ await wrapper . vm . $nextTick ( ) ;
534534
535535 expect ( CommunityLibrarySubmission . create ) . toHaveBeenCalledWith ( {
536536 description : 'Some description' ,
537537 channel : publishedNonPublicChannel . id ,
538538 countries : [ 'CZ' ] ,
539539 categories : [ Categories . SCHOOL ] ,
540540 } ) ;
541+ jest . useRealTimers ( ) ;
541542 } ) ;
542543 } ) ;
543544
0 commit comments