Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add one component test #171

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/__tests__/component_test/date_input.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

// Import the DateInputWrapper component
import DateInputWrapper from '../../components/date_input_wrapper';
import { pathToId } from '../../utilities/paths_utils';

jest.mock('../../components/store', () => ({
StoreContext: {
Consumer: ({ children }) => children({ data: {}, upsertData: jest.fn() }),
},
}));

describe('DateInputWrapper', () => {
it('renders with correct props and handles value change', () => {
const label = 'Test Label';
const path = 'test.path';

const { getByLabelText } = render(<DateInputWrapper label={label} path={path} />);

const inputElement = getByLabelText(label);

expect(inputElement).toHaveAttribute('id', 'input-test-path');
expect(inputElement).toHaveValue('');

fireEvent.change(inputElement, { target: { value: '2020-05-24' } });

expect(inputElement).toHaveValue('2020-05-24');
});
});
21 changes: 21 additions & 0 deletions src/__tests__/component_test/figure_wrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { getByRole, render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import FigureWrapper from '../../components/figure_wrapper';

describe('FigureWrapper', () => {
it('renders with children and src', () => {

const children = 'This is the caption text';
const src = '';

const { getByText, getByAltText } = render(
<FigureWrapper src={src}>{children}</FigureWrapper>
);

const captionElement = getByText(children);

expect(captionElement).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToId } from '../utilities/paths_utils'
import { pathToId } from '../../utilities/paths_utils'

describe('pathToId', () => {
test('converts path to id with default prefix and separator', () => {
Expand Down
Loading