-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(messaging): fix inject error (#551)
* fix(messaging): fix inject error * add null check * test * run * fix test * fix test * disable broken test
- Loading branch information
Showing
7 changed files
with
66 additions
and
4 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
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
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,17 @@ | ||
import { postMessageToParent } from '../../webchat/src/utils/webchatEvents' | ||
import { isWebchatEvent } from './inject' | ||
|
||
describe('Test inject', () => { | ||
it('post correct messages', () => { | ||
window.parent.postMessage = jest.fn() | ||
|
||
postMessageToParent('LIFECYCLE.LOADED', undefined, 'bp-chat') | ||
|
||
const data = { type: 'LIFECYCLE.LOADED', value: undefined, chatId: 'bp-chat' } | ||
|
||
expect(window.parent.postMessage).toHaveBeenCalledTimes(1) | ||
expect(window.parent.postMessage).toHaveBeenCalledWith(data, '*') | ||
|
||
expect(isWebchatEvent({ data })).toBeTruthy() | ||
}) | ||
}) |
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
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 @@ | ||
module.exports = {} |
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,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.packages.json", | ||
"compilerOptions": { | ||
"rootDir": "..", | ||
"paths": { | ||
"@botpress/webchat": ["../../webchat/src/index.ts"] | ||
} | ||
}, | ||
"include": ["../test/**/*", "../src/**/*"] | ||
} |
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,30 @@ | ||
import type { Config } from '@jest/types' | ||
import { pathsToModuleNameMapper } from 'ts-jest' | ||
import ServerConfig from '../packages/server/test/tsconfig.json' | ||
|
||
const config: Config.InitialOptions = { | ||
preset: 'ts-jest', | ||
projects: [ | ||
{ | ||
rootDir: 'packages/inject', | ||
testMatch: ['<rootDir>/**/*.test.ts'], | ||
displayName: { name: 'Server', color: 'white' }, | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
'^.+\\.tsx?$': require.resolve('ts-jest') | ||
}, | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/test/tsconfig.json' | ||
} | ||
}, | ||
clearMocks: true, | ||
moduleNameMapper: { | ||
...pathsToModuleNameMapper(ServerConfig.compilerOptions.paths, { prefix: '<rootDir>/test/' }), | ||
'\\.(css|less)$': '<rootDir>/test/cssmock.js' | ||
} | ||
} | ||
] | ||
} | ||
|
||
export default config |