Skip to content

Commit

Permalink
test: add unit tests and delete snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-oprea committed Apr 3, 2024
1 parent c96ac43 commit 7f2b845
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 67 deletions.
34 changes: 15 additions & 19 deletions src/Widgets/ThemePicker.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import renderer from 'react-test-renderer';
import '@testing-library/jest-dom/extend-expect';

import ThemePicker from './ThemePicker';

describe('ThemePicker', () => {
Expand All @@ -16,20 +17,15 @@ describe('ThemePicker', () => {
};

it('renders correctly', () => {
const component = renderer.create(<ThemePicker {...props} />);

const json = component.toJSON();
expect(json).toMatchSnapshot();
const label =
component.toJSON().children[0].children[0].children[0].children[0]
.children[0];
const buttons =
component.toJSON().children[0].children[0].children[0].children[0]
.children[1];

expect(label.children[0]).toBe('Test Theme Picker');
expect(buttons.children[0].props.className).toContain('color1');
expect(buttons.children[1].props.className).toContain('color2');
const { container } = render(<ThemePicker {...props} />);

expect(container.querySelector('.wrapper label')).toBeInTheDocument();
expect(
container.querySelector('.wrapper .buttons .color1[title="Color 1"]'),
).toBeInTheDocument();
expect(
container.querySelector('.wrapper .buttons .color2[title="Color 2"]'),
).toBeInTheDocument();
});

it('calls onChange with correct value when a color button is clicked', () => {
Expand All @@ -43,10 +39,10 @@ describe('ThemePicker', () => {
});

it('does not render when no colors are provided', () => {
const component = renderer.create(<ThemePicker {...props} colors={[]} />);
const { container } = render(<ThemePicker {...props} colors={[]} />);

let json = component.toJSON();
expect(json).toMatchSnapshot();
expect(json).toBeNull();
expect(
container.querySelector('.wrapper .field-test-theme-picker'),
).not.toBeInTheDocument();
});
});
48 changes: 0 additions & 48 deletions src/Widgets/__snapshots__/ThemePicker.test.jsx.snap

This file was deleted.

0 comments on commit 7f2b845

Please sign in to comment.