diff --git a/src/components/ConfirmModal.test.jsx b/src/components/ConfirmModal.test.jsx
index 045dc62cd..0311ed1ab 100644
--- a/src/components/ConfirmModal.test.jsx
+++ b/src/components/ConfirmModal.test.jsx
@@ -1,7 +1,9 @@
-import { shallow } from '@edx/react-unit-test-utils';
-
+import { render } from '@testing-library/react';
import { ConfirmModal } from './ConfirmModal';
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
+
describe('ConfirmModal', () => {
const props = {
isOpen: false,
@@ -12,10 +14,12 @@ describe('ConfirmModal', () => {
onCancel: jest.fn().mockName('this.props.onCancel'),
onConfirm: jest.fn().mockName('this.props.onConfirm'),
};
- test('snapshot: closed', () => {
- expect(shallow().snapshot).toMatchSnapshot();
+ it('should not render content when modal is closed', () => {
+ const { queryByText } = render();
+ expect(queryByText(props.content)).toBeNull();
});
- test('snapshot: open', () => {
- expect(shallow().snapshot).toMatchSnapshot();
+ it('should display content when modal is open', () => {
+ const { getByText } = render();
+ expect(getByText(props.content)).toBeInTheDocument();
});
});
diff --git a/src/components/DemoAlert/__snapshots__/index.test.jsx.snap b/src/components/DemoAlert/__snapshots__/index.test.jsx.snap
deleted file mode 100644
index 9906b50b0..000000000
--- a/src/components/DemoAlert/__snapshots__/index.test.jsx.snap
+++ /dev/null
@@ -1,23 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`DemoAlert component snapshot 1`] = `
-
-
-
- }
- isOpen={true}
- onClose={[MockFunction props.onClose]}
- title="Demo submit prevented"
->
-
- Grade submission is disabled in the Demo mode of the new ORA Staff Grader.
-
-
-`;
diff --git a/src/components/DemoAlert/index.test.jsx b/src/components/DemoAlert/index.test.jsx
index cf0dcecf3..79517bcfe 100644
--- a/src/components/DemoAlert/index.test.jsx
+++ b/src/components/DemoAlert/index.test.jsx
@@ -1,16 +1,34 @@
-import React from 'react';
-import { shallow } from '@edx/react-unit-test-utils';
+import { render, fireEvent } from '@testing-library/react';
import { formatMessage } from 'testUtils';
+import messages from './messages';
import { DemoAlert } from '.';
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
+
describe('DemoAlert component', () => {
- test('snapshot', () => {
- const props = {
- intl: { formatMessage },
- isOpen: true,
- onClose: jest.fn().mockName('props.onClose'),
- };
- expect(shallow().snapshot).toMatchSnapshot();
+ const props = {
+ intl: { formatMessage },
+ isOpen: true,
+ onClose: jest.fn().mockName('props.onClose'),
+ };
+
+ it('does not render when isOpen is false', () => {
+ const { queryByText } = render();
+ expect(queryByText(formatMessage(messages.title))).toBeNull();
+ });
+
+ it('renders with correct title and message when isOpen is true', () => {
+ const { getByText } = render();
+ expect(getByText(formatMessage(messages.title))).toBeInTheDocument();
+ expect(getByText(formatMessage(messages.warningMessage))).toBeInTheDocument();
+ });
+
+ it('calls onClose when confirmation button is clicked', () => {
+ const { getByText } = render();
+ const confirmButton = getByText(formatMessage(messages.confirm));
+ fireEvent.click(confirmButton);
+ expect(props.onClose).toHaveBeenCalled();
});
});
diff --git a/src/components/FilePopoverContent/__snapshots__/index.test.jsx.snap b/src/components/FilePopoverContent/__snapshots__/index.test.jsx.snap
deleted file mode 100644
index 2333113ac..000000000
--- a/src/components/FilePopoverContent/__snapshots__/index.test.jsx.snap
+++ /dev/null
@@ -1,89 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`FilePopoverContent component snapshot default 1`] = `
-
-
-
-
-
-
- some file name
-
-
-
-
-
-
- long descriptive text...
-
-
-
-
-
-
- filesize(6000)
-
-
-`;
-
-exports[`FilePopoverContent component snapshot invalid size 1`] = `
-
-
-
-
-
-
- some file name
-
-
-
-
-
-
- long descriptive text...
-
-
-
-
-
-
- Unknown
-
-
-`;
diff --git a/src/components/FilePopoverContent/index.test.jsx b/src/components/FilePopoverContent/index.test.jsx
index 1f9173505..1ca1eea0e 100644
--- a/src/components/FilePopoverContent/index.test.jsx
+++ b/src/components/FilePopoverContent/index.test.jsx
@@ -1,10 +1,11 @@
-import React from 'react';
-import { shallow } from '@edx/react-unit-test-utils';
+import { render } from '@testing-library/react';
import filesize from 'filesize';
import FilePopoverContent from '.';
jest.mock('filesize', () => (size) => `filesize(${size})`);
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
describe('FilePopoverContent', () => {
describe('component', () => {
@@ -14,24 +15,26 @@ describe('FilePopoverContent', () => {
downloadURL: 'this-url-is.working',
size: 6000,
};
- let el;
- beforeEach(() => {
- el = shallow();
- });
- describe('snapshot', () => {
- test('default', () => expect(el.snapshot).toMatchSnapshot());
- test('invalid size', () => {
- el = shallow();
- expect(el.snapshot).toMatchSnapshot();
- });
- });
describe('behavior', () => {
- test('content', () => {
- const childElements = el.instance.children;
- expect(childElements[0].children[2].el).toContain(props.name);
- expect(childElements[1].children[2].el).toContain(props.description);
- expect(childElements[2].children[2].el).toContain(filesize(props.size));
+ it('renders file name correctly', () => {
+ const { getByText } = render();
+ expect(getByText(props.name)).toBeInTheDocument();
+ });
+
+ it('renders file description correctly', () => {
+ const { getByText } = render();
+ expect(getByText(props.description)).toBeInTheDocument();
+ });
+
+ it('renders file size correctly', () => {
+ const { getByText } = render();
+ expect(getByText(filesize(props.size))).toBeInTheDocument();
+ });
+
+ it('renders "Unknown" when size is null', () => {
+ const { getByText } = render();
+ expect(getByText('Unknown')).toBeInTheDocument();
});
});
});
diff --git a/src/components/FilePreview/FileCard.test.jsx b/src/components/FilePreview/FileCard.test.jsx
index c31579b96..8eb9bd91f 100644
--- a/src/components/FilePreview/FileCard.test.jsx
+++ b/src/components/FilePreview/FileCard.test.jsx
@@ -1,14 +1,10 @@
-import React from 'react';
-import { shallow } from '@edx/react-unit-test-utils';
-
-import { Collapsible } from '@openedx/paragon';
-
-import FilePopoverContent from 'components/FilePopoverContent';
-import FileInfo from './FileInfo';
+import { render, screen } from '@testing-library/react';
import FileCard from './FileCard';
jest.mock('components/FilePopoverContent', () => 'FilePopoverContent');
jest.mock('./FileInfo', () => 'FileInfo');
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
describe('File Preview Card component', () => {
const props = {
@@ -19,24 +15,27 @@ describe('File Preview Card component', () => {
},
};
const children = (
some children
);
- let el;
- beforeEach(() => {
- el = shallow({children});
- });
- test('snapshot', () => {
- expect(el.snapshot).toMatchSnapshot();
- });
+
describe('Component', () => {
- test('collapsible title is name header', () => {
- const { title } = el.instance.findByType(Collapsible)[0].props;
- expect(title).toEqual({props.file.name}
);
+ it('renders with the file name in the title', () => {
+ render({children});
+ expect(screen.getByText(props.file.name)).toBeInTheDocument();
+ expect(screen.getByText(props.file.name)).toHaveClass('file-card-title');
+ });
+
+ it('renders the preview panel with file info', () => {
+ render({children});
+ const previewPanel = screen.getByTestId('preview-panel');
+ expect(previewPanel).toBeInTheDocument();
+ expect(document.querySelector('FileInfo')).toBeInTheDocument();
+ expect(document.querySelector('FilePopoverContent')).toBeInTheDocument();
});
- test('forwards children into preview-panel', () => {
- const previewPanelChildren = el.instance.findByTestId('preview-panel')[0].children;
- expect(previewPanelChildren[0].matches(
- ,
- ));
- expect(previewPanelChildren[1].matches(shallow(children))).toEqual(true);
+
+ it('renders children in the preview panel', () => {
+ render({children});
+ const previewPanel = screen.getByTestId('preview-panel');
+ expect(previewPanel).toBeInTheDocument();
+ expect(screen.getByText('some children')).toBeInTheDocument();
});
});
});
diff --git a/src/components/FilePreview/__snapshots__/FileCard.test.jsx.snap b/src/components/FilePreview/__snapshots__/FileCard.test.jsx.snap
deleted file mode 100644
index fc4fc53fb..000000000
--- a/src/components/FilePreview/__snapshots__/FileCard.test.jsx.snap
+++ /dev/null
@@ -1,36 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`File Preview Card component snapshot 1`] = `
-
-
- test-file-name.pdf
-
- }
- >
-
-
-
-
-
- some children
-
-
-
-
-`;
diff --git a/src/components/StatusBadge.test.jsx b/src/components/StatusBadge.test.jsx
index fd71f7f9f..5aa199021 100644
--- a/src/components/StatusBadge.test.jsx
+++ b/src/components/StatusBadge.test.jsx
@@ -1,34 +1,37 @@
-import React from 'react';
-import { shallow } from '@edx/react-unit-test-utils';
-
+import { render } from '@testing-library/react';
import { gradingStatuses } from 'data/services/lms/constants';
import { StatusBadge } from './StatusBadge';
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
+
const className = 'test-className';
describe('StatusBadge component', () => {
- const render = (status) => shallow();
describe('behavior', () => {
it('does not render if status does not have configured variant', () => {
- const el = render('arbitrary');
- expect(el.snapshot).toMatchSnapshot();
- expect(el.isEmptyRender()).toEqual(true);
+ const { container } = render();
+ expect(container.firstChild).toBeNull();
});
- describe('status snapshots: loads badge with configured variant and message.', () => {
- test('`ungraded` shows primary button variant and message', () => {
- const el = render(gradingStatuses.ungraded);
- expect(el.snapshot).toMatchSnapshot();
+ describe('status rendering: loads badge with configured variant and message', () => {
+ it('`ungraded` shows primary button variant and message', () => {
+ const { getByText } = render();
+ const badge = getByText('FormattedMessage');
+ expect(badge).toHaveClass('badge-primary');
});
- test('`locked` shows light button variant and message', () => {
- const el = render(gradingStatuses.locked);
- expect(el.snapshot).toMatchSnapshot();
+ it('`locked` shows light button variant and message', () => {
+ const { getByText } = render();
+ const badge = getByText('FormattedMessage');
+ expect(badge).toHaveClass('badge-light');
});
- test('`graded` shows success button variant and message', () => {
- const el = render(gradingStatuses.graded);
- expect(el.snapshot).toMatchSnapshot();
+ it('`graded` shows success button variant and message', () => {
+ const { getByText } = render();
+ const badge = getByText('FormattedMessage');
+ expect(badge).toHaveClass('badge-success');
});
- test('`inProgress` shows warning button variant and message', () => {
- const el = render(gradingStatuses.inProgress);
- expect(el.snapshot).toMatchSnapshot();
+ it('`inProgress` shows warning button variant and message', () => {
+ const { getByText } = render();
+ const badge = getByText('FormattedMessage');
+ expect(badge).toHaveClass('badge-warning');
});
});
});
diff --git a/src/components/__snapshots__/ConfirmModal.test.jsx.snap b/src/components/__snapshots__/ConfirmModal.test.jsx.snap
deleted file mode 100644
index 1aad82c07..000000000
--- a/src/components/__snapshots__/ConfirmModal.test.jsx.snap
+++ /dev/null
@@ -1,59 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`ConfirmModal snapshot: closed 1`] = `
-
-
-
-
- }
- isOpen={false}
- onClose={[MockFunction hooks.nullMethod]}
- title="test-title"
->
-
- test-content
-
-
-`;
-
-exports[`ConfirmModal snapshot: open 1`] = `
-
-
-
-
- }
- isOpen={true}
- onClose={[MockFunction hooks.nullMethod]}
- title="test-title"
->
-
- test-content
-
-
-`;
diff --git a/src/components/__snapshots__/StatusBadge.test.jsx.snap b/src/components/__snapshots__/StatusBadge.test.jsx.snap
deleted file mode 100644
index 8ea116d2f..000000000
--- a/src/components/__snapshots__/StatusBadge.test.jsx.snap
+++ /dev/null
@@ -1,55 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`StatusBadge component behavior does not render if status does not have configured variant 1`] = `null`;
-
-exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`graded\` shows success button variant and message 1`] = `
-
-
-
-`;
-
-exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`inProgress\` shows warning button variant and message 1`] = `
-
-
-
-`;
-
-exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`locked\` shows light button variant and message 1`] = `
-
-
-
-`;
-
-exports[`StatusBadge component behavior status snapshots: loads badge with configured variant and message. \`ungraded\` shows primary button variant and message 1`] = `
-
-
-
-`;