UNPKG

@transferwise/approve-api-action-helpers

Version:

An http client that handles SCA protected requests gracefully

48 lines (40 loc) 1.5 kB
/* eslint-disable fp/no-mutation */ import { iframeFlow } from './iframeFlow'; jest.mock('./config', () => ({ MESSAGE_SUCCESS: 'b', MESSAGE_FAILED: 'c', MESSAGE_CLOSED: 'd', })); describe('iFrame flow', () => { let submit; beforeEach(() => { submit = jest.fn(); window.HTMLFormElement.prototype.submit = submit; }); afterEach(() => { // cleanup JSDOM document, because jest doesn't do it after each run. https://stackoverflow.com/a/50800473 document.querySelectorAll('html')[0].innerHTML = ''; }); it('adds stylesheet', () => { expect(document.querySelector('#tw-approve-api-action-styles')).toBeFalsy(); iframeFlow({ token: 'a1b2' }); expect(document.querySelector('#tw-approve-api-action-styles')).toBeTruthy(); }); it('generates the modal with an iframe', () => { iframeFlow({ token: 'a1b2' }); const modal = document.querySelector('.tw-approval-modal'); const iframe = modal.querySelector('iframe'); expect(modal).toBeTruthy(); expect(iframe).toBeTruthy(); expect(iframe.name).toBe('tw-approve-api-action'); }); it('posts to the iframe', () => { iframeFlow({ token: 'a1b2', approvalPageUrl: 'https://a.a/' }); const form = document.querySelector('form'); expect(form.target).toBe('tw-approve-api-action'); expect(form.method).toBe('post'); expect(form.action).toBe('https://a.a/'); // eslint-disable-next-line jest/prefer-called-with expect(submit).toHaveBeenCalled(); }); });