Welcome to mirror list, hosted at ThFree Co, Russian Federation.

apollo_mock_data.js « instance_statistics « analytics « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 98eabd577ee99e5db7bc8006b7a5e02f60d51cab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const defaultPageInfo = {
  hasNextPage: false,
  hasPreviousPage: false,
  startCursor: null,
  endCursor: null,
};

export const mockApolloResponse = ({ hasNextPage = false, key, data }) => ({
  data: {
    [key]: {
      pageInfo: { ...defaultPageInfo, hasNextPage },
      nodes: data,
    },
  },
});

export const mockQueryResponse = ({ key, data = [], loading = false, additionalData = [] }) => {
  const hasNextPage = Boolean(additionalData.length);
  const response = mockApolloResponse({ hasNextPage, key, data });
  if (loading) {
    return jest.fn().mockReturnValue(new Promise(() => {}));
  }
  if (hasNextPage) {
    return jest
      .fn()
      .mockResolvedValueOnce(response)
      .mockResolvedValueOnce(
        mockApolloResponse({
          hasNextPage: false,
          key,
          data: additionalData,
        }),
      );
  }
  return jest.fn().mockResolvedValue(response);
};