-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Note: This will need to be updated to 'createMockFromModule' if we upgrade to jest 26+ | ||
const iframeCommon = jest.genMockFromModule('./iframe-common'); | ||
|
||
iframeCommon.sendToIframe = jest.fn(); | ||
|
||
module.exports = iframeCommon; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import AnswersExperienceFrame from '../../../static/js/answers-experience-frame'; | ||
import RuntimeConfig from '../../../static/js/runtime-config'; | ||
import { sendToIframe } from '../../../static/js/iframe-common'; | ||
|
||
jest.mock('../../../static/js/iframe-common'); | ||
|
||
describe('AnswersExperienceFrame works propertly', () => { | ||
let answersExperienceFrame; | ||
|
||
beforeEach(() => { | ||
const runtimeConfig = new RuntimeConfig(); | ||
answersExperienceFrame = new AnswersExperienceFrame(runtimeConfig); | ||
jest.clearAllMocks(); // ensure mock.calls are cleared before each test | ||
}); | ||
|
||
it('The init function sends an init message to the iframe', () => { | ||
answersExperienceFrame.init({}); | ||
const expectedMessage = { | ||
initAnswersExperience: true, | ||
runtimeConfig: {} | ||
}; | ||
expect(sendToIframe).toHaveBeenCalledWith(expectedMessage); | ||
}); | ||
|
||
it('Runtime config passed to the init function is sent to the child iframe', () => { | ||
answersExperienceFrame.init({linkTarget: '_blank'}); | ||
const expectedMessage = { | ||
initAnswersExperience: true, | ||
runtimeConfig: {linkTarget: '_blank'} | ||
}; | ||
expect(sendToIframe).toHaveBeenCalledWith(expectedMessage); | ||
}); | ||
|
||
it('An init message will only be sent once', () => { | ||
answersExperienceFrame.init({}); | ||
answersExperienceFrame.init({}); | ||
expect(sendToIframe).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |