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

test(help): add tests #800

Merged
merged 1 commit into from
Nov 12, 2020
Merged
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
16 changes: 0 additions & 16 deletions packages/help/src/Help.container.tsx

This file was deleted.

34 changes: 0 additions & 34 deletions packages/help/src/Help.spec.tsx

This file was deleted.

18 changes: 11 additions & 7 deletions packages/help/src/Help.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Meta, Story } from '@storybook/react/types-6-0';
import { PopoverPlacements, PopoverModes } from '@axa-fr/react-toolkit-popover';
import Help from './Help.container';
import Help from './Help';
import readme from '../README.md';
import './help-custom.scss';

Expand Down Expand Up @@ -36,13 +36,15 @@ export default {
} as Meta;

type HelpProps = React.ComponentProps<typeof Help>;
const Template: Story<HelpProps> = ({ content, ...args }) => (
<Help {...args}>{content}</Help>
const Template: Story<HelpProps> = ({ children, ...args }) => (
<Help {...args}>{children}</Help>
);

export const TextStory = Template.bind({});
export const TextStory: Story<HelpProps> = Template.bind({});
TextStory.args = {
content: 'Lorem ipsum dolor sit amet',
children: 'Lorem ipsum dolor sit amet',
mode: PopoverModes.click,
placement: PopoverPlacements.right,
};

const htmlChild = (
Expand All @@ -65,8 +67,10 @@ const htmlChild = (
</div>
);

export const HtmlStory = Template.bind({});
export const HtmlStory: Story<HelpProps> = Template.bind({});
HtmlStory.args = {
content: htmlChild,
children: htmlChild,
classModifier: 'custom',
mode: PopoverModes.over,
placement: PopoverPlacements.right,
};
26 changes: 0 additions & 26 deletions packages/help/src/__snapshots__/Help.spec.tsx.snap

This file was deleted.

118 changes: 118 additions & 0 deletions packages/help/src/__tests__/Help.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import UserEvent from '@testing-library/user-event';
import Help from '../Help';

describe('Help', () => {
describe('Mode click (default)', () => {
it('should show help on when clicking on i', async () => {
// Arrange
render(<Help>Help content</Help>);

// Act
UserEvent.click(screen.getByText('i'));

// Assert
await waitFor(() => {
expect(screen.getByText(/Help content/)).toBeInTheDocument();
});
});

it('should not hide help when clicking on help content', async () => {
// Arrange
render(<Help>Help content</Help>);
UserEvent.click(screen.getByText('i'));
await waitFor(() => {
screen.queryByText(/Help content/);
});

// Act
UserEvent.click(screen.getByText(/Help content/));

// Assert
await waitFor(() => {
expect(screen.getByText(/Help content/)).toBeInTheDocument();
});
});

it('should hide help when clicking on i', async () => {
// Arrange
render(<Help>Help content</Help>);
UserEvent.click(screen.getByText('i'));
await waitFor(() => {
screen.queryByText(/Help content/);
});

// Act
UserEvent.click(screen.getByText('i'));

// Assert
await waitFor(() => {
expect(screen.queryByText(/Help content/)).not.toBeInTheDocument();
});
});

it('should not show help on hover', async () => {
// Arrange
render(<Help>Help content</Help>);

// Act
UserEvent.hover(screen.getByText('i'));

// Assert
await waitFor(() => {
expect(screen.queryByText(/Help content/)).not.toBeInTheDocument();
});
});

it('should not show help before click', async () => {
// Arrange
render(<Help>Help content</Help>);

// Act
// No user interaction

// Assert
expect(screen.queryByText(/Help content/)).not.toBeInTheDocument();
});
});

describe('Mode hover', () => {
it('should show help when hovering i', async () => {
// Arrange
render(<Help mode="over">Help content</Help>);

// Act
UserEvent.hover(screen.getByText('i'));

// Assert
await waitFor(() => {
expect(screen.queryByText(/Help content/)).toBeInTheDocument();
});
});

it('should hide help when unhovering i', async () => {
// Arrange
render(<Help mode="over">Help content</Help>);

// Act
UserEvent.unhover(screen.getByText('i'));

// Assert
await waitFor(() => {
expect(screen.queryByText(/Help content/)).not.toBeInTheDocument();
});
});

it('should not show help before hover', async () => {
// Arrange
render(<Help mode="over">Help content</Help>);

// Act
// No user interaction

// Assert
expect(screen.queryByText(/Help content/)).not.toBeInTheDocument();
});
});
});