diff --git a/app/javascript/packs/dashboardTags.js b/app/javascript/packs/dashboardTags.js index 3a810d2ad..2905a6add 100644 --- a/app/javascript/packs/dashboardTags.js +++ b/app/javascript/packs/dashboardTags.js @@ -1,4 +1,5 @@ import { initializeDropdown } from '@utilities/dropdownUtils'; +import { showModalAfterError } from '@utilities/showUserAlertModal'; listenForButtonClicks(); @@ -57,9 +58,18 @@ function handleFollowingButtonClick(tagContainer) { }; fetchFollows(data) - .then(() => { - removeElementFromPage(followId); - updateNavigationItemCount(); + .then((response) => { + if (response.ok) { + removeElementFromPage(followId); + updateNavigationItemCount(); + } else { + showModalAfterError({ + response, + element: 'follow action', + action_ing: 'updating', + action_past: 'updated', + }); + } }) .catch((error) => console.error(error)); } @@ -75,19 +85,30 @@ function handleHideButtonClick(tagContainer) { }; fetchFollows(data) - .then(() => { - removeElementFromPage(followId); + .then((response) => { + if (response.ok) { + removeElementFromPage(followId); - // update the current navigation item count - updateNavigationItemCount(); + // update the current navigation item count + updateNavigationItemCount(); - // update the hidden tags navigation item - const hiddenTagsNavigationItem = document.querySelector( - '.js-hidden-tags-link .c-indicator', - ); - updateNavigationItemCount(hiddenTagsNavigationItem, 1); + // update the hidden tags navigation item + const hiddenTagsNavigationItem = document.querySelector( + '.js-hidden-tags-link .c-indicator', + ); + updateNavigationItemCount(hiddenTagsNavigationItem, 1); + } else { + showModalAfterError({ + response, + element: 'hide action', + action_ing: 'updating', + action_past: 'updated', + }); + } }) - .catch((error) => console.error(error)); + .catch((error) => { + console.error('Unable to hide tag', error); + }); } function handleUnhideButtonClick(tagContainer) { @@ -100,10 +121,19 @@ function handleUnhideButtonClick(tagContainer) { }; fetchFollows(data) - .then(() => { - removeElementFromPage(followId); - // update the current navigation item count - updateNavigationItemCount(); + .then((response) => { + if (response.ok) { + removeElementFromPage(followId); + // update the current navigation item count + updateNavigationItemCount(); + } else { + showModalAfterError({ + response, + element: 'unhide action', + action_ing: 'updating', + action_past: 'updated', + }); + } }) .catch((error) => console.error(error)); } diff --git a/cypress/e2e/seededFlows/dashboardFlows/followingTags.spec.js b/cypress/e2e/seededFlows/dashboardFlows/followingTags.spec.js index 6045e8351..26273420c 100644 --- a/cypress/e2e/seededFlows/dashboardFlows/followingTags.spec.js +++ b/cypress/e2e/seededFlows/dashboardFlows/followingTags.spec.js @@ -97,5 +97,38 @@ describe('Dashboard: Following Tags', () => { }); }); + it('shows a modal when there is an error with hiding a tag', () => { + cy.intercept('/follows', { statusCode: 500 }).as('followsRequest'); + + openOptionsMenu(() => { + cy.findByRole('button', { name: 'Hide tag: tag0' }).click(); + }); + cy.wait('@followsRequest'); + + cy.findByTestId('modal-container').as('confirmationModal'); + + cy.get('@confirmationModal') + .findByText('Your hide action could not be updated due to a server error') + .should('exist'); + }); + + it('shows a modal when there is an error with following a tag', () => { + cy.intercept('/follows', { statusCode: 500 }).as('followsRequest'); + cy.findByRole('button', { name: 'Following tag: tag0' }).as( + 'followingButton', + ); + + cy.get('@followingButton').click(); + cy.wait('@followsRequest'); + + cy.findByTestId('modal-container').as('confirmationModal'); + + cy.get('@confirmationModal') + .findByText( + 'Your follow action could not be updated due to a server error', + ) + .should('exist'); + }); + // TODO: add a test for the pagination }); diff --git a/cypress/e2e/seededFlows/dashboardFlows/hiddenTags.spec.js b/cypress/e2e/seededFlows/dashboardFlows/hiddenTags.spec.js index 2c8656b44..c93a0c16f 100644 --- a/cypress/e2e/seededFlows/dashboardFlows/hiddenTags.spec.js +++ b/cypress/e2e/seededFlows/dashboardFlows/hiddenTags.spec.js @@ -36,5 +36,21 @@ describe('Dashboard: Hidden Tags', () => { cy.get('@hiddenTagsCount').should('contain', '4'); }); + it('shows a modal when there is an error', () => { + cy.intercept('/follows', { statusCode: 500 }).as('followsRequest'); + cy.findByRole('button', { name: 'Unhide tag: tag5' }).as('unhideButton'); + + cy.get('@unhideButton').click(); + cy.wait('@followsRequest'); + + cy.findByTestId('modal-container').as('confirmationModal'); + + cy.get('@confirmationModal') + .findByText( + 'Your unhide action could not be updated due to a server error', + ) + .should('exist'); + }); + // TODO: add a test for the pagination });