Skip to content

Commit

Permalink
Feature/route container update (#300)
Browse files Browse the repository at this point in the history
* added ROUTE_PARAMS_DOMAIN getter

* moved update query into helper and added support for omitting empty query params.

* fix lint

* increase test timeout to avoid failure

* increasing delay before checking element exists

* check that button is enabled before clicking it

* adding enabled check to similiar tests

* fix lint

* moving delay before the button appears

* reducing delay. removing timeout

* removing delay

* copying code from passing test

* adding assertion for element to not be disabled.

* fix lint

* trying to allow test runner to retry multiple times before failing

* adjusting selector

* trying to add check on element in a retry

* making similar tests more resiliant

* forcing diff change

* adding options to summaryTest and withFullHistory and withHistory helpers

* fix lint

* make options specific to history

* fixed issue with handler option set to false explicitly.

* adding API delay for termination tests

* fix lint

* reverting README change

* reverted integration test changes as is now part of a separate PR.
  • Loading branch information
just-at-uber authored May 3, 2021
1 parent a83ccff commit 67c522d
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 11 deletions.
13 changes: 4 additions & 9 deletions client/containers/route/action-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@

import { ROUTE_PUSH, ROUTE_REPLACE, ROUTE_UPDATE_QUERY } from './action-types';
import { ROUTE_QUERY } from './getter-types';
import { getUpdatedQuery } from './helpers';

const actionCreator = router => ({
[ROUTE_PUSH]: (_, args) => router.push(args),
[ROUTE_REPLACE]: (_, args) => router.replace(args),
[ROUTE_UPDATE_QUERY]: ({ getters }, args) => {
const query = getters[ROUTE_QUERY];

[ROUTE_UPDATE_QUERY]: ({ getters }, payload) =>
router.replace({
query: {
...query,
...args,
},
});
},
query: getUpdatedQuery({ payload, query: getters[ROUTE_QUERY] }),
}),
});

export default actionCreator;
1 change: 1 addition & 0 deletions client/containers/route/getter-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
// THE SOFTWARE.

export const ROUTE_PARAMS = 'ROUTE_PARAMS';
export const ROUTE_PARAMS_DOMAIN = 'ROUTE_PARAMS_DOMAIN';
export const ROUTE_QUERY = 'ROUTE_QUERY';
3 changes: 2 additions & 1 deletion client/containers/route/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
// THE SOFTWARE.

import { get } from 'lodash-es';
import { ROUTE_PARAMS, ROUTE_QUERY } from './getter-types';
import { ROUTE_PARAMS, ROUTE_PARAMS_DOMAIN, ROUTE_QUERY } from './getter-types';

const getters = {
[ROUTE_PARAMS]: state => get(state, 'route.params', {}),
[ROUTE_PARAMS_DOMAIN]: (_, getters) => getters[ROUTE_PARAMS].domain,
[ROUTE_QUERY]: state => get(state, 'route.query', {}),
};

Expand Down
21 changes: 20 additions & 1 deletion client/containers/route/getters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import { ROUTE_PARAMS, ROUTE_QUERY } from './getter-types';
import { ROUTE_PARAMS, ROUTE_PARAMS_DOMAIN, ROUTE_QUERY } from './getter-types';
import getterFns from './getters';
import { initGetters } from '~test';

Expand Down Expand Up @@ -58,6 +58,25 @@ describe('route getters', () => {
});
});

describe('calling getters[ROUTE_PARAMS_DOMAIN]', () => {
describe('and state.route.params.domain is defined', () => {
const state = {
route: {
params: {
domain: 'domainA',
},
},
};

it('should return the value from state.route.params.domain', () => {
const getters = initGetters({ getterFns, state });
const output = getters[ROUTE_PARAMS_DOMAIN];

expect(output).toEqual('domainA');
});
});
});

describe('calling getters[ROUTE_QUERY]', () => {
describe('and state.route.query is defined', () => {
const state = {
Expand Down
59 changes: 59 additions & 0 deletions client/containers/route/helpers/get-updated-query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// omits entries from payload with empty string to be removed from original URL query params
const getUpdatedQuery = ({ payload, query }) => {
const omittedKeys = [];
const omittedPayload = Object.entries(payload).reduce(
(accumulator, [key, value]) => {
if (value === '') {
omittedKeys.push(key);

return accumulator;
}

accumulator[key] = value;

return accumulator;
},
{}
);

const omittedQuery = Object.entries(query).reduce(
(accumulator, [key, value]) => {
if (omittedKeys.includes(key)) {
return accumulator;
}

accumulator[key] = value;

return accumulator;
},
{}
);

return {
...omittedQuery,
...omittedPayload,
};
};

export default getUpdatedQuery;
40 changes: 40 additions & 0 deletions client/containers/route/helpers/get-updated-query.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import getUpdatedQuery from './get-updated-query';

describe('route helpers getUpdatedQuery', () => {
describe('when getUpdatedQuery is called with a param in payload that is an empty string', () => {
it('should omit that entry from the returned updated query.', () => {
const query = {
omittedQuery: 'previous-query-value',
};

const payload = {
omittedQuery: '',
};

const output = getUpdatedQuery({ payload, query });

expect(output.omittedQuery).toEqual(undefined);
});
});
});
22 changes: 22 additions & 0 deletions client/containers/route/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export { default as getUpdatedQuery } from './get-updated-query';

0 comments on commit 67c522d

Please sign in to comment.