Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Esteves <[email protected]>
  • Loading branch information
aesteves60 authored and dpellier committed Nov 28, 2024
1 parent 73158a5 commit 9c9e833
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 39 deletions.
22 changes: 2 additions & 20 deletions packages/ods/react/tests/_app/src/components/ods-textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { useFormik } from 'formik';
import { OdsTextarea } from 'ods-components-react';
import { ChangeEvent, type ReactElement } from 'react';
import { type ReactElement } from 'react';
import React from 'react-dom/client';

// eslint-disable-next-line func-style
const Textarea = (): ReactElement => {
const formik = useFormik({
initialValues: {
textarea: '',
},
onSubmit: (values) => {
console.log('Formik values', values);
},
validateOnMount: true,
});

function onOdsChange(e: ChangeEvent): void {
function onOdsChange(): void {
console.log('React textarea odsChange');
}

Expand All @@ -27,13 +16,6 @@ const Textarea = (): ReactElement => {
<OdsTextarea isDisabled
name="ods-textarea-disabled"
onOdsChange={ onOdsChange } />

<OdsTextarea name="ods-textarea-formik"
onOdsChange={ (e) => {
onOdsChange(e);
return formik.handleChange(e);
} }
value={ formik.values.textarea } />
</>
);
};
Expand Down
15 changes: 0 additions & 15 deletions packages/ods/react/tests/e2e/ods-textarea.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,4 @@ describe('ods-textarea react', () => {

expect(consoleLog).toBe('');
});

it('should not do an infinite loop', async () => {
const elem = await page.$('ods-textarea[name="ods-textarea-formik"] >>> textarea');
let consoleLog = '';
page.on('console', (consoleObj) => {
console.log('consoleObj', consoleObj.text())
consoleLog += consoleObj.text();
});

await elem?.type('a');
// Small delay to ensure page console event has been resolved
await new Promise((resolve) => setTimeout(resolve, 100));

expect(consoleLog).toBe('React textarea odsChangeReact textarea odsChange');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ describe('ods-datepicker behaviour', () => {
}, dummyValue);
await page.waitForChanges();

// expect(await el.getProperty('value')).toBe(new Date(dummyValue).toISOString());
expect(odsValueChangeSpy).toHaveReceivedEventTimes(1);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe('ods-input behaviour', () => {
expect(odsValueChangeSpy).toHaveReceivedEventTimes(1);
});

it('should not do an infinite loop with string', async() => {
it('should not do an infinite loop with number', async() => {
const dummyValue = 2;
await setup('<ods-input></ods-input>');
const odsValueChangeSpy = await page.spyOnEvent('odsChange');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('ods-phone-number behaviour', () => {
});

it('should not do an infinite loop', async() => {
const dummyValue = '0123456789';
const dummyValue = '+33123456789';
await setup('<ods-phone-number iso-code="fr"></ods-phone-number>');
const odsValueChangeSpy = await page.spyOnEvent('odsChange');

Expand All @@ -290,7 +290,7 @@ describe('ods-phone-number behaviour', () => {
await el.setAttribute('value', dummyValue);
await page.waitForChanges();

expect(await el.getProperty('value')).toBe('+33' + dummyValue.substring(1));
expect(await el.getProperty('value')).toBe(dummyValue);
expect(odsValueChangeSpy).toHaveReceivedEventTimes(1);
});
});
Expand Down

0 comments on commit 9c9e833

Please sign in to comment.