mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
chore: allow CR selection when no envs are enabled (#7183)
This PR allows you to configure change requests for all environments when no environments are enabled explicitly. This is the default state of the form and makes it so that you can configure CRs even if you want all envs enabled. Additionally, it preserves the case where you configure CRs for an environment and then disable all envs. This is logic only. It's not available in the UI yet.
This commit is contained in:
parent
cea64dc21d
commit
c8fa7e477a
@ -1,39 +1,70 @@
|
|||||||
import { renderHook } from '@testing-library/react-hooks';
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
import useProjectForm from './useProjectForm';
|
import useProjectForm from './useProjectForm';
|
||||||
|
|
||||||
test('setting project environments removes any change request envs that are not in the new project env list', () => {
|
describe('configuring change requests', () => {
|
||||||
const { result } = renderHook(() => useProjectForm());
|
test('setting project environments removes any change request envs that are not in the new project env list', () => {
|
||||||
|
const { result } = renderHook(() => useProjectForm());
|
||||||
|
|
||||||
result.current.setProjectEnvironments(new Set(['dev', 'prod']));
|
result.current.setProjectEnvironments(new Set(['dev', 'prod']));
|
||||||
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
||||||
'prod',
|
'prod',
|
||||||
5,
|
5,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result.current.projectChangeRequestConfiguration).toMatchObject({
|
expect(result.current.projectChangeRequestConfiguration).toMatchObject({
|
||||||
prod: { requiredApprovals: 5 },
|
prod: { requiredApprovals: 5 },
|
||||||
|
});
|
||||||
|
|
||||||
|
result.current.setProjectEnvironments(new Set(['dev']));
|
||||||
|
|
||||||
|
expect(
|
||||||
|
'prod' in result.current.projectChangeRequestConfiguration,
|
||||||
|
).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
result.current.setProjectEnvironments(new Set(['dev']));
|
test('setting project environments to an empty set preserves change request configuration', () => {
|
||||||
|
const { result } = renderHook(() => useProjectForm());
|
||||||
|
|
||||||
expect(
|
result.current.setProjectEnvironments(new Set(['dev', 'prod']));
|
||||||
'prod' in result.current.projectChangeRequestConfiguration,
|
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
||||||
).toBeFalsy();
|
'prod',
|
||||||
});
|
5,
|
||||||
|
);
|
||||||
|
|
||||||
test(`adding a change request config for an env not in the project envs doesn't work and the change request envs is not changed`, () => {
|
result.current.setProjectEnvironments(new Set([]));
|
||||||
const { result } = renderHook(() => useProjectForm());
|
|
||||||
|
|
||||||
result.current.setProjectEnvironments(new Set(['prod']));
|
expect(result.current.projectChangeRequestConfiguration).toMatchObject({
|
||||||
|
prod: { requiredApprovals: 5 },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
test(`if specific project envs are selected, adding a change request config for an env not in the project envs doesn't work and the change request envs is not changed`, () => {
|
||||||
'dev',
|
const { result } = renderHook(() => useProjectForm());
|
||||||
5,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
result.current.setProjectEnvironments(new Set(['prod']));
|
||||||
'dev' in result.current.projectChangeRequestConfiguration,
|
|
||||||
).toBeFalsy();
|
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
||||||
|
'dev',
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
'dev' in result.current.projectChangeRequestConfiguration,
|
||||||
|
).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test(`if no project envs are selected, you can add a change request for any env you want`, () => {
|
||||||
|
const { result } = renderHook(() => useProjectForm());
|
||||||
|
|
||||||
|
result.current.updateProjectChangeRequestConfig.enableChangeRequests(
|
||||||
|
'dev',
|
||||||
|
5,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
'dev' in result.current.projectChangeRequestConfiguration,
|
||||||
|
).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('payload generation', () => {
|
describe('payload generation', () => {
|
||||||
|
@ -38,13 +38,16 @@ const useProjectForm = (
|
|||||||
] = useState(initialProjectChangeRequestConfiguration);
|
] = useState(initialProjectChangeRequestConfiguration);
|
||||||
|
|
||||||
const updateProjectEnvironments = (newState: Set<string>) => {
|
const updateProjectEnvironments = (newState: Set<string>) => {
|
||||||
const filteredChangeRequestEnvs = Object.fromEntries(
|
if (newState.size !== 0) {
|
||||||
Object.entries(projectChangeRequestConfiguration).filter(([env]) =>
|
const filteredChangeRequestEnvs = Object.fromEntries(
|
||||||
newState.has(env),
|
Object.entries(projectChangeRequestConfiguration).filter(
|
||||||
),
|
([env]) => newState.has(env),
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
setProjectChangeRequestConfiguration(filteredChangeRequestEnvs);
|
||||||
|
}
|
||||||
|
|
||||||
setProjectChangeRequestConfiguration(filteredChangeRequestEnvs);
|
|
||||||
setProjectEnvironments(newState);
|
setProjectEnvironments(newState);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -57,7 +60,10 @@ const useProjectForm = (
|
|||||||
},
|
},
|
||||||
|
|
||||||
enableChangeRequests: (env: string, approvals: number) => {
|
enableChangeRequests: (env: string, approvals: number) => {
|
||||||
if (projectEnvironments.has(env)) {
|
if (
|
||||||
|
projectEnvironments.has(env) ||
|
||||||
|
projectEnvironments.size === 0
|
||||||
|
) {
|
||||||
setProjectChangeRequestConfiguration((previousState) => ({
|
setProjectChangeRequestConfiguration((previousState) => ({
|
||||||
...previousState,
|
...previousState,
|
||||||
[env]: { requiredApprovals: approvals },
|
[env]: { requiredApprovals: approvals },
|
||||||
|
Loading…
Reference in New Issue
Block a user