-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathAccessTokenSender.test.jsx
More file actions
41 lines (35 loc) · 1.61 KB
/
AccessTokenSender.test.jsx
File metadata and controls
41 lines (35 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { render } from '@tests/utils/test-utils';
import { AccessTokenSender } from '../../../src/components/AccessTokenSender';
/**
* Helper function to create a shallow wrapper around ErrorDialog
*/
function createWrapper(props) {
return render(
<AccessTokenSender
handleAccessTokenMessage={() => {}}
{...props}
/>,
);
}
describe('AccessTokenSender', () => {
it('renders nothing if there is no url', () => {
const { container } = createWrapper({});
expect(container).toBeEmptyDOMElement();
});
it('renders properly', () => {
const { container } = createWrapper({ url: 'http://example.com' });
expect(container.querySelector('iframe')).toHaveAttribute('src', 'http://example.com/?origin=http%3A%2F%2Flocalhost&messageId=http%3A%2F%2Fexample.com'); // eslint-disable-line testing-library/no-node-access, testing-library/no-container
});
it('triggers an action when the iframe sends a message', () => {
const handleAccessTokenMessage = vi.fn();
createWrapper({ handleAccessTokenMessage, url: 'http://example.com' });
window.dispatchEvent(new MessageEvent('message', { data: { messageId: 'http://example.com' } }));
expect(handleAccessTokenMessage).toHaveBeenCalledWith({ messageId: 'http://example.com' });
});
it('ignores iframe messages with the wrong messageId', () => {
const handleAccessTokenMessage = vi.fn();
createWrapper({ handleAccessTokenMessage, url: 'http://example.com' });
window.dispatchEvent(new MessageEvent('message', { data: { messageId: 'http://example.com/123' } }));
expect(handleAccessTokenMessage).not.toHaveBeenCalled();
});
});