Skip to content

Commit

Permalink
add a test for calling the stop impersonating button
Browse files Browse the repository at this point in the history
  • Loading branch information
nicknisi committed Jan 17, 2025
1 parent 5fdabcd commit 5eb29d7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion __tests__/impersonation.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { render, act } from '@testing-library/react';
import { render, act, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Impersonation } from '../src/components/impersonation.js';
import { useAuth } from '../src/components/authkit-provider.js';
import { getOrganizationAction } from '../src/actions.js';
import * as React from 'react';
import { handleSignOutAction } from '../src/actions.js';

// Mock the useAuth hook
jest.mock('../src/components/authkit-provider', () => ({
Expand Down Expand Up @@ -116,4 +117,18 @@ describe('Impersonation', () => {
const root = container.querySelector('[data-workos-impersonation-root]');
expect(root).toHaveStyle({ backgroundColor: 'red' });
});

it('should should sign out when the Stop button is called', async () => {
(useAuth as jest.Mock).mockReturnValue({
impersonator: { email: '[email protected]' },
user: { id: '123', email: '[email protected]' },
organizationId: null,
loading: false,
});

render(<Impersonation />);
const stopButton = await screen.findByText('Stop');
stopButton.click();
expect(handleSignOutAction).toHaveBeenCalled();
});
});

0 comments on commit 5eb29d7

Please sign in to comment.