Skip to content

Commit

Permalink
Fix some UT #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jmainguytalend committed Nov 16, 2023
1 parent 4834b8f commit 232b061
Show file tree
Hide file tree
Showing 21 changed files with 407 additions and 262 deletions.
2 changes: 1 addition & 1 deletion packages/a11y/src/Gesture/withCalendarGesture.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('withCalendarGesture', () => {
// .simulate('keydown', { keyCode: keycode.codes.left });

// // then
// await userEvent.keyboard('[ArrowLeft]');
// await user.keyboard('[ArrowLeft]');

expect(screen.getByTestId('10')).toHaveFocus();
// expect(document.activeElement.innerHTML).toBe('11');
Expand Down
16 changes: 10 additions & 6 deletions packages/components/src/AppGuidedTour/AppGuidedTour.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ describe('AppGuidedTour', () => {
render(<AppGuidedTour {...DEFAULT_PROPS} />);
expect(screen.getByLabelText('Import demo content')).not.toBeChecked();
});
it('should reset state on close', () => {
it('should reset state on close', async () => {
const user = userEvent.setup();

const onRequestCloseMock = jest.fn();
localStorage.setItem(DEFAULT_LOCAL_STORAGE_KEY, 'true');
render(<AppGuidedTour {...DEFAULT_PROPS} onRequestClose={onRequestCloseMock} />);
const nextBtn = document.querySelector('button[data-tour-elem="right-arrow"]');
userEvent.click(nextBtn);
userEvent.click(screen.getByText('Let me try'));
await user.click(nextBtn);
await user.click(screen.getByText('Let me try'));

expect(onRequestCloseMock).toHaveBeenCalled();
});
Expand All @@ -66,12 +68,14 @@ describe('AppGuidedTour', () => {
render(<AppGuidedTour {...DEFAULT_PROPS} isOpen={false} onRequestOpen={onRequestOpenMock} />);
expect(onRequestOpenMock).not.toHaveBeenCalled();
});
it('Should set a local storage flag when closed', () => {
it('Should set a local storage flag when closed', async () => {
const user = userEvent.setup();

const onCloseMock = jest.fn();
render(<AppGuidedTour {...DEFAULT_PROPS} onClose={onCloseMock} />);
const nextBtn = document.querySelector('button[data-tour-elem="right-arrow"]');
userEvent.click(nextBtn);
userEvent.click(screen.getByText('Let me try'));
await user.click(nextBtn);
await user.click(screen.getByText('Let me try'));
expect(localStorage.getItem(DEFAULT_LOCAL_STORAGE_KEY)).toBe('true');
});
it('Should not show demo content form if no step is provided', async () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/ConfirmDialog/ConfirmDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ describe('ConfirmDialog', () => {
expect(screen.getByLabelText('This is loading')).toHaveAttribute('aria-valuenow', '25');
});

it('should render with additional actions', () => {
it('should render with additional actions', async () => {
const user = userEvent.setup();

// given
const properties = {
header: 'Hello world',
Expand All @@ -126,7 +128,7 @@ describe('ConfirmDialog', () => {
// then
expect(screen.getByText('Hello world')).toBeVisible();
expect(screen.getByText('Keep on Github')).toBeVisible();
userEvent.click(screen.getByText('Keep on Github'));
await user.click(screen.getByText('Keep on Github'));
expect(properties.secondaryActions[0].onClick).toHaveBeenCalled();
});
});
16 changes: 9 additions & 7 deletions packages/components/src/Datalist/Datalist.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash/omit';
import keycode from 'keycode';
import get from 'lodash/get';
import Typeahead from '../Typeahead';
import theme from './Datalist.module.scss';
Expand All @@ -24,7 +23,7 @@ const DISPLAY = {
};

function isValuePresentInSuggestions(titleMap, filterValue, multiSection) {
return !!multiSection
return multiSection
? titleMap.find(group =>
group.suggestions.find(item => filterValue.toLowerCase() === item.name.toLowerCase()),
)
Expand Down Expand Up @@ -364,13 +363,14 @@ function Datalist(props) {
newHighlightedItemIndex,
newHighlightedSectionIndex,
} = params;
switch (event.which) {
case keycode.codes.esc:
switch (event.key) {
case 'Esc':
case 'Escape':
event.preventDefault();
resetFilter();
hideSuggestions();
break;
case keycode.codes.enter:
case 'Enter':
if (!suggestions) {
break;
}
Expand All @@ -386,8 +386,10 @@ function Datalist(props) {
persistValue(event);
}
break;
case keycode.codes.down:
case keycode.codes.up:
case 'Down':
case 'ArrowDown':
case 'Up':
case 'ArrowUp':
event.preventDefault();
if (!suggestions) {
// display all suggestions when they are not displayed
Expand Down
Loading

0 comments on commit 232b061

Please sign in to comment.