From cc67bcbba4420a1d1bce481d8d9b6faba47d9437 Mon Sep 17 00:00:00 2001 From: Arpit Chakraborty Date: Sat, 18 Jan 2025 21:53:06 +0530 Subject: [PATCH] Removed all ignore statements --- .../OrganizationTags.spec.tsx | 35 +++++++++++-------- .../OrganizationTags/OrganizationTags.tsx | 8 ++--- .../OrganizationTags/OrganizationTagsMocks.ts | 7 ++++ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/screens/OrganizationTags/OrganizationTags.spec.tsx b/src/screens/OrganizationTags/OrganizationTags.spec.tsx index 7f44c819c8..0ef64d538b 100644 --- a/src/screens/OrganizationTags/OrganizationTags.spec.tsx +++ b/src/screens/OrganizationTags/OrganizationTags.spec.tsx @@ -98,12 +98,10 @@ describe('Organisation Tags Page', () => { }; }); }); - afterEach(() => { vi.clearAllMocks(); cleanup(); }); - test('component loads correctly', async () => { const { getByText } = renderOrganizationTags(link); @@ -113,7 +111,6 @@ describe('Organisation Tags Page', () => { expect(getByText(translations.createTag)).toBeInTheDocument(); }); }); - test('render error component on unsuccessful userTags query', async () => { const { queryByText } = renderOrganizationTags(link2); @@ -123,7 +120,6 @@ describe('Organisation Tags Page', () => { expect(queryByText(translations.createTag)).not.toBeInTheDocument(); }); }); - test('opens and closes the create tag modal', async () => { renderOrganizationTags(link); @@ -159,7 +155,6 @@ describe('Organisation Tags Page', () => { expect(screen.getByTestId('subTagsScreen')).toBeInTheDocument(); }); }); - test('navigates to manage tag page after clicking manage tag option', async () => { renderOrganizationTags(link); @@ -174,7 +169,6 @@ describe('Organisation Tags Page', () => { expect(screen.getByTestId('manageTagScreen')).toBeInTheDocument(); }); }); - test('searchs for tags where the name matches the provided search input', async () => { renderOrganizationTags(link); @@ -195,7 +189,6 @@ describe('Organisation Tags Page', () => { expect(buttons.length).toEqual(2); }); }); - test('fetches the tags by the sort order, i.e. latest or oldest first', async () => { renderOrganizationTags(link); @@ -252,7 +245,6 @@ describe('Organisation Tags Page', () => { ); }); }); - test('fetches more tags with infinite scroll', async () => { const { getByText } = renderOrganizationTags(link); @@ -281,7 +273,6 @@ describe('Organisation Tags Page', () => { expect(getByText(translations.createTag)).toBeInTheDocument(); }); }); - test('creates a new user tag', async () => { renderOrganizationTags(link); @@ -311,7 +302,6 @@ describe('Organisation Tags Page', () => { ); }); }); - test('creates a new user tag with error', async () => { renderOrganizationTags(link3); @@ -330,7 +320,6 @@ describe('Organisation Tags Page', () => { expect(toast.error).toHaveBeenCalledWith('Mock Graphql Error'); }); }); - test('renders the no tags found message when there are no tags', async () => { renderOrganizationTags(link4); @@ -340,7 +329,6 @@ describe('Organisation Tags Page', () => { expect(screen.getByText(translations.noTagsFound)).toBeInTheDocument(); }); }); - test('sets dataLength to 0 when userTagsList is undefined', async () => { renderOrganizationTags(link5); @@ -352,7 +340,6 @@ describe('Organisation Tags Page', () => { expect(userTags).toHaveLength(0); }); }); - test('Null endCursor', async () => { renderOrganizationTags(link6); @@ -371,7 +358,6 @@ describe('Organisation Tags Page', () => { expect(screen.getByTestId('createTagBtn')).toBeInTheDocument(); }); }); - test('Null Page available', async () => { renderOrganizationTags(link7); @@ -390,4 +376,25 @@ describe('Organisation Tags Page', () => { expect(screen.getByTestId('createTagBtn')).toBeInTheDocument(); }); }); + test('creates a new user tag with undefined data', async () => { + renderOrganizationTags(link); + + await wait(); + + await waitFor(() => { + expect(screen.getByTestId('createTagBtn')).toBeInTheDocument(); + }); + userEvent.click(screen.getByTestId('createTagBtn')); + + userEvent.type( + screen.getByPlaceholderText(translations.tagNamePlaceholder), + 'userTag 13', + ); + + userEvent.click(screen.getByTestId('createTagSubmitBtn')); + + await waitFor(() => { + expect(toast.error).toHaveBeenCalledWith('Tag creation failed'); + }); + }); }); diff --git a/src/screens/OrganizationTags/OrganizationTags.tsx b/src/screens/OrganizationTags/OrganizationTags.tsx index 42143a0faf..2ad6cc4534 100644 --- a/src/screens/OrganizationTags/OrganizationTags.tsx +++ b/src/screens/OrganizationTags/OrganizationTags.tsx @@ -139,18 +139,16 @@ function OrganizationTags(): JSX.Element { organizationId: orgId, }, }); - /* istanbul ignore else -- @preserve */ if (data) { toast.success(t('tagCreationSuccess')); orgUserTagsRefetch(); setTagName(''); setCreateTagModalIsOpen(false); + } else { + toast.error('Tag creation failed'); } } catch (error: unknown) { - /* istanbul ignore else -- @preserve */ - if (error instanceof Error) { - toast.error(error.message); - } + toast.error((error as Error).message); } }; if (orgUserTagsError) { diff --git a/src/screens/OrganizationTags/OrganizationTagsMocks.ts b/src/screens/OrganizationTags/OrganizationTagsMocks.ts index e8280f11fb..a37d506686 100644 --- a/src/screens/OrganizationTags/OrganizationTagsMocks.ts +++ b/src/screens/OrganizationTags/OrganizationTagsMocks.ts @@ -307,6 +307,13 @@ export const MOCKS = [ }, result: { data: { createUserTag: { _id: '12' } } }, }, + { + request: { + query: CREATE_USER_TAG, + variables: { name: 'userTag 13', organizationId: 'orgId' }, + }, + result: { data: null }, + }, ]; export const MOCKS_ERROR = [