Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snmln committed Nov 22, 2024
1 parent d2daf73 commit f7016a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import '@testing-library/jest-dom';

import { fireEvent, prettyDOM, render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';

import { ColorRangeSlider } from './index';

Expand All @@ -20,21 +20,19 @@ describe('colorRangeSlider should render with correct content.', () => {
jest.clearAllMocks();
});

it('Renders correct content', () => {

it('Renders correct content', async () => {
const maxSlider = screen.getByTestId('maxSlider');
const minSlider = screen.getByTestId('minSlider');
const maxInput = screen.getByTestId('maxInput');
const minInput = screen.getByTestId('minInput');

expect(screen.getByText('Rescale')).toBeInTheDocument();
expect(minSlider).toHaveValue('0.131');
expect(minInput).toHaveValue('0.131');

expect(maxSlider).toHaveValue('0.263');
expect(maxInput).toHaveValue('0.263');
console.log(prettyDOM());

await waitFor(() => {
expect(minSlider).toHaveValue('0.131');
expect(maxSlider).toHaveValue('0.263');
expect(minInput).toHaveValue(0.131);
expect(maxInput).toHaveValue(0.263);
});
});

it('Shows error when number entered above max', () => {
Expand Down Expand Up @@ -68,3 +66,36 @@ describe('colorRangeSlider should render with correct content.', () => {
).toBeInTheDocument();
});
});

describe('colorRangeSlider should render with correct display content.', () => {
const colorRangeData = {
min: -0.0000003,
max: 0.0000003,
colorMapScale: { max: 0.000000263, min: -0.000000131 },
setColorMapScale: jest.fn()
};

beforeEach(() => {
render(<ColorRangeSlider {...colorRangeData} />);
});
afterEach(() => {
jest.clearAllMocks();
});

it('Renders correct content', async () => {
const maxSlider = screen.getByTestId('maxSlider');
const minSlider = screen.getByTestId('minSlider');
const maxInput = screen.getByTestId('maxInput');
const minInput = screen.getByTestId('minInput');

screen.debug();

expect(screen.getByText('Rescale')).toBeInTheDocument();
await waitFor(() => {
expect(minSlider).toHaveValue("-1.31e-7");
expect(maxSlider).toHaveValue("2.63e-7");
expect(minInput).toHaveValue(-1.31e-7);
expect(maxInput).toHaveValue(2.63e-7);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function ColorRangeSlider({

const [minVal, setMinVal] = useState(setDefaultMin);
const [maxVal, setMaxVal] = useState(setDefaultMax);
const minValRef = useRef({ actual: setDefaultMin, display: '' });
const maxValRef = useRef({ actual: setDefaultMax, display: '' });
const minValRef = useRef({ actual: setDefaultMin, display: setDefaultMin });
const maxValRef = useRef({ actual: setDefaultMax, display: setDefaultMax });
const [maxIsHovering, setMaxIsHovering] = useState(false);
const [minIsHovering, setMinIsHovering] = useState(false);
const digitCount = useRef<number>(1);
Expand Down

0 comments on commit f7016a0

Please sign in to comment.