@moda/om 15.11.3 → 16.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import wait from 'waait';
3
2
  import { render, screen } from '@testing-library/react';
4
3
  import userEvent from '@testing-library/user-event';
5
4
 
@@ -21,18 +20,18 @@ describe('Select', () => {
21
20
  );
22
21
  });
23
22
 
24
- it('expands when clicked', () => {
23
+ it('expands when clicked', async () => {
25
24
  const { container } = render(
26
25
  <Select idRef='1' name='name-1' label='Sort by' options={options} />
27
26
  );
28
27
  const button = container.querySelector('#Select__value--1')!;
29
- userEvent.click(button);
28
+ await userEvent.click(button);
30
29
  expect(container.innerHTML).toEqual(
31
30
  '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value=""><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button><div class="SelectOptions Select__options Select__options--down"><ul class="SelectOptions__list" tabindex="-1" role="listbox" aria-labelledby="Select__label--1" aria-activedescendant="SelectOption--foo-1"><li class="SelectOption SelectOption--active" aria-label="Foo" aria-selected="false" role="option">Foo</li><li class="SelectOption" aria-label="Bar" aria-selected="false" role="option">Bar</li><li class="SelectOption SelectOption--disabled" aria-label="Baz" aria-selected="false" role="option">Baz</li></ul></div></div>'
32
31
  );
33
32
  });
34
33
 
35
- it('does not expand on click when disabled', () => {
34
+ it('does not expand on click when disabled', async () => {
36
35
  const { container } = render(
37
36
  <Select
38
37
  defaultValue={undefined}
@@ -44,7 +43,7 @@ describe('Select', () => {
44
43
  />
45
44
  );
46
45
  const button = container.querySelector('#Select__value--1')!;
47
- userEvent.click(button);
46
+ await userEvent.click(button);
48
47
  expect(container.innerHTML).toEqual(
49
48
  '<div id="Select--1" class="Select Select--disabled"><input id="1" name="name-1" type="hidden" value=""><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Clickable--disabled Select__value" disabled=""><label id="Select__label--1">Sort by</label><span class="Select__icon"></span></button></div>'
50
49
  );
@@ -63,10 +62,9 @@ describe('Select', () => {
63
62
  />
64
63
  );
65
64
  const button = container.querySelector('#Select__value--1')!;
66
- userEvent.click(button);
65
+ await userEvent.click(button);
67
66
  const option = screen.getByLabelText('Bar');
68
- userEvent.click(option);
69
- await wait(0);
67
+ await userEvent.click(option);
70
68
  expect(onChange).toBeCalledWith('bar');
71
69
  });
72
70
 
@@ -83,10 +81,9 @@ describe('Select', () => {
83
81
  />
84
82
  );
85
83
  const button = container.querySelector('#Select__value--1')!;
86
- userEvent.click(button);
84
+ await userEvent.click(button);
87
85
  const option = screen.getByLabelText('Baz');
88
- userEvent.click(option);
89
- await wait(0);
86
+ await userEvent.click(option);
90
87
  expect(onChange).not.toBeCalled();
91
88
  });
92
89
 
@@ -95,10 +92,9 @@ describe('Select', () => {
95
92
  <Select idRef='1' name='name-1' label='Sort by' options={options} />
96
93
  );
97
94
  const button = container.querySelector('#Select__value--1')!;
98
- userEvent.click(button);
95
+ await userEvent.click(button);
99
96
  const option = screen.getByLabelText('Bar');
100
- userEvent.click(option);
101
- await wait(0);
97
+ await userEvent.click(option);
102
98
  expect(container.innerHTML).toEqual(
103
99
  '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value"><label id="Select__label--1">Sort by: </label>Bar<span class="Select__icon"></span></button></div>'
104
100
  );
@@ -107,10 +103,9 @@ describe('Select', () => {
107
103
  it('renders correctly when there is no label', async () => {
108
104
  const { container } = render(<Select idRef='1' name='name-1' options={options} />);
109
105
  const button = container.querySelector('#Select__value--1')!;
110
- userEvent.click(button);
106
+ await userEvent.click(button);
111
107
  const option = screen.getByLabelText('Bar');
112
- userEvent.click(option);
113
- await wait(0);
108
+ await userEvent.click(option);
114
109
  expect(container.innerHTML).toEqual(
115
110
  '<div id="Select--1" class="Select"><input id="1" name="name-1" type="hidden" value="bar"><button id="Select__value--1" aria-haspopup="listbox" aria-expanded="false" aria-labelledby="Select__label--1 Select__value--1" type="button" title="Select" class="Clickable Select__value">Bar<span class="Select__icon"></span></button></div>'
116
111
  );
@@ -73,7 +73,7 @@ export const Select: React.FC<SelectProps> = ({
73
73
  );
74
74
 
75
75
  const handleAutofill = useCallback(
76
- value => {
76
+ (value: string) => {
77
77
  value && dispatch({ type: 'SELECT', payload: { value } });
78
78
  },
79
79
  [dispatch]
@@ -21,7 +21,7 @@ export const SelectOption: React.FC<SelectOptionProps> = ({
21
21
  const ref = useRef<HTMLLIElement>(null);
22
22
 
23
23
  const handleClick = useCallback(
24
- event => {
24
+ (event: React.MouseEvent<HTMLLIElement>) => {
25
25
  event.preventDefault();
26
26
  !option.disabled && onClick(option);
27
27
  },
@@ -4,13 +4,13 @@ import userEvent from '@testing-library/user-event';
4
4
  import { Tag } from './Tag';
5
5
 
6
6
  describe('Tag', () => {
7
- it('works correctly', () => {
7
+ it('works correctly', async () => {
8
8
  const onRemove = jest.fn();
9
9
  render(<Tag onRemove={onRemove}>Hello</Tag>);
10
10
 
11
11
  expect(screen.getByText('Hello')).toBeTruthy();
12
12
 
13
- userEvent.click(screen.getByRole('button'));
13
+ await userEvent.click(screen.getByRole('button'));
14
14
  expect(onRemove).toBeCalled();
15
15
  });
16
16
  });
@@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
4
4
  import { Toast } from './Toast';
5
5
 
6
6
  describe('Toast', () => {
7
- it('works correctly', () => {
7
+ it('works correctly', async () => {
8
8
  const onRemove = jest.fn();
9
9
  render(
10
10
  <Toast theme='success' onRemove={onRemove}>
@@ -14,7 +14,7 @@ describe('Toast', () => {
14
14
 
15
15
  expect(screen.getByText('Hello')).toBeTruthy();
16
16
 
17
- userEvent.click(screen.getByRole('button', { name: 'Remove' }));
17
+ await userEvent.click(screen.getByRole('button', { name: 'Remove' }));
18
18
  expect(onRemove).toBeCalled();
19
19
  });
20
20
  });
@@ -2,8 +2,8 @@ import React, { useEffect, useCallback } from 'react';
2
2
 
3
3
  export const useClickOutside = (ref: React.RefObject<HTMLElement>, onClickOutside: () => void) => {
4
4
  const handleClickOutside = useCallback(
5
- event => {
6
- if (ref.current && !ref.current.contains(event.target)) onClickOutside();
5
+ (event: MouseEvent) => {
6
+ if (ref.current && !ref.current.contains(event.target as Node)) onClickOutside();
7
7
  },
8
8
  [onClickOutside, ref]
9
9
  );
@@ -1,4 +1,4 @@
1
- import { renderHook, act } from '@testing-library/react-hooks';
1
+ import { renderHook, act } from '@testing-library/react';
2
2
  import { fireEvent } from '@testing-library/react';
3
3
  import { useKeyboardListNavigation } from './useKeyboardListNavigation';
4
4
  import { useRef } from 'react';