Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4624 Navigating between activities using the nav menu doesn't update the Activity Name #4630

Merged
merged 8 commits into from Mar 28, 2023
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