-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL error scenarios to test cases Added
- Loading branch information
Showing
1 changed file
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import { BrowserRouter } from 'react-router-dom'; | |
import LeaveOrganization from './LeaveOrganization'; | ||
import { ORGANIZATIONS_LIST } from 'GraphQl/Queries/Queries'; | ||
import { REMOVE_MEMBER_MUTATION } from 'GraphQl/Mutations/mutations'; | ||
// import useLocalStorage from 'utils/useLocalstorage'; | ||
|
||
// Mock the custom hook | ||
jest.mock('utils/useLocalStorage', () => { | ||
|
@@ -50,12 +49,28 @@ const mocks = [ | |
}, | ||
}, | ||
}, | ||
// Mock for query error | ||
{ | ||
request: { | ||
query: ORGANIZATIONS_LIST, | ||
variables: { id: 'test-org-id' }, | ||
}, | ||
error: new Error('Failed to load organization details'), | ||
}, | ||
// Mock for mutation error | ||
{ | ||
request: { | ||
query: REMOVE_MEMBER_MUTATION, | ||
variables: { orgid: 'test-org-id', userid: 'test-user-id' }, | ||
}, | ||
error: new Error('Failed to leave organization'), | ||
}, | ||
]; | ||
|
||
describe('LeaveOrganization Component', () => { | ||
test('renders organization details', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<MockedProvider mocks={mocks.slice(0, 2)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
|
@@ -72,9 +87,26 @@ describe('LeaveOrganization Component', () => { | |
}); | ||
}); | ||
|
||
test('shows error message when query fails', async () => { | ||
render( | ||
<MockedProvider mocks={mocks.slice(2, 3)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
</MockedProvider>, | ||
); | ||
|
||
await waitFor(() => screen.getByText(/Loading/i)); | ||
await waitFor(() => { | ||
expect( | ||
screen.getByText(/Failed to load organization details/i), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('opens modal on leave button click', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<MockedProvider mocks={mocks.slice(0, 2)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
|
@@ -91,7 +123,7 @@ describe('LeaveOrganization Component', () => { | |
|
||
test('verifies email and submits', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<MockedProvider mocks={mocks.slice(0, 2)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
|
@@ -117,7 +149,7 @@ describe('LeaveOrganization Component', () => { | |
|
||
test('shows error for incorrect email', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<MockedProvider mocks={mocks.slice(0, 2)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
|
@@ -140,4 +172,32 @@ describe('LeaveOrganization Component', () => { | |
expect(screen.getByText(/Verification failed/i)).toBeInTheDocument(), | ||
); | ||
}); | ||
|
||
test('shows error message when mutation fails', async () => { | ||
render( | ||
<MockedProvider mocks={mocks.slice(3, 4)} addTypename={false}> | ||
<BrowserRouter> | ||
<LeaveOrganization /> | ||
</BrowserRouter> | ||
</MockedProvider>, | ||
); | ||
|
||
await waitFor(() => screen.getByText('Leave Organization')); | ||
fireEvent.click(screen.getByText('Leave Organization')); | ||
|
||
await waitFor(() => screen.getByText('Continue')); | ||
fireEvent.click(screen.getByText('Continue')); | ||
|
||
fireEvent.change(screen.getByPlaceholderText(/Enter your email/i), { | ||
target: { value: '[email protected]' }, | ||
}); | ||
|
||
fireEvent.click(screen.getByText('Confirm')); | ||
|
||
await waitFor(() => | ||
expect( | ||
screen.getByText(/Failed to leave organization/i), | ||
).toBeInTheDocument(), | ||
); | ||
}); | ||
}); |