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

[EuiSuperDatePicker] Fix duplicate value when pasting absolute value #8311

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: update test to ensure user pasting event is correctly tested
mgadewoll committed Feb 7, 2025
commit 4a8179c4792f8d0270b052c2da74c2ede4093ad6
Original file line number Diff line number Diff line change
@@ -7,11 +7,12 @@
*/

import React from 'react';
import { fireEvent } from '@testing-library/react';
import { fireEvent, waitFor } from '@testing-library/react';
import { render } from '../../../../test/rtl';

import { EuiAbsoluteTab } from './absolute_tab';
import { LocaleSpecifier } from 'moment';
import { userEvent } from '@storybook/test';

// Mock EuiDatePicker - 3rd party datepicker lib causes render issues
jest.mock('../../date_picker', () => ({
@@ -69,7 +70,7 @@ describe('EuiAbsoluteTab', () => {
expect(queryByText(formatHelpText)).toHaveClass('euiFormErrorText');
});

it('immediately parses pasted text without needing an extra click or keypress', () => {
it('immediately parses pasted text without needing an extra click or keypress', async () => {
const { getByTestSubject, queryByText } = render(
<EuiAbsoluteTab {...props} />
);
@@ -80,9 +81,21 @@ describe('EuiAbsoluteTab', () => {
fireEvent.paste(input, {
clipboardData: { getData: () => '1970-01-01' },
});

expect(input).not.toBeInvalid();
expect(input.value).toContain('Jan 1, 1970');

// Additional pasting check as userEvent.paste more accurately simulates
// the pasting behavior with side effects
await waitFor(() => {
input.focus();
userEvent.paste('1970-01-02');
});

// ensure value is replaced, not appended
expect(input.value).not.toEqual('Jan 1, 1970 @ 00:00:00.0001970-01-02');
expect(input.value).toEqual('Jan 2, 1970 @ 00:00:00.000');

input.value = '';
fireEvent.paste(input, {
clipboardData: { getData: () => 'not a date' },