Skip to content

Commit 7b73d35

Browse files
committed
refactor
1 parent 4dccaf9 commit 7b73d35

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

cypress/support/component.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { ThemeProvider } from '@ui5/webcomponents-react';
2020
import { mount } from 'cypress/react';
2121
// Import commands.js using ES2015 syntax:
2222
import './commands';
23-
import { FrontendConfigProvider } from '../../src/context/FrontendConfigContext';
23+
import { FrontendConfigContext } from '../../src/context/FrontendConfigContext';
24+
import { mockedFrontendConfig } from '../../src/utils/testing';
2425

2526
// Augment the Cypress namespace to include type definitions for
2627
// your custom command.
@@ -38,9 +39,9 @@ declare global {
3839

3940
Cypress.Commands.add('mount', (component, options) => {
4041
return mount(<ThemeProvider>
41-
<FrontendConfigProvider>
42-
{component}
43-
</FrontendConfigProvider>
42+
<FrontendConfigContext value={mockedFrontendConfig}>
43+
{component}
44+
</FrontendConfigContext>
4445
</ThemeProvider>, options);
4546
});
4647

src/context/FrontendConfigContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ReactNode, createContext, use } from 'react';
22
import { DocLinkCreator } from '../lib/shared/links';
3-
import { isInTestingMode } from '../utils';
43

54
export enum Landscape {
65
Live = 'LIVE',
76
Canary = 'CANARY',
87
Staging = 'STAGING',
98
Development = 'DEV',
9+
Local = 'LOCAL',
1010
}
1111

1212
interface FrontendConfigContextProps {
@@ -16,12 +16,12 @@ interface FrontendConfigContextProps {
1616
links: DocLinkCreator;
1717
}
1818

19-
const FrontendConfigContext = createContext<FrontendConfigContextProps | null>(
19+
export const FrontendConfigContext = createContext<FrontendConfigContextProps | null>(
2020
null,
2121
);
2222

2323

24-
const fetchPromise = fetch(isInTestingMode ? '/__cypress/src/frontend-config.json': '/frontend-config.json').then((res) => res.json());
24+
const fetchPromise = fetch('/frontend-config.json').then((res) => res.json());
2525

2626
interface FrontendConfigProviderProps {
2727
children: ReactNode;

src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ export const projectnameToNamespace = (projectname: string) => {
1111
return `project-${projectname}`;
1212
};
1313

14-
export const isInTestingMode:Boolean = !!window.Cypress;

src/utils/testing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DocLinkCreator } from '../lib/shared/links.ts';
2+
import { Landscape } from '../context/FrontendConfigContext.tsx';
3+
4+
export const isInTestingMode: Boolean = !!window.Cypress;
5+
const documentationBaseUrl = 'http://localhost:3000';
6+
export const mockedFrontendConfig = {
7+
backendUrl: 'http://localhost:3000',
8+
landscape: Landscape.Local,
9+
documentationBaseUrl: 'http://localhost:3000',
10+
links: new DocLinkCreator(documentationBaseUrl),
11+
};

0 commit comments

Comments
 (0)