Skip to content

Commit

Permalink
Merge pull request #532 from shopgate/PWA-1699-incorrect-tracking-data
Browse files Browse the repository at this point in the history
Fixed wrong tracking events
  • Loading branch information
devbucket committed Feb 8, 2019
2 parents 963c3d4 + d4205f1 commit ac0b8f5
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`<Slider /> renders with a fraction indicator 1`] = `
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={true}
initialSlide={0}
interval={3000}
Expand Down Expand Up @@ -175,7 +175,7 @@ exports[`<Slider /> renders with bullet indicators 1`] = `
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={true}
initialSlide={0}
interval={3000}
Expand Down Expand Up @@ -294,7 +294,7 @@ exports[`<Slider /> renders with children 1`] = `
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={false}
initialSlide={0}
interval={3000}
Expand Down Expand Up @@ -412,7 +412,7 @@ exports[`<Slider /> renders with controls 1`] = `
controls={true}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={false}
initialSlide={0}
interval={3000}
Expand Down
21 changes: 8 additions & 13 deletions libraries/common/selectors/history.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createSelector } from 'reselect';
import { getCurrentRoute } from '@shopgate/pwa-common/helpers/router';
import { getCurrentQuery, getRouterStack } from '@shopgate/pwa-common/selectors/router';
import {
getCurrentPathname,
getCurrentQuery,
getRouterStack,
} from '@shopgate/pwa-common/selectors/router';
import { parseObjectToQueryString } from '../helpers/router';
import { DEFAULT_SORT } from '../constants/DisplayOptions';

Expand Down Expand Up @@ -46,25 +49,17 @@ export const getSortOrder = createSelector(
* @returns {string|null} The current search phrase.
*/
export const getSearchPhrase = createSelector(
state => getQueryParam(state, 's'),
(state, props) => getQueryParam(state, props, 's'),
param => (param ? param.trim() : null)
);

/**
* Gets the current history pathname.
* @deprecated
* @param {Object} state The current application state.
* @returns {string}
*/
export const getHistoryPathname = createSelector(
getCurrentRoute,
(route) => {
if (!route) {
return null;
}

return route.pathname;
}
);
export const getHistoryPathname = getCurrentPathname;

/**
* Gets the length of the current history stack.
Expand Down
11 changes: 4 additions & 7 deletions libraries/tracking/selectors/page.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createSelector } from 'reselect';
import { shopNumber } from '@shopgate/pwa-common/helpers/config';
import {
getHistoryPathname,
getQueryParamsAsString,
} from '@shopgate/pwa-common/selectors/history';
import { getCurrentPathname } from '@shopgate/pwa-common/selectors/router';

import { isDev } from '@shopgate/pwa-common/helpers/environment';

/**
Expand All @@ -29,8 +27,7 @@ const pageNameMap = {
* @returns {string} The URL.
*/
const getTrackingUrl = createSelector(
getHistoryPathname,
getQueryParamsAsString,
getCurrentPathname,
pathname => `${baseUrl}/${shopNumber}${pathname}`
);

Expand All @@ -40,7 +37,7 @@ const getTrackingUrl = createSelector(
* @returns {string} The name.
*/
const getPageName = createSelector(
getHistoryPathname,
getCurrentPathname,
pathname => pathname.split('?')[0].split('/')[1]
);

Expand Down
1 change: 1 addition & 0 deletions libraries/tracking/streams/category.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jest.mock('@shopgate/pwa-common/selectors/router', () => ({
},
state: {},
}),
getCurrentPathname: () => ({}),
getCurrentQuery: () => ({}),
getRouterStack: () => ({}),
getCurrentState: () => ({}),
Expand Down
1 change: 1 addition & 0 deletions libraries/tracking/streams/product.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jest.mock('@shopgate/pwa-common/selectors/router', () => ({
productId: mockBin2Hex(mockedRouteProductId),
},
}),
getCurrentPathname: () => ({}),
getCurrentQuery: () => ({}),
getRouterStack: () => ({}),
getCurrentState: () => ({}),
Expand Down
1 change: 1 addition & 0 deletions libraries/tracking/streams/search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jest.mock('@shopgate/pwa-common/selectors/router', () => ({
},
state: {},
}),
getCurrentPathname: () => ({}),
getCurrentQuery: () => ({}),
getRouterStack: () => ({}),
getCurrentState: () => ({}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ exports[`<Bar /> should match snapshot 1`] = `
scrollTop={null}
>
<FilterChips
currentPathname="/"
currentPathname={null}
filters={null}
openFilters={[Function]}
routeId=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ exports[`<FormButtons /> should render submit and cancel button 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ exports[`<ImageSliderWidget /> should map the correct image settings to the comp
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={true}
initialSlide={0}
interval={7000}
Expand Down Expand Up @@ -593,7 +593,7 @@ exports[`<ImageSliderWidget /> should render the images with links 1`] = `
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={true}
initialSlide={0}
interval={7000}
Expand Down Expand Up @@ -949,7 +949,7 @@ exports[`<ImageSliderWidget /> should render the slider with the correct number
controls={false}
disabled={false}
dispatch={[Function]}
historyPath="/"
historyPath={null}
indicators={true}
initialSlide={0}
interval={7000}
Expand Down
37 changes: 18 additions & 19 deletions themes/theme-ios11/components/TabBar/selectors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,56 @@ jest.mock('@shopgate/pwa-common/helpers/config', () => ({
},
}));

let mockedPathname;
jest.mock('@shopgate/pwa-common/helpers/router', () => ({
getCurrentRoute: () => ({
pathname: mockedPathname,
}),
}));
/**
* Creates a mocked router state for the selectors.
* @param {string} pathname The pathname for the current route.
* @returns {Object}
*/
const getMockedRouterState = pathname => ({
router: {
currentRoute: {
pathname,
},
},
});

describe('TabBar selectors', () => {
beforeEach(() => {
mockedPathname = '';
jest.resetModules();
});

describe('getActiveTab()', () => {
it('should return TAB_HOME', () => {
mockedPathname = INDEX_PATH;
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState(INDEX_PATH));
expect(result).toEqual(TAB_HOME);
});

it('should return TAB_BROWSE', () => {
const paths = [BROWSE_PATH, SEARCH_PATH, CATEGORY_PATH];

paths.forEach((pathname) => {
mockedPathname = pathname;
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState(pathname));
expect(result).toEqual(TAB_BROWSE);
});
});

it('should return TAB_CART', () => {
mockedPathname = CART_PATH;
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState(CART_PATH));
expect(result).toEqual(TAB_CART);
});

it('should return TAB_MORE', () => {
mockedPathname = MORE_PATH;
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState(MORE_PATH));
expect(result).toEqual(TAB_MORE);
});

it('should return TAB_FAVORITES', () => {
mockedPathname = FAVORITES_PATH;
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState(FAVORITES_PATH));
expect(result).toEqual(TAB_FAVORITES);
});

it('should return TAB_NONE', () => {
mockedPathname = '/unknown';
const result = getActiveTab({});
const result = getActiveTab(getMockedRouterState('/unknown'));
expect(result).toEqual(TAB_NONE);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ exports[`<Bar /> should match snapshot 1`] = `
scrollTop={null}
>
<FilterChips
currentPathname="/"
currentPathname={null}
filters={null}
openFilters={[Function]}
routeId=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,12 @@ exports[`<ReviewForm /> should render empty 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -1662,12 +1662,12 @@ exports[`<ReviewForm /> should render form correctly 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -2811,12 +2811,12 @@ exports[`<ReviewForm /> should set form data 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -3901,12 +3901,12 @@ exports[`<ReviewForm /> should submit with valid review 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -4991,12 +4991,12 @@ exports[`<ReviewForm /> should validate fields on change 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -6086,12 +6086,12 @@ exports[`<ReviewForm /> should validate fields on change 2`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -7176,12 +7176,12 @@ exports[`<ReviewForm /> should validate fields on change 3`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down Expand Up @@ -8066,12 +8066,12 @@ exports[`<ReviewForm /> should validate form on submit 1`] = `
<Connect(Component)>
<Component
cancel={[Function]}
pathname="/some/path"
pathname={null}
>
<FormButtons
cancel={[Function]}
isLoading={false}
pathname="/some/path"
pathname={null}
>
<div
className="css-1v7qljm"
Expand Down

0 comments on commit ac0b8f5

Please sign in to comment.