Skip to content

Commit

Permalink
mock useContext for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ds committed Jan 6, 2024
1 parent be38764 commit 6dc1744
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 1 deletion.
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenAcceleratora.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Given Accelerator components', function () {
test('When accelerator is specificed then convert output is correct', function () {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenComponentsEvolve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import MapElements from '../MapElements';
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Given Components Evolve', function () {
test('When evolve text is supplied then convert output is correct', function () {
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/__tests__/GivenComponentsHavePipelines.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import MapElements from '../MapElements';
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({
enableNewPipelines: true,
});

describe('Given Components Have Pipelines', function () {
test('When pipeline is specificed then convert output is correct', function () {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenConverter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Convert test suite', function () {
const genericMapComponents = [
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenLinksGiveContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Given Links can support context', function () {
test('When link is established, additional context can be supplied to be made visible on the map.', function () {
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/__tests__/GivenMapElementsGoldenMaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ const fs = require('fs');
const path = require('path');
import MapElements from '../MapElements';
import Converter from '../conversion/Converter';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({
enableDashboard: false,
enableNewPipelines: true,
enableLinkContext: true,
enableAccelerators: true,
enableDoubleClickRename: true,
});

// Function to load the content of a file
function loadFileContent(fileName) {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenSubmaps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import Converter from '../conversion/Converter';
import { EditorPrefixes } from '../constants/editorPrefixes';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Given Submaps', function () {
test.each(['Foo', 'Bar', 'Bleh'])(
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/__tests__/GivenUrls.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import Converter from '../conversion/Converter';
import { EditorPrefixes } from '../constants/editorPrefixes';
import { useContext } from 'react';

jest.mock('react', () => ({
...jest.requireActual('react'),
useContext: jest.fn(),
}));

useContext.mockReturnValue({});

describe('Given Urls', function () {
test.each(['Foo', 'Bar', 'Bleh'])(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/conversion/PipelineExtractionStrategy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ExtractionFunctions from '../constants/extractionFunctions';
import PipelineStrategyRunner from './PipelineStrategyRunner';
import BaseStrategyRunner from './BaseStrategyRunner';
import { useFeatureSwitches } from '../FeatureSwitchesContext';
import { useFeatureSwitches } from '../components/FeatureSwitchesContext';

export default class PipelineExtractionStrategy {
constructor(data) {
Expand Down

0 comments on commit 6dc1744

Please sign in to comment.