import React from 'react'; import { HotTable } from '../src/hotTable'; import { HotColumn } from '../src/hotColumn'; import { createSpreadsheetData, mockElementDimensions, mountComponentWithRef } from './_helpers'; import { BaseEditorComponent } from '../src/baseEditorComponent'; describe('React Context', () => { it('should be possible to declare a context and use it inside both renderers and editors', async () => { let hotTableInstance = null; const TestContext = React.createContext('def-test-val'); function RendererComponent2() { return ( {(context) => <>{context}} ); } class EditorComponent2 extends BaseEditorComponent { render(): React.ReactElement { return ( {(context) => <>{context}} ); } } class RendererComponent3 extends React.Component { render() { return ( <> {this.context} ) } } RendererComponent3.contextType = TestContext; class EditorComponent3 extends React.Component { render() { return ( <> {this.context} ) } } EditorComponent3.contextType = TestContext; mountComponentWithRef(( )); const hotInstance = hotTableInstance.hotInstance; expect(hotInstance.getCell(0, 0).innerHTML).toEqual('
testContextValue
'); expect(hotInstance.getCell(1, 0).innerHTML).toEqual('
testContextValue
'); expect(document.querySelector('.ec2').innerHTML).toEqual('testContextValue'); expect(hotInstance.getCell(0, 1).innerHTML).toEqual('
testContextValue
'); expect(hotInstance.getCell(1, 1).innerHTML).toEqual('
testContextValue
'); expect(document.querySelector('.ec3').innerHTML).toEqual('testContextValue'); }); });