Skip to content

Commit

Permalink
fix: include reviewed to allowed statuses (#933)
Browse files Browse the repository at this point in the history
* fix: include reviewed to allowed statuses

* fix: test changes
  • Loading branch information
kiram15 authored Jan 3, 2024
1 parent 849c2a5 commit 4a01a5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/components/SidePanes/CatalogInclusionPane.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Form, Spinner } from '@edx/paragon';
import { PUBLISHED, UNPUBLISHED } from '../../data/constants';
import { PUBLISHED, REVIEWED, UNPUBLISHED } from '../../data/constants';

import DiscoveryDataApiService from '../../data/services/DiscoveryDataApiService';
import Pane from './Pane';
Expand All @@ -24,7 +24,7 @@ const CatalogInclusionPane = ({
e.preventDefault();
setIsLoading(true);
let draft = null;
if (draftStatuses.includes(PUBLISHED)) {
if (draftStatuses.includes(PUBLISHED) || draftStatuses.includes(REVIEWED)) {
draft = false;
} else if (draftStatuses.includes(UNPUBLISHED)) {
draft = true;
Expand All @@ -47,7 +47,7 @@ const CatalogInclusionPane = ({
setError(null);
setIsLoading(false);
} catch (err) {
const errorText = `Unable to toggle attribute, recieved error: ${err.response.status} ${err.response.statusText}`;
const errorText = `Unable to toggle attribute, received error: ${err.response.status} ${err.response.statusText}`;
setIsLoading(false);
setError(errorText);
}
Expand Down
44 changes: 37 additions & 7 deletions src/components/SidePanes/CatalogInclusionPane.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,71 @@ import React from 'react';
import { mount } from 'enzyme';

import CatalogInclusionPane from './CatalogInclusionPane';
import DiscoveryDataApiService from '../../data/services/DiscoveryDataApiService';

describe('CatalogInclusionPane', () => {
const mockUuid = 'test-enterprise-id';
const mockInclusion = false;
const mockSubInclusion = false;
const mockOrgInclusion = true;
const spy = jest.spyOn(DiscoveryDataApiService, 'editCourse');

it('correct toggle behavior', () => {
const wrapper = mount(<CatalogInclusionPane
courseUuid={mockUuid}
subInclusion={mockInclusion}
subInclusion={mockSubInclusion}
draftStatuses={['published']}
orgInclusion
orgInclusion={mockOrgInclusion}
/>);
wrapper.find(CatalogInclusionPane);
const title = wrapper.find('Enterprise Subscriptions');
expect(title);
const toggle = wrapper.find('.pgn__form-switch-input');
toggle.simulate('change', { target: { checked: false } });
expect(toggle.props().checked).toBe(false);
expect(spy).toBeCalledWith(
{
draft: false,
enterprise_subscription_inclusion: !mockSubInclusion,
uuid: 'test-enterprise-id',
},
);
});

it('allow course runs who have been reviewed', () => {
const wrapper = mount(<CatalogInclusionPane
courseUuid={mockUuid}
subInclusion={mockSubInclusion}
draftStatuses={['reviewed']}
orgInclusion={mockOrgInclusion}
/>);
wrapper.find(CatalogInclusionPane);
const title = wrapper.find('Enterprise Subscriptions');
expect(title);
const toggle = wrapper.find('.pgn__form-switch-input');
toggle.simulate('change', { target: { checked: false } });
expect(spy).toBeCalledWith(
{
draft: false,
enterprise_subscription_inclusion: !mockSubInclusion,
uuid: 'test-enterprise-id',
},
);
});
it('toggle disabled when org is false', () => {
const wrapper = mount(<CatalogInclusionPane
courseUuid={mockUuid}
subInclusion={mockInclusion}
subInclusion={mockSubInclusion}
draftStatuses={['published']}
orgInclusion={false}
/>);
// org not included helper text
expect(wrapper.find('.text-gray-300')).toHaveLength(1);
});
it('toggle blocked in review status', () => {
const wrapper = mount(<CatalogInclusionPane
courseUuid={mockUuid}
subInclusion={mockInclusion}
subInclusion={mockSubInclusion}
draftStatuses={['review_by_internal']}
orgInclusion
orgInclusion={mockOrgInclusion}
/>);
const toggle = wrapper.find('.pgn__form-switch-input');
toggle.simulate('change', { target: { checked: false } });
Expand Down

0 comments on commit 4a01a5b

Please sign in to comment.