Skip to content

Commit

Permalink
increase orgprofilefieldsettings' coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JamarTG committed Dec 1, 2023
1 parent 19fb60b commit 3391b92
Showing 1 changed file with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ const MOCKS = [
{
request: {
query: REMOVE_CUSTOM_FIELD,
variables: {
organizationId: '',
customFieldId: '',
},
variables: {},
},
result: {
data: {
Expand Down Expand Up @@ -68,6 +65,53 @@ const MOCKS = [
},
];

const ERROR_MOCKS = [
{
request: {
query: ADD_CUSTOM_FIELD,
variables: {
type: '',
name: '',
},
},
result: {
data: {
addOrganizationCustomField: {
name: 'Custom Field Name',
type: 'string',
},
},
},
},
{
request: {
query: REMOVE_CUSTOM_FIELD,
variables: {
organizationId: '',
customFieldId: '',
},
},
error: new Error('Failed to remove custom field'),
},
{
request: {
query: ORGANIZATION_CUSTOM_FIELDS,
variables: {},
},
result: {
data: {
customFieldsByOrganization: [
{
_id: 'adsdasdsa334343yiu423434',
type: 'fieldType',
name: 'fieldName',
},
],
},
},
},
];

const NO_C_FIELD_MOCK = [
{
request: {
Expand Down Expand Up @@ -102,6 +146,7 @@ const NO_C_FIELD_MOCK = [

const link = new StaticMockLink(MOCKS, true);
const link2 = new StaticMockLink(NO_C_FIELD_MOCK, true);
const link3 = new StaticMockLink(ERROR_MOCKS, true);

async function wait(ms = 100): Promise<void> {
await act(() => {
Expand Down Expand Up @@ -139,7 +184,7 @@ describe('Testing Save Button', () => {
const fieldNameInput = getByTestId('customFieldInput');
userEvent.type(fieldNameInput, 'Age');
});
test('When No Custom Data is Presenet', async () => {
test('When No Custom Data is Present', async () => {
const { getByText } = render(
<MockedProvider mocks={NO_C_FIELD_MOCK} addTypename={false} link={link2}>
<I18nextProvider i18n={i18nForTest}>
Expand All @@ -153,7 +198,7 @@ describe('Testing Save Button', () => {
});
test('Testing Remove Custom Field Button', async () => {
render(
<MockedProvider mocks={MOCKS} addTypename={false} link={link}>
<MockedProvider mocks={MOCKS} addTypename={false} link={link3}>
<I18nextProvider i18n={i18nForTest}>
<OrgProfileFieldSettings />
</I18nextProvider>
Expand All @@ -163,4 +208,16 @@ describe('Testing Save Button', () => {
await wait();
userEvent.click(screen.getByTestId('removeCustomFieldBtn'));
});

test('Testing Failure Case for Removing Custom Field', async () => {
const { getByText } = render(
<MockedProvider mocks={ERROR_MOCKS} addTypename={false} link={link2}>
<I18nextProvider i18n={i18nForTest}>
<OrgProfileFieldSettings />
</I18nextProvider>
</MockedProvider>
);
await wait();
expect(getByText('Field Type')).toBeInTheDocument();
});
});

0 comments on commit 3391b92

Please sign in to comment.