mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding web viewport context test
This commit is contained in:
parent
90aaab80d6
commit
ab3cd5b0b0
@ -2,7 +2,12 @@ import { useEffect, useState } from 'react';
|
|||||||
|
|
||||||
export function useViewportContext() {
|
export function useViewportContext() {
|
||||||
|
|
||||||
const [state, setState] = useState({ });
|
const [state, setState] = useState({
|
||||||
|
display: null,
|
||||||
|
width: null,
|
||||||
|
height: null,
|
||||||
|
});
|
||||||
|
|
||||||
const SMALL_MEDIUM = 650;
|
const SMALL_MEDIUM = 650;
|
||||||
const MEDIUM_LARGE = 1000;
|
const MEDIUM_LARGE = 1000;
|
||||||
const LARGE_XLARGE = 1400;
|
const LARGE_XLARGE = 1400;
|
||||||
|
44
net/web/test/Viewport.test.js
Normal file
44
net/web/test/Viewport.test.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import React, { useState, useEffect, useContext } from 'react';
|
||||||
|
import {render, act, screen, waitFor, fireEvent} from '@testing-library/react'
|
||||||
|
|
||||||
|
import { ViewportContext, ViewportContextProvider } from 'context/ViewportContext';
|
||||||
|
|
||||||
|
function ViewportView() {
|
||||||
|
const [renderCount, setRenderCount] = useState(0);
|
||||||
|
const viewport = useContext(ViewportContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setRenderCount(renderCount + 1);
|
||||||
|
}, [viewport.state]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<span data-testid="count">{ renderCount }</span>
|
||||||
|
<span data-testid="display">{ viewport.state.display }</span>
|
||||||
|
<span data-testid="width">{ viewport.state.width }</span>
|
||||||
|
<span data-testid="height">{ viewport.state.height }</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ViewportTestApp() {
|
||||||
|
return (
|
||||||
|
<ViewportContextProvider>
|
||||||
|
<ViewportView />
|
||||||
|
</ViewportContextProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('get, set and clear', async () => {
|
||||||
|
render(<ViewportTestApp />);
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect(screen.getByTestId('display').textContent).toBe('large');
|
||||||
|
expect(screen.getByTestId('width').textContent).toBe('1024');
|
||||||
|
expect(screen.getByTestId('height').textContent).toBe('768');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user