import React from 'react';
import { HotTable } from '../src/hotTable';
import { HotColumn } from '../src/hotColumn';
import {
createSpreadsheetData,
mockElementDimensions,
mountComponentWithRef
} from './_helpers';
import { HotRendererProps, HotTableRef } from '../src/types'
describe('React Context', () => {
it('should be possible to declare a context and use it inside both renderers and editors', async () => {
let hotTableInstance: HotTableRef = null!;
const TestContext = React.createContext('def-test-val');
function RendererComponent2() {
return (
{(context) => <>{context}>}
);
}
const EditorComponent2 = ({ className }: { className?: string }) => {
return (
{(context) => <>{context}>}
);
}
class RendererComponent3 extends React.Component {
render() {
return (
<>
{this.context}
>
)
}
}
RendererComponent3.contextType = TestContext;
class EditorComponent3 extends React.Component<{ className: string }> {
declare context: string;
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');
});
});