Skip to content

Commit

Permalink
Fixes #36515 - Don't show promote out of order for in-order envs
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Jun 23, 2023
1 parent 7efc0cb commit 1d43c6b
Show file tree
Hide file tree
Showing 4 changed files with 739 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ const ContentViewVersionPromote = ({
);

const isValid = useCallback((env) => {
if (!env.prior) return true;
if (!env.prior || versionEnvironments.some(item => item.id === env.prior.id)) return true;
if (!isChecked(prior(env))) return false;
return isValid(prior(env));
}, [prior, isChecked]);
}, [prior, isChecked, versionEnvironments]);

useDeepCompareEffect(() => {
setForcePromote(userCheckedItems.filter(item => !isValid(item)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@
},
{
"id": 2,
"name": "dev",
"label": "dev",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 3,
"name": "dev1",
"label": "dev1",
"publish_date": "4 days",
Expand All @@ -81,90 +67,6 @@
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 4,
"name": "dev2",
"label": "dev2",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 5,
"name": "dev3",
"label": "dev3",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 6,
"name": "test",
"label": "test",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 7,
"name": "test1",
"label": "test1",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 9,
"name": "test2",
"label": "test2",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
},
{
"id": 8,
"name": "test3",
"label": "test3",
"publish_date": "4 days",
"permissions": {
"readable": true,
"promotable_or_removable": true,
"all_hosts_editable": true,
"all_keys_editable": true
},
"host_count": 0,
"activation_key_count": 0
}
],
"repositories": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import api from '../../../../../services/api';
import CONTENT_VIEWS_KEY from '../../../ContentViewsConstants';
import ContentViewVersions from '../ContentViewVersions';
import cvVersionsData from './contentViewVersions.fixtures.json';
import cvVersionsOutOfEnvData from './contentViewVersionsLatestEnvironment.fixtures.json';
import emptyCVVersionData from './emptyCVVersion.fixtures.json';
import cvVersionsTasksData from './contentViewVersionsWithTask.fixtures.json';
import contentViewTaskInProgressResponseData from './contentViewTaskInProgressResponse.fixtures.json';
Expand All @@ -15,6 +16,7 @@ import environmentPathsData from '../../../Publish/__tests__/environmentPaths.fi
import cvIndexData from '../../../__tests__/contentViewList.fixtures.json';

const cvPromotePath = api.getApiUrl('/content_view_versions/10/promote');
const cvPromotePath2 = api.getApiUrl('/content_view_versions/11/promote');
const cvIndexPath = api.getApiUrl('/content_views');
const promoteResponseData = contentViewTaskInProgressResponseData;

Expand Down Expand Up @@ -91,7 +93,7 @@ test('Can link to view environment and see publish time', async (done) => {
expect(getAllByText('Library')[0].closest('a'))
.toHaveAttribute('href', '/lifecycle_environments/1');
expect(getByText('5 days ago')).toBeTruthy();
expect(getAllByText('dev')[0].closest('a'))
expect(getAllByText('dev1')[0].closest('a'))
.toHaveAttribute('href', '/lifecycle_environments/2');
expect(getAllByText('4 days ago')[0]).toBeTruthy();

Expand Down Expand Up @@ -271,6 +273,106 @@ test('Can open Promote Modal', async (done) => {
act(done);
});

test('Can open Promote Modal and show out of path warnings', async (done) => {
const autocompleteScope = mockAutocomplete(nockInstance, autocompleteUrl);
const cvScope = nockInstance
.get(cvIndexPath)
.query(true)
.reply(200, cvIndexData);

const scope = nockInstance
.get(cvVersions)
.query(true)
.reply(200, cvVersionsOutOfEnvData);

const cvPromoteParams = {
id: 11,
versionEnvironments: [
{
id: 1,
name: 'Library',
label: 'Library',
publish_date: '5 days',
permissions: {
readable: true,
promotable_or_removable: true,
all_hosts_editable: true,
all_keys_editable: true,
},
host_count: 0,
activation_key_count: 0,
},
{
id: 3,
name: 'test',
label: 'test',
publish_date: '4 days',
permissions: {
readable: true,
promotable_or_removable: true,
all_hosts_editable: true,
all_keys_editable: true,
},
host_count: 0,
activation_key_count: 0,
},
],
description: '',
environment_ids: [5, 4],
force: true,
};

const promoteScope = nockInstance
.post(cvPromotePath2, cvPromoteParams)
.reply(202, promoteResponseData);

const {
getByText, queryByText, getByLabelText, getAllByLabelText,
} = renderWithRedux(
withCVRoute(<ContentViewVersions cvId={5} details={cvDetailData} />),
renderOptions,
);

expect(queryByText(`Version ${firstVersion.version}`)).toBeNull();
await patientlyWaitFor(() => {
expect(getByText(`Version ${firstVersion.version}`)).toBeInTheDocument();
});
// Expand Row Action
expect(getAllByLabelText('Actions')[0]).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(getAllByLabelText('Actions')[0]);
expect(getAllByLabelText('Actions')[0]).toHaveAttribute('aria-expanded', 'true');
fireEvent.click(getByText('Promote'));
await patientlyWaitFor(() => {
expect(getByText('Select a lifecycle environment from the available promotion paths to promote new version.')).toBeInTheDocument();
expect(getByLabelText('prod')).toBeInTheDocument();
});
// Select env prod out of Env path: Library, dev1, test, test2, prod
fireEvent.click(getByLabelText('prod'));
await patientlyWaitFor(() => {
// Force promotion info is shown because test -> prod is out of order
expect(getByText('Force promotion')).toBeInTheDocument();
});
fireEvent.click(getByLabelText('test2'));
await patientlyWaitFor(() => {
// Force promotion info is shown because test -> test2 -> prod is out of order
expect(queryByText('Force promotion')).toBeNull();
});

fireEvent.click(getByLabelText('promote_content_view'));
// Modal closes itself
await patientlyWaitFor(() => {
expect(queryByText('Select a lifecycle environment from the available promotion paths to promote new version.')).toBeNull();
expect(getByText(`Version ${firstVersion.version}`)).toBeInTheDocument();
});
assertNockRequest(autocompleteScope);
assertNockRequest(scope);
assertNockRequest(promoteScope);
// Page is refreshed
assertNockRequest(scope);
assertNockRequest(cvScope);
act(done);
});

test('Can reload versions upon task completion', async (done) => {
const autocompleteScope = mockAutocomplete(nockInstance, autocompleteUrl);
const { results: withTaskResults } = cvVersionsTasksData;
Expand Down
Loading

0 comments on commit 1d43c6b

Please sign in to comment.