@@ -107,6 +108,7 @@ exports[`Datafile details panel component should render correctly 1`] = `
exports[`Datafile details panel component should render parameters tab when present in the data 1`] = `
diff --git a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/datasetDetailsPanel.component.test.tsx.snap b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/datasetDetailsPanel.component.test.tsx.snap
index edf6cda09..007b136c8 100644
--- a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/datasetDetailsPanel.component.test.tsx.snap
+++ b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/datasetDetailsPanel.component.test.tsx.snap
@@ -3,6 +3,7 @@
exports[`Dataset details panel component should render correctly 1`] = `
@@ -146,6 +147,7 @@ exports[`Dataset details panel component should render correctly 1`] = `
exports[`Dataset details panel component should render type tab when present in the data 1`] = `
diff --git a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/instrumentDetailsPanel.component.test.tsx.snap b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/instrumentDetailsPanel.component.test.tsx.snap
index 66b64b473..4cc2f1fd4 100644
--- a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/instrumentDetailsPanel.component.test.tsx.snap
+++ b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/instrumentDetailsPanel.component.test.tsx.snap
@@ -3,6 +3,7 @@
exports[`Instrument details panel component should gracefully handle InstrumentScientists without Users 1`] = `
@@ -158,6 +159,7 @@ exports[`Instrument details panel component should gracefully handle InstrumentS
exports[`Instrument details panel component should render correctly 1`] = `
@@ -283,6 +285,7 @@ exports[`Instrument details panel component should render correctly 1`] = `
exports[`Instrument details panel component should render users tab when present in the data 1`] = `
diff --git a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/investigationDetailsPanel.component.test.tsx.snap b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/investigationDetailsPanel.component.test.tsx.snap
index 8433f2906..687f63aa9 100644
--- a/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/investigationDetailsPanel.component.test.tsx.snap
+++ b/packages/datagateway-common/src/detailsPanels/isis/__snapshots__/investigationDetailsPanel.component.test.tsx.snap
@@ -3,6 +3,7 @@
exports[`Investigation details panel component should check if multiple publications result in change of title to plural version 1`] = `
@@ -247,6 +248,7 @@ exports[`Investigation details panel component should check if multiple publicat
exports[`Investigation details panel component should check if multiple samples result in change of title to plural version 1`] = `
@@ -491,6 +493,7 @@ exports[`Investigation details panel component should check if multiple samples
exports[`Investigation details panel component should gracefully handles StudyInvestigations without Studies and InvestigationUsers without Users 1`] = `
@@ -693,6 +696,7 @@ exports[`Investigation details panel component should gracefully handles StudyIn
exports[`Investigation details panel component should render correctly 1`] = `
@@ -885,6 +889,7 @@ exports[`Investigation details panel component should render correctly 1`] = `
exports[`Investigation details panel component should render user, sample and publication tabs when present in the data 1`] = `
diff --git a/packages/datagateway-common/src/detailsPanels/isis/datafileDetailsPanel.component.tsx b/packages/datagateway-common/src/detailsPanels/isis/datafileDetailsPanel.component.tsx
index a92fe0991..b7d74929c 100644
--- a/packages/datagateway-common/src/detailsPanels/isis/datafileDetailsPanel.component.tsx
+++ b/packages/datagateway-common/src/detailsPanels/isis/datafileDetailsPanel.component.tsx
@@ -85,7 +85,11 @@ const DatafileDetailsPanel = (
}, [selectedTab, data, changeTab]);
return (
-
+
+
+
+
{
- it('receives and uses the theme options', () => {
- // Create a basic theme.
- const theme = createTheme({
- palette: {
- mode: 'dark',
- },
- });
-
- const wrapper = shallow(
+ it('uses default theme before receiving theme event', () => {
+ render(
- Test
+
+ test
+
);
- // Dispatch the theme options event.
+ // value taken from https://mui.com/material-ui/customization/default-theme/
+ // (default value is #1976d2)
+ // mui converts the hex value to CSS rgb expression
+
+ expect(screen.getByTestId('box')).toHaveStyle(
+ 'background-color: rgb(25, 118, 210);'
+ );
+ });
+
+ it('uses the theme sent through the theme event', () => {
document.dispatchEvent(
new CustomEvent(MicroFrontendId, {
detail: {
type: SendThemeOptionsType,
payload: {
- theme,
+ theme: createTheme({
+ palette: {
+ primary: {
+ main: '#123456',
+ },
+ },
+ }),
},
},
})
);
- // Force update the wrapper as the state will not
- // update since the theme options are from a global variable.
- wrapper.instance().forceUpdate();
+ render(
+
+
+ test
+
+
+ );
+
+ expect(screen.getByTestId('box')).toHaveStyle(
+ 'background-color: rgb(18, 52, 86);'
+ );
+ });
- expect(wrapper.childAt(0).props()).toHaveProperty('theme');
- expect(wrapper.childAt(0).prop('theme')).toEqual(theme);
+ it('ignores non-theme events', () => {
+ document.dispatchEvent(
+ new CustomEvent(MicroFrontendId, {
+ detail: {
+ type: SendThemeOptionsType,
+ payload: {
+ theme: createTheme({
+ palette: {
+ primary: {
+ main: '#abcdef',
+ },
+ },
+ }),
+ },
+ },
+ })
+ );
+
+ document.dispatchEvent(
+ new CustomEvent(MicroFrontendId, {
+ detail: {
+ type: 'ImposterEvent',
+ payload: {
+ theme: createTheme(),
+ yellow: 'sus',
+ },
+ },
+ })
+ );
+
+ render(
+
+
+ test
+
+
+ );
+
+ // value taken from https://mui.com/material-ui/customization/default-theme/
+ // (default value is #1976d2)
+ // mui converts the hex value to CSS rgb expression
+
+ // expect the dispatched theme to be used.
+ expect(screen.getByTestId('box')).toHaveStyle(
+ 'background-color: rgb(171, 205, 239);'
+ );
});
});
diff --git a/packages/datagateway-common/src/homePage/__snapshots__/homePage.component.test.tsx.snap b/packages/datagateway-common/src/homePage/__snapshots__/homePage.component.test.tsx.snap
index b551682fe..eacddbf4e 100644
--- a/packages/datagateway-common/src/homePage/__snapshots__/homePage.component.test.tsx.snap
+++ b/packages/datagateway-common/src/homePage/__snapshots__/homePage.component.test.tsx.snap
@@ -1,54 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Home page component homepage renders correctly 1`] = `
-
+
-
-
-
Data discovery
@@ -57,390 +24,233 @@ exports[`Home page component homepage renders correctly 1`] = `
access
-
-
-
-
+
for
large-scale
science facilities
-
-
-
+
+
+
-
-
-
-
-
-
-
- home_page.browse.title
-
-
- home_page.browse.description1
-
-
-
+ home_page.browse.title
+
+
+ home_page.browse.description1
+
+
DataGateway
focuses on providing data discovery and data access functionality to the data.
-
-
-
-
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
- home_page.search.title
-
-
- home_page.search.description
-
-
-
- home_page.search.button
-
-
-
-
-
-
-
+
+
+
+
+ home_page.search.title
+
+
+ home_page.search.description
+
+
+
+
+
+
-
-
-
-
-
- home_page.download.title
-
-
- home_page.download.description
-
-
-
- home_page.download.button
-
-
-
-
-
-
-
+
+
+
+
+ home_page.download.title
+
+
+ home_page.download.description
+
+
+
+
+
+
-
-
- home_page.facility.title
-
-
- home_page.facility.description
-
-
-
+ home_page.facility.title
+
+
+ home_page.facility.description
+
+
+
+
-
-
-
-
-
+
+
+
+
+
`;
diff --git a/packages/datagateway-common/src/homePage/homePage.component.test.tsx b/packages/datagateway-common/src/homePage/homePage.component.test.tsx
index 07a8256a0..85c040c17 100644
--- a/packages/datagateway-common/src/homePage/homePage.component.test.tsx
+++ b/packages/datagateway-common/src/homePage/homePage.component.test.tsx
@@ -1,6 +1,7 @@
import React from 'react';
-import { shallow } from 'enzyme';
import HomePage, { HomePageProps } from './homePage.component';
+import { render } from '@testing-library/react';
+import { MemoryRouter } from 'react-router-dom';
describe('Home page component', () => {
let props: HomePageProps;
@@ -20,7 +21,11 @@ describe('Home page component', () => {
});
it('homepage renders correctly', () => {
- const wrapper = shallow(
);
- expect(wrapper).toMatchSnapshot();
+ const { asFragment } = render(
+
+
+
+ );
+ expect(asFragment()).toMatchSnapshot();
});
});
diff --git a/packages/datagateway-common/src/hooks/useSticky.test.ts b/packages/datagateway-common/src/hooks/useSticky.test.ts
new file mode 100644
index 000000000..23bac3067
--- /dev/null
+++ b/packages/datagateway-common/src/hooks/useSticky.test.ts
@@ -0,0 +1,86 @@
+import { renderHook } from '@testing-library/react-hooks';
+import useSticky from './useSticky';
+import { fireEvent } from '@testing-library/react';
+
+describe('useSticky', () => {
+ it('returns isSticky true if the bottom of the target element is scrolled past', () => {
+ const mockGetBoundingClientRect = jest.fn();
+ const target = document.createElement('div');
+ target.getBoundingClientRect = mockGetBoundingClientRect;
+
+ // if window scrollY is greater than boundingClientRect bottom
+ // that means the element is scrolled out of view
+ global.scrollY = 100;
+ mockGetBoundingClientRect.mockReturnValue({
+ bottom: 50,
+ });
+
+ const { waitFor, result } = renderHook(() =>
+ useSticky({ current: target })
+ );
+
+ // scroll the window
+ fireEvent.scroll(window, {});
+
+ waitFor(() => {
+ expect(result.current.isSticky).toBe(true);
+ });
+ });
+
+ it('returns isSticky false if the bottom of the target element is still in view', () => {
+ const mockGetBoundingClientRect = jest.fn();
+ const target = document.createElement('div');
+ target.getBoundingClientRect = mockGetBoundingClientRect;
+
+ // if window scrollY is greater than boundingClientRect bottom
+ // that means the element is scrolled out of view
+ global.scrollY = 100;
+ mockGetBoundingClientRect.mockReturnValue({
+ bottom: 150,
+ });
+
+ const { waitFor, result } = renderHook(() =>
+ useSticky({ current: target })
+ );
+
+ // scroll the window
+ fireEvent.scroll(window, {});
+
+ waitFor(() => {
+ expect(result.current.isSticky).toBe(false);
+ });
+ });
+
+ it('returns isSticky false upon window scroll if the given react ref points to null', () => {
+ const { waitFor, result } = renderHook(() => useSticky({ current: null }));
+ // scroll the window
+ fireEvent.scroll(window, {});
+ waitFor(() => {
+ expect(result.current.isSticky).toBe(false);
+ });
+ });
+
+ it('returns isStick false upon window scroll if bottom coordinate of the target element is unavailable', () => {
+ const mockGetBoundingClientRect = jest.fn();
+ const target = document.createElement('div');
+ target.getBoundingClientRect = mockGetBoundingClientRect;
+
+ // if window scrollY is greater than boundingClientRect bottom
+ // that means the element is scrolled out of view
+ global.scrollY = 100;
+ mockGetBoundingClientRect.mockReturnValue({
+ top: 150,
+ });
+
+ const { waitFor, result } = renderHook(() =>
+ useSticky({ current: target })
+ );
+
+ // scroll the window
+ fireEvent.scroll(window, {});
+
+ waitFor(() => {
+ expect(result.current.isSticky).toBe(false);
+ });
+ });
+});
diff --git a/packages/datagateway-common/src/hooks/useSticky.ts b/packages/datagateway-common/src/hooks/useSticky.ts
new file mode 100644
index 000000000..aeb12c51f
--- /dev/null
+++ b/packages/datagateway-common/src/hooks/useSticky.ts
@@ -0,0 +1,36 @@
+import React from 'react';
+import debounce from 'lodash.debounce';
+
+function useSticky(targetElement: React.RefObject
): {
+ isSticky: boolean;
+} {
+ const [isSticky, setIsSticky] = React.useState(false);
+
+ const handleScroll = React.useCallback((): void => {
+ if (
+ targetElement.current &&
+ targetElement.current.getBoundingClientRect().bottom
+ ) {
+ if (
+ window.scrollY > targetElement.current.getBoundingClientRect().bottom
+ ) {
+ setIsSticky(true);
+ } else {
+ setIsSticky(false);
+ }
+ }
+ }, [targetElement]);
+
+ React.useEffect(() => {
+ // Use lodash.debounce for handleScroll with a wait of 20ms.
+ window.addEventListener('scroll', debounce(handleScroll, 20));
+
+ return () => {
+ window.removeEventListener('scroll', () => handleScroll);
+ };
+ }, [handleScroll]);
+
+ return { isSticky };
+}
+
+export default useSticky;
diff --git a/packages/datagateway-common/src/index.tsx b/packages/datagateway-common/src/index.tsx
index aa77e92fa..3bf565712 100644
--- a/packages/datagateway-common/src/index.tsx
+++ b/packages/datagateway-common/src/index.tsx
@@ -77,6 +77,6 @@ export { default as DLSDatasetDetailsPanel } from './detailsPanels/dls/datasetDe
export { default as DLSVisitDetailsPanel } from './detailsPanels/dls/visitDetailsPanel.component';
export { default as InvestigationDetailsPanel } from './detailsPanels/investigationDetailsPanel.component';
export { default as DatasetDetailsPanel } from './detailsPanels/datasetDetailsPanel.component';
-export { default as DatafileDetailsPanel } from './detailsPanels/datasetDetailsPanel.component';
+export { default as DatafileDetailsPanel } from './detailsPanels/datafileDetailsPanel.component';
// ReactDOM.render(, document.getElementById('root'));
diff --git a/packages/datagateway-common/src/preloader/__snapshots__/preloader.component.test.tsx.snap b/packages/datagateway-common/src/preloader/__snapshots__/preloader.component.test.tsx.snap
index edee2ed52..91c6aa27e 100644
--- a/packages/datagateway-common/src/preloader/__snapshots__/preloader.component.test.tsx.snap
+++ b/packages/datagateway-common/src/preloader/__snapshots__/preloader.component.test.tsx.snap
@@ -1,180 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Preloader component does not render when the site is not loading 1`] = ``;
+exports[`Preloader component does not render when the site is not loading 1`] = `
+
+
+
+`;
exports[`Preloader component renders when the site is loading 1`] = `
-
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ Loading...
-
- Loading...
-
-
-
+
+
`;
diff --git a/packages/datagateway-common/src/preloader/preloader.component.test.tsx b/packages/datagateway-common/src/preloader/preloader.component.test.tsx
index fcad4d6a5..1a234e533 100644
--- a/packages/datagateway-common/src/preloader/preloader.component.test.tsx
+++ b/packages/datagateway-common/src/preloader/preloader.component.test.tsx
@@ -1,15 +1,15 @@
-import React from 'react';
+import { render } from '@testing-library/react';
+import * as React from 'react';
import Preloader from './preloader.component';
-import { shallow } from 'enzyme';
describe('Preloader component', () => {
- it('renders when the site is loading', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('renders when the site is loading', async () => {
+ const { asFragment } = render();
+ expect(asFragment()).toMatchSnapshot();
});
- it('does not render when the site is not loading', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('does not render when the site is not loading', async () => {
+ const { asFragment } = render();
+ expect(asFragment()).toMatchSnapshot();
});
});
diff --git a/packages/datagateway-common/src/setupTests.tsx b/packages/datagateway-common/src/setupTests.tsx
index f56f55044..2ef17f1cc 100644
--- a/packages/datagateway-common/src/setupTests.tsx
+++ b/packages/datagateway-common/src/setupTests.tsx
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import '@testing-library/jest-dom';
import React from 'react';
-import Enzyme from 'enzyme';
-import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { Action } from 'redux';
import { StateType } from './state/app.types';
import { initialState } from './state/reducers/dgcommon.reducer';
@@ -17,9 +15,6 @@ import { createMemoryHistory, History } from 'history';
jest.setTimeout(15000);
-// Unofficial React 17 Enzyme adapter
-Enzyme.configure({ adapter: new Adapter() });
-
if (typeof window.URL.createObjectURL === 'undefined') {
// required as work-around for enzyme/jest environment not implementing window.URL.createObjectURL method
Object.defineProperty(window.URL, 'createObjectURL', {
diff --git a/packages/datagateway-common/src/sticky.component.test.tsx b/packages/datagateway-common/src/sticky.component.test.tsx
index 58af59c88..86df4256a 100644
--- a/packages/datagateway-common/src/sticky.component.test.tsx
+++ b/packages/datagateway-common/src/sticky.component.test.tsx
@@ -1,118 +1,46 @@
import React from 'react';
-import { mount, shallow, ReactWrapper } from 'enzyme';
-import Sticky, { useSticky } from './sticky.component';
-import { Paper } from '@mui/material';
-import { act, renderHook } from '@testing-library/react-hooks';
+import { render, screen } from '@testing-library/react';
+import Sticky from './sticky.component';
+import useSticky from './hooks/useSticky';
-describe('Sticky component', () => {
- const createShallowWrapper = (): ReactWrapper => {
- return shallow(
-
-
-
- );
- };
+jest.mock('./hooks/useSticky', () => ({
+ __esModule: true,
+ default: jest.fn(),
+}));
- const createWrapper = (): ReactWrapper => {
- return mount(
+describe('Sticky component', () => {
+ it('renders children with fixed position and 100% width when sticky', async () => {
+ (useSticky as jest.MockedFn).mockReturnValue({
+ isSticky: true,
+ });
+ render(
);
- };
-
- const currentMock: HTMLDivElement = document.createElement('div');
- const dimensionsMock = {
- height: 0,
- width: 0,
- x: 0,
- y: 0,
- bottom: 1,
- left: 0,
- right: 0,
- top: 0,
- toJSON: jest.fn(),
- };
-
- it('eventListener added and removed with useEffect', () => {
- // Allow cleanUp to be called manually
- let cleanUp;
- const spyUseEffect = jest
- .spyOn(React, 'useEffect')
- .mockImplementation((f) => {
- cleanUp = f();
- });
- const spyAdd = jest.spyOn(window, 'addEventListener');
- const spyRemove = jest.spyOn(window, 'removeEventListener');
-
- createShallowWrapper();
- expect(spyAdd).toHaveBeenCalledTimes(1);
- expect(spyRemove).toHaveBeenCalledTimes(0);
-
- cleanUp();
- expect(spyAdd).toHaveBeenCalledTimes(1);
- expect(spyRemove).toHaveBeenCalledTimes(1);
-
- spyUseEffect.mockRestore();
- spyAdd.mockRestore();
- spyRemove.mockRestore();
- });
- it('handleScroll does nothing when target undefined', () => {
- // Allow handleScroll to be called manually
- let handleScrollMock;
- const spyUseCallback = jest
- .spyOn(React, 'useCallback')
- .mockImplementation((f) => {
- handleScrollMock = f;
- return f;
- });
+ const paper = screen.getByTestId('sticky-paper');
- // Elevation is initially 0 (not stickied)
- const wrapper = createWrapper();
- expect(wrapper.find(Paper).props().elevation).toEqual(0);
-
- // Mock scrolling beyond bottom of getBoundingClientRect
- Object.defineProperty(global.window, 'scrollY', { value: 2 });
- handleScrollMock();
- expect(wrapper.find(Paper).props().elevation).toEqual(0);
-
- spyUseCallback.mockRestore();
+ // should be elevated when sticky
+ expect(paper).toHaveStyle(
+ 'z-index: 9; position: fixed; width: 100%; top: 0'
+ );
});
- it('useSticky works correctly', () => {
- // Allow handleScroll to be called manually
- let handleScrollMock;
- const spyUseCallback = jest
- .spyOn(React, 'useCallback')
- .mockImplementation((f) => {
- handleScrollMock = f;
- return f;
- });
- const spyGetRect = jest
- .spyOn(currentMock, 'getBoundingClientRect')
- .mockImplementation(() => {
- return dimensionsMock;
- });
- const { result } = renderHook(() => useSticky({ current: currentMock }));
-
- Object.defineProperty(global.window, 'scrollY', { value: 0 });
- act(() => {
- handleScrollMock();
- });
-
- expect(result.current.isSticky).toEqual(false);
-
- Object.defineProperty(global.window, 'scrollY', { value: 2 });
- act(() => {
- handleScrollMock();
+ it('renders children normally when not sticky', () => {
+ (useSticky as jest.MockedFn).mockReturnValue({
+ isSticky: false,
});
+ render(
+
+
+
+ );
- expect(result.current.isSticky).toEqual(true);
+ const paper = screen.getByTestId('sticky-paper');
- spyUseCallback.mockRestore();
- spyGetRect.mockRestore();
+ // should not be elevated
+ expect(paper).not.toHaveStyle('position: fixed; width: 100%; top: 0');
+ expect(paper).toHaveStyle('z-index: 9');
});
-
- // Sticky functionality tested in dataview e2e breadcrumbs tests
});
diff --git a/packages/datagateway-common/src/sticky.component.tsx b/packages/datagateway-common/src/sticky.component.tsx
index f45e15167..edc8179a1 100644
--- a/packages/datagateway-common/src/sticky.component.tsx
+++ b/packages/datagateway-common/src/sticky.component.tsx
@@ -1,39 +1,7 @@
import React from 'react';
import { keyframes, Paper, styled } from '@mui/material';
-import debounce from 'lodash.debounce';
-
-export function useSticky(targetElement: React.RefObject): {
- isSticky: boolean;
-} {
- const [isSticky, setIsSticky] = React.useState(false);
-
- const handleScroll = React.useCallback((): void => {
- if (
- targetElement.current &&
- targetElement.current.getBoundingClientRect().bottom
- ) {
- if (
- window.scrollY > targetElement.current.getBoundingClientRect().bottom
- ) {
- setIsSticky(true);
- } else {
- setIsSticky(false);
- }
- }
- }, [targetElement]);
-
- React.useEffect(() => {
- // Use lodash.debounce for handleScroll with a wait of 20ms.
- window.addEventListener('scroll', debounce(handleScroll, 20));
-
- return () => {
- window.removeEventListener('scroll', () => handleScroll);
- };
- }, [handleScroll]);
-
- return { isSticky };
-}
+import useSticky from './hooks/useSticky';
const moveDown = keyframes`
from {
@@ -77,6 +45,7 @@ const Sticky = (props: { children: React.ReactNode }): React.ReactElement => {
// Wrap navbar components in Paper to allow for when
// it is sticky to stand out on the page when scrolling.
-
-
+
+
+
+ Rendered an action using test!
+
+
+
`;
exports[`Action cell component renders no actions correctly 1`] = `
-
+
+
+
`;
diff --git a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/cellContentRenderers.test.tsx.snap b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/cellContentRenderers.test.tsx.snap
deleted file mode 100644
index e4219fc3e..000000000
--- a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/cellContentRenderers.test.tsx.snap
+++ /dev/null
@@ -1,64 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`Cell content renderers datasetLink renders correctly 1`] = `
-
- test
-
-`;
-
-exports[`Cell content renderers investigationLink renders correctly 1`] = `
-
- test
-
-`;
-
-exports[`Cell content renderers tableLink renders correctly 1`] = `
-
- test text
-
-`;
diff --git a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/dataCell.component.test.tsx.snap b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/dataCell.component.test.tsx.snap
index 41551ea48..b9f68e7f7 100644
--- a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/dataCell.component.test.tsx.snap
+++ b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/dataCell.component.test.tsx.snap
@@ -1,141 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Data cell component renders correctly 1`] = `
-
-
+
-
non nested property
-
-
-
-
+
`;
exports[`Data cell component renders nested cell data correctly 1`] = `
-
-
+
-
nested property
-
-
-
-
+
`;
exports[`Data cell component renders provided cell data correctly 1`] = `
-
-
+
-
provided test
-
-
-
-
+
`;
diff --git a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/expandCell.component.test.tsx.snap b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/expandCell.component.test.tsx.snap
index 6265c2ecf..ab35deda1 100644
--- a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/expandCell.component.test.tsx.snap
+++ b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/expandCell.component.test.tsx.snap
@@ -1,36 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Expand cell component renders correctly when expanded 1`] = `
-
-
+
+
`;
exports[`Expand cell component renders correctly when not expanded 1`] = `
-
-
+
+
`;
diff --git a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/selectCell.component.test.tsx.snap b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/selectCell.component.test.tsx.snap
index 47a33262b..15ff48788 100644
--- a/packages/datagateway-common/src/table/cellRenderers/__snapshots__/selectCell.component.test.tsx.snap
+++ b/packages/datagateway-common/src/table/cellRenderers/__snapshots__/selectCell.component.test.tsx.snap
@@ -1,219 +1,202 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Select cell component renders correctly when checked 1`] = `
-
-
+
+
`;
exports[`Select cell component renders correctly when selectedRows is undefined 1`] = `
-
-
+
+
`;
exports[`Select cell component renders correctly when selectedRows loading is true 1`] = `
-
-
+
+
`;
exports[`Select cell component renders correctly when selectedRows parentSelected is true 1`] = `
-
-
+
+
`;
exports[`Select cell component renders correctly when unchecked 1`] = `
-
-
+
+
`;
diff --git a/packages/datagateway-common/src/table/cellRenderers/actionCell.component.test.tsx b/packages/datagateway-common/src/table/cellRenderers/actionCell.component.test.tsx
index 014426cfc..a44943d73 100644
--- a/packages/datagateway-common/src/table/cellRenderers/actionCell.component.test.tsx
+++ b/packages/datagateway-common/src/table/cellRenderers/actionCell.component.test.tsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { shallow } from 'enzyme';
+import { render } from '@testing-library/react';
+import * as React from 'react';
import ActionCell from './actionCell.component';
import { TableActionProps } from '../table.component';
@@ -13,13 +13,15 @@ describe('Action cell component', () => {
className: 'test-class',
};
- it('renders no actions correctly', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('renders no actions correctly', async () => {
+ const { asFragment } = render(
+
+ );
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders an action correctly', () => {
- const wrapper = shallow(
+ it('renders an action correctly', async () => {
+ const { asFragment } = render(
{
]}
/>
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
});
diff --git a/packages/datagateway-common/src/table/cellRenderers/cellContentRenderers.test.tsx b/packages/datagateway-common/src/table/cellRenderers/cellContentRenderers.test.tsx
index 2b4c6c16a..0035a45f9 100644
--- a/packages/datagateway-common/src/table/cellRenderers/cellContentRenderers.test.tsx
+++ b/packages/datagateway-common/src/table/cellRenderers/cellContentRenderers.test.tsx
@@ -1,15 +1,13 @@
import React from 'react';
-import { shallow } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';
-import { Link } from '@mui/material';
import {
- formatBytes,
datasetLink,
- investigationLink,
- tableLink,
+ filterStudyInfoInvestigations,
+ formatBytes,
formatCountOrSize,
getStudyInfoInvestigation,
- filterStudyInfoInvestigations,
+ investigationLink,
+ tableLink,
} from './cellContentRenderers';
import type {
DateFilter,
@@ -17,6 +15,7 @@ import type {
Study,
TextFilter,
} from '../../app.types';
+import { render, screen } from '@testing-library/react';
describe('Cell content renderers', () => {
describe('formatBytes', () => {
@@ -345,28 +344,37 @@ describe('Cell content renderers', () => {
describe('datasetLink', () => {
it('renders correctly', () => {
- const wrapper = shallow(
+ render(
{datasetLink('1', 2, 'test', 'card')}
);
- expect(wrapper.find(Link)).toMatchSnapshot();
+ expect(screen.getByRole('link', { name: 'test' })).toHaveAttribute(
+ 'href',
+ '/browse/investigation/1/dataset/2/datafile?view=card'
+ );
});
});
describe('investigationLink', () => {
it('renders correctly', () => {
- const wrapper = shallow(
+ render(
{investigationLink(1, 'test', 'card')}
);
- expect(wrapper.find(Link)).toMatchSnapshot();
+ expect(screen.getByRole('link', { name: 'test' })).toHaveAttribute(
+ 'href',
+ '/browse/investigation/1/dataset?view=card'
+ );
});
});
describe('tableLink', () => {
it('renders correctly', () => {
- const wrapper = shallow(
+ render(
{tableLink('/test/url', 'test text')}
);
- expect(wrapper.find(Link)).toMatchSnapshot();
+ expect(screen.getByRole('link', { name: 'test text' })).toHaveAttribute(
+ 'href',
+ '/test/url'
+ );
});
});
});
diff --git a/packages/datagateway-common/src/table/cellRenderers/dataCell.component.test.tsx b/packages/datagateway-common/src/table/cellRenderers/dataCell.component.test.tsx
index 64c3c17e3..410f9e2f3 100644
--- a/packages/datagateway-common/src/table/cellRenderers/dataCell.component.test.tsx
+++ b/packages/datagateway-common/src/table/cellRenderers/dataCell.component.test.tsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { shallow } from 'enzyme';
+import { render } from '@testing-library/react';
+import * as React from 'react';
import DataCell from './dataCell.component';
describe('Data cell component', () => {
@@ -10,37 +10,37 @@ describe('Data cell component', () => {
rowIndex: 1,
rowData: {
test: 'non nested property',
- nested: { test: 'nested property' },
+ nested: {
+ test: 'nested property',
+ },
},
};
- it('renders correctly', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('renders correctly', async () => {
+ const { asFragment } = render();
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders provided cell data correctly', () => {
- const wrapper = shallow(
+ it('renders provided cell data correctly', async () => {
+ const { asFragment } = render(
{'provided test'}}
/>
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders nested cell data correctly', () => {
- const wrapper = shallow(
+ it('renders nested cell data correctly', async () => {
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('gracefully handles invalid dataKeys', () => {
- shallow();
-
- shallow();
-
- shallow();
+ it('gracefully handles invalid dataKeys', async () => {
+ render();
+ render();
+ render();
});
});
diff --git a/packages/datagateway-common/src/table/cellRenderers/expandCell.component.test.tsx b/packages/datagateway-common/src/table/cellRenderers/expandCell.component.test.tsx
index e7be5932c..860030baa 100644
--- a/packages/datagateway-common/src/table/cellRenderers/expandCell.component.test.tsx
+++ b/packages/datagateway-common/src/table/cellRenderers/expandCell.component.test.tsx
@@ -1,8 +1,11 @@
-import React from 'react';
-import { shallow } from 'enzyme';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import type { UserEvent } from '@testing-library/user-event/setup/setup';
+import * as React from 'react';
import ExpandCell from './expandCell.component';
describe('Expand cell component', () => {
+ let user: UserEvent;
const setExpandedIndex = jest.fn();
const expandCellProps = {
columnIndex: 1,
@@ -14,35 +17,39 @@ describe('Expand cell component', () => {
setExpandedIndex,
};
+ beforeEach(() => {
+ user = userEvent.setup();
+ });
+
afterEach(() => {
setExpandedIndex.mockClear();
});
- it('renders correctly when expanded', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('renders correctly when expanded', async () => {
+ const { asFragment } = render();
+ expect(asFragment()).toMatchSnapshot();
});
- it('sets the expanded index to -1 when ExpandLess button is pressed', () => {
- const wrapper = shallow();
-
- wrapper.childAt(0).prop('onClick')();
+ it('sets the expanded index to -1 when ExpandLess button is pressed', async () => {
+ render();
+ await user.click(
+ await screen.findByRole('button', { name: 'Hide details' })
+ );
expect(setExpandedIndex).toHaveBeenCalledWith(-1);
});
- it('renders correctly when not expanded', () => {
- const wrapper = shallow(
+ it('renders correctly when not expanded', async () => {
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('sets the expanded index to rowIndex when ExpandMore button is pressed', () => {
- const wrapper = shallow(
-
+ it('sets the expanded index to rowIndex when ExpandMore button is pressed', async () => {
+ render();
+ await user.click(
+ await screen.findByRole('button', { name: 'Show details' })
);
-
- wrapper.childAt(0).prop('onClick')();
expect(setExpandedIndex).toHaveBeenCalledWith(expandCellProps.rowIndex);
});
});
diff --git a/packages/datagateway-common/src/table/cellRenderers/selectCell.component.test.tsx b/packages/datagateway-common/src/table/cellRenderers/selectCell.component.test.tsx
index d2d83d57e..9fd588a49 100644
--- a/packages/datagateway-common/src/table/cellRenderers/selectCell.component.test.tsx
+++ b/packages/datagateway-common/src/table/cellRenderers/selectCell.component.test.tsx
@@ -1,8 +1,11 @@
+import { fireEvent, render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import type { UserEvent } from '@testing-library/user-event/setup/setup';
import React from 'react';
-import { shallow } from 'enzyme';
import SelectCell from './selectCell.component';
describe('Select cell component', () => {
+ let user: UserEvent;
const setLastChecked = jest.fn();
const onCheck = jest.fn();
const onUncheck = jest.fn();
@@ -36,100 +39,99 @@ describe('Select cell component', () => {
loading: false,
};
+ beforeEach(() => {
+ user = userEvent.setup();
+ });
+
afterEach(() => {
setLastChecked.mockClear();
onCheck.mockClear();
onUncheck.mockClear();
});
- it('renders correctly when unchecked', () => {
- const wrapper = shallow();
- expect(wrapper).toMatchSnapshot();
+ it('renders correctly when unchecked', async () => {
+ const { asFragment } = render();
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders correctly when checked', () => {
- const wrapper = shallow(
+ it('renders correctly when checked', async () => {
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders correctly when selectedRows is undefined', () => {
- const wrapper = shallow(
+ it('renders correctly when selectedRows is undefined', async () => {
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('renders correctly when selectedRows loading is true', () => {
- const wrapper = shallow(
+ it('renders correctly when selectedRows loading is true', async () => {
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
it('renders correctly when selectedRows parentSelected is true', () => {
- const wrapper = shallow(
+ const { asFragment } = render(
);
- expect(wrapper).toMatchSnapshot();
+ expect(asFragment()).toMatchSnapshot();
});
- it('calls setLastChecked when checkbox is clicked', () => {
- const wrapper = shallow();
-
- wrapper.find('.tour-dataview-add-to-cart').prop('onClick')(
- new MouseEvent('click')
+ it('calls setLastChecked when checkbox is clicked', async () => {
+ render();
+ await user.click(
+ await screen.findByRole('checkbox', { name: 'select row 2' })
);
expect(setLastChecked).toHaveBeenCalledWith(2);
});
- it('calls onCheck when the row is unselected and the checkbox is clicked', () => {
- const wrapper = shallow();
-
- wrapper.find('.tour-dataview-add-to-cart').prop('onClick')(
- new MouseEvent('click')
+ it('calls onCheck when the row is unselected and the checkbox is clicked', async () => {
+ render();
+ await user.click(
+ await screen.findByRole('checkbox', { name: 'select row 2' })
);
expect(onCheck).toHaveBeenCalledWith([3]);
});
- it('calls onUncheck when the row is selected and the checkbox is clicked', () => {
- const wrapper = shallow(
-
- );
-
- wrapper.find('.tour-dataview-add-to-cart').prop('onClick')(
- new MouseEvent('click')
+ it('calls onUncheck when the row is selected and the checkbox is clicked', async () => {
+ render();
+ await user.click(
+ await screen.findByRole('checkbox', { name: 'select row 2' })
);
expect(onUncheck).toHaveBeenCalledWith([3]);
});
-
- it('calls onCheck when the row is selected via shift-click and the checkbox is clicked', () => {
- const wrapper = shallow(
-
- );
-
- wrapper.find('.tour-dataview-add-to-cart').prop('onClick')(
- new MouseEvent('click', { shiftKey: true })
+ it('calls onCheck when the row is selected via shift-click and the checkbox is clicked', async () => {
+ render();
+ fireEvent.click(
+ await screen.findByRole('checkbox', {
+ name: 'select row 2',
+ }),
+ { shiftKey: true }
);
expect(onCheck).toHaveBeenCalledWith([1, 2, 3]);
});
-
- it('calls onUncheck when the row is unselected via shift-click and the checkbox is clicked', () => {
- const wrapper = shallow(
+ it('calls onUncheck when the row is unselected via shift-click and the checkbox is clicked', async () => {
+ render(
);
-
- wrapper.find('.tour-dataview-add-to-cart').prop('onClick')(
- new MouseEvent('click', { shiftKey: true })
+ fireEvent.click(
+ await screen.findByRole('checkbox', {
+ name: 'select row 2',
+ }),
+ { shiftKey: true }
);
expect(onUncheck).toHaveBeenCalledWith([1, 2, 3]);
});
diff --git a/packages/datagateway-common/src/table/columnFilters/__snapshots__/dateColumnFilter.component.test.tsx.snap b/packages/datagateway-common/src/table/columnFilters/__snapshots__/dateColumnFilter.component.test.tsx.snap
index 6cdf309c3..10e416a6e 100644
--- a/packages/datagateway-common/src/table/columnFilters/__snapshots__/dateColumnFilter.component.test.tsx.snap
+++ b/packages/datagateway-common/src/table/columnFilters/__snapshots__/dateColumnFilter.component.test.tsx.snap
@@ -1,303 +1,199 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Date filter component CustomClearButton renders correctly 1`] = `
-
- Clear
-
-`;
-
-exports[`Date filter component DatePicker functionality useTextFilter hook returns a function which can generate a working text filter 1`] = `
-
+
+
`;
-exports[`Date filter component DateTimePicker functionality useTextFilter hook returns a function which can generate a working text filter 1`] = `
-
+
+
`;
exports[`Text filter component usePrincipalExperimenterFilter hook returns a function which can generate a working PI filter 1`] = `
-
+
+
+