Tags Dashboard Error Handling (#20051)
* feat: add an error modal for the dashboard page tags * spec: add the tests for the tags dashboard pages * spec: add the tests for the hiding tags dashboard pages
This commit is contained in:
parent
ed853f7e1e
commit
789907d289
3 changed files with 96 additions and 17 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue