mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 01:01:43 +10:00
Gatsby mock: expanded useStaticQuery to support Templates, refactoring
This commit is contained in:
@ -1,49 +1,79 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
const Gatsby = jest.requireActual('gatsby');
|
const Gatsby = jest.requireActual('gatsby');
|
||||||
|
|
||||||
const fluidImagesShapeMock = [
|
const fluidImageShapes = [
|
||||||
{
|
{
|
||||||
aspectRatio: 2,
|
aspectRatio: 2,
|
||||||
src: `test_image.jpg`,
|
src: 'test_image.jpg',
|
||||||
srcSet: `some srcSet`,
|
srcSet: 'some srcSet',
|
||||||
srcSetWebp: `some srcSetWebp`,
|
srcSetWebp: 'some srcSetWebp',
|
||||||
sizes: `(max-width: 600px) 100vw, 600px`,
|
sizes: '(max-width: 600px) 100vw, 600px',
|
||||||
base64: `string_of_base64`,
|
base64: 'string_of_base64',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
aspectRatio: 3,
|
aspectRatio: 3,
|
||||||
src: `test_image_2.jpg`,
|
src: 'test_image_2.jpg',
|
||||||
srcSet: `some other srcSet`,
|
srcSet: 'some other srcSet',
|
||||||
srcSetWebp: `some other srcSetWebp`,
|
srcSetWebp: 'some other srcSetWebp',
|
||||||
sizes: `(max-width: 600px) 100vw, 600px`,
|
sizes: '(max-width: 400px) 100vw, 400px',
|
||||||
base64: `string_of_base64`,
|
base64: 'string_of_base64',
|
||||||
media: `only screen and (min-width: 768px)`,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const useStaticQuery = () => ({
|
||||||
|
site: {
|
||||||
|
siteMetadata: {
|
||||||
|
title: 'Test title',
|
||||||
|
description: 'Test description',
|
||||||
|
author: 'Test author',
|
||||||
|
siteUrl: 'https://testsiteurl/',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
file: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onyx: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pikachu: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
gengar: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
castform: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
glalie: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
celebi: {
|
||||||
|
childImageSharp: {
|
||||||
|
fluid: fluidImageShapes[1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
...Gatsby,
|
...Gatsby,
|
||||||
graphql: jest.fn(),
|
graphql: jest.fn(),
|
||||||
Link: jest.fn().mockImplementation(({ to, ...rest }) =>
|
Link: jest.fn().mockImplementation(({ to, ...rest }) =>
|
||||||
React.createElement(`a`, {
|
React.createElement('a', {
|
||||||
...rest,
|
...rest,
|
||||||
href: to,
|
href: to,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
StaticQuery: jest.fn(),
|
useStaticQuery: useStaticQuery,
|
||||||
useStaticQuery: jest.fn().mockReturnValue({
|
|
||||||
site: {
|
|
||||||
siteMetadata: {
|
|
||||||
title: '',
|
|
||||||
description: '',
|
|
||||||
author: '',
|
|
||||||
siteUrl: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
file: {
|
|
||||||
childImageSharp: {
|
|
||||||
fluid: fluidImagesShapeMock[0],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user