Skip to content

Commit

Permalink
4624 Navigating between activities using the nav menu doesn't update …
Browse files Browse the repository at this point in the history
…the Activity Name (#4630)

* update name field when name changes

* add bug test
  • Loading branch information
amyd11 committed Mar 28, 2023
1 parent 11ca459 commit d0503c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
27 changes: 27 additions & 0 deletions e2e/cypress/integration/04-bug-tests/01-state-staff-bugs.cy.js
Expand Up @@ -3,6 +3,9 @@
// Tests out bugs that have been fixed
// so the same bugs don't happen twice

const activityIndex1Name = 'Cool Activity';
const activityIndex2Name = 'Best Activity';

describe('APD builder bugs', { tags: ['@apd'] }, function () {
let apdUrl;
let apdId;
Expand Down Expand Up @@ -33,6 +36,18 @@ describe('APD builder bugs', { tags: ['@apd'] }, function () {
years.push(list[index].value)
);
});

// Add additional activities and give them names
cy.goToActivityDashboard();
cy.contains('Add Activity').click();
cy.contains('Add Activity').click();
cy.goToActivityDashboard();
cy.get('#activities').findAllByText('Edit').eq(1).click();
cy.findByLabelText('Activity name').type(activityIndex1Name);
cy.goToActivityDashboard();
cy.get('#activities').findAllByText('Edit').eq(2).click();
cy.findByLabelText('Activity name').type(activityIndex2Name);
cy.waitForSave();
});

beforeEach(function () {
Expand Down Expand Up @@ -106,4 +121,16 @@ describe('APD builder bugs', { tags: ['@apd'] }, function () {
cy.findByRole('button', { name: 'Continue to Review' }).click();
cy.wait('@loadImage', { timeout: 30000 });
});

it('should display the correct activity name when navigating between activities, bug #4624', () => {
// Go to second activity and check displayed name
cy.goToActivityOverview(1);
cy.contains('Activity name').should('exist');
cy.checkTinyMCE('activity-name-field', activityIndex1Name);

// Go to third activity and check displayed name
cy.goToActivityOverview(2);
cy.contains('Activity name').should('exist');
cy.checkTinyMCE('activity-name-field', activityIndex2Name);
});
});
7 changes: 6 additions & 1 deletion web/src/pages/apd/activities/overview/NameForm.js
Expand Up @@ -15,6 +15,7 @@ const NameForm = ({ index, item: { name }, setName, adminCheck }) => {
control,
trigger,
clearErrors,
setValue,
formState: { errors }
} = useForm({
defaultValues: {
Expand All @@ -23,9 +24,13 @@ const NameForm = ({ index, item: { name }, setName, adminCheck }) => {
resolver: joiResolver(schema)
});

useEffect(() => {
setValue('name', name);
}, [name, setValue]);

useEffect(() => {
if (adminCheck) {
trigger(['name']);
trigger('name');
} else {
clearErrors();
}
Expand Down

0 comments on commit d0503c7

Please sign in to comment.