Skip to content

Commit

Permalink
Update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jmainguytalend committed Nov 16, 2023
1 parent 232b061 commit fc9a802
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/cmf-cqrs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@talend/scripts-config-babel": "^13.1.0",
"@talend/scripts-config-react-webpack": "^16.2.0",
"@talend/scripts-config-typescript": "^11.1.0",
"@testing-library/react": "^12.1.5",
"@testing-library/react": "^14.0.0",
"@testing-library/react-hooks": "^8.0.1",
"mock-socket": "^9.3.1",
"prop-types": "^15.8.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/components/src/AppGuidedTour/AppGuidedTour.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ describe('AppGuidedTour', () => {
localStorage.setItem(DEFAULT_LOCAL_STORAGE_KEY, null);
});
it('should not trigger import function if "load demo content" is not selected', async () => {
const user = userEvent.setup();

const onImportDemoContentMock = jest.fn();
render(<AppGuidedTour {...DEFAULT_PROPS} onImportDemoContent={onImportDemoContentMock} />);

await userEvent.click(screen.getByLabelText('Import demo content'));
await userEvent.click(screen.getByText('Let me try'));
await user.click(screen.getByLabelText('Import demo content'));
await user.click(screen.getByText('Let me try'));
expect(onImportDemoContentMock).not.toHaveBeenCalled();
});
it('should trigger import function if "load demo content" is selected', async () => {
const user = userEvent.setup();

const onImportDemoContentMock = jest.fn();

render(<AppGuidedTour {...DEFAULT_PROPS} onImportDemoContent={onImportDemoContentMock} />);
const nextBtn = document.querySelector('button[data-tour-elem="right-arrow"]');
expect(nextBtn).toBeInTheDocument();
await userEvent.click(nextBtn);
await user.click(nextBtn);
expect(onImportDemoContentMock).toHaveBeenCalled();
});
it('should import content by default on first time use', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ describe('TreeHeader', () => {
expect(container.firstChild).toMatchSnapshot();
});
it('should render with the collapse button', async () => {
const user = userEvent.setup();

const onClickCollapseAll = jest.fn();
render(<Component title="myTitle" onClickCollapseAll={onClickCollapseAll} />);
expect(screen.getByTestId('collapse-all')).toBeVisible();
await userEvent.click(screen.getByTestId('collapse-all'));
await user.click(screen.getByTestId('collapse-all'));
expect(onClickCollapseAll).toHaveBeenCalled();
});
it('should render with the expand button', async () => {
const user = userEvent.setup();

const onClickExpandAll = jest.fn();
render(<Component title="myTitle" onClickExpandAll={onClickExpandAll} />);
expect(screen.getByTestId('expand-all')).toBeVisible();
await userEvent.click(screen.getByTestId('expand-all'));
await user.click(screen.getByTestId('expand-all'));
expect(onClickExpandAll).toHaveBeenCalled();
});
it('should render other actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('TreeManager#onToggle', () => {
setState: jest.fn(),
};
it('when the handler emitter is an union, and has been click for the first time', async () => {
const user = userEvent.setup();

// given
const options = {
firstClickUnion: true,
Expand All @@ -45,11 +47,13 @@ describe('TreeManager#onToggle', () => {
)}
/>,
);
await userEvent.click(screen.getByTestId('btn'));
await user.click(screen.getByTestId('btn'));
// then nothing
expect(setStateSpy).not.toHaveBeenCalled();
});
it('default', async () => {
const user = userEvent.setup();

// when
const options = {
firstClickUnion: false,
Expand All @@ -66,7 +70,7 @@ describe('TreeManager#onToggle', () => {
)}
/>,
);
await userEvent.click(screen.getByTestId('btn'));
await user.click(screen.getByTestId('btn'));
// then
expect(setStateSpy).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ describe('Date.Manager', () => {
dateFormat: 'DD/MM/YYYY',
},
])('$name', async ({ textInput, expectedDate, dateFormat }) => {
const user = userEvent.setup();

// given
render(
<Manager id={DEFAULT_ID} dateFormat={dateFormat}>
Expand All @@ -205,8 +207,8 @@ describe('Date.Manager', () => {
);

// when
await userEvent.click(screen.getByTestId('DateConsumerDivInput'));
await userEvent.keyboard(textInput);
await user.click(screen.getByTestId('DateConsumerDivInput'));
await user.keyboard(textInput);

// then
const props = JSON.parse(screen.getByTestId('DateConsumerDiv').dataset.props);
Expand All @@ -217,6 +219,8 @@ describe('Date.Manager', () => {
});

it('should trigger props.onChange with valid date', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -227,8 +231,8 @@ describe('Date.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('DateConsumerDivInput'));
await userEvent.keyboard('2015-01-15');
await user.click(screen.getByTestId('DateConsumerDivInput'));
await user.keyboard('2015-01-15');

// then
expect(onChange).toHaveBeenCalledWith(expect.anything(), {
Expand All @@ -241,6 +245,8 @@ describe('Date.Manager', () => {
});

it('should trigger props.onChange with invalid date', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -251,8 +257,8 @@ describe('Date.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('DateConsumerDivInput'));
await userEvent.keyboard('2015-01-15');
await user.click(screen.getByTestId('DateConsumerDivInput'));
await user.keyboard('2015-01-15');

// then
expect(onChange).toHaveBeenCalled();
Expand Down Expand Up @@ -286,6 +292,8 @@ describe('Date.Manager', () => {
expectedTextInput: '15/01/2015',
},
])('$name', async ({ date, expectedTextInput, dateFormat }) => {
const user = userEvent.setup();

// given
render(
<Manager id={DEFAULT_ID} dateFormat={dateFormat} value={date}>
Expand All @@ -294,14 +302,16 @@ describe('Date.Manager', () => {
);

// when
await userEvent.click(screen.getByRole('button'));
await user.click(screen.getByRole('button'));

// then
const props = JSON.parse(screen.getByTestId('DateConsumerDiv').dataset.props);
expect(props.value.textInput).toBe(expectedTextInput);
});

it('should trigger props.onChange with valid date', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -313,9 +323,9 @@ describe('Date.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('DateConsumerDivInput'));
await userEvent.keyboard('2015-01-15');
await userEvent.click(screen.getByRole('button'));
await user.click(screen.getByTestId('DateConsumerDivInput'));
await user.keyboard('2015-01-15');
await user.click(screen.getByRole('button'));

// then
expect(onChange).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ describe('DateTime.Manager', () => {
expectedTime: '12:34',
},
])('$name', async ({ initialDate, expectedDate, expectedTime }) => {
const user = userEvent.setup();

// when
const getProps = jest.fn();
render(
Expand All @@ -91,7 +93,7 @@ describe('DateTime.Manager', () => {
);

// then
await userEvent.click(screen.getByTestId('getProps'));
await user.click(screen.getByTestId('getProps'));
const props = getProps.mock.calls[0][0];
expect(props.date).toStrictEqual(expectedDate);
expect(props.time).toStrictEqual(expectedTime);
Expand Down Expand Up @@ -135,6 +137,8 @@ describe('DateTime.Manager', () => {
useSeconds: true,
},
])('$name', async ({ initialDate, newDate, expectedDate, expectedTime, useSeconds }) => {
const user = userEvent.setup();

// given

const getProps = jest.fn();
Expand All @@ -152,7 +156,7 @@ describe('DateTime.Manager', () => {
);

// then
await userEvent.click(screen.getByTestId('getProps'));
await user.click(screen.getByTestId('getProps'));
const props = getProps.mock.calls[0][0];
expect(props.date).toEqual(expectedDate);
expect(props.time).toEqual(expectedTime);
Expand Down Expand Up @@ -223,6 +227,8 @@ describe('DateTime.Manager', () => {
dateFormat: 'DD/MM/YYYY',
},
])('$name', async ({ expectedDate, expectedTime, textInput, dateFormat, useSeconds }) => {
const user = userEvent.setup();

// given
const getProps = jest.fn();
render(
Expand All @@ -232,8 +238,8 @@ describe('DateTime.Manager', () => {
);

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await userEvent.click(screen.getByTestId('getProps'));
await user.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('getProps'));
// then
const props = getProps.mock.calls[0][0];
expect(props.date).toEqual(expectedDate);
Expand Down Expand Up @@ -265,6 +271,8 @@ describe('DateTime.Manager', () => {
dateFormat,
useSeconds,
}) => {
const user = userEvent.setup();

// given
const getProps = jest.fn();

Expand All @@ -280,8 +288,8 @@ describe('DateTime.Manager', () => {
);

// when
await userEvent.click(screen.getByTestId('onTimeChange'));
await userEvent.click(screen.getByTestId('getProps'));
await user.click(screen.getByTestId('onTimeChange'));
await user.click(screen.getByTestId('getProps'));
// then
const props = getProps.mock.calls[0][0];

Expand All @@ -291,6 +299,8 @@ describe('DateTime.Manager', () => {
);

it('should trigger props.onChange when date change', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -307,7 +317,7 @@ describe('DateTime.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('onDateChange'));

// then
expect(onChange).toHaveBeenCalled();
Expand All @@ -322,6 +332,8 @@ describe('DateTime.Manager', () => {
});

it('should trigger props.onChange when date change with default time', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -338,7 +350,7 @@ describe('DateTime.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('onDateChange'));

// then
expect(onChange).toHaveBeenCalled();
Expand All @@ -348,6 +360,8 @@ describe('DateTime.Manager', () => {
});

it('should trigger props.onChange with invalid date', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
render(
Expand All @@ -364,7 +378,7 @@ describe('DateTime.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('onDateChange'));
// then
expect(onChange).toHaveBeenCalled();
const args = onChange.mock.calls[0];
Expand All @@ -376,6 +390,8 @@ describe('DateTime.Manager', () => {
});

it('should trigger props.onChange when time change', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
const { rerender } = render(
Expand All @@ -392,7 +408,7 @@ describe('DateTime.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('onDateChange'));
rerender(
<Manager id={DEFAULT_ID} onChange={onChange}>
<DateTimeConsumer
Expand All @@ -404,7 +420,7 @@ describe('DateTime.Manager', () => {
/>
</Manager>,
);
await userEvent.click(screen.getByTestId('onTimeChange'));
await user.click(screen.getByTestId('onTimeChange'));

expect(onChange).toHaveBeenCalledTimes(2);
const args = onChange.mock.calls[1];
Expand All @@ -415,6 +431,8 @@ describe('DateTime.Manager', () => {
expect(args[1].errorMessage).toBe(null);
});
it("shouldn't trigger props.onChange if the default datetime is valid", async () => {
const user = userEvent.setup();

const onChange = jest.fn();
const getProps = jest.fn();
const textInput = '2015-01-15 11:11';
Expand All @@ -424,7 +442,7 @@ describe('DateTime.Manager', () => {
</Manager>,
);
expect(onChange).not.toHaveBeenCalled();
await userEvent.click(screen.getByTestId('getProps'));
await user.click(screen.getByTestId('getProps'));
const contextValue = getProps.mock.calls[0][0];
expect(contextValue.date).toEqual('2015-01-15');
expect(contextValue.time).toEqual('11:11');
Expand Down Expand Up @@ -455,6 +473,8 @@ describe('DateTime.Manager', () => {
expect(data.errors[0].code).toEqual('INVALID_TIME_EMPTY');
});
it('should trigger props.onChange with invalid time', async () => {
const user = userEvent.setup();

// given
const onChange = jest.fn();
const { rerender } = render(
Expand All @@ -471,7 +491,7 @@ describe('DateTime.Manager', () => {
expect(onChange).not.toHaveBeenCalled();

// when
await userEvent.click(screen.getByTestId('onDateChange'));
await user.click(screen.getByTestId('onDateChange'));
rerender(
<Manager id={DEFAULT_ID} onChange={onChange}>
<DateTimeConsumer
Expand All @@ -482,7 +502,7 @@ describe('DateTime.Manager', () => {
/>
</Manager>,
);
await userEvent.click(screen.getByTestId('onTimeChange'));
await user.click(screen.getByTestId('onTimeChange'));

// then
expect(onChange).toHaveBeenCalledTimes(2);
Expand Down
Loading

0 comments on commit fc9a802

Please sign in to comment.