Skip to content

Commit

Permalink
add error component for tagNode subtags query
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Oct 28, 2024
1 parent d3e91ac commit 2a49ea0
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 4 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"successfullyAssignedToTags": "Successfully Assigned to Tags",
"successfullyRemovedFromTags": "Successfully Removed from Tags",
"errorOccurredWhileLoadingOrganizationUserTags": "Error occurred while loading organization tags",
"errorOccurredWhileLoadingSubTags": "Error occurred while loading subTags tags",
"removeUserTag": "Delete Tag",
"removeUserTagMessage": "Do you want to delete this tag? It delete all the sub tags and all the associations.",
"tagDetails": "Tag Details",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"successfullyAssignedToTags": "Attribué aux tags avec succès",
"successfullyRemovedFromTags": "Retiré des tags avec succès",
"errorOccurredWhileLoadingOrganizationUserTags": "Erreur lors du chargement des tags de l'organisation",
"errorOccurredWhileLoadingSubTags": "Une erreur s'est produite lors du chargement des sous-tags",
"removeUserTag": "Supprimer le tag",
"removeUserTagMessage": "Voulez-vous supprimer ce tag ? Cela supprimera tous les sous-tags et toutes les associations.",
"tagDetails": "Détails du tag",
Expand Down
1 change: 1 addition & 0 deletions public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"successfullyAssignedToTags": "सफलतापूर्वक टैग्स को असाइन किया गया",
"successfullyRemovedFromTags": "सफलतापूर्वक टैग्स से हटाया गया",
"errorOccurredWhileLoadingOrganizationUserTags": "संगठन टैग्स को लोड करते समय त्रुटि हुई",
"errorOccurredWhileLoadingSubTags": "उप-टैग लोड करते समय त्रुटि हुई",
"removeUserTag": "टैग हटाएं",
"removeUserTagMessage": "क्या आप इस टैग को हटाना चाहते हैं? यह सभी उप-टैग्स और सभी संबंधों को हटा देगा।",
"tagDetails": "टैग विवरण",
Expand Down
1 change: 1 addition & 0 deletions public/locales/sp/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"successfullyAssignedToTags": "Asignado a etiquetas con éxito",
"successfullyRemovedFromTags": "Eliminado de etiquetas con éxito",
"errorOccurredWhileLoadingOrganizationUserTags": "Error al cargar las etiquetas de la organización",
"errorOccurredWhileLoadingSubTags": "Ocurrió un error al cargar las subetiquetas",
"removeUserTag": "Eliminar etiqueta",
"removeUserTagMessage": "¿Desea eliminar esta etiqueta? Esto eliminará todas las subetiquetas y todas las asociaciones.",
"tagDetails": "Detalles de la etiqueta",
Expand Down
1 change: 1 addition & 0 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"successfullyAssignedToTags": "成功分配到标签",
"successfullyRemovedFromTags": "成功从标签中移除",
"errorOccurredWhileLoadingOrganizationUserTags": "加载组织标签时出错",
"errorOccurredWhileLoadingSubTags": "加载子标签时发生错误",
"removeUserTag": "删除标签",
"removeUserTagMessage": "您要删除此标签吗?这将删除所有子标签和所有关联。",
"tagDetails": "标签详情",
Expand Down
27 changes: 25 additions & 2 deletions src/components/TagActions/TagActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ import type { ApolloLink } from '@apollo/client';
import type { InterfaceTagActionsProps } from './TagActions';
import TagActions from './TagActions';
import i18n from 'utils/i18nForTest';
import { MOCKS, MOCKS_ERROR } from './TagActionsMocks';
import {
MOCKS,
MOCKS_ERROR_ORGANIZATION_TAGS_QUERY,
MOCKS_ERROR_SUBTAGS_QUERY,
} from './TagActionsMocks';

const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(MOCKS_ERROR, true);
const link2 = new StaticMockLink(MOCKS_ERROR_ORGANIZATION_TAGS_QUERY, true);
const link3 = new StaticMockLink(MOCKS_ERROR_SUBTAGS_QUERY, true);

async function wait(ms = 500): Promise<void> {
await act(() => {
Expand Down Expand Up @@ -132,6 +137,24 @@ describe('Organisation Tags Page', () => {
});
});

test('Renders error component when when subTags query is unsuccessful', async () => {
const { getByText } = renderTagActionsModal(props[0], link3);

await wait();

// expand tag 1 to list its subtags
await waitFor(() => {
expect(screen.getByTestId('expandSubTags1')).toBeInTheDocument();
});
userEvent.click(screen.getByTestId('expandSubTags1'));

await waitFor(() => {
expect(
getByText(translations.errorOccurredWhileLoadingSubTags),
).toBeInTheDocument();
});
});

test('Renders more members with infinite scroll', async () => {
const { getByText } = renderTagActionsModal(props[0], link);

Expand Down
71 changes: 69 additions & 2 deletions src/components/TagActions/TagActionsMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export const MOCKS = [
},
];

export const MOCKS_ERROR = [
export const MOCKS_ERROR_ORGANIZATION_TAGS_QUERY = [
{
request: {
query: ORGANIZATION_USER_TAGS_LIST,
Expand All @@ -461,6 +461,73 @@ export const MOCKS_ERROR = [
first: TAGS_QUERY_LIMIT,
},
},
error: new Error('Mock Graphql Error'),
error: new Error('Mock Graphql Error for organization root tags query'),
},
];

export const MOCKS_ERROR_SUBTAGS_QUERY = [
{
request: {
query: ORGANIZATION_USER_TAGS_LIST,
variables: {
id: '123',
first: TAGS_QUERY_LIMIT,
},
},
result: {
data: {
organizations: [
{
userTags: {
edges: [
{
node: {
_id: '1',
name: 'userTag 1',
usersAssignedTo: {
totalCount: 5,
},
childTags: {
totalCount: 11,
},
},
cursor: '1',
},
{
node: {
_id: '2',
name: 'userTag 2',
usersAssignedTo: {
totalCount: 5,
},
childTags: {
totalCount: 0,
},
},
cursor: '2',
},
],
pageInfo: {
startCursor: '1',
endCursor: '2',
hasNextPage: false,
hasPreviousPage: false,
},
totalCount: 2,
},
},
],
},
},
},
{
request: {
query: USER_TAG_SUB_TAGS,
variables: {
id: '1',
first: TAGS_QUERY_LIMIT,
},
},
error: new Error('Mock Graphql Error for subTags query'),
},
];
15 changes: 15 additions & 0 deletions src/components/TagActions/TagNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
import { TAGS_QUERY_LIMIT } from 'utils/organizationTagsUtils';
import styles from './TagActions.module.css';
import InfiniteScroll from 'react-infinite-scroll-component';
import { WarningAmberRounded } from '@mui/icons-material';

/**
* Props for the `TagNode` component.
Expand All @@ -34,6 +35,7 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
const {
data: subTagsData,
loading: subTagsLoading,
error: subTagsError,
fetchMore: fetchMoreSubTags,
}: {
data?: {
Expand Down Expand Up @@ -62,6 +64,19 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
skip: !expanded,
});

if (subTagsError) {
return (
<div className={`${styles.errorContainer} bg-white rounded-4 my-3`}>
<div className={styles.errorMessage}>
<WarningAmberRounded className={styles.errorIcon} fontSize="large" />
<h6 className="fw-bold text-danger text-center">
{t('errorOccurredWhileLoadingSubTags')}
</h6>
</div>
</div>
);
}

const subTagsList = subTagsData?.getUserTag.childTags.edges.map(
(edge) => edge.node,
);
Expand Down

0 comments on commit 2a49ea0

Please sign in to comment.