-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8da21ba
commit c939b8e
Showing
7 changed files
with
770 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { GraphQLError } from 'graphql'; | ||
|
||
import { QUERY_TRENDING_FAMOUS } from '@/components/stacks/famous/screens/trending-famous/use-trending-famous'; | ||
import { DEFAULT_HEIGHT } from '@/components/stacks/famous/screens/trending-famous/components/trending-famous-list-item/TrendingFamousListItem.styles'; | ||
import { QueryTrendingFamous_trendingFamous_items } from '@/types/schema'; | ||
import metrics from '@styles/metrics'; | ||
|
||
type Errors = 'network' | 'graphql'; | ||
|
||
export const TRENDING_FAMOUS_ITEMS_PER_PAGE = Math.floor( | ||
metrics.height / DEFAULT_HEIGHT, | ||
); | ||
|
||
export const trendingFamousList = (page: number = 1) => | ||
Array(TRENDING_FAMOUS_ITEMS_PER_PAGE) | ||
.fill({}) | ||
.map((_, index) => ({ | ||
profilePath: `page${page}-profilePath-${index}`, | ||
name: `page${page}-name-${index}-${page}`, | ||
id: page * TRENDING_FAMOUS_ITEMS_PER_PAGE + index, | ||
__typename: 'TrendingFamousItem', | ||
})) as QueryTrendingFamous_trendingFamous_items[]; | ||
|
||
type BaseMockNewsQueryResponseParams = { | ||
items: QueryTrendingFamous_trendingFamous_items[]; | ||
page: number; | ||
hasMore: boolean; | ||
}; | ||
|
||
const baseMockTrendingFamousQueryResponse = ( | ||
params: BaseMockNewsQueryResponseParams, | ||
) => { | ||
const request = { | ||
request: { | ||
query: QUERY_TRENDING_FAMOUS, | ||
variables: { | ||
page: params.page, | ||
}, | ||
}, | ||
}; | ||
const result = { | ||
result: { | ||
data: { | ||
trendingFamous: { | ||
hasMore: params.hasMore, | ||
items: params.items, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const responseWithNetworkError = { | ||
...request, | ||
error: new Error('A Network error occurred'), | ||
}; | ||
|
||
const responseWithGraphQLError = { | ||
...request, | ||
errors: [new GraphQLError('A GraphQL error occurred')], | ||
}; | ||
|
||
return { | ||
responseWithGraphQLError, | ||
responseWithNetworkError, | ||
request, | ||
result, | ||
}; | ||
}; | ||
|
||
export const mockTrendingFamousEntryQuerySuccessResponse = ( | ||
hasMore = true, | ||
withEmptyResponse = false, | ||
) => { | ||
const entryQueryResult = baseMockTrendingFamousQueryResponse({ | ||
items: withEmptyResponse ? [] : trendingFamousList(), | ||
page: 1, | ||
hasMore, | ||
}); | ||
return [ | ||
{ | ||
...entryQueryResult.request, | ||
...entryQueryResult.result, | ||
}, | ||
]; | ||
}; | ||
|
||
export const mockTrendingFamousEntryQueryErrorResponse = (error: Errors) => { | ||
const entryQueryResult = baseMockTrendingFamousQueryResponse({ | ||
hasMore: false, | ||
page: 1, | ||
items: [], | ||
}); | ||
const errorResponse = | ||
error === 'network' | ||
? entryQueryResult.responseWithNetworkError | ||
: entryQueryResult.responseWithGraphQLError; | ||
return [ | ||
{ | ||
...entryQueryResult.request, | ||
...errorResponse, | ||
}, | ||
]; | ||
}; | ||
|
||
export const mockTrendingFamousPaginationQuerySuccessResponse = ( | ||
hasMore = true, | ||
) => { | ||
const entryQueryResult = baseMockTrendingFamousQueryResponse({ | ||
items: trendingFamousList(), | ||
page: 1, | ||
hasMore: true, | ||
}); | ||
const paginationQueryResult = baseMockTrendingFamousQueryResponse({ | ||
items: trendingFamousList(2), | ||
page: 2, | ||
hasMore, | ||
}); | ||
return [ | ||
{ | ||
...entryQueryResult.request, | ||
...entryQueryResult.result, | ||
}, | ||
{ | ||
...paginationQueryResult.request, | ||
...paginationQueryResult.result, | ||
}, | ||
]; | ||
}; | ||
|
||
export const mockTrendingFamousPaginationQueryErrorResponse = ( | ||
error: Errors, | ||
) => { | ||
const entryQueryResult = baseMockTrendingFamousQueryResponse({ | ||
items: trendingFamousList(), | ||
page: 1, | ||
hasMore: true, | ||
}); | ||
const paginationQueryResult = baseMockTrendingFamousQueryResponse({ | ||
items: trendingFamousList(), | ||
page: 2, | ||
hasMore: false, | ||
}); | ||
const errorResponse = | ||
error === 'network' | ||
? paginationQueryResult.responseWithNetworkError | ||
: paginationQueryResult.responseWithGraphQLError; | ||
return [ | ||
{ | ||
...entryQueryResult.request, | ||
...entryQueryResult.result, | ||
}, | ||
{ | ||
...errorResponse.request, | ||
...errorResponse, | ||
}, | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.