Skip to content

Commit

Permalink
Timestamp data in state.ui.queryArguments to fix prev test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsf committed Jul 2, 2016
1 parent 11a8166 commit afc2dd7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
23 changes: 13 additions & 10 deletions client/state/ui/guided-tours/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import uniq from 'lodash/uniq';
/**
* Internal dependencies
*/
import { GUIDED_TOUR_UPDATE, ROUTE_SET } from 'state/action-types';
import { ROUTE_SET } from 'state/action-types';
import { isSectionLoading, getInitialQueryArguments } from 'state/ui/selectors';
import { getActionLog } from 'state/ui/action-log/selectors';
import { getPreference } from 'state/preferences/selectors';
Expand Down Expand Up @@ -98,12 +98,14 @@ const getTourFromQuery = createSelector(
* otherwise.
*/
const hasJustSeenTour = createSelector(
( state, tour ) => find( getActionLog( state ), {
type: GUIDED_TOUR_UPDATE,
shouldShow: false,
tour,
} ),
getActionLog
( state, tourName ) => {
const { timestamp } = getInitialQueryArguments( state );
return getToursHistory( state ).some( entry =>
entry.tourName === tourName &&
entry.timestamp > timestamp
);
},
[ getInitialQueryArguments, getToursHistory ]
);

/*
Expand Down Expand Up @@ -180,9 +182,10 @@ export const getGuidedTourState = createSelector(
const tour = findEligibleTour( state );
const shouldReallyShow = !! tour;

console.log( 'tours reached', getToursFromFeaturesReached( state ) );
console.log( 'tours seen', getToursSeen( state ) );
console.log( 'found', tour );
console.log(
'tours: reached', getToursFromFeaturesReached( state ),
'seen', getToursSeen( state ),
'found', tour );

if ( ! tour ) {
return {
Expand Down
26 changes: 14 additions & 12 deletions client/state/ui/guided-tours/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import {
getGuidedTourState,
findEligibleTour,
} from '../selectors';
import {
GUIDED_TOUR_UPDATE,
} from 'state/action-types';
import guidedToursConfig from 'layout/guided-tours/config';

describe( 'selectors', () => {
Expand Down Expand Up @@ -106,6 +103,12 @@ describe( 'selectors', () => {
finished: true,
};

const testTourSeen = {
tourName: 'test',
timestamp: 1337,
finished: true,
};

it( 'should return undefined if nothing relevant in log', () => {
const state = makeState( { actionLog: [ { type: 'IRRELEVANT' } ] } );
const tour = findEligibleTour( state );
Expand Down Expand Up @@ -139,16 +142,15 @@ describe( 'selectors', () => {
expect( tour ).to.equal( 'main' );
} );
it( 'should dismiss a requested tour at the end', () => {
const finishMainTour = {
type: GUIDED_TOUR_UPDATE,
tour: 'main',
shouldShow: false,
const mainTourJustSeen = {
tourName: 'main',
timestamp: 1338,
finished: true,
};
const state = makeState( {
actionLog: [ navigateToThemes, finishMainTour ],
toursHistory: [ themesTourSeen ],
queryArguments: { tour: 'main' }
actionLog: [ navigateToThemes ],
toursHistory: [ themesTourSeen, mainTourJustSeen ],
queryArguments: { tour: 'main', timestamp: 0 }
} );
const tour = findEligibleTour( state );

Expand All @@ -162,8 +164,8 @@ describe( 'selectors', () => {
*/
const state = makeState( {
actionLog: times( 50, constant( navigateToTest ) ),
toursHistory: [ themesTourSeen ],
queryArguments: { tour: 'themes' }
toursHistory: [ testTourSeen, themesTourSeen ],
queryArguments: { tour: 'themes', timestamp: 0 }
} );
const tour = findEligibleTour( state );

Expand Down
9 changes: 7 additions & 2 deletions client/state/ui/query-arguments/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import {
ROUTE_SET,
} from 'state/action-types';

const timestamped = ( query ) => ( {
...query,
timestamp: Date.now(),
} );

const initial = createReducer( false, {
[ ROUTE_SET ]: ( state, { query } ) =>
state === false ? query : state,
state === false ? timestamped( query ) : state,
} );

const current = createReducer( {}, {
[ ROUTE_SET ]: ( state, { query } ) => query,
[ ROUTE_SET ]: ( state, { query } ) => timestamped( query ),
} );

export default combineReducers( {
Expand Down

0 comments on commit afc2dd7

Please sign in to comment.