-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(react-core): add provider initialization component tests
- Loading branch information
1 parent
60cf71d
commit 4ec083f
Showing
1 changed file
with
75 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,75 @@ | ||
import React, { useEffect } from 'react'; | ||
import { Scalprum, getScalprum, initialize, removeScalprum } from '@scalprum/core'; | ||
import { ScalprumProvider } from './scalprum-provider'; | ||
import { ScalprumComponent } from './scalprum-component'; | ||
|
||
function mockModule(scalprum: Scalprum, moduleName: string) { | ||
// set new module directly to the exposedModules registry | ||
scalprum.exposedModules[moduleName] = { | ||
default: () => <div>{moduleName}</div>, | ||
}; | ||
} | ||
|
||
describe('ScalprumProvider.cy.tsx', () => { | ||
beforeEach(() => { | ||
removeScalprum(); | ||
}); | ||
it('Should create scalprum provider from scalprum instance', () => { | ||
const scalprum = initialize({ | ||
appsConfig: { | ||
foo: { | ||
manifestLocation: '/foo/manifest.json', | ||
name: 'foo', | ||
}, | ||
}, | ||
}); | ||
|
||
mockModule(scalprum, 'foo#foo'); | ||
cy.mount( | ||
<ScalprumProvider scalprum={scalprum}> | ||
<div>Test</div> | ||
<ScalprumComponent module="foo" scope="foo" /> | ||
</ScalprumProvider>, | ||
); | ||
|
||
cy.contains('Test').should('exist'); | ||
cy.contains('foo#foo').should('exist'); | ||
}); | ||
|
||
it('Should create scalprum provider from config props', () => { | ||
const InitComponent = () => { | ||
const [initialized, setInitialized] = React.useState(false); | ||
useEffect(() => { | ||
const scalprum = getScalprum(); | ||
|
||
mockModule(scalprum, 'bar#bar'); | ||
// ensure the mocked module is ready | ||
setTimeout(() => { | ||
setInitialized(true); | ||
}); | ||
}, []); | ||
|
||
if (!initialized) { | ||
return <div>Not initialized</div>; | ||
} | ||
|
||
return <ScalprumComponent module="bar" scope="bar" />; | ||
}; | ||
cy.mount( | ||
<ScalprumProvider | ||
config={{ | ||
bar: { | ||
name: 'bar', | ||
manifestLocation: '/bar/manifest.json', | ||
}, | ||
}} | ||
> | ||
<div>Test</div> | ||
<InitComponent /> | ||
</ScalprumProvider>, | ||
); | ||
|
||
cy.contains('Test').should('exist'); | ||
cy.contains('bar#bar').should('exist'); | ||
}); | ||
}); |