@@ -3,8 +3,10 @@ import {
33 getSpotlightStyle ,
44 renderTipTapContent ,
55 normalizeUrl ,
6+ hasTourWaitPeriodPassed ,
67} from '../../extensions/product-tours/product-tours-utils'
78import { doesTourActivateByEvent , doesTourActivateByAction } from '../../utils/product-tour-utils'
9+ import { LAST_SEEN_TOUR_DATE_KEY_PREFIX } from '../../extensions/product-tours/constants'
810
911describe ( 'calculateTooltipPosition' , ( ) => {
1012 const mockWindow = {
@@ -248,3 +250,43 @@ describe('doesTourActivateByAction', () => {
248250 expect ( doesTourActivateByAction ( tour ) ) . toBe ( false )
249251 } )
250252} )
253+
254+ describe ( 'hasTourWaitPeriodPassed' , ( ) => {
255+ beforeEach ( ( ) => localStorage . clear ( ) )
256+
257+ const setLastSeen = ( type : string , daysAgo : number ) => {
258+ const date = new Date ( )
259+ date . setDate ( date . getDate ( ) - daysAgo )
260+ localStorage . setItem ( `${ LAST_SEEN_TOUR_DATE_KEY_PREFIX } ${ type } ` , JSON . stringify ( date . toISOString ( ) ) )
261+ }
262+
263+ it . each ( [
264+ [ 'no config' , undefined , true ] ,
265+ [ 'days is 0' , { days : 0 , types : [ 'tour' as const ] } , true ] ,
266+ [ 'empty types' , { days : 7 , types : [ ] } , true ] ,
267+ [ 'no stored date' , { days : 7 , types : [ 'tour' as const ] } , true ] ,
268+ ] ) ( 'returns true when %s' , ( _desc , config , expected ) => {
269+ expect ( hasTourWaitPeriodPassed ( config ) ) . toBe ( expected )
270+ } )
271+
272+ it ( 'returns false when within the wait period' , ( ) => {
273+ setLastSeen ( 'tour' , 0 )
274+ expect ( hasTourWaitPeriodPassed ( { days : 7 , types : [ 'tour' ] } ) ) . toBe ( false )
275+ } )
276+
277+ it ( 'returns true when past the wait period' , ( ) => {
278+ setLastSeen ( 'tour' , 10 )
279+ expect ( hasTourWaitPeriodPassed ( { days : 7 , types : [ 'tour' ] } ) ) . toBe ( true )
280+ } )
281+
282+ it ( 'ignores types not in the config' , ( ) => {
283+ setLastSeen ( 'announcement' , 0 )
284+ expect ( hasTourWaitPeriodPassed ( { days : 7 , types : [ 'tour' ] } ) ) . toBe ( true )
285+ } )
286+
287+ it ( 'uses the most recent date across multiple types' , ( ) => {
288+ setLastSeen ( 'tour' , 10 )
289+ setLastSeen ( 'announcement' , 0 )
290+ expect ( hasTourWaitPeriodPassed ( { days : 7 , types : [ 'tour' , 'announcement' ] } ) ) . toBe ( false )
291+ } )
292+ } )
0 commit comments