Refactor Filters and Search (#119)
This commit is contained in:
@ -7,130 +7,3 @@ Object {
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter city 2`] = `
|
||||
Object {
|
||||
"_not": Object {
|
||||
"city": Object {
|
||||
"_eq": "Paris",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter company_name 1`] = `
|
||||
Object {
|
||||
"company": Object {
|
||||
"name": Object {
|
||||
"_eq": "Airbnb",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter company_name 2`] = `
|
||||
Object {
|
||||
"_not": Object {
|
||||
"company": Object {
|
||||
"name": Object {
|
||||
"_eq": "Airbnb",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter email 1`] = `
|
||||
Object {
|
||||
"email": Object {
|
||||
"_eq": "john@linkedin.com",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter email 2`] = `
|
||||
Object {
|
||||
"_not": Object {
|
||||
"email": Object {
|
||||
"_eq": "john@linkedin.com",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter fullname 1`] = `
|
||||
Object {
|
||||
"_and": Array [
|
||||
Object {
|
||||
"firstname": Object {
|
||||
"_eq": "John",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"lastname": Object {
|
||||
"_eq": "Doe",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the filter fullname 2`] = `
|
||||
Object {
|
||||
"_not": Object {
|
||||
"_and": Array [
|
||||
Object {
|
||||
"firstname": Object {
|
||||
"_eq": "John",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"lastname": Object {
|
||||
"_eq": "Doe",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the serch city with the searchValue 1`] = `
|
||||
Object {
|
||||
"city": Object {
|
||||
"_ilike": "%Search value%",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the serch company_name with the searchValue 1`] = `
|
||||
Object {
|
||||
"name": Object {
|
||||
"_ilike": "%Search value%",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the serch email with the searchValue 1`] = `
|
||||
Object {
|
||||
"email": Object {
|
||||
"_ilike": "%Search value%",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`PeopleFilter should render the serch fullname with the searchValue 1`] = `
|
||||
Object {
|
||||
"_or": Array [
|
||||
Object {
|
||||
"firstname": Object {
|
||||
"_ilike": "%Search value%",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"lastname": Object {
|
||||
"_ilike": "%Search value%",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
@ -1,65 +1,19 @@
|
||||
import { FilterType } from '../../../components/table/table-header/interface';
|
||||
import { People_Bool_Exp } from '../../../generated/graphql';
|
||||
import { GraphqlQueryCompany } from '../../../interfaces/company.interface';
|
||||
import { GraphqlQueryPerson } from '../../../interfaces/person.interface';
|
||||
import {
|
||||
SEARCH_COMPANY_QUERY,
|
||||
SEARCH_PEOPLE_QUERY,
|
||||
} from '../../../services/search/search';
|
||||
import { mockData as mockCompanyData } from '../../companies/__tests__/__data__/mock-data';
|
||||
import { mockData as mockPeopleData } from './__data__/mock-data';
|
||||
import { availableFilters } from '../people-table';
|
||||
|
||||
function assertFilterUseCompanySearch<FilterValue>(
|
||||
filter: FilterType<People_Bool_Exp>,
|
||||
): filter is FilterType<People_Bool_Exp> & {
|
||||
searchResultMapper: (data: GraphqlQueryCompany) => {
|
||||
displayValue: string;
|
||||
value: FilterValue;
|
||||
};
|
||||
} {
|
||||
return filter.searchQuery === SEARCH_COMPANY_QUERY;
|
||||
}
|
||||
|
||||
function assertFilterUsePeopleSearch<FilterValue>(
|
||||
filter: FilterType<People_Bool_Exp>,
|
||||
): filter is FilterType<People_Bool_Exp> & {
|
||||
searchResultMapper: (data: GraphqlQueryPerson) => {
|
||||
displayValue: string;
|
||||
value: FilterValue;
|
||||
};
|
||||
} {
|
||||
return filter.searchQuery === SEARCH_PEOPLE_QUERY;
|
||||
}
|
||||
|
||||
const JohnDoeUser = mockPeopleData.find(
|
||||
(user) => user.email === 'john@linkedin.com',
|
||||
) as GraphqlQueryPerson;
|
||||
import { cityFilter } from '../people-table';
|
||||
|
||||
describe('PeopleFilter', () => {
|
||||
for (const filter of availableFilters) {
|
||||
it(`should render the filter ${filter.key}`, () => {
|
||||
if (assertFilterUseCompanySearch(filter)) {
|
||||
const filterSelectedValue = filter.searchResultMapper(
|
||||
mockCompanyData[0],
|
||||
);
|
||||
for (const operand of filter.operands) {
|
||||
expect(
|
||||
filter.whereTemplate(operand, filterSelectedValue.value),
|
||||
).toMatchSnapshot();
|
||||
}
|
||||
}
|
||||
if (assertFilterUsePeopleSearch(filter)) {
|
||||
const filterSelectedValue = filter.searchResultMapper(JohnDoeUser);
|
||||
for (const operand of filter.operands) {
|
||||
expect(
|
||||
filter.whereTemplate(operand, filterSelectedValue.value),
|
||||
).toMatchSnapshot();
|
||||
}
|
||||
}
|
||||
});
|
||||
it(`should render the serch ${filter.key} with the searchValue`, () => {
|
||||
expect(filter.searchTemplate('Search value')).toMatchSnapshot();
|
||||
});
|
||||
}
|
||||
it(`should render the filter ${cityFilter.key}`, () => {
|
||||
expect(
|
||||
cityFilter.operands[0].whereTemplate({
|
||||
id: 'test-id',
|
||||
city: 'Paris',
|
||||
email: 'john@doe.com',
|
||||
firstname: 'John',
|
||||
lastname: 'Doe',
|
||||
phone: '0123456789',
|
||||
creationDate: new Date(),
|
||||
pipe: null,
|
||||
company: null,
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user