From 184669918445a0e6953f1541a253f0a38576f998 Mon Sep 17 00:00:00 2001 From: Kristofer Giltvedt Selbekk Date: Mon, 14 Oct 2024 10:18:04 +0200 Subject: [PATCH] Legg til toggle for delvis revurdering (#6685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- _mocks/featureToggles.ts | 4 ++++ deploy/dev-fss-k9saksbehandling.yml | 2 ++ deploy/prod-fss-k9saksbehandling.yml | 2 ++ envDir/.env.development | 1 + feature-toggles.json | 4 ++++ packages/rest-api/index.ts | 15 ++++++++------- packages/sak-app/src/data/k9sakApi.ts | 2 +- .../src/MenyNyBehandlingIndex.spec.tsx | 5 ++++- .../src/MenyNyBehandlingIndex.stories.tsx | 5 +++-- .../src/components/NyBehandlingModal.spec.tsx | 8 ++++++-- .../src/components/NyBehandlingModal.tsx | 15 ++++++++++----- .../src/hooks/useFeatureToggles.tsx | 4 ++-- 12 files changed, 47 insertions(+), 20 deletions(-) diff --git a/_mocks/featureToggles.ts b/_mocks/featureToggles.ts index a9f255c840..127fdc26e5 100644 --- a/_mocks/featureToggles.ts +++ b/_mocks/featureToggles.ts @@ -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, + }, ]; diff --git a/deploy/dev-fss-k9saksbehandling.yml b/deploy/dev-fss-k9saksbehandling.yml index 629220140e..fa82456cf2 100644 --- a/deploy/dev-fss-k9saksbehandling.yml +++ b/deploy/dev-fss-k9saksbehandling.yml @@ -113,3 +113,5 @@ spec: value: "true" - name: AUTOMATISK_VURDERT_MEDLEMSKAP value: "true" + - name: DELVIS_REVURDERING + value: "true" diff --git a/deploy/prod-fss-k9saksbehandling.yml b/deploy/prod-fss-k9saksbehandling.yml index 8933e17c45..5cf3fabcdd 100644 --- a/deploy/prod-fss-k9saksbehandling.yml +++ b/deploy/prod-fss-k9saksbehandling.yml @@ -110,3 +110,5 @@ spec: value: "false" - name: AUTOMATISK_VURDERT_MEDLEMSKAP value: "true" + - name: DELVIS_REVURDERING + value: "false" diff --git a/envDir/.env.development b/envDir/.env.development index f363a894ac..5d62672aaa 100644 --- a/envDir/.env.development +++ b/envDir/.env.development @@ -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 diff --git a/feature-toggles.json b/feature-toggles.json index 48fa6f26dd..1bb708fa39 100644 --- a/feature-toggles.json +++ b/feature-toggles.json @@ -94,5 +94,9 @@ { "key": "AUTOMATISK_VURDERT_MEDLEMSKAP", "value": "${AUTOMATISK_VURDERT_MEDLEMSKAP}" + }, + { + "key": "DELVIS_REVURDERING", + "value": "${DELVIS_REVURDERING}" } ] diff --git a/packages/rest-api/index.ts b/packages/rest-api/index.ts index f44a8a0874..e2cab65136 100644 --- a/packages/rest-api/index.ts +++ b/packages/rest-api/index.ts @@ -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; }; diff --git a/packages/sak-app/src/data/k9sakApi.ts b/packages/sak-app/src/data/k9sakApi.ts index 9636bc3e5d..c351395946 100644 --- a/packages/sak-app/src/data/k9sakApi.ts +++ b/packages/sak-app/src/data/k9sakApi.ts @@ -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) diff --git a/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.spec.tsx b/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.spec.tsx index a643f38f19..e73ca733f8 100644 --- a/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.spec.tsx +++ b/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.spec.tsx @@ -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('', () => { + 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(); diff --git a/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.stories.tsx b/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.stories.tsx index 89ac6063fa..46b138eb99 100644 --- a/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.stories.tsx +++ b/packages/sak-meny-ny-behandling/src/MenyNyBehandlingIndex.stories.tsx @@ -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 = [ { diff --git a/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.spec.tsx b/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.spec.tsx index a9ddb9b4f9..d05c379d24 100644 --- a/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.spec.tsx +++ b/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.spec.tsx @@ -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, @@ -25,6 +25,10 @@ describe('', () => { 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' }, @@ -69,7 +73,7 @@ describe('', () => { 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 () => { diff --git a/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.tsx b/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.tsx index 64cb3206d6..b68675befe 100644 --- a/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.tsx +++ b/packages/sak-meny-ny-behandling/src/components/NyBehandlingModal.tsx @@ -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'; @@ -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 ( createOptions(bt, enabledBehandlingstyper))} /> - {erRevurdering && ( + {erDelvisRevurderingToggleAktivert && erRevurdering && ( )} - {behandlingArsakTyper.length > 0 && (!erRevurdering || steg === 'inngangsvilkår') && ( + {visÅrsak && ( ( @@ -164,7 +170,7 @@ export const NyBehandlingModal = ({ ))} /> )} - {erRevurdering && steg === 'RE-ENDRET-FORDELING' && ( + {erDelvisRevurderingToggleAktivert && erRevurdering && steg === 'RE-ENDRET-FORDELING' && (
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) diff --git a/packages/shared-components/src/hooks/useFeatureToggles.tsx b/packages/shared-components/src/hooks/useFeatureToggles.tsx index abc554e4a2..2e3cf5baf2 100644 --- a/packages/shared-components/src/hooks/useFeatureToggles.tsx +++ b/packages/shared-components/src/hooks/useFeatureToggles.tsx @@ -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 }[]>( @@ -16,7 +16,7 @@ const useFeatureToggles = (): [FeatureToggles] => { [featureTogglesData], ); - return [featureToggles]; + return [featureToggles ?? {}]; }; export default useFeatureToggles;