From 2b976709de21bd37804b002cdae84fdcf5c281ac Mon Sep 17 00:00:00 2001 From: Marko Haarni Date: Mon, 14 Aug 2023 14:51:00 +0300 Subject: [PATCH 01/12] HAI-1789 Make sure that cable report application form is valid before save and quit (#352) When saving and quitting validate current page of the form and if it's not valid don't save and quit. --- .../johtoselvitys/JohtoselvitysContainer.tsx | 6 ++-- .../johtoselvitys/JohtoselvitysForm.test.tsx | 33 +++---------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/src/domain/johtoselvitys/JohtoselvitysContainer.tsx b/src/domain/johtoselvitys/JohtoselvitysContainer.tsx index bed82919d..2b4724464 100644 --- a/src/domain/johtoselvitys/JohtoselvitysContainer.tsx +++ b/src/domain/johtoselvitys/JohtoselvitysContainer.tsx @@ -486,11 +486,11 @@ const JohtoselvitysContainer: React.FC = ({ hankeData, application }) => } async function handleSaveAndQuit() { - // Make sure that name for the application exists before saving and quitting - const applicationNameValid = await trigger('applicationData.name', { + // Make sure that current application page is valid before saving and quitting + const applicationPageValid = await trigger(pageFieldsToValidate[activeStepIndex], { shouldFocus: true, }); - if (applicationNameValid) { + if (applicationPageValid) { await handlePageChange(saveAndQuit); } } diff --git a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx index 1fff51c55..7cd6ede1f 100644 --- a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx +++ b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx @@ -326,12 +326,6 @@ test('Save and quit works', async () => { // Fill basic information page fillBasicInformation(); - // Move to areas page - await user.click(screen.getByRole('button', { name: /seuraava/i })); - - expect(screen.queryByText(/hakemus tallennettu/i)).toBeInTheDocument(); - - fireEvent.click(screen.getByRole('button', { name: /sulje ilmoitus/i })); await user.click(screen.getByRole('button', { name: /tallenna ja keskeytä/i })); expect(screen.queryAllByText(/hakemus tallennettu/i).length).toBe(2); @@ -344,42 +338,24 @@ test('Save and quit works without hanke existing first', async () => { // Fill basic information page fillBasicInformation(); - // Move to areas page - await user.click(screen.getByRole('button', { name: /seuraava/i })); - - expect(screen.queryByText(/hakemus tallennettu/i)).toBeInTheDocument(); - - fireEvent.click(screen.getByRole('button', { name: /sulje ilmoitus/i })); await user.click(screen.getByRole('button', { name: /tallenna ja keskeytä/i })); expect(screen.queryAllByText(/hakemus tallennettu/i).length).toBe(2); expect(window.location.pathname).toBe('/fi/hankesalkku/HAI22-13'); }); -test('Should save and quit from the first page with just application name entered', async () => { - const { user } = render(, undefined, '/fi/johtoselvityshakemus'); - - fireEvent.change(screen.getByLabelText(/työn nimi/i), { - target: { value: 'Johtoselvitys testi' }, - }); - await user.click(screen.getByRole('button', { name: /tallenna ja keskeytä/i })); - - expect(screen.queryAllByText(/hakemus tallennettu/i).length).toBe(2); - expect(window.location.pathname).toBe('/fi/hankesalkku/HAI22-14'); -}); - -test('Should not save and quit if there is no application name', async () => { +test('Should not save and quit if current form page is not valid', async () => { const { user } = render(, undefined, '/fi/johtoselvityshakemus'); await user.click(screen.getByRole('button', { name: /tallenna ja keskeytä/i })); expect(window.location.pathname).toBe('/fi/johtoselvityshakemus'); - expect(screen.queryByText('Kenttä on pakollinen')).toBeInTheDocument(); + expect(screen.queryAllByText('Kenttä on pakollinen').length).toBeGreaterThan(1); }); test('Should show error message and not navigate away when save and quit fails', async () => { server.use( - rest.put('/api/hakemukset/:id', async (req, res, ctx) => { + rest.post('/api/hakemukset/:id', async (req, res, ctx) => { return res(ctx.status(500), ctx.json({ errorMessage: 'Failed for testing purposes' })); }) ); @@ -387,7 +363,6 @@ test('Should show error message and not navigate away when save and quit fails', const { user } = render(, undefined, '/fi/johtoselvityshakemus'); fillBasicInformation(); - await user.click(screen.getByRole('button', { name: /seuraava/i })); await user.click(screen.getByRole('button', { name: /tallenna ja keskeytä/i })); expect(screen.queryAllByText(/tallentaminen epäonnistui/i)[0]).toBeInTheDocument(); @@ -410,7 +385,7 @@ test('Should not save application between page changes when nothing is changed', expect(screen.queryByText(/hakemus tallennettu/i)).not.toBeInTheDocument(); }); -test('Should save existing application between page changes when there is changes', async () => { +test('Should save existing application between page changes when there are changes', async () => { const { user } = render(); fireEvent.change(screen.getByLabelText(/työn kuvaus/i), { From 5e451830efb124a72b670e397e56b72b5f87d29d Mon Sep 17 00:00:00 2001 From: Marko Haarni Date: Mon, 14 Aug 2023 15:06:21 +0300 Subject: [PATCH 02/12] HAI-1469 Make Helsinki logo to be language dependant (#354) Defined logoLanguage prop for Navigation and Footer components so that Helsinki logo language is changed when UI language is changed. --- src/common/components/footer/Footer.tsx | 6 +++--- src/common/components/header/Header.tsx | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/components/footer/Footer.tsx b/src/common/components/footer/Footer.tsx index b19657620..2418106a2 100644 --- a/src/common/components/footer/Footer.tsx +++ b/src/common/components/footer/Footer.tsx @@ -1,15 +1,15 @@ import React from 'react'; import { Link } from 'react-router-dom'; -import { Footer } from 'hds-react'; +import { Footer, LogoLanguage } from 'hds-react'; import { useTranslation } from 'react-i18next'; import { useLocalizedRoutes } from '../../hooks/useLocalizedRoutes'; const HaitatonFooter: React.FC = () => { - const { t } = useTranslation(); + const { t, i18n } = useTranslation(); const { MANUAL, HAITATON_INFO, ACCESSIBILITY, PRIVACY_POLICY } = useLocalizedRoutes(); return ( -