Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Aug 16, 2024
1 parent b6ef346 commit efc5821
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
21 changes: 18 additions & 3 deletions src/screens/ManageTag/ManageTag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { store } from 'state/store';
import { StaticMockLink } from 'utils/StaticMockLink';
import i18n from 'utils/i18nForTest';
import ManageTag from './ManageTag';
import { MOCKS, MOCKS_ERROR } from './ManageTagMocks';
import {
MOCKS,
MOCKS_ERROR_ASSIGNED_MEMBERS,
MOCKS_ERROR_TAG_ANCESTORS,
} from './ManageTagMocks';
import { InMemoryCache, type ApolloLink } from '@apollo/client';

const translations = {
Expand All @@ -31,7 +35,8 @@ const translations = {
};

const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(MOCKS_ERROR, true);
const link2 = new StaticMockLink(MOCKS_ERROR_ASSIGNED_MEMBERS, true);
const link3 = new StaticMockLink(MOCKS_ERROR_TAG_ANCESTORS, true);

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

test('render error component on unsuccessful userTags query', async () => {
test('renders error component on unsuccessful userTag assigned members query', async () => {
const { queryByText } = renderManageTag(link2);

await wait();
Expand All @@ -128,6 +133,16 @@ describe('Organisation Tags Page', () => {
});
});

test('renders error component on unsuccessful userTag ancestors query', async () => {
const { queryByText } = renderManageTag(link3);

await wait();

await waitFor(() => {
expect(queryByText(translations.addPeopleToTag)).not.toBeInTheDocument();
});
});

test('opens and closes the add people to tag modal', async () => {
renderManageTag(link);

Expand Down
1 change: 1 addition & 0 deletions src/screens/ManageTag/ManageTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ function ManageTag(): JSX.Element {
{tag.name}

{orgUserTagAncestors.length - 1 !== index && (
/* istanbul ignore next */
<i className={'mx-2 fa fa-caret-right'} />
)}
</div>
Expand Down
47 changes: 46 additions & 1 deletion src/screens/ManageTag/ManageTagMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const MOCKS = [
},
];

export const MOCKS_ERROR = [
export const MOCKS_ERROR_ASSIGNED_MEMBERS = [
{
request: {
query: USER_TAGS_ASSIGNED_MEMBERS,
Expand All @@ -233,6 +233,51 @@ export const MOCKS_ERROR = [
},
error: new Error('Mock Graphql Error'),
},
{
request: {
query: USER_TAG_ANCESTORS,
variables: {
id: '1',
},
},
result: {
data: {
getUserTagAncestors: [],
},
},
},
];

export const MOCKS_ERROR_TAG_ANCESTORS = [
{
request: {
query: USER_TAGS_ASSIGNED_MEMBERS,
variables: {
id: '1',
after: null,
before: null,
first: 5,
last: null,
},
},
result: {
data: {
getUserTag: {
name: 'tag1',
usersAssignedTo: {
edges: [],
pageInfo: {
startCursor: '1',
endCursor: '5',
hasNextPage: true,
hasPreviousPage: false,
},
totalCount: 6,
},
},
},
},
},
{
request: {
query: USER_TAG_ANCESTORS,
Expand Down

0 comments on commit efc5821

Please sign in to comment.