From a98c0bcab762b61dcd2b499b39ad20d1d9d2c3d4 Mon Sep 17 00:00:00 2001 From: stigus Date: Thu, 4 Jan 2024 16:54:04 +0100 Subject: [PATCH] =?UTF-8?q?Lagt=20til=20test=20for=20FlyttPersoner=20og=20?= =?UTF-8?q?endret=20en=20god=20del=20p=C3=A5=20oppsett=20for=20Cypress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/js/cypress/e2e/FlyttPersoner.cy.ts | 27 ++++++ .../src/main/js/cypress/e2e/Gruppe.cy.ts | 32 +------ .../src/main/js/cypress/mocks/BasicMocks.tsx | 2 + .../src/main/js/cypress/support/e2e.ts | 3 +- .../src/main/js/package-lock.json | 38 ++++---- .../fagsystem/krrstub/form/KrrForm.tsx | 16 +--- .../fagsystem/krrstub/form/KrrValidation.tsx | 5 +- .../FlyttPersonButton/FlyttPersonModal.tsx | 81 ++++++++--------- .../components/ui/form/inputs/label/Label.tsx | 4 +- .../ui/form/inputs/select/Select.tsx | 5 +- .../js/src/components/velgGruppe/NyGruppe.tsx | 87 ++++++++++--------- .../src/pages/minSide/maler/Maloversikt.tsx | 16 +++- 12 files changed, 159 insertions(+), 157 deletions(-) create mode 100644 apps/dolly-frontend/src/main/js/cypress/e2e/FlyttPersoner.cy.ts diff --git a/apps/dolly-frontend/src/main/js/cypress/e2e/FlyttPersoner.cy.ts b/apps/dolly-frontend/src/main/js/cypress/e2e/FlyttPersoner.cy.ts new file mode 100644 index 00000000000..06794891d0b --- /dev/null +++ b/apps/dolly-frontend/src/main/js/cypress/e2e/FlyttPersoner.cy.ts @@ -0,0 +1,27 @@ +import { CypressSelector } from '../mocks/Selectors' + +describe('Dolly flyttPersoner testing', () => { + it('passes', () => { + cy.visit('http://localhost:5678/gruppe') + + cy.get('div').contains('Testytest').click() + + cy.dollyGet(CypressSelector.BUTTON_FLYTT_PERSONER).click() + + cy.dollyGet(CypressSelector.TOGGLE_ALLE_GRUPPER).click() + cy.dollyGet(CypressSelector.TOGGLE_EKSISTERENDE_GRUPPE).click() + cy.dollyGet(CypressSelector.TOGGLE_NY_GRUPPE).click() + + cy.dollyGet(CypressSelector.INPUT_NY_GRUPPE_NAVN).type('TestNavn') + cy.dollyGet(CypressSelector.INPUT_NY_GRUPPE_HENSIKT).type('TestHensikt') + cy.dollyGet(CypressSelector.BUTTON_NY_GRUPPE_OPPRETT).click() + + cy.get('.navds-checkbox__label').contains('12345678912').click() + + cy.dollyGet(CypressSelector.CONTAINER_VALGTE_PERSONER).should('contain', '12345678912') + cy.dollyGet(CypressSelector.BUTTON_FLYTT_PERSONER_NULLSTILL).click() + cy.dollyGet(CypressSelector.CONTAINER_VALGTE_PERSONER).should('not.contain', '12345678912') + + cy.dollyGet(CypressSelector.BUTTON_FLYTT_PERSONER_AVBRYT).click() + }) +}) diff --git a/apps/dolly-frontend/src/main/js/cypress/e2e/Gruppe.cy.ts b/apps/dolly-frontend/src/main/js/cypress/e2e/Gruppe.cy.ts index 257c2c92ced..cfa640f4333 100644 --- a/apps/dolly-frontend/src/main/js/cypress/e2e/Gruppe.cy.ts +++ b/apps/dolly-frontend/src/main/js/cypress/e2e/Gruppe.cy.ts @@ -1,48 +1,18 @@ import { CypressSelector } from '../mocks/Selectors' import { avbruttBestillingMock, - personFragmentNavigerMock, uferdigBestillingMock, uferdigeBestillingerMock, } from '../mocks/BasicMocks' -import { ERROR_NAVIGATE_IDENT } from '../../src/ducks/errors/ErrorMessages' const uferdigBestilling = new RegExp(/dolly-backend\/api\/v1\/bestilling\/2$/) const uferdigeBestillinger = new RegExp(/dolly-backend\/api\/v1\/bestilling\/gruppe\/2\/ikkeferdig/) const personFragmentNaviger = new RegExp(/dolly-backend\/api\/v1\/ident\/naviger\/12345678912/) -describe('Navigering, Opprett gruppe og start bestilling med alle mulige tilvalg', () => { +describe('Opprett gruppe og start bestilling med alle mulige tilvalg', () => { it('passes', () => { cy.visit('http://localhost:5678/gruppe') - //Midlertidig not found på navigering til ident etter søk - cy.intercept({ method: 'GET', url: personFragmentNaviger }, { statusCode: 404 }) - - cy.dollyType(CypressSelector.INPUT_DOLLY_SOEK, '12345') - cy.dollyGet(CypressSelector.BUTTON_NAVIGER_DOLLY).click() - cy.wait(400) - - cy.dollyGet(CypressSelector.ERROR_MESSAGE_NAVIGERING).should( - 'contains.text', - ERROR_NAVIGATE_IDENT, - ) - - //Korrekt navigering igjen - cy.intercept({ method: 'GET', url: personFragmentNaviger }, personFragmentNavigerMock) - - cy.dollyGet(CypressSelector.TOGGLE_SEARCH_BESTILLING).click() - cy.dollyType(CypressSelector.INPUT_DOLLY_SOEK, '1') - cy.dollyGet(CypressSelector.BUTTON_NAVIGER_DOLLY).click() - cy.dollyGet(CypressSelector.TOGGLE_SEARCH_PERSON).click() - - cy.dollyType(CypressSelector.INPUT_DOLLY_SOEK, '12345') - cy.dollyGet(CypressSelector.BUTTON_NAVIGER_DOLLY).click() - cy.wait(400) - - cy.url().should('include', '/gruppe/1') - - cy.dollyGet(CypressSelector.BUTTON_HEADER_PERSONER).click() - // Naviger mellom tabs cy.dollyGet(CypressSelector.TOGGLE_FAVORITTER).click() cy.dollyGet(CypressSelector.TOGGLE_ALLE).click() diff --git a/apps/dolly-frontend/src/main/js/cypress/mocks/BasicMocks.tsx b/apps/dolly-frontend/src/main/js/cypress/mocks/BasicMocks.tsx index ae7b8d6eabb..6622ad99984 100644 --- a/apps/dolly-frontend/src/main/js/cypress/mocks/BasicMocks.tsx +++ b/apps/dolly-frontend/src/main/js/cypress/mocks/BasicMocks.tsx @@ -881,6 +881,8 @@ export const pensjonMock = [ export const pensjonTpMock = [{ ordning: '4095' }, { ordning: '3010' }] +export const tagsMock = [{ tag: 'DUMMY', beskrivelse: 'Dummy' }] + export const kontoregisterMock = { kontohaver: '12345678912', kontonummer: '99999999999', diff --git a/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts b/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts index f80bcaef901..565f0f3ac27 100644 --- a/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts +++ b/apps/dolly-frontend/src/main/js/cypress/support/e2e.ts @@ -35,6 +35,7 @@ import { personFragmentSearchMock, sigrunstubMock, skjermingMock, + tagsMock, tpsMessagingMock, udistubMock, } from '../mocks/BasicMocks' @@ -120,7 +121,7 @@ beforeEach(() => { cy.intercept({ method: 'GET', url: pdlPersonEnkelt }, pdlPersonEnkeltMock) cy.intercept({ method: 'GET', url: pdlForvalter }, pdlForvalterMock) cy.intercept({ method: 'POST', url: kontoregister }, kontoregisterMock) - cy.intercept({ method: 'GET', url: tags }, { body: {} }) + cy.intercept({ method: 'GET', url: tags }, tagsMock) cy.intercept({ method: 'GET', url: backendTransaksjon }, backendTransaksjonMock) cy.intercept({ method: 'GET', url: brukerMaler }, brukerMalerMock) cy.intercept({ method: 'GET', url: oppsummeringsdokService }, oppsummeringsdokumentServiceMock) diff --git a/apps/dolly-frontend/src/main/js/package-lock.json b/apps/dolly-frontend/src/main/js/package-lock.json index 898df9fd528..405f464ccbc 100644 --- a/apps/dolly-frontend/src/main/js/package-lock.json +++ b/apps/dolly-frontend/src/main/js/package-lock.json @@ -1375,9 +1375,9 @@ } }, "node_modules/@hookform/resolvers": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.3.3.tgz", - "integrity": "sha512-bOMxKkSD3zWcS11TKoUQ8O0ZqKslFohvUsPKSrdCHiuEuMjRo/u3cq9YRJD/+xtNGYup++XD2LkjhegP5XENiw==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.3.4.tgz", + "integrity": "sha512-o5cgpGOuJYrd+iMKvkttOclgwRW86EsWJZZRC23prf0uU2i48Htq4PuT73AVb9ionFyZrwYEITuOFGF+BydEtQ==", "peerDependencies": { "react-hook-form": "^7.0.0" } @@ -3171,9 +3171,9 @@ } }, "node_modules/@types/node-forge": { - "version": "1.3.10", - "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.10.tgz", - "integrity": "sha512-y6PJDYN4xYBxwd22l+OVH35N+1fCYWiuC3aiP2SlXVE6Lo7SS+rSx9r89hLxrP4pn6n1lBGhHJ12pj3F3Mpttw==", + "version": "1.3.11", + "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.11.tgz", + "integrity": "sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==", "dev": true, "dependencies": { "@types/node": "*" @@ -4129,11 +4129,11 @@ } }, "node_modules/axios": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.3.tgz", - "integrity": "sha512-fWyNdeawGam70jXSVlKl+SUNVcL6j6W79CuSIPfi6HnDUmSCH6gyUys/HrqHeA/wU0Az41rRgean494d0Jb+ww==", + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.4.tgz", + "integrity": "sha512-heJnIs6N4aa1eSthhN9M5ioILu8Wi8vmQW9iHQ9NUvfkJb0lEEDUiIdQNAuBtfUt3FxReaKdpQA5DbmMOqzF/A==", "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.4", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -4360,9 +4360,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001572", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001572.tgz", - "integrity": "sha512-1Pbh5FLmn5y4+QhNyJE9j3/7dK44dGB83/ZMjv/qJk86TvDbjk0LosiZo0i0WB0Vx607qMX9jYrn1VLHCkN4rw==", + "version": "1.0.30001574", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001574.tgz", + "integrity": "sha512-BtYEK4r/iHt/txm81KBudCUcTy7t+s9emrIaHqjYurQ10x71zJ5VQ9x1dYPcz/b+pKSp4y/v1xSI67A+LzpNyg==", "funding": [ { "type": "opencollective", @@ -5356,9 +5356,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.616", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.616.tgz", - "integrity": "sha512-1n7zWYh8eS0L9Uy+GskE0lkBUNK83cXTVJI0pU3mGprFsbfSdAc15VTFbo+A+Bq4pwstmL30AVcEU3Fo463lNg==" + "version": "1.4.620", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.620.tgz", + "integrity": "sha512-a2fcSHOHrqBJsPNXtf6ZCEZpXrFCcbK1FBxfX3txoqWzNgtEDG1f3M59M98iwxhRW4iMKESnSjbJ310/rkrp0g==" }, "node_modules/emoji-regex": { "version": "9.2.2", @@ -10516,9 +10516,9 @@ "dev": true }, "node_modules/sass": { - "version": "1.69.6", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.69.6.tgz", - "integrity": "sha512-qbRr3k9JGHWXCvZU77SD2OTwUlC+gNT+61JOLcmLm+XqH4h/5D+p4IIsxvpkB89S9AwJOyb5+rWNpIucaFxSFQ==", + "version": "1.69.7", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.69.7.tgz", + "integrity": "sha512-rzj2soDeZ8wtE2egyLXgOOHQvaC2iosZrkF6v3EUG+tBwEvhqUCzm0VP3k9gHF9LXbSrRhT5SksoI56Iw8NPnQ==", "dev": true, "dependencies": { "chokidar": ">=3.0.0 <4.0.0", diff --git a/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrForm.tsx b/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrForm.tsx index 6dc72bfe3d2..b4b8fe4c480 100644 --- a/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrForm.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrForm.tsx @@ -94,18 +94,4 @@ export const KrrstubForm = () => { ) } -KrrstubForm.validation = { - krrstub: Yup.object({ - epost: Yup.string(), - gyldigFra: Yup.date().nullable(), - mobil: Yup.string().matches(/^\+?\d{8,14}$/, { - message: 'Ugyldig telefonnummer', - excludeEmptyString: true, - }), - sdpAdresse: Yup.string(), - sdpLeverandoer: Yup.string().nullable(), - spraak: Yup.string(), - registrert: ifPresent('$krrstub.registrert', requiredBoolean), - reservert: Yup.boolean().nullable(), - }), -} +KrrstubForm.validation = KrrValidation diff --git a/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrValidation.tsx b/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrValidation.tsx index ac0abaf766f..11aed24829a 100644 --- a/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrValidation.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/fagsystem/krrstub/form/KrrValidation.tsx @@ -7,7 +7,10 @@ export const KrrValidation = { Yup.object({ epost: Yup.string(), gyldigFra: Yup.date().nullable(), - mobil: Yup.string().matches(/^\+?\d*$/, 'Ugyldig mobilnummer'), + mobil: Yup.string().matches(/^\+?\d{8,14}$/, { + message: 'Ugyldig telefonnummer', + excludeEmptyString: true, + }), sdpAdresse: Yup.string(), sdpLeverandoer: Yup.string().nullable(), spraak: Yup.string(), diff --git a/apps/dolly-frontend/src/main/js/src/components/ui/button/FlyttPersonButton/FlyttPersonModal.tsx b/apps/dolly-frontend/src/main/js/src/components/ui/button/FlyttPersonButton/FlyttPersonModal.tsx index d198893cffc..8c1e73c1db3 100644 --- a/apps/dolly-frontend/src/main/js/src/components/ui/button/FlyttPersonButton/FlyttPersonModal.tsx +++ b/apps/dolly-frontend/src/main/js/src/components/ui/button/FlyttPersonButton/FlyttPersonModal.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useRef, useState } from 'react' +import React, { useState } from 'react' import * as Yup from 'yup' import Button from '@/components/ui/button/Button' import DollyModal from '@/components/ui/modal/DollyModal' @@ -135,7 +135,7 @@ const StyledErrorMessageWithFocus = styled(DollyErrorMessage)` export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPersonButtonTypes) => { const formMethods = useForm({ - defaultValues: { identer: [], gruppeId: null }, + defaultValues: { identer: [], gruppeId: '' }, resolver: yupResolver(validation), }) const [loading, setLoading] = useState(false) @@ -169,7 +169,10 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer const gruppeOptions = getGruppeOptions() const gruppeIdenterListe = Array.isArray(gruppeOptions) - ? gruppeOptions?.map((person) => person?.value).filter((person) => person) + ? gruppeOptions + ?.map((person) => person?.value) + .filter((person) => person) + .map((person) => ({ fnr: person })) : [] const getRelatertePersoner = (identer: Array, identerHentet = [] as Array) => { @@ -182,7 +185,7 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer ) if (funnetIdent) { relatertePersonerHentet.push(funnetIdent.value) - identerNye.push(...funnetIdent.relasjoner) + funnetIdent.relasjoner && identerNye.push(...funnetIdent.relasjoner) } }) if (identerNye.length > 0) { @@ -206,31 +209,22 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer return relatert } - const mountedRef = useRef(true) - - const handleSubmit = useCallback( - (formMethods: any) => { - const submit = async () => { - setLoading(true) - const { gruppeId, identer } = formMethods - const relasjoner = getRelatertePersoner(identer) - const identerSamlet = Array.from(new Set([...identer, ...relasjoner])) - await DollyApi.flyttPersonerTilGruppe(gruppeId, identerSamlet) - .then(() => { - closeModal() - setLoading(false) - navigate(`../gruppe/${gruppeId}`) - }) - .catch((e: Error) => { - setError(e.message) - setLoading(false) - }) - } - mountedRef.current = false - return submit() - }, - [gruppeOptions], - ) + const handleSubmit = () => { + const { identer, gruppeId } = formMethods.getValues() + const identerFormatert = identer.map((ident) => ident.fnr) + const relasjoner = getRelatertePersoner(identerFormatert) + const identerSamlet = Array.from(new Set([...identerFormatert, ...relasjoner])) + DollyApi.flyttPersonerTilGruppe(gruppeId, identerSamlet) + .then(() => { + closeModal() + setLoading(false) + navigate(`../gruppe/${gruppeId}`) + }) + .catch((e: Error) => { + setError(e.message) + setLoading(false) + }) + } const handleClose = () => { closeModal() @@ -241,12 +235,16 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer const FlyttPersonForm = () => { const formMethods = useFormContext() const [searchText, setSearchText] = useState('') - const fieldMethods = useFieldArray({ control: formMethods.control, name: 'identer' }) - const values = fieldMethods.fields.values?.identer - const isChecked = (id: string) => values?.includes(id) + const fieldMethods = useFieldArray({ + control: formMethods.control, + name: 'identer', + }) + const isChecked = (id: string) => fieldMethods.fields?.find((i) => i.fnr === id) const onClick = (e: { target: any }) => { - const { id } = e.target - isChecked(id) ? fieldMethods.remove(values?.indexOf(id)) : fieldMethods.append(id) + const id = e.target.id + isChecked(id) + ? fieldMethods.remove(fieldMethods.fields?.map((value) => value.fnr).indexOf(id)) + : fieldMethods.append({ fnr: id }) } return ( @@ -301,7 +299,9 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer key={person.value} id={person.value} label={person.label} - checked={values?.includes(person.value)} + checked={fieldMethods.fields + .map((val) => val.fnr) + ?.includes(person.value)} onChange={onClick} size="small" attributtCheckbox @@ -325,6 +325,7 @@ export const FlyttPersonModal = ({ gruppeId, modalIsOpen, closeModal }: FlyttPer VELG ALLE