Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Extract custom hooks from controllers #3217

Merged
merged 4 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions packages/ra-core/src/controller/ListController.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import TextField from '@material-ui/core/TextField/TextField';

import ListController, {
getListControllerProps,
getQuery,
sanitizeListRestProps,
} from './ListController';

Expand Down Expand Up @@ -227,159 +226,4 @@ describe('ListController', () => {
});
});
});
describe('getQuery', () => {
it('Returns the values from the location first', () => {
const query = getQuery({
location: {
search: `?page=3&perPage=15&sort=name&order=ASC&filter=${JSON.stringify(
{ name: 'marmelab' }
)}`,
},
params: {
page: 1,
perPage: 10,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
},
filterDefaultValues: {},
perPage: 50,
sort: {
field: 'company',
order: 'DESC',
},
});

expect(query).toEqual({
page: '3',
perPage: '15',
sort: 'name',
order: 'ASC',
filter: {
name: 'marmelab',
},
});
});
it('Extends the values from the location with those from the props', () => {
const query = getQuery({
location: {
search: `?filter=${JSON.stringify({ name: 'marmelab' })}`,
},
params: {
page: 1,
perPage: 10,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
},
filterDefaultValues: {},
perPage: 50,
sort: {
field: 'company',
order: 'DESC',
},
});

expect(query).toEqual({
page: 1,
perPage: 50,
sort: 'company',
order: 'DESC',
filter: {
name: 'marmelab',
},
});
});
it('Sets the values from the redux store if location does not have them', () => {
const query = getQuery({
location: {
search: ``,
},
params: {
page: 2,
perPage: 10,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
},
filterDefaultValues: {},
perPage: 50,
sort: {
field: 'company',
order: 'DESC',
},
});

expect(query).toEqual({
page: 2,
perPage: 10,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
});
});
it('Extends the values from the redux store with those from the props', () => {
const query = getQuery({
location: {
search: ``,
},
params: {
page: 2,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
},
filterDefaultValues: {},
perPage: 50,
sort: {
field: 'company',
order: 'DESC',
},
});

expect(query).toEqual({
page: 2,
perPage: 50,
sort: 'city',
order: 'DESC',
filter: {
city: 'Dijon',
},
});
});
it('Uses the filterDefaultValues if neither the location or the redux store have them', () => {
const query = getQuery({
location: {
search: ``,
},
params: {},
filterDefaultValues: { city: 'Nancy' },
perPage: 50,
sort: {
field: 'company',
order: 'DESC',
},
});

expect(query).toEqual({
page: 1,
perPage: 50,
sort: 'company',
order: 'DESC',
filter: {
city: 'Nancy',
},
});
});
});
});
Loading