2021-02-05 14:21:04 -08:00
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { MemoryRouter } from 'react-router';
|
2021-03-09 23:14:52 -08:00
|
|
|
import { ThemeProvider } from 'styled-components';
|
|
|
|
|
2021-08-02 22:48:22 +08:00
|
|
|
import { CLIENT_AUTH_COOKIE } from '../../conf/Global';
|
2021-02-12 13:57:38 -08:00
|
|
|
import { DatasetEntity } from '../../app/entity/dataset/DatasetEntity';
|
2021-04-21 12:06:31 -07:00
|
|
|
import { DataFlowEntity } from '../../app/entity/dataFlow/DataFlowEntity';
|
|
|
|
import { DataJobEntity } from '../../app/entity/dataJob/DataJobEntity';
|
2021-02-12 13:57:38 -08:00
|
|
|
import { UserEntity } from '../../app/entity/user/User';
|
2021-08-16 20:47:18 -07:00
|
|
|
import { GroupEntity } from '../../app/entity/group/Group';
|
2021-02-12 13:57:38 -08:00
|
|
|
import EntityRegistry from '../../app/entity/EntityRegistry';
|
2021-02-05 14:21:04 -08:00
|
|
|
import { EntityRegistryContext } from '../../entityRegistryContext';
|
2021-03-07 11:26:47 -08:00
|
|
|
import { TagEntity } from '../../app/entity/tag/Tag';
|
2021-02-05 14:21:04 -08:00
|
|
|
|
2021-03-09 23:14:52 -08:00
|
|
|
import defaultThemeConfig from '../../conf/theme/theme_light.config.json';
|
2021-05-13 09:18:49 +05:30
|
|
|
import { GlossaryTermEntity } from '../../app/entity/glossaryTerm/GlossaryTermEntity';
|
2021-07-21 02:42:21 +08:00
|
|
|
import { MLFeatureTableEntity } from '../../app/entity/mlFeatureTable/MLFeatureTableEntity';
|
2021-07-28 20:39:05 -07:00
|
|
|
import { MLModelEntity } from '../../app/entity/mlModel/MLModelEntity';
|
|
|
|
import { MLModelGroupEntity } from '../../app/entity/mlModelGroup/MLModelGroupEntity';
|
2021-10-19 22:20:31 -07:00
|
|
|
import { ChartEntity } from '../../app/entity/chart/ChartEntity';
|
|
|
|
import { DashboardEntity } from '../../app/entity/dashboard/DashboardEntity';
|
2021-03-09 23:14:52 -08:00
|
|
|
|
2021-02-05 14:21:04 -08:00
|
|
|
type Props = {
|
|
|
|
children: React.ReactNode;
|
2021-02-22 22:25:20 -08:00
|
|
|
initialEntries?: string[];
|
2021-02-05 14:21:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export function getTestEntityRegistry() {
|
|
|
|
const entityRegistry = new EntityRegistry();
|
|
|
|
entityRegistry.register(new DatasetEntity());
|
2021-10-19 22:20:31 -07:00
|
|
|
entityRegistry.register(new ChartEntity());
|
|
|
|
entityRegistry.register(new DashboardEntity());
|
2021-02-05 14:21:04 -08:00
|
|
|
entityRegistry.register(new UserEntity());
|
2021-08-16 20:47:18 -07:00
|
|
|
entityRegistry.register(new GroupEntity());
|
2021-03-07 11:26:47 -08:00
|
|
|
entityRegistry.register(new TagEntity());
|
2021-04-21 12:06:31 -07:00
|
|
|
entityRegistry.register(new DataFlowEntity());
|
|
|
|
entityRegistry.register(new DataJobEntity());
|
2021-05-13 09:18:49 +05:30
|
|
|
entityRegistry.register(new GlossaryTermEntity());
|
2021-07-21 02:42:21 +08:00
|
|
|
entityRegistry.register(new MLFeatureTableEntity());
|
2021-07-28 20:39:05 -07:00
|
|
|
entityRegistry.register(new MLModelEntity());
|
|
|
|
entityRegistry.register(new MLModelGroupEntity());
|
2021-02-05 14:21:04 -08:00
|
|
|
return entityRegistry;
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:25:20 -08:00
|
|
|
export default ({ children, initialEntries }: Props) => {
|
2021-02-05 14:21:04 -08:00
|
|
|
const entityRegistry = useMemo(() => getTestEntityRegistry(), []);
|
2021-05-03 07:51:46 -07:00
|
|
|
Object.defineProperty(window.document, 'cookie', {
|
|
|
|
writable: true,
|
2021-08-02 22:48:22 +08:00
|
|
|
value: `${CLIENT_AUTH_COOKIE}=urn:li:corpuser:2`,
|
2021-05-03 07:51:46 -07:00
|
|
|
});
|
2021-08-02 22:48:22 +08:00
|
|
|
jest.mock('js-cookie', () => ({ get: () => 'urn:li:corpuser:2' }));
|
|
|
|
|
2021-02-05 14:21:04 -08:00
|
|
|
return (
|
2021-03-09 23:14:52 -08:00
|
|
|
<ThemeProvider theme={defaultThemeConfig}>
|
|
|
|
<MemoryRouter initialEntries={initialEntries}>
|
|
|
|
<EntityRegistryContext.Provider value={entityRegistry}>{children}</EntityRegistryContext.Provider>
|
|
|
|
</MemoryRouter>
|
|
|
|
</ThemeProvider>
|
2021-02-05 14:21:04 -08:00
|
|
|
);
|
|
|
|
};
|