From 8df30d071820c3a0731269fbd4c5d37e8f670a7f Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Mon, 7 Jun 2021 18:34:30 -0400 Subject: [PATCH 1/8] TTAHUB-105: Added test for updating goal objectives. --- .../Pages/components/__tests__/GoalPicker.js | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js index b1d1d877d0..379eb4dd6c 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js @@ -5,7 +5,7 @@ import { render, screen, fireEvent, - waitFor, + waitFor } from '@testing-library/react'; import React from 'react'; import { FormProvider, useForm } from 'react-hook-form/dist/index.ie11'; @@ -154,6 +154,43 @@ describe('GoalPicker', () => { expect(screen.queryByText('test goal edited')).toBeVisible(); expect(screen.queryByText('another goal')).toBeVisible(); }); + + it('objective can be updated', async () => { + const availableGoals = []; + const selectedGoals = [ + { + id: 1, name: 'goal to edit', new: true, + objectives: [{ + id: 1, + title: 'orig objective 1', + ttaProvided: 'objective 1 desc', + status: 'In Progress', + }] + } + ]; + + render( + , + ); + + const optionsObjBtn = screen.getByRole('button', { name: /edit or delete objective 1 on goal 1/i }); + fireEvent.click(optionsObjBtn); + + const editObjBtn = await screen.findByRole('button', { name: 'Edit' }); + fireEvent.click(editObjBtn); + + let objectiveTitleTxtBx = screen.getByDisplayValue(/objective 1/i); + fireEvent.change(objectiveTitleTxtBx, { target: { value: 'updated objective 1' } }); + + const saveObjectiveBtn = await screen.getByRole('button', { name: /save objective 1 on goal 1/i }); + userEvent.click(saveObjectiveBtn); + + expect(screen.queryByText('orig objective 1')).not.toBeInTheDocument(); + expect(screen.queryByText('updated objective 1')).toBeVisible(); + }); }); describe('input box', () => { From 1aaeebc99f2adc529602e733257a4c824cbcae3c Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Mon, 7 Jun 2021 18:41:01 -0400 Subject: [PATCH 2/8] TTAHUB-105: Fix lint issue. --- .../Pages/components/__tests__/GoalPicker.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js index 379eb4dd6c..bc79140236 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js @@ -5,7 +5,7 @@ import { render, screen, fireEvent, - waitFor + waitFor, } from '@testing-library/react'; import React from 'react'; import { FormProvider, useForm } from 'react-hook-form/dist/index.ie11'; @@ -159,14 +159,16 @@ describe('GoalPicker', () => { const availableGoals = []; const selectedGoals = [ { - id: 1, name: 'goal to edit', new: true, + id: 1, + name: 'goal to edit', + new: true, objectives: [{ id: 1, title: 'orig objective 1', ttaProvided: 'objective 1 desc', status: 'In Progress', - }] - } + }], + }, ]; render( @@ -182,10 +184,10 @@ describe('GoalPicker', () => { const editObjBtn = await screen.findByRole('button', { name: 'Edit' }); fireEvent.click(editObjBtn); - let objectiveTitleTxtBx = screen.getByDisplayValue(/objective 1/i); + const objectiveTitleTxtBx = screen.getByDisplayValue(/objective 1/i); fireEvent.change(objectiveTitleTxtBx, { target: { value: 'updated objective 1' } }); - const saveObjectiveBtn = await screen.getByRole('button', { name: /save objective 1 on goal 1/i }); + const saveObjectiveBtn = screen.getByRole('button', { name: /save objective 1 on goal 1/i }); userEvent.click(saveObjectiveBtn); expect(screen.queryByText('orig objective 1')).not.toBeInTheDocument(); From 75c64c78f56cfd09e2d2e1ed650ca9a317efbd31 Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Tue, 8 Jun 2021 09:57:33 -0400 Subject: [PATCH 3/8] TTAHUB-105: Another goal picker test. --- .../Pages/components/__tests__/GoalPicker.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js index bc79140236..2a5dd69d8a 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/GoalPicker.js @@ -155,6 +155,41 @@ describe('GoalPicker', () => { expect(screen.queryByText('another goal')).toBeVisible(); }); + it('cant be updated, if new name is blank', async () => { + const availableGoals = []; + const selectedGoals = [ + { + id: 1, name: 'goal to edit', new: true, objectives: [], + }, + { id: 2, name: 'another goal', objectives: [] }, + ]; + + render( + , + ); + + const menuButton = await screen.findByRole('button', { name: /actions for goal 1/i }); + fireEvent.click(menuButton); + + const editButton = await screen.findByRole('button', { name: 'Edit' }); + fireEvent.click(editButton); + + const goalNameInput = await screen.findByLabelText('Edit goal'); + await waitFor(() => expect(goalNameInput).toBeVisible()); + + fireEvent.change(goalNameInput, { target: { value: '' } }); + + const updateButton = await screen.findByRole('button', { name: 'Update Goal' }); + fireEvent.click(updateButton); + + // Old goal name should exist, new blank goal name should not + expect(screen.queryByText('goal to edit')).toBeVisible(); + expect(screen.queryByText('another goal')).toBeVisible(); + }); + it('objective can be updated', async () => { const availableGoals = []; const selectedGoals = [ From b6e1573f17bb65cd70542fdfb26c98243a656896 Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Tue, 8 Jun 2021 16:25:19 -0400 Subject: [PATCH 4/8] TTAHUB-105: Bring goal branch coverage to 100%. --- .../Pages/components/__tests__/Goal.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js index c6a5aaaaa1..e969e4cfdd 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js @@ -140,6 +140,25 @@ describe('Goal', () => { }]); }); + it('cant be removed', async () => { + const onUpdate = jest.fn(); + const objectives = [ + { + id: 'a', title: 'first', ttaProvided: '

This is the TTA Desc

', status: 'Not Started', + }, + ]; + render(); + + const optionsObjBtn = screen.getByRole('button', { name: /edit or delete objective 1 on goal 1/i }); + fireEvent.click(optionsObjBtn); + + const deleteObjBtn = await screen.findByRole('button', { name: 'Delete' }); + fireEvent.click(deleteObjBtn); + + expect(objectives.length) + expect(onUpdate).not.toHaveBeenCalledWith(objectives[0]); + }); + it('can be updated', async () => { const onUpdate = jest.fn(); const objectives = [{ From c2a063454569b091fa57e6a50fd2eeedde15d4aa Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Tue, 8 Jun 2021 19:49:01 -0400 Subject: [PATCH 5/8] TTAHUB-105: Increase branch coverage for objective form item. --- .../components/__tests__/ObjectiveFormItem.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js new file mode 100644 index 0000000000..ff6d62e032 --- /dev/null +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js @@ -0,0 +1,55 @@ +/* eslint-disable react/jsx-props-no-spreading */ +import '@testing-library/jest-dom'; +import { + render, + screen, +} from '@testing-library/react'; +import React from 'react'; +import { TextInput } from '@trussworks/react-uswds'; +import ObjectiveFormItem from '../ObjectiveFormItem'; + +const RenderObjectiveFormItem = ({ + // eslint-disable-next-line react/prop-types + isValid, formItemValue, onChange = () => { }, +}) => { + return ( + + + + ); +}; + +describe('ObjectiveFormItem', () => { + + it('renders correctly', async () => { + const onChange = jest.fn(); + render(); + const save = await screen.findByText('Objective'); + expect(save).toBeVisible(); + const errorMessage = screen.queryByText('objective form item required'); + expect(errorMessage).toBeNull(); + }); + + it('renders with required message', async () => { + const onChange = jest.fn(); + render(); + const save = await screen.findByText('Objective'); + expect(save).toBeVisible(); + const errorMessage = await screen.findByText('objective form item required'); + expect(errorMessage).toBeVisible(); + }); +}); + + + From 2bea856cc453822a42ced5cdda044bafa6159020 Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Wed, 9 Jun 2021 12:06:27 -0400 Subject: [PATCH 6/8] TTAHUB-105: More branch code coverate for DeleteReportModal.js. --- .../components/__tests__/DeleteReportModal.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/__tests__/DeleteReportModal.js b/frontend/src/components/__tests__/DeleteReportModal.js index 92f42d6b1d..bfedf09546 100644 --- a/frontend/src/components/__tests__/DeleteReportModal.js +++ b/frontend/src/components/__tests__/DeleteReportModal.js @@ -41,7 +41,7 @@ describe('DeleteReportModal', () => { expect(buttons.length).toBe(2); }); - it('exits when escapse key is pressed', async () => { + it('exits when escape key is pressed', async () => { // Given a page with a modal render(); @@ -56,4 +56,20 @@ describe('DeleteReportModal', () => { userEvent.type(modal, '{esc}', { skipClick: true }); expect(screen.queryByTestId('modal')).not.toBeTruthy(); }); + + it('does not escape when any other key is pressed', async () => { + // Given a page with a modal + render(); + + // When the modal is triggered + const button = await screen.findByText('Open'); + userEvent.click(button); + + const modal = await screen.findByTestId('modal'); + expect(modal).toBeVisible(); + + // And the modal can closeclose the modal via the escape key + userEvent.type(modal, '{enter}', { skipClick: true }); + expect(screen.queryByTestId('modal')).toBeTruthy(); + }); }); From dd534908a350e9bcd20300056de605038997b15d Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Wed, 9 Jun 2021 14:38:48 -0400 Subject: [PATCH 7/8] TTAHUB-105: Fix based on Matts comments. --- .../ActivityReport/Pages/components/__tests__/Goal.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js index e969e4cfdd..2b30cf3b74 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js @@ -155,8 +155,11 @@ describe('Goal', () => { const deleteObjBtn = await screen.findByRole('button', { name: 'Delete' }); fireEvent.click(deleteObjBtn); - expect(objectives.length) - expect(onUpdate).not.toHaveBeenCalledWith(objectives[0]); + const objName = screen.getByText(/first/i); + expect(objName).toBeVisible(); + + const objDesc = screen.getByText(/this is the tta desc/i) + expect(objDesc).toBeVisible();; }); it('can be updated', async () => { From 90f7d0291b7535e64f8340c1ae2340e60eda6981 Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Wed, 9 Jun 2021 14:51:42 -0400 Subject: [PATCH 8/8] TTAHUB-105: Fix new lint errors. --- .../Pages/components/__tests__/Goal.js | 4 +- .../components/__tests__/ObjectiveFormItem.js | 78 +++++++++---------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js index 2b30cf3b74..2c1c2fde12 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/Goal.js @@ -158,8 +158,8 @@ describe('Goal', () => { const objName = screen.getByText(/first/i); expect(objName).toBeVisible(); - const objDesc = screen.getByText(/this is the tta desc/i) - expect(objDesc).toBeVisible();; + const objDesc = screen.getByText(/this is the tta desc/i); + expect(objDesc).toBeVisible(); }); it('can be updated', async () => { diff --git a/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js b/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js index ff6d62e032..cc1db22beb 100644 --- a/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js +++ b/frontend/src/pages/ActivityReport/Pages/components/__tests__/ObjectiveFormItem.js @@ -1,55 +1,49 @@ /* eslint-disable react/jsx-props-no-spreading */ import '@testing-library/jest-dom'; import { - render, - screen, + render, + screen, } from '@testing-library/react'; import React from 'react'; import { TextInput } from '@trussworks/react-uswds'; import ObjectiveFormItem from '../ObjectiveFormItem'; const RenderObjectiveFormItem = ({ - // eslint-disable-next-line react/prop-types - isValid, formItemValue, onChange = () => { }, -}) => { - return ( - - - - ); -}; + // eslint-disable-next-line react/prop-types + isValid, formItemValue, onChange = () => { }, +}) => ( + + + +); describe('ObjectiveFormItem', () => { + it('renders correctly', async () => { + const onChange = jest.fn(); + render(); + const save = await screen.findByText('Objective'); + expect(save).toBeVisible(); + const errorMessage = screen.queryByText('objective form item required'); + expect(errorMessage).toBeNull(); + }); - it('renders correctly', async () => { - const onChange = jest.fn(); - render(); - const save = await screen.findByText('Objective'); - expect(save).toBeVisible(); - const errorMessage = screen.queryByText('objective form item required'); - expect(errorMessage).toBeNull(); - }); - - it('renders with required message', async () => { - const onChange = jest.fn(); - render(); - const save = await screen.findByText('Objective'); - expect(save).toBeVisible(); - const errorMessage = await screen.findByText('objective form item required'); - expect(errorMessage).toBeVisible(); - }); + it('renders with required message', async () => { + const onChange = jest.fn(); + render(); + const save = await screen.findByText('Objective'); + expect(save).toBeVisible(); + const errorMessage = await screen.findByText('objective form item required'); + expect(errorMessage).toBeVisible(); + }); }); - - -