Skip to content

Commit

Permalink
fix: adding more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Oct 9, 2023
1 parent 1ea08b7 commit 9f6f802
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/containers/ListView/SubmissionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ export class SubmissionsTable extends React.Component {

formatStatus = ({ value }) => <StatusBadge status={value} />;

handleProblemStepClick = (problemStepType) => {
console.log(problemStepType);
};

formatProblemStepsStatus = () => {
const stepProblems = Object.keys(problemSteps);
return (
Expand All @@ -80,7 +76,6 @@ export class SubmissionsTable extends React.Component {
<Button
variant="tertiary"
className="step-problems-button-badge"
onClick={() => this.handleProblemStepClick(stepProblem)}
key={stepProblem}
>
<StatusBadge
Expand Down
75 changes: 75 additions & 0 deletions src/containers/ListView/SubmissionsTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ describe('SubmissionsTable component', () => {
accessor: submissionFields.username,
});
});
test('email column', () => {
expect(columns[1]).toEqual({
Header: messages.emailLabel.defaultMessage,
accessor: null,
Cell: el.instance().emailAddressCell,
});
});
test('submission date column', () => {
expect(columns[2]).toEqual({
Header: messages.learnerSubmissionDate.defaultMessage,
Expand Down Expand Up @@ -259,6 +266,74 @@ describe('SubmissionsTable component', () => {
});
});
});

describe('methods', () => {
it('should call the appropriate functions when the handleProblemStepsDetailClick method is called', () => {
// const shaddow = mount(table);
// const tableWrap = mount(<SubmissionsTable {...props} />);
// const button = tableWrap.find('.btn-view-details').first();
const mockData = [
{
gradingStatus: 'ungraded',
submissionUUID: '701616b5-b394-47e0-bd2d-cd13462b9471',
username: 'username1',
teamName: null,
dateSubmitted: '2023-10-04 17:13:22.873876+00:00',
dateGraded: 'None',
gradedBy: null,
score: null,
},
{
gradingStatus: 'ungraded',
submissionUUID: '29c3c216-56e0-4686-a925-8fe65641eb8e',
username: 'username2',
teamName: null,
dateSubmitted: '2023-10-05 15:45:18.732687+00:00',
dateGraded: 'None',
gradedBy: null,
score: null,
},
];

const mockCurrentRow = {
id: '0',
index: 0,
isSelected: false,
isSomeSelected: false,
original: {
dateGraded: 'None',
dateSubmitted: '2023-10-04 17:13:22.873876+00:00',
gradedBy: null,
gradingStatus: 'ungraded',
score: null,
submissionUUID: '701616b5-b394-47e0-bd2d-cd13462b9471',
teamName: null,
username: 'username1',
},

};

el.instance().handleProblemStepsDetailClick(mockData, mockCurrentRow);

expect(props.loadSelectionForReview).toHaveBeenCalled();
expect(props.setActiveSubmissionIndex).toHaveBeenCalled();
expect(props.setProblemStepsModal).toHaveBeenCalled();

// Check it's arguments
expect(props.loadSelectionForReview).toHaveBeenCalledWith(
[mockData[0].submissionUUID, mockData[1].submissionUUID],
false,
mockCurrentRow.original.submissionUUID,
);
expect(props.setActiveSubmissionIndex).toHaveBeenCalledWith(0);
expect(props.setProblemStepsModal).toHaveBeenCalledWith(true);

// Check that the functions were called once each
expect(props.loadSelectionForReview).toHaveBeenCalledTimes(1);
expect(props.setActiveSubmissionIndex).toHaveBeenCalledTimes(1);
expect(props.setProblemStepsModal).toHaveBeenCalledTimes(1);
});
});
});
});
describe('behavior', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { shallow } from 'enzyme';
import ReviewProblemStepActions from '.'; // Replace with the correct import path

describe('ReviewProblemStepActions component', () => {
it('renders without crashing', () => {
const wrapper = shallow(<ReviewProblemStepActions />);
expect(wrapper.exists()).toBe(true);
});
it('should render the component with correct content', () => {
const wrapper = shallow(<ReviewProblemStepActions />);

// Check if certain elements with expected text content exist in the rendered component
expect(wrapper.find('h3').text()).toEqual('John Doe');
expect(wrapper.find('p').at(0).text()).toEqual('jhon_20');
expect(wrapper.find('h4').at(0).text()).toEqual('Email');
expect(wrapper.find('p').at(1).text()).toEqual('[email protected]');
expect(wrapper.find('h4').at(1).text()).toEqual('Submission ID');
expect(wrapper.find('p').at(2).text()).toEqual('483234704918');
expect(wrapper.find('h4').at(2).text()).toEqual('Submission date');
expect(wrapper.find('p').at(3).text()).toEqual('9/13/2023, 7:13:56 AM');
expect(wrapper.find('h4').at(3).text()).toEqual('Grade');
expect(wrapper.find('p').at(4).text()).toEqual('3/10');
expect(wrapper.find('h4').at(4).text()).toEqual('Grading status');
expect(wrapper.find('p').at(5).text()).toEqual('Upgraded');

// Check if StatusBadges with expected titles exist
expect(wrapper.find('StatusBadge').at(0).prop('title')).toEqual('Training');
expect(wrapper.find('StatusBadge').at(1).prop('title')).toEqual('Peers');
expect(wrapper.find('StatusBadge').at(2).prop('title')).toEqual('Self');
expect(wrapper.find('StatusBadge').at(3).prop('title')).toEqual('Staff');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import ResponseItem from '.';

describe('ResponseItem component', () => {
it('renders without crashing', () => {
const wrapper = shallow(<ResponseItem title="Title" response="Response Content" />);
expect(wrapper.exists()).toBe(true);
});

it('displays the title and response', () => {
const title = 'Title';
const response = 'Response Content';
const wrapper = shallow(<ResponseItem title={title} response={response} />);
expect(wrapper.find('h4').text()).toBe(title);
expect(wrapper.find('.collapsible-body').text()).toBe(response);
});

it('collapses when trigger is clicked twice', () => {
const title = 'Title';
const response = 'Response Content';
const wrapper = mount(<ResponseItem title={title} response={response} />);

// Click on the trigger to expand
wrapper.find('.collapsible-trigger').simulate('click');
// Click again to collapse
wrapper.find('.collapsible-trigger').simulate('click');
// After clicking twice, the Collapsible should be closed
expect(wrapper.find('.collapsible-body').hasClass('collapsible-body--open')).toBe(false);
});
});
32 changes: 32 additions & 0 deletions src/data/redux/problem-steps/reducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { actions, reducer, initialState } from './reducer'; // Replace with your actual reducer import

describe('problemSteps reducer', () => {
it('should return the initial state', () => {
const state = reducer(undefined, {});
expect(state).toEqual(initialState);
});

it('should handle setOpenReviewModal correctly', () => {
const newState = reducer(initialState, actions.setOpenReviewModal(true));

// Check if reviewModalOpen is set to true
expect(newState.reviewModalOpen).toEqual(true);

// Check if other properties in state remain unchanged
expect(newState.someOtherProperty).toEqual(initialState.someOtherProperty); // Update as needed
});

it('should handle setOpenReviewModal with false correctly', () => {
// If you want to test setting reviewModalOpen to false
const stateWithOpenModal = { ...initialState, reviewModalOpen: true };
const newState = reducer(stateWithOpenModal, actions.setOpenReviewModal(false));

// Check if reviewModalOpen is set to false
expect(newState.reviewModalOpen).toEqual(false);

// Check if other properties in state remain unchanged
expect(newState.someOtherProperty).toEqual(stateWithOpenModal.someOtherProperty); // Update as needed
});

// Add more test cases as needed
});
25 changes: 25 additions & 0 deletions src/data/redux/problem-steps/selector.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { simpleSelectors } from './selectors'; // Replace with your actual selector import

describe('simpleSelectors', () => {
it('should select reviewModalOpen from the state', () => {
const initialState = {
problemSteps: {
reviewModalOpen: true, // Set to true for the test
},
// Other slices of state if needed
};

// Create a mock Redux store with the initial state
const store = {
getState: () => initialState,
};

// Call the selector with the mock store
const selectedReviewModalOpen = simpleSelectors.reviewModalOpen(store.getState());

// Expect the selector to return the value from the state
expect(selectedReviewModalOpen).toEqual(true);
});

// Add more test cases if needed
});

0 comments on commit 9f6f802

Please sign in to comment.