Skip to content

Commit

Permalink
Legg til toggle for delvis revurdering (#6685)
Browse files Browse the repository at this point in the history
* Legg til feature toggle DELVIS_REVURDERING

* Sett opp feature toggles i tester på riktig måte

* Fiks URLen til backend

* Autofiks imports

* Gjør useFeatureToggles litt mer resilient

* Forbedre typesettinger
  • Loading branch information
selbekk authored Oct 14, 2024
1 parent ecf6ee4 commit 1846699
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 20 deletions.
4 changes: 4 additions & 0 deletions _mocks/featureToggles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ export const featureTogglesFactory = () => [
key: 'AUTOMATISK_VURDERT_MEDLEMSKAP',
value: process.env.AUTOMATISK_VURDERT_MEDLEMSKAP,
},
{
key: 'DELVIS_REVURDERING',
value: process.env.VITE_DELVIS_REVURDERING,
},
];
2 changes: 2 additions & 0 deletions deploy/dev-fss-k9saksbehandling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ spec:
value: "true"
- name: AUTOMATISK_VURDERT_MEDLEMSKAP
value: "true"
- name: DELVIS_REVURDERING
value: "true"
2 changes: 2 additions & 0 deletions deploy/prod-fss-k9saksbehandling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,5 @@ spec:
value: "false"
- name: AUTOMATISK_VURDERT_MEDLEMSKAP
value: "true"
- name: DELVIS_REVURDERING
value: "false"
1 change: 1 addition & 0 deletions envDir/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ VITE_NYE_NOKKELTALL=true
VITE_PROSESS_VILKAR_SOKNADSFRIST=true
VITE_SKILL_UT_PRIVATPERSON=true
VITE_AUTOMATISK_VURDERT_MEDLEMSKAP=true
VITE_DELVIS_REVURDERING=true
4 changes: 4 additions & 0 deletions feature-toggles.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@
{
"key": "AUTOMATISK_VURDERT_MEDLEMSKAP",
"value": "${AUTOMATISK_VURDERT_MEDLEMSKAP}"
},
{
"key": "DELVIS_REVURDERING",
"value": "${DELVIS_REVURDERING}"
}
]
15 changes: 8 additions & 7 deletions packages/rest-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import getAxiosHttpClientApi from './src/axios/getAxiosHttpClientApi';
import RequestApi from './src/requestApi/RequestApi';
import RequestConfig from './src/RequestConfig';
import AbstractRequestApi from './src/requestApi/AbstractRequestApi';
import RequestApi from './src/requestApi/RequestApi';
import RequestApiMock from './src/requestApi/RequestApiMock';
import RequestConfig from './src/RequestConfig';

export { default as RequestApi } from './src/requestApi/RequestApi';
export { REQUEST_POLLING_CANCELLED } from './src/requestApi/RequestRunner';
export { default as RestApiConfigBuilder } from './src/RestApiConfigBuilder';
export { default as AbstractRequestApi } from './src/requestApi/AbstractRequestApi';
export { ErrorTypes, errorOfType, getErrorResponseData } from './src/requestApi/error/ErrorTypes';
export { default as apiPaths } from './src/requestApi/apiPaths';
export type { default as ErrorType } from './src/requestApi/error/errorTsType';
export { ErrorTypes, errorOfType, getErrorResponseData } from './src/requestApi/error/ErrorTypes';
export type { default as Link } from './src/requestApi/LinkTsType';
export { default as apiPaths } from './src/requestApi/apiPaths';
export { default as RequestApi } from './src/requestApi/RequestApi';
export { REQUEST_POLLING_CANCELLED } from './src/requestApi/RequestRunner';
export { default as RestApiConfigBuilder } from './src/RestApiConfigBuilder';

let isUnitTestModeOn = false;

export const switchOnTestMode = () => {
isUnitTestModeOn = true;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/sak-app/src/data/k9sakApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const endpoints = new RestApiConfigBuilder()
)
.withAsyncPost('/k9/tilbake/api/behandlinger/opprett', K9sakApiKeys.NEW_BEHANDLING_TILBAKE)
.withAsyncPost(
'/k9/tilbake/api/behandlinger/revurder-periode-fra-steg',
'/k9/sak/api/behandlinger/revurder-periode-fra-steg',
K9sakApiKeys.NEW_BEHANDLING_REVURDERING_FRA_STEG_K9SAK,
)
.withAsyncPut('/k9/sak/api/behandlinger', K9sakApiKeys.NEW_BEHANDLING_K9SAK)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import behandlingType from '@fpsak-frontend/kodeverk/src/behandlingType';
import fagsakYtelseType from '@fpsak-frontend/kodeverk/src/fagsakYtelseType';
import { renderWithIntlAndReduxForm } from '@fpsak-frontend/utils-test/test-utils';
import { K9sakApiKeys, requestApi } from '@k9-sak-web/sak-app/src/data/k9sakApi';
import { act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import MenyNyBehandlingIndex from './MenyNyBehandlingIndex';

describe('<MenyNyBehandlingIndex>', () => {
beforeEach(() => {
requestApi.mock(K9sakApiKeys.FEATURE_TOGGLE, [{ key: 'DELVIS_REVURDERING', value: true }]);
});
it('skal vise modal og så lage ny behandling', async () => {
const lagNyBehandlingCallback = vi.fn().mockImplementation(() => Promise.resolve());
const lukkModalCallback = vi.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { action } from '@storybook/addon-actions';
import React from 'react';

import behandlingArsakType from '@fpsak-frontend/kodeverk/src/behandlingArsakType';
import behandlingType from '@fpsak-frontend/kodeverk/src/behandlingType';
import fagsakYtelseType from '@fpsak-frontend/kodeverk/src/fagsakYtelseType';
import { Meta } from '@storybook/react';
import MenyNyBehandlingIndex from './MenyNyBehandlingIndex';

export default {
title: 'sak/sak-meny-ny-behandling',
component: MenyNyBehandlingIndex,
};
parameters: {},
} satisfies Meta;

const behandlingstyper = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import fagsakYtelseType from '@fpsak-frontend/kodeverk/src/fagsakYtelseType';
import { intlWithMessages } from '@fpsak-frontend/utils-test/intl-test-helper';
import { reduxFormPropsMock } from '@fpsak-frontend/utils-test/redux-form-test-helper';
import { renderWithIntlAndReduxForm } from '@fpsak-frontend/utils-test/test-utils';
import { K9sakApiKeys, requestApi } from '@k9-sak-web/sak-app/src/data/k9sakApi';
import { act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import {
NyBehandlingModal,
getBehandlingAarsaker,
Expand All @@ -25,6 +25,10 @@ describe('<NyBehandlingModal>', () => {
kodeverk: '',
};

beforeEach(() => {
requestApi.mock(K9sakApiKeys.FEATURE_TOGGLE, [{ key: 'DELVIS_REVURDERING', value: true }]);
});

it('skal rendre komponent korrekt', () => {
const behandlingstyper = [
{ kode: behandlingType.FORSTEGANGSSOKNAD, navn: 'FØRSTEGANGSSØKNAD', kodeverk: 'BEHANDLING_TYPE' },
Expand Down Expand Up @@ -69,7 +73,7 @@ describe('<NyBehandlingModal>', () => {

expect(screen.getByRole('dialog', { name: 'Ny behandling' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Opprett behandling' })).toBeInTheDocument();
expect(screen.getAllByRole('combobox').length).toBe(2);
expect(screen.getAllByRole('combobox').length).toBe(1);
});

it('skal bruke submit-callback når en trykker lagre', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CheckboxField, DatepickerField, SelectField } from '@fpsak-frontend/form';
import behandlingArsakType from '@fpsak-frontend/kodeverk/src/behandlingArsakType';
import bType from '@fpsak-frontend/kodeverk/src/behandlingType';
import { useFeatureToggles } from '@fpsak-frontend/shared-components';
import { required } from '@fpsak-frontend/utils';
import { Kodeverk, KodeverkMedNavn } from '@k9-sak-web/types';
import { Button, Fieldset, HStack, Modal, VStack } from '@navikt/ds-react';
Expand Down Expand Up @@ -106,8 +107,13 @@ export const NyBehandlingModal = ({
}
}
}, []);
const [featureToggles] = useFeatureToggles();
const erFørstegangsbehandling = valgtBehandlingTypeKode === bType.FORSTEGANGSSOKNAD;
const erRevurdering = valgtBehandlingTypeKode === bType.REVURDERING;
const erDelvisRevurderingToggleAktivert = featureToggles?.DELVIS_REVURDERING;
const visÅrsak =
(erDelvisRevurderingToggleAktivert && erRevurdering && steg === 'inngangsvilkår') ||
(!erDelvisRevurderingToggleAktivert && behandlingArsakTyper.length > 0);
return (
<Modal
className={styles.modal}
Expand All @@ -129,7 +135,7 @@ export const NyBehandlingModal = ({
validate={[required]}
selectValues={behandlingTyper.map(bt => createOptions(bt, enabledBehandlingstyper))}
/>
{erRevurdering && (
{erDelvisRevurderingToggleAktivert && erRevurdering && (
<SelectField
name="steg"
label="Hvor i prosessen vil du starte revurderingen?"
Expand All @@ -151,10 +157,10 @@ export const NyBehandlingModal = ({
label="Behandlingen opprettes som et resultat av klagebehandling"
/>
)}
{behandlingArsakTyper.length > 0 && (!erRevurdering || steg === 'inngangsvilkår') && (
{visÅrsak && (
<SelectField
name="behandlingArsakType"
label="Hva er årsaken til revurderingen?"
label="Hva er årsaken til den nye behandlingen?"
placeholder="Velg årsak"
validate={[required]}
selectValues={behandlingArsakTyper.map(b => (
Expand All @@ -164,7 +170,7 @@ export const NyBehandlingModal = ({
))}
/>
)}
{erRevurdering && steg === 'RE-ENDRET-FORDELING' && (
{erDelvisRevurderingToggleAktivert && erRevurdering && steg === 'RE-ENDRET-FORDELING' && (
<Fieldset className={styles.datePickerContainer} legend="Hvilken periode vil du revurdere?">
<DatepickerField name="fom" disabledDays={{ before: null, after: new Date() }} label="Fra og med" />
<DatepickerField
Expand Down Expand Up @@ -236,7 +242,6 @@ export const getBehandlingAarsaker = createSelector(
.map(ar => alleTilbakekrevingRevurderingArsaker.find(el => el.kode === ar))
.filter(ar => ar);
}
// TODO lage en egen for UNNTAK når vi vet hvilke det skal være
if (valgtBehandlingType === bType.REVURDERING) {
return alleRevurderingArsaker
.filter(bat => manuelleRevurderingsArsaker.indexOf(bat.kode) > -1)
Expand Down
4 changes: 2 additions & 2 deletions packages/shared-components/src/hooks/useFeatureToggles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { K9sakApiKeys, restApiHooks } from '@k9-sak-web/sak-app/src/data/k9sakApi';
import FeatureToggles from '@k9-sak-web/types/src/featureTogglesTsType';
import { useMemo } from 'react';

const useFeatureToggles = (): [FeatureToggles] => {
const featureTogglesData = restApiHooks.useGlobalStateRestApiData<{ key: string; value: string }[]>(
Expand All @@ -16,7 +16,7 @@ const useFeatureToggles = (): [FeatureToggles] => {
[featureTogglesData],
);

return [featureToggles];
return [featureToggles ?? {}];
};

export default useFeatureToggles;

0 comments on commit 1846699

Please sign in to comment.