Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Jan 10, 2023
1 parent d2300b9 commit e70bbd8
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,78 @@ describe('<DateField /> - Editing', () => {
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2022, 8, 16, 3, 3, 3));
});
});

describe('Android editing', () => {
let originalUserAgent: string = '';

beforeEach(() => {
originalUserAgent = global.navigator.userAgent;
Object.defineProperty(global.navigator, 'userAgent', {
configurable: true,
writable: true,
value:
'Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.5359.128 Mobile Safari/537.36',
});
});

afterEach(() => {
Object.defineProperty(global.navigator, 'userAgent', {
configurable: true,
value: originalUserAgent,
});
});

it('should support digit editing', () => {
render(<DateField defaultValue={adapterToUse.date(new Date(2022, 4, 16))} />);

const input = screen.getByRole('textbox');
const initialValueStr = input.value;
const sectionStart = initialValueStr.indexOf('1');

clickOnInput(input, sectionStart, sectionStart + 1);

// Remove the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('16', '') } });

// // Set the key pressed in the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('16', '2') } });

// Remove the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('16', '') } });

// Set the key pressed in the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('16', '1') } });

expectInputValue(input, '05 / 21 / 2022');
});

it.only('should support letter editing', () => {
render(
<DateField
defaultValue={adapterToUse.date(new Date(2022, 4, 16))}
format={`${adapterToUse.formats.month} ${adapterToUse.formats.year}`}
/>,
);

const input = screen.getByRole('textbox');
const initialValueStr = input.value;
const sectionStart = initialValueStr.indexOf('M');

clickOnInput(input, sectionStart, sectionStart + 1);

// Remove the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('May', '') } });

// // Set the key pressed in the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('May', 'J') } });

// Remove the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('May', '') } });

// Set the key pressed in the selected section
fireEvent.change(input, { target: { value: initialValueStr.replace('May', 'u') } });

expectInputValue(input, 'June 2022');
});
});
});

0 comments on commit e70bbd8

Please sign in to comment.