jest.fn()} />);
- expect(el.snapshot).toMatchSnapshot();
+
+ beforeEach(() => {
+ jest.clearAllMocks();
});
- test('Inactive Button "View All Responses"', () => {
+ it('renders button with correct text', () => {
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toBeInTheDocument();
+ expect(button).toHaveTextContent(messages.viewAllResponses.defaultMessage);
+ });
+
+ it('applies correct CSS class to button', () => {
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toHaveClass('view-all-responses-btn');
+ expect(button).toHaveClass('btn-primary');
+ });
+
+ it('enables button when rows are present', () => {
+ render();
+ const button = screen.getByRole('button');
+ expect(button).not.toBeDisabled();
+ });
+
+ it('disables button when no rows are present', () => {
const emptyProps = {
tableInstance: { rows: [] },
- handleClick: jest.fn(),
+ handleClick: jest.fn(() => () => {}),
};
- const el = shallow();
- expect(el.snapshot).toMatchSnapshot();
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toBeDisabled();
});
- test('handleClick', () => {
- shallow();
+ it('calls handleClick with table rows on render', () => {
+ render();
expect(props.handleClick).toHaveBeenCalledWith(props.tableInstance.rows);
});
});
diff --git a/src/containers/ListView/__snapshots__/ListViewBreadcrumb.test.jsx.snap b/src/containers/ListView/__snapshots__/ListViewBreadcrumb.test.jsx.snap
deleted file mode 100644
index 1d30142..0000000
--- a/src/containers/ListView/__snapshots__/ListViewBreadcrumb.test.jsx.snap
+++ /dev/null
@@ -1,38 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`ListViewBreadcrumb component component snapshot: empty (no list data) 1`] = `
-
-
-
-
-
-
-
- fake-ora-name
-
-
-
-
-
-
-`;
diff --git a/src/containers/ListView/__snapshots__/SelectedBulkAction.test.jsx.snap b/src/containers/ListView/__snapshots__/SelectedBulkAction.test.jsx.snap
deleted file mode 100644
index 6c67533..0000000
--- a/src/containers/ListView/__snapshots__/SelectedBulkAction.test.jsx.snap
+++ /dev/null
@@ -1,20 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`SelectedBulkAction component snapshots 1`] = `
-
-`;
diff --git a/src/containers/ListView/__snapshots__/SubmissionsTable.test.jsx.snap b/src/containers/ListView/__snapshots__/SubmissionsTable.test.jsx.snap
deleted file mode 100644
index 1a8bdad..0000000
--- a/src/containers/ListView/__snapshots__/SubmissionsTable.test.jsx.snap
+++ /dev/null
@@ -1,247 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`SubmissionsTable component component render tests snapshots snapshot: empty (no list data) 1`] = `null`;
-
-exports[`SubmissionsTable component component render tests snapshots snapshot: happy path 1`] = `
-
- ,
- ]
- }
- columns={
- [
- {
- "Header": "Username",
- "accessor": "username",
- },
- {
- "Cell": [Function],
- "Header": "Learner submission date",
- "accessor": "dateSubmitted",
- "disableFilters": true,
- },
- {
- "Cell": [Function],
- "Header": "Grade",
- "accessor": "score",
- "disableFilters": true,
- },
- {
- "Cell": [Function],
- "Filter": "MultiSelectDropdownFilter",
- "Header": "Grading status",
- "accessor": "gradingStatus",
- "filter": "includesValue",
- "filterChoices": [
- {
- "name": "Ungraded",
- "value": "ungraded",
- },
- {
- "name": "Grading Completed",
- "value": "graded",
- },
- {
- "name": "Currently being graded by someone else",
- "value": "locked",
- },
- {
- "name": "You are currently grading this response",
- "value": "in-progress",
- },
- ],
- },
- ]
- }
- data={
- [
- {
- "dateSubmitted": "2021-12-08 09:06:15.319213+00:00",
- "gradingStatus": "ungraded",
- "score": {
- "pointsEarned": 1,
- "pointsPossible": 10,
- },
- "username": "username-1",
- },
- {
- "dateSubmitted": "2021-12-10 18:06:15.319213+00:00",
- "gradingStatus": "graded",
- "score": {
- "pointsEarned": 2,
- "pointsPossible": 10,
- },
- "username": "username-2",
- },
- {
- "dateSubmitted": "2021-12-11 07:06:15.319213+00:00",
- "gradingStatus": "in-progress",
- "score": {
- "pointsEarned": 3,
- "pointsPossible": 10,
- },
- "username": "username-3",
- },
- ]
- }
- data-testid="data-table"
- defaultColumnValues={
- {
- "Filter": "TextFilter",
- }
- }
- initialState={
- {
- "pageIndex": 0,
- "pageSize": 10,
- }
- }
- isFilterable={true}
- isPaginated={true}
- isSelectable={true}
- isSortable={true}
- itemCount={3}
- numBreakoutFilters={2}
- tableActions={
- [
- ,
- ]
- }
- >
-
-
-
-
-
-`;
-
-exports[`SubmissionsTable component component render tests snapshots snapshot: team happy path 1`] = `
-
- ,
- ]
- }
- columns={
- [
- {
- "Header": "Team name",
- "accessor": "teamName",
- },
- {
- "Cell": [Function],
- "Header": "Team submission date",
- "accessor": "dateSubmitted",
- "disableFilters": true,
- },
- {
- "Cell": [Function],
- "Header": "Grade",
- "accessor": "score",
- "disableFilters": true,
- },
- {
- "Cell": [Function],
- "Filter": "MultiSelectDropdownFilter",
- "Header": "Grading status",
- "accessor": "gradingStatus",
- "filter": "includesValue",
- "filterChoices": [
- {
- "name": "Ungraded",
- "value": "ungraded",
- },
- {
- "name": "Grading Completed",
- "value": "graded",
- },
- {
- "name": "Currently being graded by someone else",
- "value": "locked",
- },
- {
- "name": "You are currently grading this response",
- "value": "in-progress",
- },
- ],
- },
- ]
- }
- data={
- [
- {
- "dateSubmitted": "2021-12-08 09:06:15.319213+00:00",
- "gradingStatus": "ungraded",
- "score": {
- "pointsEarned": 1,
- "pointsPossible": 10,
- },
- "teamName": "teamName-1",
- },
- {
- "dateSubmitted": "2021-12-10 18:06:15.319213+00:00",
- "gradingStatus": "graded",
- "score": {
- "pointsEarned": 2,
- "pointsPossible": 10,
- },
- "teamName": "teamName-2",
- },
- {
- "dateSubmitted": "2021-12-11 07:06:15.319213+00:00",
- "gradingStatus": "in-progress",
- "score": {
- "pointsEarned": 3,
- "pointsPossible": 10,
- },
- "teamName": "teamName-3",
- },
- ]
- }
- data-testid="data-table"
- defaultColumnValues={
- {
- "Filter": "TextFilter",
- }
- }
- initialState={
- {
- "pageIndex": 0,
- "pageSize": 10,
- }
- }
- isFilterable={true}
- isPaginated={true}
- isSelectable={true}
- isSortable={true}
- itemCount={3}
- numBreakoutFilters={2}
- tableActions={
- [
- ,
- ]
- }
- >
-
-
-
-
-
-`;
diff --git a/src/containers/ListView/__snapshots__/TableAction.test.jsx.snap b/src/containers/ListView/__snapshots__/TableAction.test.jsx.snap
deleted file mode 100644
index 8867be0..0000000
--- a/src/containers/ListView/__snapshots__/TableAction.test.jsx.snap
+++ /dev/null
@@ -1,30 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`TableAction component Inactive Button "View All Responses" 1`] = `
-
-`;
-
-exports[`TableAction component snapshots 1`] = `
-
-`;
diff --git a/src/containers/ResponseDisplay/FileDownload.test.jsx b/src/containers/ResponseDisplay/FileDownload.test.jsx
index 30504b1..5fd0965 100644
--- a/src/containers/ResponseDisplay/FileDownload.test.jsx
+++ b/src/containers/ResponseDisplay/FileDownload.test.jsx
@@ -1,6 +1,6 @@
-import React from 'react';
-import { shallow } from '@edx/react-unit-test-utils';
-
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { IntlProvider } from '@edx/frontend-platform/i18n';
import { RequestKeys, RequestStates } from 'data/constants/requests';
import { selectors, thunkActions } from 'data/redux';
import {
@@ -9,10 +9,15 @@ import {
FileDownload,
statusMapping,
} from './FileDownload';
+import messages from './messages';
+
+jest.unmock('@openedx/paragon');
+jest.unmock('react');
+jest.unmock('@edx/frontend-platform/i18n');
jest.mock('data/redux', () => ({
selectors: {
- requests: { requestStatus: (...args) => ({ requestStatus: args }) },
+ requests: { requestStatus: jest.fn((state, { requestKey }) => ({ status: 'inactive', requestKey })) },
},
thunkActions: {
download: { downloadFiles: jest.fn() },
@@ -20,50 +25,77 @@ jest.mock('data/redux', () => ({
}));
describe('FileDownload', () => {
- describe('component', () => {
- const props = {
- requestStatus: { status: RequestStates.inactive },
- };
- let el;
- beforeEach(() => {
- props.downloadFiles = jest.fn().mockName('this.props.downloadFiles');
- el = shallow();
+ const defaultProps = {
+ requestStatus: { status: RequestStates.inactive },
+ downloadFiles: jest.fn(),
+ };
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe('behavior', () => {
+ it('renders StatefulButton with default state when inactive', () => {
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toBeInTheDocument();
+ expect(button).toHaveTextContent(messages.downloadFiles.defaultMessage);
});
- describe('snapshot', () => {
- test('download is inactive', () => {
- expect(el.snapshot).toMatchSnapshot();
- expect(el.instance.props.state).toEqual(statusMapping[RequestStates.inactive]);
- });
- test('download is pending', () => {
- el = shallow();
- expect(el.snapshot).toMatchSnapshot();
- expect(el.instance.props.state).toEqual(statusMapping[RequestStates.pending]);
- });
- test('download is completed', () => {
- el = shallow();
- expect(el.snapshot).toMatchSnapshot();
- expect(el.instance.props.state).toEqual(statusMapping[RequestStates.completed]);
- });
- test('download is failed', () => {
- el = shallow();
- expect(el.snapshot).toMatchSnapshot();
- expect(el.instance.props.state).toEqual(statusMapping[RequestStates.failed]);
- });
+
+ it('renders with pending state when download is pending', () => {
+ const props = { ...defaultProps, requestStatus: { status: RequestStates.pending } };
+ render();
+ const button = screen.getByRole('button');
+ screen.debug();
+ expect(button).toHaveClass('pgn__stateful-btn-state-pending');
+ expect(button).toHaveAttribute('aria-disabled', 'true');
+ expect(button).toHaveTextContent(messages.downloading.defaultMessage);
+ });
+
+ it('renders with completed state when download is completed', () => {
+ const props = { ...defaultProps, requestStatus: { status: RequestStates.completed } };
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toHaveClass('pgn__stateful-btn-state-completed');
+ });
+
+ it('renders with failed state when download fails', () => {
+ const props = { ...defaultProps, requestStatus: { status: RequestStates.failed } };
+ render();
+ const button = screen.getByRole('button');
+ expect(button).toBeInTheDocument();
+ expect(button).toHaveClass('pgn__stateful-btn-state-failed');
+ expect(button).toHaveTextContent(messages.retryDownload.defaultMessage);
+ });
+
+ it('calls downloadFiles when button is clicked', async () => {
+ render();
+ const user = userEvent.setup();
+ const button = screen.getByRole('button');
+ await user.click(button);
+ expect(defaultProps.downloadFiles).toHaveBeenCalledTimes(1);
+ });
+
+ it('maps request states to button states correctly', () => {
+ expect(statusMapping[RequestStates.inactive]).toBe('default');
+ expect(statusMapping[RequestStates.pending]).toBe('pending');
+ expect(statusMapping[RequestStates.completed]).toBe('completed');
+ expect(statusMapping[RequestStates.failed]).toBe('failed');
});
});
+
describe('mapStateToProps', () => {
- let mapped;
- const requestKey = RequestKeys.downloadFiles;
const testState = { some: 'test-state' };
- beforeEach(() => {
- mapped = mapStateToProps(testState);
- });
- test('requestStatus loads from requests.requestStatus(downloadFiles)', () => {
- expect(mapped.requestStatus).toEqual(selectors.requests.requestStatus(testState, { requestKey }));
+
+ it('maps requestStatus from requests.requestStatus selector', () => {
+ const mapped = mapStateToProps(testState);
+ const expectedResult = selectors.requests.requestStatus(testState, { requestKey: RequestKeys.downloadFiles });
+ expect(mapped.requestStatus).toEqual(expectedResult);
});
});
+
describe('mapDispatchToProps', () => {
- it('loads downloadFiles from thunkActions.download.downloadFiles', () => {
+ it('maps downloadFiles from thunkActions', () => {
expect(mapDispatchToProps.downloadFiles).toEqual(thunkActions.download.downloadFiles);
});
});
diff --git a/src/containers/ResponseDisplay/__snapshots__/FileDownload.test.jsx.snap b/src/containers/ResponseDisplay/__snapshots__/FileDownload.test.jsx.snap
deleted file mode 100644
index cad5a51..0000000
--- a/src/containers/ResponseDisplay/__snapshots__/FileDownload.test.jsx.snap
+++ /dev/null
@@ -1,213 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`FileDownload component snapshot download is completed 1`] = `
-,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- labels={
- {
- "complete": ,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- onClick={[MockFunction this.props.downloadFiles]}
- state="completed"
-/>
-`;
-
-exports[`FileDownload component snapshot download is failed 1`] = `
-,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- labels={
- {
- "complete": ,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- onClick={[MockFunction this.props.downloadFiles]}
- state="failed"
-/>
-`;
-
-exports[`FileDownload component snapshot download is inactive 1`] = `
-,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- labels={
- {
- "complete": ,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- onClick={[MockFunction this.props.downloadFiles]}
- state="default"
-/>
-`;
-
-exports[`FileDownload component snapshot download is pending 1`] = `
-,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- labels={
- {
- "complete": ,
- "default": ,
- "failed": ,
- "pending": ,
- }
- }
- onClick={[MockFunction this.props.downloadFiles]}
- state="pending"
-/>
-`;
diff --git a/src/containers/ReviewModal/index.test.jsx b/src/containers/ReviewModal/index.test.jsx
index bb34d06..e3f73b7 100644
--- a/src/containers/ReviewModal/index.test.jsx
+++ b/src/containers/ReviewModal/index.test.jsx
@@ -81,7 +81,6 @@ describe('ReviewModal', () => {
});
render();
- screen.debug();
expect(useDispatch).toHaveBeenCalled();
});
@@ -126,7 +125,6 @@ describe('ReviewModal', () => {
});
render();
- screen.debug();
const loadingMessage = screen.getByText(messages.loadingResponse.defaultMessage);
expect(loadingMessage).toBeInTheDocument();
});