Skip to content

Commit

Permalink
Description text change for manage policy modal
Browse files Browse the repository at this point in the history
Signed-off-by: Gowtham Shanmugasundaram <[email protected]>
  • Loading branch information
GowthamShanmugam committed Aug 23, 2023
1 parent 7a07e8e commit 66ecd03
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 75 deletions.
13 changes: 7 additions & 6 deletions locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@
"{{selected}} of {{total}} selected": "{{selected}} of {{total}} selected",
"subscription-selector": "subscription-selector",
"Select the subscriptions groups you wish to replicate via": "Select the subscriptions groups you wish to replicate via",
"Assign policy": "Assign policy",
"Assign data policy": "Assign data policy",
"Secure your application by assigning a policy from the available policy templates.": "Secure your application by assigning a policy from the available policy templates.",
"Manage data policy": "Manage data policy",
"Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.": "Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.",
"PVC details": "PVC details",
"Assign a policy to protect the application and to ensure a quick recovery.": "Assign a policy to protect the application and to ensure a quick recovery.",
"Policy": "Policy",
"PersistentVolumeClaim": "PersistentVolumeClaim",
"Review and assign": "Review and assign",
"Assign": "Assign",
"New policy assigned to application.": "New policy assigned to application.",
Expand All @@ -229,6 +230,7 @@
"Assigned on": "Assigned on",
"View configurations": "View configurations",
"No activity": "No activity",
"No assigned data policy found": "No assigned data policy found",
"Delete": "Delete",
"Select a placement": "Select a placement",
"{{count}} selected_one": "{{count}} selected",
Expand All @@ -238,7 +240,6 @@
"If no label is provided, all PVCs will be protected. Define your preferences to protect specific resources.": "If no label is provided, all PVCs will be protected. Define your preferences to protect specific resources.",
"Application resource": "Application resource",
"Add application resource": "Add application resource",
"Policy": "Policy",
"Select a policy": "Select a policy",
"Search": "Search",
"Search input": "Search input",
Expand All @@ -250,7 +251,8 @@
"Selected policies ({{ count }}) unassigned for the application._one": "Selected policies ({{ count }}) unassigned for the application.",
"Selected policies ({{ count }}) unassigned for the application._other": "Selected policies ({{ count }}) unassigned for the application.",
"Unable to unassign all selected policies for the application.": "Unable to unassign all selected policies for the application.",
"My policies": "My policies",
"My assigned policies": "My assigned policies",
"You haven't set a data policy for your application yet. To protect your application, click the 'Assign data policy' button and select a policy from the available templates.": "You haven't set a data policy for your application yet. To protect your application, click the 'Assign data policy' button and select a policy from the available templates.",
"Relocate in progress": "Relocate in progress",
"Failover in progress": "Failover in progress",
"List all the connected applications under a policy.": "List all the connected applications under a policy.",
Expand Down Expand Up @@ -896,7 +898,6 @@
"NamespaceStore details": "NamespaceStore details",
"Target Blob Container": "Target Blob Container",
"Num Volumes": "Num Volumes",
"PersistentVolumeClaim": "PersistentVolumeClaim",
"Raw Capacity": "Raw Capacity",
"Add Capacity": "Add Capacity",
"External": "External",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
const getModalTitle = (modalViewContext: ModalViewContext, t: TFunction) => {
if (modalViewContext === ModalViewContext.ASSIGN_POLICY_VIEW) {
return {
title: t('Assign policy'),
title: t('Assign data policy'),
description: t(
'Secure your application by assigning a policy from the available policy templates.'
),
Expand All @@ -34,7 +34,7 @@ const getModalTitle = (modalViewContext: ModalViewContext, t: TFunction) => {
return {
title: t('Manage data policy'),
description: t(
'Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.'
'Assign a policy to protect the application and to ensure a quick recovery.'
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createSteps = (
): WizardStep[] => [
{
id: 1,
name: t('Select policy'),
name: t('Policy'),
component: (
<SelectPolicyWizardContent
matchingPolicies={matchingPolicies}
Expand All @@ -53,7 +53,7 @@ export const createSteps = (
},
{
id: 2,
name: t('PVC details'),
name: t('PersistentVolumeClaim'),
component: (
<PVCDetailsWizardContent
placementControInfo={state.policy?.placementControlInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@odf/shared/table/selectable-table';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { TFunction } from 'i18next';
import { Text } from '@patternfly/react-core';
import { Text, Bullseye } from '@patternfly/react-core';
import { ActionsColumn, IAction } from '@patternfly/react-table';
import { Td } from '@patternfly/react-table';
import { ModalActionContext, ModalViewContext } from '../utils/reducer';
Expand Down Expand Up @@ -133,6 +133,9 @@ export const PolicyListViewTable: React.FC<PolicyListViewTableProps> = ({
setModalContext,
}}
loaded={true}
emptyRowMessage={() => (
<Bullseye> {t('No assigned data policy found')} </Bullseye>
)}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const SelectPolicyWizardContent: React.FC<SelectPolicyWizardContentProps>
<Form className="mco-manage-policies__form--width">
<FormGroup
fieldId="policy-type-selector"
label={t('Policy')}
label={t('Policy name')}
isRequired
>
<SingleSelectDropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
import { createRefFromK8Resource } from '../../../../utils';
import { ApplicationSetParser } from './application-set-parser';

let testCase = 1;

const mockApplicationSet1: ArgoApplicationSetKind = {
apiVersion: `${ArgoApplicationSetModel.apiGroup}/${ArgoApplicationSetModel.apiVersion}`,
kind: ArgoApplicationSetModel.kind,
Expand Down Expand Up @@ -51,6 +53,35 @@ const mockApplicationSet1: ArgoApplicationSetKind = {
},
};

const mockApplicationSet2: ArgoApplicationSetKind = {
apiVersion: `${ArgoApplicationSetModel.apiGroup}/${ArgoApplicationSetModel.apiVersion}`,
kind: ArgoApplicationSetModel.kind,
metadata: {
name: 'mock-appset-2',
namespace: 'mock-appset-2',
},
spec: {
generators: [
{
clusterDecisionResource: {
labelSelector: {
matchLabels: {
[PLACEMENT_REF_LABEL]: 'mock-placement-2',
},
},
},
},
],
template: {
spec: {
destination: {
namespace: 'mock-appset-2',
},
},
},
},
};

const mockPlacement1: ACMPlacementKind = {
apiVersion: `${ACMPlacementModel.apiGroup}/${ACMPlacementModel.apiVersion}`,
kind: ACMPlacementModel.kind,
Expand All @@ -61,6 +92,16 @@ const mockPlacement1: ACMPlacementKind = {
spec: {},
};

const mockPlacement2: ACMPlacementKind = {
apiVersion: `${ACMPlacementModel.apiGroup}/${ACMPlacementModel.apiVersion}`,
kind: ACMPlacementModel.kind,
metadata: {
name: 'mock-placement-2',
namespace: 'mock-appset-2',
},
spec: {},
};

const mockPlacementDecision1: ACMPlacementDecisionKind = {
apiVersion: `${ACMPlacementDecisionModel.apiGroup}/${ACMPlacementDecisionModel.apiVersion}`,
kind: ACMPlacementDecisionModel.kind,
Expand All @@ -81,6 +122,26 @@ const mockPlacementDecision1: ACMPlacementDecisionKind = {
},
};

const mockPlacementDecision2: ACMPlacementDecisionKind = {
apiVersion: `${ACMPlacementDecisionModel.apiGroup}/${ACMPlacementDecisionModel.apiVersion}`,
kind: ACMPlacementDecisionModel.kind,
metadata: {
name: 'mock-placement-decision-2',
namespace: 'mock-appset-2',
labels: {
[PLACEMENT_REF_LABEL]: 'mock-placement-2',
},
},
status: {
decisions: [
{
clusterName: 'east-1',
reason: '',
},
],
},
};

const mockDRPolicy1: DRPolicyKind = {
apiVersion: `${DRPolicyModel.apiGroup}/${DRPolicyModel.apiVersion}`,
kind: DRPolicyModel.kind,
Expand Down Expand Up @@ -150,7 +211,7 @@ const mockDRPC1: DRPlacementControlKind = {
},
};

const drResources: DisasterRecoveryResourceKind = {
const drResources1: DisasterRecoveryResourceKind = {
drClusters: [mockDRClusterEast1, mockDRClusterWest1],
drPolicies: [mockDRPolicy1],
drPlacementControls: [mockDRPC1],
Expand All @@ -163,7 +224,20 @@ const drResources: DisasterRecoveryResourceKind = {
],
};

const appResources: ArgoApplicationSetResourceKind = {
const drResources2: DisasterRecoveryResourceKind = {
drClusters: [],
drPolicies: [],
drPlacementControls: [],
formattedResources: [
{
drClusters: [],
drPolicy: {},
drPlacementControls: [],
},
],
};

const appResources1: ArgoApplicationSetResourceKind = {
formattedResources: [
{
application: mockApplicationSet1,
Expand All @@ -182,44 +256,91 @@ const appResources: ArgoApplicationSetResourceKind = {
],
};

const appResources2: ArgoApplicationSetResourceKind = {
formattedResources: [
{
application: mockApplicationSet2,
placements: [
{
placement: mockPlacement2,
placementDecision: mockPlacementDecision2,
},
],
managedClusters: [],
siblingApplications: [],
},
],
};

const onClose = jest.fn();
jest.mock('@odf/mco/hooks/disaster-recovery', () => ({
__esModule: true,
useDisasterRecoveryResourceWatch: () => [drResources, true, ''],
useDisasterRecoveryResourceWatch: jest.fn(() => {
if ([1].includes(testCase)) {
return [drResources2, true, ''];
} else {
return [drResources1, true, ''];
}
}),
}));
jest.mock('@odf/mco/hooks/argo-application-set', () => ({
__esModule: true,
useArgoApplicationSetResourceWatch: () => [appResources, true, ''],
useArgoApplicationSetResourceWatch: jest.fn(() => {
if ([1].includes(testCase)) {
return [appResources2, true, ''];
} else {
return [appResources1, true, ''];
}
}),
}));
jest.mock('../utils/k8s-utils', () => ({
unAssignPromises: jest.fn(() => [Promise.resolve({ data: {} })]),
}));

describe('ApplicationSet manage data policy modal', () => {
beforeEach(async () => {
test('Empty list page test', async () => {
testCase = 1;
render(
<ApplicationSetParser
application={mockApplicationSet1}
application={mockApplicationSet2}
close={onClose}
isOpen={true}
/>
);
// Ensure empty state
expect(
screen.getByText('No assigned data policy found')
).toBeInTheDocument();
expect(
screen.getByText(
"You haven't set a data policy for your application yet. To protect your application, click the 'Assign data policy' button and select a policy from the available templates."
)
).toBeInTheDocument();
});

test('manage data policy list view test', async () => {
testCase = 2;
render(
<ApplicationSetParser
application={mockApplicationSet1}
close={onClose}
isOpen={true}
/>
);

const searchBox = screen.getByPlaceholderText('Search');

// Modal headers
expect(screen.getByText('Manage data policy')).toBeInTheDocument();
expect(
screen.getByText(
'Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.'
'Assign a policy to protect the application and to ensure a quick recovery.'
)
).toBeInTheDocument();
expect(screen.getByText('My policies')).toBeInTheDocument();
expect(screen.getByText('My assigned policies')).toBeInTheDocument();

// Check primary action is enabled
expect(screen.getByText('Assign policy')).toBeEnabled();
expect(screen.getByText('Assign data policy')).toBeEnabled();

// Policy list table
expect(screen.getByLabelText('Selectable table')).toBeInTheDocument();
Expand All @@ -245,7 +366,9 @@ describe('ApplicationSet manage data policy modal', () => {
expect(screen.getByText('View configurations')).toBeInTheDocument();
// 2) Search using invalid policy
fireEvent.change(searchBox, { target: { value: 'invalid policy' } });
expect(screen.getByText('Not found')).toBeInTheDocument();
expect(
screen.getByText('No assigned data policy found')
).toBeInTheDocument();
fireEvent.change(searchBox, { target: { value: '' } });
});

Expand All @@ -254,7 +377,7 @@ describe('ApplicationSet manage data policy modal', () => {
// Select all policy
fireEvent.click(screen.getByLabelText('Select all rows'));
// Check primary action is disabled
expect(screen.getByText('Assign policy')).toBeDisabled();
expect(screen.getByText('Assign data policy')).toBeDisabled();
// Check secondary action is enabled
expect(screen.getByLabelText('Select input')).toBeEnabled();
// Trigger bulk unassign
Expand All @@ -279,6 +402,14 @@ describe('ApplicationSet manage data policy modal', () => {
});

test('Policy configuration view test', async () => {
testCase = 3;
render(
<ApplicationSetParser
application={mockApplicationSet1}
close={onClose}
isOpen={true}
/>
);
// Row actions
fireEvent.click(
screen.getByRole('button', {
Expand Down Expand Up @@ -322,6 +453,6 @@ describe('ApplicationSet manage data policy modal', () => {
// Footer
fireEvent.click(screen.getByText('Back'));
// Make sure context is switched to list view
expect(screen.getByText('My policies')).toBeInTheDocument();
expect(screen.getByText('My assigned policies')).toBeInTheDocument();
});
});
Loading

0 comments on commit 66ecd03

Please sign in to comment.