From 009f5c64ae900957b9f895e725815561139a213f Mon Sep 17 00:00:00 2001 From: Samir Jha Date: Thu, 6 Jul 2023 11:31:17 -0400 Subject: [PATCH] Fixes #36529 - CV page needs refresh to get the current filters state (#10628) --- .../Details/ContentViewDetails.js | 3 +- .../__tests__/contentViewVersions.test.js | 7 +++ .../contentViewDetails.fixtures.json | 1 + .../ContentViews/Publish/CVPublishReview.js | 15 ++++++- .../Publish/PublishContentViewWizard.js | 5 ++- .../__tests__/publishContentView.test.js | 43 ++++++++++++++----- 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/webpack/scenes/ContentViews/Details/ContentViewDetails.js b/webpack/scenes/ContentViews/Details/ContentViewDetails.js index 267553ad333..c180bda25bd 100644 --- a/webpack/scenes/ContentViews/Details/ContentViewDetails.js +++ b/webpack/scenes/ContentViews/Details/ContentViewDetails.js @@ -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 () => { @@ -73,6 +73,7 @@ export default () => { useEffect(() => { dispatch(getContentViewDetails(cvId)); + dispatch({ type: CONTENT_VIEW_NEEDS_PUBLISH_RESET }); }, [cvId, dispatch]); diff --git a/webpack/scenes/ContentViews/Details/Versions/__tests__/contentViewVersions.test.js b/webpack/scenes/ContentViews/Details/Versions/__tests__/contentViewVersions.test.js index 3dd8d73d7c4..a7e1ee40092 100644 --- a/webpack/scenes/ContentViews/Details/Versions/__tests__/contentViewVersions.test.js +++ b/webpack/scenes/ContentViews/Details/Versions/__tests__/contentViewVersions.test.js @@ -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'); @@ -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; @@ -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(), renderOptions, @@ -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); }); diff --git a/webpack/scenes/ContentViews/Details/__tests__/contentViewDetails.fixtures.json b/webpack/scenes/ContentViews/Details/__tests__/contentViewDetails.fixtures.json index 8e8eeacfd68..822efd16b2e 100644 --- a/webpack/scenes/ContentViews/Details/__tests__/contentViewDetails.fixtures.json +++ b/webpack/scenes/ContentViews/Details/__tests__/contentViewDetails.fixtures.json @@ -7,6 +7,7 @@ "latest_version": "5.0", "auto_publish": false, "solve_dependencies": false, + "needs_publish": false, "generated_for": "none", "repository_ids": [ 58, diff --git a/webpack/scenes/ContentViews/Publish/CVPublishReview.js b/webpack/scenes/ContentViews/Publish/CVPublishReview.js index 7bfd24a6f10..ff80e37dbba 100644 --- a/webpack/scenes/ContentViews/Publish/CVPublishReview.js +++ b/webpack/scenes/ContentViews/Publish/CVPublishReview.js @@ -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) { @@ -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 ( <> { dispatch(getEnvironmentPaths()); + dispatch(getContentViewFilters(cvId, {})); }, - [dispatch], + [dispatch, cvId], ); const envPathFlat = useMemo(() => { diff --git a/webpack/scenes/ContentViews/Publish/__tests__/publishContentView.test.js b/webpack/scenes/ContentViews/Publish/__tests__/publishContentView.test.js index cdd50d3f646..5b69ff97523 100644 --- a/webpack/scenes/ContentViews/Publish/__tests__/publishContentView.test.js +++ b/webpack/scenes/ContentViews/Publish/__tests__/publishContentView.test.js @@ -7,18 +7,21 @@ 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( { 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) => { @@ -36,6 +43,9 @@ test('Can show Wizard and show environment paths', async (done) => { .get(environmentPathsPath) .query(true) .reply(200, environmentPathsData); + const filterScope = nockInstance + .get(cvFiltersPath) + .reply(200, contentViewFilterData); const useSelectorMock = jest.spyOn(reactRedux, 'useSelector'); useSelectorMock.mockReturnValue(environmentPathsData); @@ -55,7 +65,8 @@ 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) => { @@ -63,6 +74,9 @@ test('Can show and hide force promotion alert', async (done) => { .get(environmentPathsPath) .query(true) .reply(200, environmentPathsData); + const filterScope = nockInstance + .get(cvFiltersPath) + .reply(200, contentViewFilterData); const useSelectorMock = jest.spyOn(reactRedux, 'useSelector'); useSelectorMock.mockReturnValue(environmentPathsData); @@ -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( { 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) => { @@ -144,7 +164,9 @@ test('Can move to Finish step and publish CV', async (done) => { .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, }; @@ -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 });