Skip to content

Commit

Permalink
Fixes #36529 - CV page needs refresh to get the current filters state (
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 authored Jul 6, 2023
1 parent 80a84ae commit 009f5c6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
3 changes: 2 additions & 1 deletion webpack/scenes/ContentViews/Details/ContentViewDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { hasPermission } from '../helpers';
import CopyContentViewModal from '../Copy/CopyContentViewModal';
import ContentViewDeleteWizard from '../Delete/ContentViewDeleteWizard';
import EmptyStateMessage from '../../../components/Table/EmptyStateMessage';
import { cvVersionTaskPollingKey } from '../ContentViewsConstants';
import { CONTENT_VIEW_NEEDS_PUBLISH_RESET, cvVersionTaskPollingKey } from '../ContentViewsConstants';
import { clearPollTaskData, stopPollingTask } from '../../Tasks/TaskActions';

export default () => {
Expand Down Expand Up @@ -73,6 +73,7 @@ export default () => {

useEffect(() => {
dispatch(getContentViewDetails(cvId));
dispatch({ type: CONTENT_VIEW_NEEDS_PUBLISH_RESET });
}, [cvId, dispatch]);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import contentViewTaskResponseData from './contentViewTaskResponse.fixtures.json
import cvDetailData from '../../../../ContentViews/__tests__/mockDetails.fixtures.json';
import environmentPathsData from '../../../Publish/__tests__/environmentPaths.fixtures.json';
import cvIndexData from '../../../__tests__/contentViewList.fixtures.json';
import contentViewFilterData from '../../Filters/__tests__/contentViewFilters.fixtures.json';

const cvPromotePath = api.getApiUrl('/content_view_versions/10/promote');
const cvPromotePath2 = api.getApiUrl('/content_view_versions/11/promote');
Expand All @@ -36,6 +37,7 @@ const renderOptions = {
const cvVersions = api.getApiUrl('/content_view_versions');
const autocompleteUrl = '/content_view_versions/auto_complete_search';
const taskPollingUrl = '/foreman_tasks/api/tasks/6b900ff8-62bb-42ac-8c45-da86b7258520';
const cvFiltersPath = api.getApiUrl('/content_view_filters?content_view_id=5');

let firstVersion;
let envScope;
Expand Down Expand Up @@ -432,6 +434,10 @@ test('Shows call-to-action when there are no versions', async (done) => {
.query(true)
.reply(200, environmentPathsData);

const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);

const { getByText, queryByText } = renderWithRedux(
withCVRoute(<ContentViewVersions cvId={5} details={cvDetailData} />),
renderOptions,
Expand All @@ -449,6 +455,7 @@ test('Shows call-to-action when there are no versions', async (done) => {
assertNockRequest(scopeWizard);
assertNockRequest(autocompleteScope);
assertNockRequest(scope);
assertNockRequest(filterScope);
act(done);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"latest_version": "5.0",
"auto_publish": false,
"solve_dependencies": false,
"needs_publish": false,
"generated_for": "none",
"repository_ids": [
58,
Expand Down
15 changes: 13 additions & 2 deletions webpack/scenes/ContentViews/Publish/CVPublishReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ import InactiveText from '../components/InactiveText';
import ComponentEnvironments from '../Details/ComponentContentViews/ComponentEnvironments';
import { selectEnvironmentPaths, selectEnvironmentPathsStatus } from '../components/EnvironmentPaths/EnvironmentPathSelectors';
import WizardHeader from '../components/WizardHeader';
import { selectCVFilters, selectCVFiltersStatus } from '../Details/ContentViewDetailSelectors';

const CVPublishReview = ({
details: {
id, name, composite, filtered, next_version: nextVersion,
id, name, composite, next_version: nextVersion,
},
userCheckedItems,
}) => {
const environmentPathResponse = useSelector(selectEnvironmentPaths);
const environmentPathStatus = useSelector(selectEnvironmentPathsStatus);
const cvFiltersResponse = useSelector(state => selectCVFilters(state, id));
const cvFiltersStatus = useSelector(state => selectCVFiltersStatus(state, id));
const environmentPathLoading = environmentPathStatus === STATUS.PENDING;
const cvFiltersLoading = cvFiltersStatus === STATUS.PENDING;

const promotedToEnvironments = useMemo(() => {
if (!environmentPathLoading) {
Expand All @@ -35,6 +39,14 @@ const CVPublishReview = ({
return [];
}, [environmentPathResponse, environmentPathLoading, userCheckedItems]);

const filtered = useMemo(() => {
if (!cvFiltersLoading) {
const { results } = cvFiltersResponse || {};
return results.length > 0;
}
return [];
}, [cvFiltersResponse, cvFiltersLoading]);

return (
<>
<WizardHeader
Expand Down Expand Up @@ -94,7 +106,6 @@ CVPublishReview.propTypes = {
]).isRequired,
name: PropTypes.string.isRequired,
composite: PropTypes.bool.isRequired,
filtered: PropTypes.bool.isRequired,
next_version: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../components/EnvironmentPaths/EnvironmentPathSelectors';
import { stopPollingTask } from '../../Tasks/TaskActions';
import { cvVersionTaskPollingKey } from '../ContentViewsConstants';
import { getContentViewFilters } from '../Details/ContentViewDetailActions';

const PublishContentViewWizard = ({
details, show, onClose,
Expand All @@ -30,6 +31,7 @@ const PublishContentViewWizard = ({
const environmentPathStatus = useSelector(selectEnvironmentPathsStatus);
const environmentPathLoading = environmentPathStatus === STATUS.PENDING;


const steps = [
{
id: 1,
Expand Down Expand Up @@ -71,8 +73,9 @@ const PublishContentViewWizard = ({
useEffect(
() => {
dispatch(getEnvironmentPaths());
dispatch(getContentViewFilters(cvId, {}));
},
[dispatch],
[dispatch, cvId],
);

const envPathFlat = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,45 @@ import PublishContentViewWizard from '../PublishContentViewWizard';
import cvDetailData from '../../Details/__tests__/contentViewDetails.fixtures.json';
import publishResponseData from './publishResponse.fixture.json';
import environmentPathsData from './environmentPaths.fixtures.json';
import contentViewFilterData from './../../Details/Filters/__tests__/contentViewFilters.fixtures.json';

const cvPublishPath = api.getApiUrl('/content_views/1/publish');

const environmentPathsPath = api.getApiUrl('/organizations/1/environments/paths');
const cvFiltersPath = api.getApiUrl('/content_view_filters?content_view_id=1');

test('Can call API and show Wizard', async (done) => {
const scope = nockInstance
.get(environmentPathsPath)
.query(true)
.reply(200, environmentPathsData);
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
useSelectorMock.mockReturnValue(environmentPathsData);
const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);

const { getByText } = renderWithRedux(<PublishContentViewWizard
details={cvDetailData}
show
onClose={() => { }}
/>);

await patientlyWaitFor(() => expect(getByText('Publish new version - 6.0')).toBeInTheDocument());
useSelectorMock.mockClear();
assertNockRequest(scope, done);
await patientlyWaitFor(() => {
expect(getByText('Publish new version - 6.0')).toBeInTheDocument();
expect(getByText('Newly published version will be the same as the previous version.')).toBeTruthy();
});

assertNockRequest(scope);
assertNockRequest(filterScope, done);
});

test('Can show Wizard and show environment paths', async (done) => {
const scope = nockInstance
.get(environmentPathsPath)
.query(true)
.reply(200, environmentPathsData);
const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
useSelectorMock.mockReturnValue(environmentPathsData);

Expand All @@ -55,14 +65,18 @@ test('Can show Wizard and show environment paths', async (done) => {
expect(getByText('dev1')).toBeTruthy();
});
useSelectorMock.mockClear();
assertNockRequest(scope, done);
assertNockRequest(scope);
assertNockRequest(filterScope, done);
});

test('Can show and hide force promotion alert', async (done) => {
const scope = nockInstance
.get(environmentPathsPath)
.query(true)
.reply(200, environmentPathsData);
const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);
const useSelectorMock = jest.spyOn(reactRedux, 'useSelector');
useSelectorMock.mockReturnValue(environmentPathsData);

Expand Down Expand Up @@ -109,15 +123,18 @@ test('Can show and hide force promotion alert', async (done) => {
expect(queryByText('Force promotion')).not.toBeInTheDocument();

useSelectorMock.mockClear();
assertNockRequest(scope, done);
assertNockRequest(scope);
assertNockRequest(filterScope, done);
});


test('Can show Wizard form and move to review', async (done) => {
const scope = nockInstance
.get(environmentPathsPath)
.query(true)
.reply(200, environmentPathsData);
const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);

const { getByText } = renderWithRedux(<PublishContentViewWizard
details={cvDetailData}
Expand All @@ -134,17 +151,22 @@ test('Can show Wizard form and move to review', async (done) => {
expect(getByText('Newly published')).toBeInTheDocument();
expect(getByText('Version 6.0')).toBeInTheDocument();
expect(getByText('Library')).toBeTruthy();
expect(getByText('Filters')).toBeTruthy();
expect(getByText('Filters will be applied to this content view version.')).toBeTruthy();
});
useSelectorMock.mockClear();
assertNockRequest(scope, done);
assertNockRequest(scope);
assertNockRequest(filterScope, done);
});

test('Can move to Finish step and publish CV', async (done) => {
const scope = nockInstance
.get(environmentPathsPath)
.query(true)
.reply(200, environmentPathsData);

const filterScope = nockInstance
.get(cvFiltersPath)
.reply(200, contentViewFilterData);
const cvPublishParams = {
id: 1, versionCount: 5, description: '', environment_ids: [], is_force_promote: false,
};
Expand All @@ -166,6 +188,7 @@ test('Can move to Finish step and publish CV', async (done) => {
fireEvent.click(getByText('Finish'));

assertNockRequest(scope);
assertNockRequest(filterScope);
assertNockRequest(publishScope, done);
act(done); // stop listening for nocks
});

0 comments on commit 009f5c6

Please sign in to comment.