Add tests on companies page (#155)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { GraphqlQueryCompany } from '../../interfaces/entities/company.interface';
|
||||
|
||||
export const mockCompaniesData: Array<GraphqlQueryCompany> = [
|
||||
export const mockedCompaniesData: Array<GraphqlQueryCompany> = [
|
||||
{
|
||||
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
|
||||
domainName: 'airbnb.com',
|
||||
@ -8,7 +8,12 @@ export const mockCompaniesData: Array<GraphqlQueryCompany> = [
|
||||
createdAt: '2023-04-26T10:08:54.724515+00:00',
|
||||
address: '17 rue de clignancourt',
|
||||
employees: 12,
|
||||
accountOwner: null,
|
||||
accountOwner: {
|
||||
email: 'charles@test.com',
|
||||
displayName: 'Charles Test',
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||
__typename: 'users',
|
||||
},
|
||||
__typename: 'companies',
|
||||
},
|
||||
{
|
||||
|
||||
@ -23,7 +23,10 @@ function filterData<DataT>(
|
||||
|
||||
if (filterElement.is) {
|
||||
const nestedKey = Object.keys(filterElement.is)[0] as string;
|
||||
if (typeof item[key as keyof typeof item] === 'object') {
|
||||
if (
|
||||
item[key as keyof typeof item] &&
|
||||
typeof item[key as keyof typeof item] === 'object'
|
||||
) {
|
||||
const nestedItem = item[key as keyof typeof item];
|
||||
return (
|
||||
nestedItem[nestedKey as keyof typeof nestedItem] ===
|
||||
@ -71,6 +74,7 @@ export function filterAndSortData<DataT>(
|
||||
limit: number,
|
||||
): Array<DataT> {
|
||||
let filteredData = filterData<DataT>(data, where);
|
||||
console.log(filteredData);
|
||||
|
||||
if (orderBy) {
|
||||
const firstOrderBy = orderBy[0];
|
||||
@ -84,8 +88,12 @@ export function filterAndSortData<DataT>(
|
||||
return 0;
|
||||
}
|
||||
|
||||
const sortDirection =
|
||||
firstOrderBy[key as unknown as keyof typeof firstOrderBy];
|
||||
if (typeof itemAValue === 'string' && typeof itemBValue === 'string') {
|
||||
return itemBValue.localeCompare(itemAValue);
|
||||
return sortDirection === 'desc'
|
||||
? itemBValue.localeCompare(itemAValue)
|
||||
: -itemBValue.localeCompare(itemAValue);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
16
front/src/testing/mock-data/users.ts
Normal file
16
front/src/testing/mock-data/users.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { GraphqlQueryUser } from '../../interfaces/entities/user.interface';
|
||||
|
||||
export const mockedUsersData: Array<GraphqlQueryUser> = [
|
||||
{
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||
__typename: 'User',
|
||||
email: 'charles@test.com',
|
||||
displayName: 'Charles Test',
|
||||
},
|
||||
{
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6c',
|
||||
__typename: 'User',
|
||||
email: 'felix@test.com',
|
||||
displayName: 'Felix Test',
|
||||
},
|
||||
];
|
||||
16
front/src/testing/mockedClient.ts
Normal file
16
front/src/testing/mockedClient.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ApolloClient, InMemoryCache } from '@apollo/client';
|
||||
|
||||
export const mockedClient = new ApolloClient({
|
||||
uri: process.env.REACT_APP_API_URL,
|
||||
cache: new InMemoryCache(),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
fetchPolicy: 'no-cache',
|
||||
errorPolicy: 'all',
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: 'no-cache',
|
||||
errorPolicy: 'all',
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user