From 4a6dc9b4d9bb344a1c29ad34eda2b08bb1395d9f Mon Sep 17 00:00:00 2001 From: Martin Marosi Date: Wed, 29 May 2024 13:55:48 +0200 Subject: [PATCH] chore(react-core): add provider initialization component tests --- .../react-core/src/ScalprumProvider.cy.tsx | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 packages/react-core/src/ScalprumProvider.cy.tsx diff --git a/packages/react-core/src/ScalprumProvider.cy.tsx b/packages/react-core/src/ScalprumProvider.cy.tsx new file mode 100644 index 0000000..f2af6e4 --- /dev/null +++ b/packages/react-core/src/ScalprumProvider.cy.tsx @@ -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: () =>
{moduleName}
, + }; +} + +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( + +
Test
+ +
, + ); + + 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
Not initialized
; + } + + return ; + }; + cy.mount( + +
Test
+ +
, + ); + + cy.contains('Test').should('exist'); + cy.contains('bar#bar').should('exist'); + }); +});