chore(fe): replace deprecate aliased Jest matchers with corresponding substituents (#30355)

Signed-off-by: hainenber <dotronghai96@gmail.com>
Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
Đỗ Trọng Hải 2024-10-30 01:27:20 +07:00 committed by GitHub
parent f2a9f31135
commit 576ad85eb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
48 changed files with 294 additions and 293 deletions

View File

@ -280,7 +280,6 @@ module.exports = {
'theme-colors/no-literal-colors': 0, 'theme-colors/no-literal-colors': 0,
'translation-vars/no-template-vars': 0, 'translation-vars/no-template-vars': 0,
'no-restricted-imports': 0, 'no-restricted-imports': 0,
'jest/no-alias-methods': 0,
'react/no-void-elements': 0, 'react/no-void-elements': 0,
}, },
}, },
@ -371,7 +370,6 @@ module.exports = {
'react-prefer-function-component/react-prefer-function-component': 1, 'react-prefer-function-component/react-prefer-function-component': 1,
'prettier/prettier': 'error', 'prettier/prettier': 'error',
// disabling some things that come with the eslint 7->8 upgrade. Will address these in a separate PR // disabling some things that come with the eslint 7->8 upgrade. Will address these in a separate PR
'jest/no-alias-methods': 0,
'react/no-unknown-property': 0, 'react/no-unknown-property': 0,
'react/no-void-elements': 0, 'react/no-void-elements': 0,
'react/function-component-definition': [ 'react/function-component-definition': [

View File

@ -24,8 +24,8 @@ test('call callback the first time with undefined and value', () => {
renderHook(props => useChangeEffect(props.value, props.callback), { renderHook(props => useChangeEffect(props.value, props.callback), {
initialProps: { value: 'value', callback }, initialProps: { value: 'value', callback },
}); });
expect(callback).toBeCalledTimes(1); expect(callback).toHaveBeenCalledTimes(1);
expect(callback).nthCalledWith(1, undefined, 'value'); expect(callback).toHaveBeenNthCalledWith(1, undefined, 'value');
}); });
test('do not call callback 2 times if the value do not change', () => { test('do not call callback 2 times if the value do not change', () => {
@ -37,7 +37,7 @@ test('do not call callback 2 times if the value do not change', () => {
}, },
); );
hook.rerender({ value: 'value', callback }); hook.rerender({ value: 'value', callback });
expect(callback).toBeCalledTimes(1); expect(callback).toHaveBeenCalledTimes(1);
}); });
test('call callback whenever the value changes', () => { test('call callback whenever the value changes', () => {
@ -49,6 +49,6 @@ test('call callback whenever the value changes', () => {
}, },
); );
hook.rerender({ value: 'value-2', callback }); hook.rerender({ value: 'value-2', callback });
expect(callback).toBeCalledTimes(2); expect(callback).toHaveBeenCalledTimes(2);
expect(callback).nthCalledWith(2, 'value', 'value-2'); expect(callback).toHaveBeenNthCalledWith(2, 'value', 'value-2');
}); });

View File

@ -22,7 +22,7 @@ import { useComponentDidMount } from './useComponentDidMount';
test('the effect should only be executed on the first render', () => { test('the effect should only be executed on the first render', () => {
const effect = jest.fn(); const effect = jest.fn();
const hook = renderHook(() => useComponentDidMount(effect)); const hook = renderHook(() => useComponentDidMount(effect));
expect(effect).toBeCalledTimes(1); expect(effect).toHaveBeenCalledTimes(1);
hook.rerender(); hook.rerender();
expect(effect).toBeCalledTimes(1); expect(effect).toHaveBeenCalledTimes(1);
}); });

View File

@ -24,8 +24,8 @@ test('the effect should not be executed on the first render', () => {
const hook = renderHook(props => useComponentDidUpdate(props.effect), { const hook = renderHook(props => useComponentDidUpdate(props.effect), {
initialProps: { effect }, initialProps: { effect },
}); });
expect(effect).toBeCalledTimes(0); expect(effect).toHaveBeenCalledTimes(0);
const changedEffect = jest.fn(); const changedEffect = jest.fn();
hook.rerender({ effect: changedEffect }); hook.rerender({ effect: changedEffect });
expect(changedEffect).toBeCalledTimes(1); expect(changedEffect).toHaveBeenCalledTimes(1);
}); });

View File

@ -192,7 +192,7 @@ describe('LabelsColorMap', () => {
labelsColorMap.updateColorMap(categoricalNamespace, 'testColors'); labelsColorMap.updateColorMap(categoricalNamespace, 'testColors');
const colorMap = labelsColorMap.getColorMap(); const colorMap = labelsColorMap.getColorMap();
expect(Object.fromEntries(colorMap)).not.toEqual({}); expect(Object.fromEntries(colorMap)).not.toEqual({});
expect(getAnalogousColorsSpy).not.toBeCalled(); expect(getAnalogousColorsSpy).not.toHaveBeenCalled();
}); });
it('should use analagous colors', () => { it('should use analagous colors', () => {
@ -207,7 +207,7 @@ describe('LabelsColorMap', () => {
labelsColorMap.updateColorMap(categoricalNamespace, 'testColors'); labelsColorMap.updateColorMap(categoricalNamespace, 'testColors');
const colorMap = labelsColorMap.getColorMap(); const colorMap = labelsColorMap.getColorMap();
expect(Object.fromEntries(colorMap)).not.toEqual({}); expect(Object.fromEntries(colorMap)).not.toEqual({});
expect(getAnalogousColorsSpy).toBeCalled(); expect(getAnalogousColorsSpy).toHaveBeenCalled();
}); });
}); });

View File

@ -396,31 +396,31 @@ describe('Registry', () => {
it('calls the listener when a value is registered', () => { it('calls the listener when a value is registered', () => {
registry.registerValue('foo', 'bar'); registry.registerValue('foo', 'bar');
expect(listener).toBeCalledWith(['foo']); expect(listener).toHaveBeenCalledWith(['foo']);
}); });
it('calls the listener when a loader is registered', () => { it('calls the listener when a loader is registered', () => {
registry.registerLoader('foo', () => 'bar'); registry.registerLoader('foo', () => 'bar');
expect(listener).toBeCalledWith(['foo']); expect(listener).toHaveBeenCalledWith(['foo']);
}); });
it('calls the listener when a value is overridden', () => { it('calls the listener when a value is overridden', () => {
registry.registerValue('foo', 'bar'); registry.registerValue('foo', 'bar');
listener.mockClear(); listener.mockClear();
registry.registerValue('foo', 'baz'); registry.registerValue('foo', 'baz');
expect(listener).toBeCalledWith(['foo']); expect(listener).toHaveBeenCalledWith(['foo']);
}); });
it('calls the listener when a value is removed', () => { it('calls the listener when a value is removed', () => {
registry.registerValue('foo', 'bar'); registry.registerValue('foo', 'bar');
listener.mockClear(); listener.mockClear();
registry.remove('foo'); registry.remove('foo');
expect(listener).toBeCalledWith(['foo']); expect(listener).toHaveBeenCalledWith(['foo']);
}); });
it('does not call the listener when a value is not actually removed', () => { it('does not call the listener when a value is not actually removed', () => {
registry.remove('foo'); registry.remove('foo');
expect(listener).not.toBeCalled(); expect(listener).not.toHaveBeenCalled();
}); });
it('calls the listener when registry is cleared', () => { it('calls the listener when registry is cleared', () => {
@ -428,13 +428,13 @@ describe('Registry', () => {
registry.registerLoader('fluz', () => 'baz'); registry.registerLoader('fluz', () => 'baz');
listener.mockClear(); listener.mockClear();
registry.clear(); registry.clear();
expect(listener).toBeCalledWith(['foo', 'fluz']); expect(listener).toHaveBeenCalledWith(['foo', 'fluz']);
}); });
it('removes listeners correctly', () => { it('removes listeners correctly', () => {
registry.removeListener(listener); registry.removeListener(listener);
registry.registerValue('foo', 'bar'); registry.registerValue('foo', 'bar');
expect(listener).not.toBeCalled(); expect(listener).not.toHaveBeenCalled();
}); });
describe('with a broken listener', () => { describe('with a broken listener', () => {
@ -456,10 +456,10 @@ describe('Registry', () => {
registry.addListener(lastListener); registry.addListener(lastListener);
registry.registerValue('foo', 'bar'); registry.registerValue('foo', 'bar');
expect(listener).toBeCalledWith(['foo']); expect(listener).toHaveBeenCalledWith(['foo']);
expect(errorListener).toBeCalledWith(['foo']); expect(errorListener).toHaveBeenCalledWith(['foo']);
expect(lastListener).toBeCalledWith(['foo']); expect(lastListener).toHaveBeenCalledWith(['foo']);
expect(console.error).toBeCalled(); expect(console.error).toHaveBeenCalled();
}); });
}); });
}); });

View File

@ -138,7 +138,7 @@ describe('buildQueryContext', () => {
}, },
() => [{}], () => [{}],
); );
expect(spyNormalizeTimeColumn).toBeCalled(); expect(spyNormalizeTimeColumn).toHaveBeenCalled();
spyNormalizeTimeColumn.mockRestore(); spyNormalizeTimeColumn.mockRestore();
}); });
}); });

View File

@ -80,7 +80,7 @@ describe('TranslatorSingleton', () => {
expect(t('second')).toEqual('second'); expect(t('second')).toEqual('second');
resetTranslation(); resetTranslation();
expect(t('second')).toEqual('second'); expect(t('second')).toEqual('second');
expect(console.warn).toBeCalledTimes(2); expect(console.warn).toHaveBeenCalledTimes(2);
restoreConsole(); restoreConsole();
}); });
}); });

View File

@ -294,7 +294,7 @@ describe('comms', () => {
}); });
port2.start(); port2.start();
await expect(ours.get('someMethod')).rejects.toThrowError( await expect(ours.get('someMethod')).rejects.toThrow(
'Unexpected response message', 'Unexpected response message',
); );
}); });

View File

@ -127,7 +127,7 @@ describe('ShareSqlLabQuery', () => {
const storeQuerySpy = jest.spyOn(utils, 'storeQuery'); const storeQuerySpy = jest.spyOn(utils, 'storeQuery');
userEvent.click(button); userEvent.click(button);
expect(storeQuerySpy.mock.calls).toHaveLength(1); expect(storeQuerySpy.mock.calls).toHaveLength(1);
expect(storeQuerySpy).toBeCalledWith(expected); expect(storeQuerySpy).toHaveBeenCalledWith(expected);
storeQuerySpy.mockRestore(); storeQuerySpy.mockRestore();
}); });
@ -142,7 +142,7 @@ describe('ShareSqlLabQuery', () => {
const storeQuerySpy = jest.spyOn(utils, 'storeQuery'); const storeQuerySpy = jest.spyOn(utils, 'storeQuery');
userEvent.click(button); userEvent.click(button);
expect(storeQuerySpy.mock.calls).toHaveLength(1); expect(storeQuerySpy.mock.calls).toHaveLength(1);
expect(storeQuerySpy).toBeCalledWith(expected); expect(storeQuerySpy).toHaveBeenCalledWith(expected);
storeQuerySpy.mockRestore(); storeQuerySpy.mockRestore();
}); });
}); });

View File

@ -28,7 +28,7 @@ test('Should send correct props to ReactCronPicker', () => {
myCustomProp: 'myCustomProp', myCustomProp: 'myCustomProp',
}; };
render(<CronPicker {...(props as any)} />); render(<CronPicker {...(props as any)} />);
expect(spy).toBeCalledWith( expect(spy).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
className: expect.any(String), className: expect.any(String),
locale: expect.anything(), locale: expect.anything(),

View File

@ -219,9 +219,9 @@ test('Refresh should work', async () => {
await waitFor(() => { await waitFor(() => {
expect(fetchMock.calls(databaseApiRoute).length).toBe(1); expect(fetchMock.calls(databaseApiRoute).length).toBe(1);
expect(fetchMock.calls(schemaApiRoute).length).toBe(1); expect(fetchMock.calls(schemaApiRoute).length).toBe(1);
expect(props.handleError).toBeCalledTimes(0); expect(props.handleError).toHaveBeenCalledTimes(0);
expect(props.onDbChange).toBeCalledTimes(0); expect(props.onDbChange).toHaveBeenCalledTimes(0);
expect(props.onSchemaChange).toBeCalledTimes(0); expect(props.onSchemaChange).toHaveBeenCalledTimes(0);
}); });
// click schema reload // click schema reload
@ -230,9 +230,9 @@ test('Refresh should work', async () => {
await waitFor(() => { await waitFor(() => {
expect(fetchMock.calls(databaseApiRoute).length).toBe(1); expect(fetchMock.calls(databaseApiRoute).length).toBe(1);
expect(fetchMock.calls(schemaApiRoute).length).toBe(2); expect(fetchMock.calls(schemaApiRoute).length).toBe(2);
expect(props.handleError).toBeCalledTimes(0); expect(props.handleError).toHaveBeenCalledTimes(0);
expect(props.onDbChange).toBeCalledTimes(0); expect(props.onDbChange).toHaveBeenCalledTimes(0);
expect(props.onSchemaChange).toBeCalledTimes(0); expect(props.onSchemaChange).toHaveBeenCalledTimes(0);
}); });
}); });

View File

@ -45,8 +45,8 @@ test('Calling "onHide"', () => {
}; };
const modal = <DeleteModal {...props} />; const modal = <DeleteModal {...props} />;
render(modal); render(modal);
expect(props.onHide).toBeCalledTimes(0); expect(props.onHide).toHaveBeenCalledTimes(0);
expect(props.onConfirm).toBeCalledTimes(0); expect(props.onConfirm).toHaveBeenCalledTimes(0);
// type "del" in the input // type "del" in the input
userEvent.type(screen.getByTestId('delete-modal-input'), 'del'); userEvent.type(screen.getByTestId('delete-modal-input'), 'del');
@ -55,8 +55,8 @@ test('Calling "onHide"', () => {
// close the modal // close the modal
expect(screen.getByText('×')).toBeVisible(); expect(screen.getByText('×')).toBeVisible();
userEvent.click(screen.getByText('×')); userEvent.click(screen.getByText('×'));
expect(props.onHide).toBeCalledTimes(1); expect(props.onHide).toHaveBeenCalledTimes(1);
expect(props.onConfirm).toBeCalledTimes(0); expect(props.onConfirm).toHaveBeenCalledTimes(0);
// confirm input has been cleared // confirm input has been cleared
expect(screen.getByTestId('delete-modal-input')).toHaveValue(''); expect(screen.getByTestId('delete-modal-input')).toHaveValue('');
@ -71,19 +71,19 @@ test('Calling "onConfirm" only after typing "delete" in the input', () => {
open: true, open: true,
}; };
render(<DeleteModal {...props} />); render(<DeleteModal {...props} />);
expect(props.onHide).toBeCalledTimes(0); expect(props.onHide).toHaveBeenCalledTimes(0);
expect(props.onConfirm).toBeCalledTimes(0); expect(props.onConfirm).toHaveBeenCalledTimes(0);
expect(screen.getByTestId('delete-modal-input')).toBeVisible(); expect(screen.getByTestId('delete-modal-input')).toBeVisible();
expect(props.onConfirm).toBeCalledTimes(0); expect(props.onConfirm).toHaveBeenCalledTimes(0);
// do not execute "onConfirm" if you have not typed "delete" // do not execute "onConfirm" if you have not typed "delete"
userEvent.click(screen.getByText('Delete')); userEvent.click(screen.getByText('Delete'));
expect(props.onConfirm).toBeCalledTimes(0); expect(props.onConfirm).toHaveBeenCalledTimes(0);
// execute "onConfirm" if you have typed "delete" // execute "onConfirm" if you have typed "delete"
userEvent.type(screen.getByTestId('delete-modal-input'), 'delete'); userEvent.type(screen.getByTestId('delete-modal-input'), 'delete');
userEvent.click(screen.getByText('Delete')); userEvent.click(screen.getByText('Delete'));
expect(props.onConfirm).toBeCalledTimes(1); expect(props.onConfirm).toHaveBeenCalledTimes(1);
// confirm input has been cleared // confirm input has been cleared
expect(screen.getByTestId('delete-modal-input')).toHaveValue(''); expect(screen.getByTestId('delete-modal-input')).toHaveValue('');

View File

@ -37,20 +37,20 @@ test('render right content', async () => {
screen.getByRole('img', { name: 'favorite-selected' }), screen.getByRole('img', { name: 'favorite-selected' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.saveFaveStar).toBeCalledTimes(0); expect(props.saveFaveStar).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(props.saveFaveStar).toBeCalledTimes(1); expect(props.saveFaveStar).toHaveBeenCalledTimes(1);
expect(props.saveFaveStar).toBeCalledWith(props.itemId, true); expect(props.saveFaveStar).toHaveBeenCalledWith(props.itemId, true);
rerender(<FaveStar {...props} />); rerender(<FaveStar {...props} />);
expect( expect(
await findByRole('img', { name: 'favorite-unselected' }), await findByRole('img', { name: 'favorite-unselected' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.saveFaveStar).toBeCalledTimes(1); expect(props.saveFaveStar).toHaveBeenCalledTimes(1);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(props.saveFaveStar).toBeCalledTimes(2); expect(props.saveFaveStar).toHaveBeenCalledTimes(2);
expect(props.saveFaveStar).toBeCalledWith(props.itemId, false); expect(props.saveFaveStar).toHaveBeenCalledWith(props.itemId, false);
}); });
test('render content on tooltip', async () => { test('render content on tooltip', async () => {
@ -87,9 +87,9 @@ test('Call fetchFaveStar on first render and on itemId change', async () => {
expect( expect(
await findByRole('img', { name: 'favorite-unselected' }), await findByRole('img', { name: 'favorite-unselected' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.fetchFaveStar).toBeCalledTimes(1); expect(props.fetchFaveStar).toHaveBeenCalledTimes(1);
expect(props.fetchFaveStar).toBeCalledWith(props.itemId); expect(props.fetchFaveStar).toHaveBeenCalledWith(props.itemId);
rerender(<FaveStar {...{ ...props, itemId: 2 }} />); rerender(<FaveStar {...{ ...props, itemId: 2 }} />);
expect(props.fetchFaveStar).toBeCalledTimes(2); expect(props.fetchFaveStar).toHaveBeenCalledTimes(2);
}); });

View File

@ -61,7 +61,7 @@ test('redirects to first page when page index is invalid', async () => {
}); });
await waitFor(() => { await waitFor(() => {
expect(window.location.search).toEqual('?pageIndex=0'); expect(window.location.search).toEqual('?pageIndex=0');
expect(fetchData).toBeCalledTimes(2); expect(fetchData).toHaveBeenCalledTimes(2);
expect(fetchData).toHaveBeenCalledWith( expect(fetchData).toHaveBeenCalledWith(
expect.objectContaining({ pageIndex: 9 }), expect.objectContaining({ pageIndex: 9 }),
); );

View File

@ -24,15 +24,15 @@ import { Ellipsis } from './Ellipsis';
test('Ellipsis - click when the button is enabled', () => { test('Ellipsis - click when the button is enabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Ellipsis onClick={click} />); render(<Ellipsis onClick={click} />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(1); expect(click).toHaveBeenCalledTimes(1);
}); });
test('Ellipsis - click when the button is disabled', () => { test('Ellipsis - click when the button is disabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Ellipsis onClick={click} disabled />); render(<Ellipsis onClick={click} disabled />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
}); });

View File

@ -28,9 +28,9 @@ test('Item - click when the item is not active', () => {
<div data-test="test" /> <div data-test="test" />
</Item>, </Item>,
); );
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(1); expect(click).toHaveBeenCalledTimes(1);
expect(screen.getByTestId('test')).toBeInTheDocument(); expect(screen.getByTestId('test')).toBeInTheDocument();
}); });
@ -41,8 +41,8 @@ test('Item - click when the item is active', () => {
<div data-test="test" /> <div data-test="test" />
</Item>, </Item>,
); );
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
expect(screen.getByTestId('test')).toBeInTheDocument(); expect(screen.getByTestId('test')).toBeInTheDocument();
}); });

View File

@ -24,15 +24,15 @@ import { Next } from './Next';
test('Next - click when the button is enabled', () => { test('Next - click when the button is enabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Next onClick={click} />); render(<Next onClick={click} />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(1); expect(click).toHaveBeenCalledTimes(1);
}); });
test('Next - click when the button is disabled', () => { test('Next - click when the button is disabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Next onClick={click} disabled />); render(<Next onClick={click} disabled />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
}); });

View File

@ -24,15 +24,15 @@ import { Prev } from './Prev';
test('Prev - click when the button is enabled', () => { test('Prev - click when the button is enabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Prev onClick={click} />); render(<Prev onClick={click} />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(1); expect(click).toHaveBeenCalledTimes(1);
}); });
test('Prev - click when the button is disabled', () => { test('Prev - click when the button is disabled', () => {
const click = jest.fn(); const click = jest.fn();
render(<Prev onClick={click} disabled />); render(<Prev onClick={click} disabled />);
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button')); userEvent.click(screen.getByRole('button'));
expect(click).toBeCalledTimes(0); expect(click).toHaveBeenCalledTimes(0);
}); });

View File

@ -123,10 +123,10 @@ test('Should render "appliedCrossFilterIndicators"', async () => {
screen.getByRole('button', { name: 'Clinical Stage' }), screen.getByRole('button', { name: 'Clinical Stage' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onHighlightFilterSource).toBeCalledTimes(0); expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Clinical Stage' })); userEvent.click(screen.getByRole('button', { name: 'Clinical Stage' }));
expect(props.onHighlightFilterSource).toBeCalledTimes(1); expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(1);
expect(props.onHighlightFilterSource).toBeCalledWith([ expect(props.onHighlightFilterSource).toHaveBeenCalledWith([
'ROOT_ID', 'ROOT_ID',
'TABS-wUKya7eQ0Z', 'TABS-wUKya7eQ0Z',
'TAB-BCIJF4NvgQ', 'TAB-BCIJF4NvgQ',
@ -153,10 +153,10 @@ test('Should render "appliedIndicators"', async () => {
expect(await screen.findByText('Applied filters (1)')).toBeInTheDocument(); expect(await screen.findByText('Applied filters (1)')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Country' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Country' })).toBeInTheDocument();
expect(props.onHighlightFilterSource).toBeCalledTimes(0); expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Country' })); userEvent.click(screen.getByRole('button', { name: 'Country' }));
expect(props.onHighlightFilterSource).toBeCalledTimes(1); expect(props.onHighlightFilterSource).toHaveBeenCalledTimes(1);
expect(props.onHighlightFilterSource).toBeCalledWith([ expect(props.onHighlightFilterSource).toHaveBeenCalledWith([
'ROOT_ID', 'ROOT_ID',
'TABS-wUKya7eQ0Z', 'TABS-wUKya7eQ0Z',
'TAB-BCIJF4NvgQ', 'TAB-BCIJF4NvgQ',

View File

@ -51,9 +51,9 @@ test('Should call "onClick"', () => {
const props = createProps(); const props = createProps();
render(<FilterIndicator {...props} />); render(<FilterIndicator {...props} />);
expect(props.onClick).toBeCalledTimes(0); expect(props.onClick).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Vaccine Approach' })); userEvent.click(screen.getByRole('button', { name: 'Vaccine Approach' }));
expect(props.onClick).toBeCalledTimes(1); expect(props.onClick).toHaveBeenCalledTimes(1);
}); });
test('Should render "value"', () => { test('Should render "value"', () => {

View File

@ -315,10 +315,10 @@ test('should NOT render the fave icon on anonymous user', () => {
setup(anonymousUserProps); setup(anonymousUserProps);
expect(() => expect(() =>
screen.getByRole('img', { name: 'favorite-unselected' }), screen.getByRole('img', { name: 'favorite-unselected' }),
).toThrowError('Unable to find'); ).toThrow('Unable to find');
expect(() => expect(() => screen.getByRole('img', { name: 'favorite-selected' })).toThrow(
screen.getByRole('img', { name: 'favorite-selected' }), 'Unable to find',
).toThrowError('Unable to find'); );
}); });
test('should fave', async () => { test('should fave', async () => {

View File

@ -143,7 +143,7 @@ describe.skip('PropertiesModal', () => {
const spy = jest.spyOn(Modal, 'error'); const spy = jest.spyOn(Modal, 'error');
expect(() => expect(() =>
modalInstance.onColorSchemeChange('THIS_WILL_NOT_WORK'), modalInstance.onColorSchemeChange('THIS_WILL_NOT_WORK'),
).toThrowError('A valid color scheme is required'); ).toThrow('A valid color scheme is required');
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
}); });
}); });

View File

@ -181,7 +181,7 @@ test('should render - FeatureFlag disabled', async () => {
expect(screen.getAllByRole('textbox')).toHaveLength(4); expect(screen.getAllByRole('textbox')).toHaveLength(4);
expect(screen.getByRole('combobox')).toBeInTheDocument(); expect(screen.getByRole('combobox')).toBeInTheDocument();
expect(spyColorSchemeControlWrapper).toBeCalledWith( expect(spyColorSchemeControlWrapper).toHaveBeenCalledWith(
expect.objectContaining({ colorScheme: 'supersetColors' }), expect.objectContaining({ colorScheme: 'supersetColors' }),
{}, {},
); );
@ -222,7 +222,7 @@ test('should render - FeatureFlag enabled', async () => {
expect(screen.getAllByRole('textbox')).toHaveLength(4); expect(screen.getAllByRole('textbox')).toHaveLength(4);
expect(screen.getAllByRole('combobox')).toHaveLength(3); expect(screen.getAllByRole('combobox')).toHaveLength(3);
expect(spyColorSchemeControlWrapper).toBeCalledWith( expect(spyColorSchemeControlWrapper).toHaveBeenCalledWith(
expect.objectContaining({ colorScheme: 'supersetColors' }), expect.objectContaining({ colorScheme: 'supersetColors' }),
{}, {},
); );
@ -255,11 +255,11 @@ test('should close modal', async () => {
await screen.findByTestId('dashboard-edit-properties-form'), await screen.findByTestId('dashboard-edit-properties-form'),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onHide).not.toBeCalled(); expect(props.onHide).not.toHaveBeenCalled();
userEvent.click(screen.getByRole('button', { name: 'Cancel' })); userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
expect(props.onHide).toBeCalledTimes(1); expect(props.onHide).toHaveBeenCalledTimes(1);
userEvent.click(screen.getByRole('button', { name: 'Close' })); userEvent.click(screen.getByRole('button', { name: 'Close' }));
expect(props.onHide).toBeCalledTimes(2); expect(props.onHide).toHaveBeenCalledTimes(2);
}); });
test('submitting with onlyApply:false', async () => { test('submitting with onlyApply:false', async () => {
@ -293,13 +293,13 @@ test('submitting with onlyApply:false', async () => {
await screen.findByTestId('dashboard-edit-properties-form'), await screen.findByTestId('dashboard-edit-properties-form'),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onHide).not.toBeCalled(); expect(props.onHide).not.toHaveBeenCalled();
expect(props.onSubmit).not.toBeCalled(); expect(props.onSubmit).not.toHaveBeenCalled();
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSubmit).toBeCalledTimes(1); expect(props.onSubmit).toHaveBeenCalledTimes(1);
expect(props.onSubmit).toBeCalledWith({ expect(props.onSubmit).toHaveBeenCalledWith({
certificationDetails: 'Sample certification', certificationDetails: 'Sample certification',
certifiedBy: 'John Doe', certifiedBy: 'John Doe',
colorScheme: 'supersetColors', colorScheme: 'supersetColors',
@ -332,12 +332,12 @@ test('submitting with onlyApply:true', async () => {
await screen.findByTestId('dashboard-edit-properties-form'), await screen.findByTestId('dashboard-edit-properties-form'),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onHide).not.toBeCalled(); expect(props.onHide).not.toHaveBeenCalled();
expect(props.onSubmit).not.toBeCalled(); expect(props.onSubmit).not.toHaveBeenCalled();
userEvent.click(screen.getByRole('button', { name: 'Apply' })); userEvent.click(screen.getByRole('button', { name: 'Apply' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSubmit).toBeCalledTimes(1); expect(props.onSubmit).toHaveBeenCalledTimes(1);
}); });
}); });

View File

@ -444,33 +444,33 @@ test('Correct actions to "SliceHeaderControls"', () => {
const props = createProps(); const props = createProps();
render(<SliceHeader {...props} />, { useRedux: true, useRouter: true }); render(<SliceHeader {...props} />, { useRedux: true, useRouter: true });
expect(props.toggleExpandSlice).toBeCalledTimes(0); expect(props.toggleExpandSlice).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('toggleExpandSlice')); userEvent.click(screen.getByTestId('toggleExpandSlice'));
expect(props.toggleExpandSlice).toBeCalledTimes(1); expect(props.toggleExpandSlice).toHaveBeenCalledTimes(1);
expect(props.forceRefresh).toBeCalledTimes(0); expect(props.forceRefresh).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('forceRefresh')); userEvent.click(screen.getByTestId('forceRefresh'));
expect(props.forceRefresh).toBeCalledTimes(1); expect(props.forceRefresh).toHaveBeenCalledTimes(1);
expect(props.logExploreChart).toBeCalledTimes(0); expect(props.logExploreChart).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('exploreChart')); userEvent.click(screen.getByTestId('exploreChart'));
expect(props.logExploreChart).toBeCalledTimes(1); expect(props.logExploreChart).toHaveBeenCalledTimes(1);
expect(props.exportCSV).toBeCalledTimes(0); expect(props.exportCSV).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('exportCSV')); userEvent.click(screen.getByTestId('exportCSV'));
expect(props.exportCSV).toBeCalledTimes(1); expect(props.exportCSV).toHaveBeenCalledTimes(1);
expect(props.addSuccessToast).toBeCalledTimes(0); expect(props.addSuccessToast).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('addSuccessToast')); userEvent.click(screen.getByTestId('addSuccessToast'));
expect(props.addSuccessToast).toBeCalledTimes(1); expect(props.addSuccessToast).toHaveBeenCalledTimes(1);
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('addDangerToast')); userEvent.click(screen.getByTestId('addDangerToast'));
expect(props.addDangerToast).toBeCalledTimes(1); expect(props.addDangerToast).toHaveBeenCalledTimes(1);
expect(props.handleToggleFullSize).toBeCalledTimes(0); expect(props.handleToggleFullSize).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('handleToggleFullSize')); userEvent.click(screen.getByTestId('handleToggleFullSize'));
expect(props.handleToggleFullSize).toBeCalledTimes(1); expect(props.handleToggleFullSize).toHaveBeenCalledTimes(1);
}); });
test('Add extension to SliceHeader', () => { test('Add extension to SliceHeader', () => {

View File

@ -180,21 +180,21 @@ test('Should render default props', () => {
test('Should "export to CSV"', async () => { test('Should "export to CSV"', async () => {
const props = createProps(); const props = createProps();
renderWrapper(props); renderWrapper(props);
expect(props.exportCSV).toBeCalledTimes(0); expect(props.exportCSV).toHaveBeenCalledTimes(0);
userEvent.hover(screen.getByText('Download')); userEvent.hover(screen.getByText('Download'));
userEvent.click(await screen.findByText('Export to .CSV')); userEvent.click(await screen.findByText('Export to .CSV'));
expect(props.exportCSV).toBeCalledTimes(1); expect(props.exportCSV).toHaveBeenCalledTimes(1);
expect(props.exportCSV).toBeCalledWith(371); expect(props.exportCSV).toHaveBeenCalledWith(371);
}); });
test('Should "export to Excel"', async () => { test('Should "export to Excel"', async () => {
const props = createProps(); const props = createProps();
renderWrapper(props); renderWrapper(props);
expect(props.exportXLSX).toBeCalledTimes(0); expect(props.exportXLSX).toHaveBeenCalledTimes(0);
userEvent.hover(screen.getByText('Download')); userEvent.hover(screen.getByText('Download'));
userEvent.click(await screen.findByText('Export to Excel')); userEvent.click(await screen.findByText('Export to Excel'));
expect(props.exportXLSX).toBeCalledTimes(1); expect(props.exportXLSX).toHaveBeenCalledTimes(1);
expect(props.exportXLSX).toBeCalledWith(371); expect(props.exportXLSX).toHaveBeenCalledWith(371);
}); });
test('Export full CSV is under featureflag', async () => { test('Export full CSV is under featureflag', async () => {
@ -214,11 +214,11 @@ test('Should "export full CSV"', async () => {
}; };
const props = createProps('table'); const props = createProps('table');
renderWrapper(props); renderWrapper(props);
expect(props.exportFullCSV).toBeCalledTimes(0); expect(props.exportFullCSV).toHaveBeenCalledTimes(0);
userEvent.hover(screen.getByText('Download')); userEvent.hover(screen.getByText('Download'));
userEvent.click(await screen.findByText('Export to full .CSV')); userEvent.click(await screen.findByText('Export to full .CSV'));
expect(props.exportFullCSV).toBeCalledTimes(1); expect(props.exportFullCSV).toHaveBeenCalledTimes(1);
expect(props.exportFullCSV).toBeCalledWith(371); expect(props.exportFullCSV).toHaveBeenCalledWith(371);
}); });
test('Should not show export full CSV if report is not table', async () => { test('Should not show export full CSV if report is not table', async () => {
@ -248,11 +248,11 @@ test('Should "export full Excel"', async () => {
}; };
const props = createProps('table'); const props = createProps('table');
renderWrapper(props); renderWrapper(props);
expect(props.exportFullXLSX).toBeCalledTimes(0); expect(props.exportFullXLSX).toHaveBeenCalledTimes(0);
userEvent.hover(screen.getByText('Download')); userEvent.hover(screen.getByText('Download'));
userEvent.click(await screen.findByText('Export to full Excel')); userEvent.click(await screen.findByText('Export to full Excel'));
expect(props.exportFullXLSX).toBeCalledTimes(1); expect(props.exportFullXLSX).toHaveBeenCalledTimes(1);
expect(props.exportFullXLSX).toBeCalledWith(371); expect(props.exportFullXLSX).toHaveBeenCalledWith(371);
}); });
test('Should not show export full Excel if report is not table', async () => { test('Should not show export full Excel if report is not table', async () => {
@ -268,29 +268,29 @@ test('Should not show export full Excel if report is not table', async () => {
test('Should "Show chart description"', () => { test('Should "Show chart description"', () => {
const props = createProps(); const props = createProps();
renderWrapper(props); renderWrapper(props);
expect(props.toggleExpandSlice).toBeCalledTimes(0); expect(props.toggleExpandSlice).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByText('Show chart description')); userEvent.click(screen.getByText('Show chart description'));
expect(props.toggleExpandSlice).toBeCalledTimes(1); expect(props.toggleExpandSlice).toHaveBeenCalledTimes(1);
expect(props.toggleExpandSlice).toBeCalledWith(371); expect(props.toggleExpandSlice).toHaveBeenCalledWith(371);
}); });
test('Should "Force refresh"', () => { test('Should "Force refresh"', () => {
const props = createProps(); const props = createProps();
renderWrapper(props); renderWrapper(props);
expect(props.forceRefresh).toBeCalledTimes(0); expect(props.forceRefresh).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByText('Force refresh')); userEvent.click(screen.getByText('Force refresh'));
expect(props.forceRefresh).toBeCalledTimes(1); expect(props.forceRefresh).toHaveBeenCalledTimes(1);
expect(props.forceRefresh).toBeCalledWith(371, 26); expect(props.forceRefresh).toHaveBeenCalledWith(371, 26);
expect(props.addSuccessToast).toBeCalledTimes(1); expect(props.addSuccessToast).toHaveBeenCalledTimes(1);
}); });
test('Should "Enter fullscreen"', () => { test('Should "Enter fullscreen"', () => {
const props = createProps(); const props = createProps();
renderWrapper(props); renderWrapper(props);
expect(props.handleToggleFullSize).toBeCalledTimes(0); expect(props.handleToggleFullSize).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByText('Enter fullscreen')); userEvent.click(screen.getByText('Enter fullscreen'));
expect(props.handleToggleFullSize).toBeCalledTimes(1); expect(props.handleToggleFullSize).toHaveBeenCalledTimes(1);
}); });
test('Drill to detail modal is under featureflag', () => { test('Drill to detail modal is under featureflag', () => {

View File

@ -116,7 +116,7 @@ test('Render tab (no content)', () => {
useDnd: true, useDnd: true,
}); });
expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument(); expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument();
expect(EditableTitle).toBeCalledTimes(1); expect(EditableTitle).toHaveBeenCalledTimes(1);
expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); expect(getByTestId('dragdroppable-object')).toBeInTheDocument();
}); });
@ -129,7 +129,7 @@ test('Render tab (no content) editMode:true', () => {
useDnd: true, useDnd: true,
}); });
expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument(); expect(screen.getByText('🚀 Aspiring Developers')).toBeInTheDocument();
expect(EditableTitle).toBeCalledTimes(1); expect(EditableTitle).toHaveBeenCalledTimes(1);
expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); expect(getByTestId('dragdroppable-object')).toBeInTheDocument();
}); });
@ -222,12 +222,12 @@ test('Edit table title', () => {
useDnd: true, useDnd: true,
}); });
expect(EditableTitle).toBeCalledTimes(1); expect(EditableTitle).toHaveBeenCalledTimes(1);
expect(getByTestId('dragdroppable-object')).toBeInTheDocument(); expect(getByTestId('dragdroppable-object')).toBeInTheDocument();
expect(props.updateComponents).not.toBeCalled(); expect(props.updateComponents).not.toHaveBeenCalled();
userEvent.click(screen.getByText('🚀 Aspiring Developers')); userEvent.click(screen.getByText('🚀 Aspiring Developers'));
expect(props.updateComponents).toBeCalled(); expect(props.updateComponents).toHaveBeenCalled();
}); });
test('Render tab (with content)', () => { test('Render tab (with content)', () => {
@ -237,7 +237,7 @@ test('Render tab (with content)', () => {
useRedux: true, useRedux: true,
useDnd: true, useDnd: true,
}); });
expect(DashboardComponent).toBeCalledTimes(2); expect(DashboardComponent).toHaveBeenCalledTimes(2);
expect(DashboardComponent).toHaveBeenNthCalledWith( expect(DashboardComponent).toHaveBeenNthCalledWith(
1, 1,
expect.objectContaining({ expect.objectContaining({
@ -316,7 +316,7 @@ test('Render tab (with content) editMode:true', () => {
useRedux: true, useRedux: true,
useDnd: true, useDnd: true,
}); });
expect(DashboardComponent).toBeCalledTimes(2); expect(DashboardComponent).toHaveBeenCalledTimes(2);
expect(DashboardComponent).toHaveBeenNthCalledWith( expect(DashboardComponent).toHaveBeenNthCalledWith(
1, 1,
expect.objectContaining({ expect.objectContaining({
@ -369,14 +369,14 @@ test('Should call "handleDrop" and "handleTopDropTargetDrop"', () => {
}, },
); );
expect(props.handleComponentDrop).not.toBeCalled(); expect(props.handleComponentDrop).not.toHaveBeenCalled();
userEvent.click(getAllByTestId('MockDroppable')[0]); userEvent.click(getAllByTestId('MockDroppable')[0]);
expect(props.handleComponentDrop).toBeCalledTimes(1); expect(props.handleComponentDrop).toHaveBeenCalledTimes(1);
expect(props.onDropOnTab).not.toBeCalled(); expect(props.onDropOnTab).not.toHaveBeenCalled();
rerender(<Tab {...props} />); rerender(<Tab {...props} />);
userEvent.click(getAllByTestId('MockDroppable')[1]); userEvent.click(getAllByTestId('MockDroppable')[1]);
expect(props.onDropOnTab).toBeCalledTimes(1); expect(props.onDropOnTab).toHaveBeenCalledTimes(1);
expect(props.handleComponentDrop).toBeCalledTimes(2); expect(props.handleComponentDrop).toHaveBeenCalledTimes(2);
}); });
test('Render tab content with no children, editMode: true, canEdit: true', () => { test('Render tab content with no children, editMode: true, canEdit: true', () => {

View File

@ -47,15 +47,15 @@ test('Should call download image on click', async () => {
const props = createProps(); const props = createProps();
renderComponent(); renderComponent();
await waitFor(() => { await waitFor(() => {
expect(downloadAsImage).toBeCalledTimes(0); expect(downloadAsImage).toHaveBeenCalledTimes(0);
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
}); });
userEvent.click(screen.getByRole('button', { name: 'Download as Image' })); userEvent.click(screen.getByRole('button', { name: 'Download as Image' }));
await waitFor(() => { await waitFor(() => {
expect(downloadAsImage).toBeCalledTimes(1); expect(downloadAsImage).toHaveBeenCalledTimes(1);
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
}); });
}); });

View File

@ -33,8 +33,8 @@ test('should call onHover when mouse enters and leaves', () => {
const hoverMenu = screen.getByTestId('hover-menu'); const hoverMenu = screen.getByTestId('hover-menu');
userEvent.hover(hoverMenu); userEvent.hover(hoverMenu);
expect(onHover).toBeCalledWith({ isHovered: true }); expect(onHover).toHaveBeenCalledWith({ isHovered: true });
userEvent.unhover(hoverMenu); userEvent.unhover(hoverMenu);
expect(onHover).toBeCalledWith({ isHovered: false }); expect(onHover).toHaveBeenCalledWith({ isHovered: false });
}); });

View File

@ -96,20 +96,20 @@ test('Click on "Copy dashboard URL" and succeed', async () => {
); );
await waitFor(() => { await waitFor(() => {
expect(spy).toBeCalledTimes(0); expect(spy).toHaveBeenCalledTimes(0);
expect(props.addSuccessToast).toBeCalledTimes(0); expect(props.addSuccessToast).toHaveBeenCalledTimes(0);
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
}); });
userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' })); userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' }));
await waitFor(async () => { await waitFor(async () => {
expect(spy).toBeCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
const value = await spy.mock.calls[0][0](); const value = await spy.mock.calls[0][0]();
expect(value).toBe('http://localhost/superset/dashboard/p/123/'); expect(value).toBe('http://localhost/superset/dashboard/p/123/');
expect(props.addSuccessToast).toBeCalledTimes(1); expect(props.addSuccessToast).toHaveBeenCalledTimes(1);
expect(props.addSuccessToast).toBeCalledWith('Copied to clipboard!'); expect(props.addSuccessToast).toHaveBeenCalledWith('Copied to clipboard!');
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
}); });
}); });
@ -124,20 +124,20 @@ test('Click on "Copy dashboard URL" and fail', async () => {
); );
await waitFor(() => { await waitFor(() => {
expect(spy).toBeCalledTimes(0); expect(spy).toHaveBeenCalledTimes(0);
expect(props.addSuccessToast).toBeCalledTimes(0); expect(props.addSuccessToast).toHaveBeenCalledTimes(0);
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
}); });
userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' })); userEvent.click(screen.getByRole('button', { name: 'Copy dashboard URL' }));
await waitFor(async () => { await waitFor(async () => {
expect(spy).toBeCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
const value = await spy.mock.calls[0][0](); const value = await spy.mock.calls[0][0]();
expect(value).toBe('http://localhost/superset/dashboard/p/123/'); expect(value).toBe('http://localhost/superset/dashboard/p/123/');
expect(props.addSuccessToast).toBeCalledTimes(0); expect(props.addSuccessToast).toHaveBeenCalledTimes(0);
expect(props.addDangerToast).toBeCalledTimes(1); expect(props.addDangerToast).toHaveBeenCalledTimes(1);
expect(props.addDangerToast).toBeCalledWith( expect(props.addDangerToast).toHaveBeenCalledWith(
'Sorry, something went wrong. Try again later.', 'Sorry, something went wrong. Try again later.',
); );
}); });
@ -153,7 +153,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
); );
await waitFor(() => { await waitFor(() => {
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
expect(window.location.href).toBe(''); expect(window.location.href).toBe('');
}); });
@ -162,7 +162,7 @@ test('Click on "Share dashboard by email" and succeed', async () => {
); );
await waitFor(() => { await waitFor(() => {
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
expect(window.location.href).toBe( expect(window.location.href).toBe(
'mailto:?Subject=Superset%20dashboard%20COVID%20Vaccine%20Dashboard%20&Body=Check%20out%20this%20dashboard%3A%20http%3A%2F%2Flocalhost%2Fsuperset%2Fdashboard%2Fp%2F123%2F', 'mailto:?Subject=Superset%20dashboard%20COVID%20Vaccine%20Dashboard%20&Body=Check%20out%20this%20dashboard%3A%20http%3A%2F%2Flocalhost%2Fsuperset%2Fdashboard%2Fp%2F123%2F',
); );
@ -184,7 +184,7 @@ test('Click on "Share dashboard by email" and fail', async () => {
); );
await waitFor(() => { await waitFor(() => {
expect(props.addDangerToast).toBeCalledTimes(0); expect(props.addDangerToast).toHaveBeenCalledTimes(0);
expect(window.location.href).toBe(''); expect(window.location.href).toBe('');
}); });
@ -194,8 +194,8 @@ test('Click on "Share dashboard by email" and fail', async () => {
await waitFor(() => { await waitFor(() => {
expect(window.location.href).toBe(''); expect(window.location.href).toBe('');
expect(props.addDangerToast).toBeCalledTimes(1); expect(props.addDangerToast).toHaveBeenCalledTimes(1);
expect(props.addDangerToast).toBeCalledWith( expect(props.addDangerToast).toHaveBeenCalledWith(
'Sorry, something went wrong. Try again later.', 'Sorry, something went wrong. Try again later.',
); );
}); });

View File

@ -84,12 +84,12 @@ test('Should call "setFields" when "datasetId" changes', () => {
const { rerender } = render(<ColumnSelect {...(props as any)} />, { const { rerender } = render(<ColumnSelect {...(props as any)} />, {
useRedux: true, useRedux: true,
}); });
expect(props.form.setFields).not.toBeCalled(); expect(props.form.setFields).not.toHaveBeenCalled();
props.datasetId = 456; props.datasetId = 456;
rerender(<ColumnSelect {...(props as any)} />); rerender(<ColumnSelect {...(props as any)} />);
expect(props.form.setFields).toBeCalled(); expect(props.form.setFields).toHaveBeenCalled();
}); });
test('Should call "getClientErrorObject" when api returns an error', async () => { test('Should call "getClientErrorObject" when api returns an error', async () => {
@ -98,12 +98,12 @@ test('Should call "getClientErrorObject" when api returns an error', async () =>
props.datasetId = 789; props.datasetId = 789;
const spy = jest.spyOn(uiCore, 'getClientErrorObject'); const spy = jest.spyOn(uiCore, 'getClientErrorObject');
expect(spy).not.toBeCalled(); expect(spy).not.toHaveBeenCalled();
render(<ColumnSelect {...(props as any)} />, { render(<ColumnSelect {...(props as any)} />, {
useRedux: true, useRedux: true,
}); });
await waitFor(() => { await waitFor(() => {
expect(spy).toBeCalled(); expect(spy).toHaveBeenCalled();
}); });
}); });

View File

@ -18058,7 +18058,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
}); });
it('Avoids runtime error with invalid inputs', () => { it('Avoids runtime error with invalid inputs', () => {
@ -18073,7 +18073,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
expect(() => { expect(() => {
buildTree( buildTree(
@ -18086,7 +18086,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
expect(() => { expect(() => {
buildTree( buildTree(
@ -18099,7 +18099,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
expect(() => { expect(() => {
buildTree( buildTree(
@ -18112,7 +18112,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
expect(() => { expect(() => {
buildTree( buildTree(
@ -18125,7 +18125,7 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
initiallyExcludedCharts, initiallyExcludedCharts,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
expect(() => { expect(() => {
buildTree( buildTree(
@ -18138,6 +18138,6 @@ describe('Ensure buildTree does not throw runtime errors when encountering an in
null, null,
() => 'Fake title', () => 'Fake title',
); );
}).not.toThrowError(); }).not.toThrow();
}); });
}); });

View File

@ -160,11 +160,11 @@ test('Clicking on checkbox', () => {
(getControlItems as jest.Mock).mockReturnValue(createControlItems()); (getControlItems as jest.Mock).mockReturnValue(createControlItems());
const controlItemsMap = getControlItemsMap(props); const controlItemsMap = getControlItemsMap(props);
renderControlItems(controlItemsMap); renderControlItems(controlItemsMap);
expect(props.forceUpdate).not.toBeCalled(); expect(props.forceUpdate).not.toHaveBeenCalled();
expect(setNativeFilterFieldValues).not.toBeCalled(); expect(setNativeFilterFieldValues).not.toHaveBeenCalled();
userEvent.click(screen.getByRole('checkbox')); userEvent.click(screen.getByRole('checkbox'));
expect(setNativeFilterFieldValues).toBeCalled(); expect(setNativeFilterFieldValues).toHaveBeenCalled();
expect(props.forceUpdate).toBeCalled(); expect(props.forceUpdate).toHaveBeenCalled();
}); });
test('Clicking on checkbox when resetConfig:false', () => { test('Clicking on checkbox when resetConfig:false', () => {
@ -174,9 +174,9 @@ test('Clicking on checkbox when resetConfig:false', () => {
]); ]);
const controlItemsMap = getControlItemsMap(props); const controlItemsMap = getControlItemsMap(props);
renderControlItems(controlItemsMap); renderControlItems(controlItemsMap);
expect(props.forceUpdate).not.toBeCalled(); expect(props.forceUpdate).not.toHaveBeenCalled();
expect(setNativeFilterFieldValues).not.toBeCalled(); expect(setNativeFilterFieldValues).not.toHaveBeenCalled();
userEvent.click(screen.getByRole('checkbox')); userEvent.click(screen.getByRole('checkbox'));
expect(props.forceUpdate).toBeCalled(); expect(props.forceUpdate).toHaveBeenCalled();
expect(setNativeFilterFieldValues).not.toBeCalled(); expect(setNativeFilterFieldValues).not.toHaveBeenCalled();
}); });

View File

@ -131,6 +131,6 @@ describe('dashboardFilters reducer', () => {
// when UPDATE_DASHBOARD_FILTERS_SCOPE is changed, applicable filters to a chart // when UPDATE_DASHBOARD_FILTERS_SCOPE is changed, applicable filters to a chart
// might be changed. // might be changed.
expect(activeDashboardFilters.buildActiveFilters).toBeCalled(); expect(activeDashboardFilters.buildActiveFilters).toHaveBeenCalled();
}); });
}); });

View File

@ -76,9 +76,9 @@ test('call setControlValue if isVisible is false', async () => {
default: false, default: false,
}), }),
); );
expect(defaultProps.actions.setControlValue).not.toBeCalled(); expect(defaultProps.actions.setControlValue).not.toHaveBeenCalled();
rerender(setup({ isVisible: false, default: false })); rerender(setup({ isVisible: false, default: false }));
await waitFor(() => await waitFor(() =>
expect(defaultProps.actions.setControlValue).toBeCalled(), expect(defaultProps.actions.setControlValue).toHaveBeenCalled(),
); );
}); });

View File

@ -30,8 +30,8 @@ test('Render a FilterInput', async () => {
render(<FilterInput onChangeHandler={onChangeHandler} />); render(<FilterInput onChangeHandler={onChangeHandler} />);
expect(await screen.findByRole('textbox')).toBeInTheDocument(); expect(await screen.findByRole('textbox')).toBeInTheDocument();
expect(onChangeHandler).toBeCalledTimes(0); expect(onChangeHandler).toHaveBeenCalledTimes(0);
userEvent.type(screen.getByRole('textbox'), 'test'); userEvent.type(screen.getByRole('textbox'), 'test');
expect(onChangeHandler).toBeCalledTimes(4); expect(onChangeHandler).toHaveBeenCalledTimes(4);
}); });

View File

@ -124,8 +124,8 @@ test('can collapse metrics and columns', () => {
{ useDnd: true }, { useDnd: true },
); );
fireEvent.click(getByRole('button')); fireEvent.click(getByRole('button'));
expect(mockData.onCollapseMetricsChange).toBeCalled(); expect(mockData.onCollapseMetricsChange).toHaveBeenCalled();
expect(mockData.onCollapseColumnsChange).not.toBeCalled(); expect(mockData.onCollapseColumnsChange).not.toHaveBeenCalled();
const startIndexOfColumnSection = mockData.metricSlice.length + 3; const startIndexOfColumnSection = mockData.metricSlice.length + 3;
rerender( rerender(
@ -136,7 +136,7 @@ test('can collapse metrics and columns', () => {
/>, />,
); );
fireEvent.click(getByRole('button')); fireEvent.click(getByRole('button'));
expect(mockData.onCollapseColumnsChange).toBeCalled(); expect(mockData.onCollapseColumnsChange).toHaveBeenCalled();
rerender( rerender(
<DatasourcePanelItem <DatasourcePanelItem

View File

@ -294,7 +294,7 @@ describe('Additional actions tests', () => {
render(<ExploreHeader {...props} />, { render(<ExploreHeader {...props} />, {
useRedux: true, useRedux: true,
}); });
expect(props.actions.redirectSQLLab).toBeCalledTimes(0); expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByLabelText('Menu actions trigger')); userEvent.click(screen.getByLabelText('Menu actions trigger'));
userEvent.click( userEvent.click(
screen.getByRole('menuitem', { name: 'Edit chart properties' }), screen.getByRole('menuitem', { name: 'Edit chart properties' }),
@ -309,14 +309,14 @@ describe('Additional actions tests', () => {
useRedux: true, useRedux: true,
}); });
expect(getChartDataRequest).toBeCalledTimes(0); expect(getChartDataRequest).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByLabelText('Menu actions trigger')); userEvent.click(screen.getByLabelText('Menu actions trigger'));
expect(getChartDataRequest).toBeCalledTimes(0); expect(getChartDataRequest).toHaveBeenCalledTimes(0);
const menuItem = screen.getByText('View query').parentElement!; const menuItem = screen.getByText('View query').parentElement!;
userEvent.click(menuItem); userEvent.click(menuItem);
await waitFor(() => expect(getChartDataRequest).toBeCalledTimes(1)); await waitFor(() => expect(getChartDataRequest).toHaveBeenCalledTimes(1));
}); });
test('Should call onOpenInEditor when click on "Run in SQL Lab"', async () => { test('Should call onOpenInEditor when click on "Run in SQL Lab"', async () => {
@ -326,12 +326,12 @@ describe('Additional actions tests', () => {
}); });
expect(await screen.findByText('Save')).toBeInTheDocument(); expect(await screen.findByText('Save')).toBeInTheDocument();
expect(props.actions.redirectSQLLab).toBeCalledTimes(0); expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByLabelText('Menu actions trigger')); userEvent.click(screen.getByLabelText('Menu actions trigger'));
expect(props.actions.redirectSQLLab).toBeCalledTimes(0); expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('menuitem', { name: 'Run in SQL Lab' })); userEvent.click(screen.getByRole('menuitem', { name: 'Run in SQL Lab' }));
expect(props.actions.redirectSQLLab).toBeCalledTimes(1); expect(props.actions.redirectSQLLab).toHaveBeenCalledTimes(1);
}); });
describe('Download', () => { describe('Download', () => {
@ -354,16 +354,16 @@ describe('Additional actions tests', () => {
useRedux: true, useRedux: true,
}); });
expect(spy).toBeCalledTimes(0); expect(spy).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByLabelText('Menu actions trigger')); userEvent.click(screen.getByLabelText('Menu actions trigger'));
expect(spy).toBeCalledTimes(0); expect(spy).toHaveBeenCalledTimes(0);
userEvent.hover(screen.getByText('Download')); userEvent.hover(screen.getByText('Download'));
const downloadAsImageElement = const downloadAsImageElement =
await screen.findByText('Download as image'); await screen.findByText('Download as image');
userEvent.click(downloadAsImageElement); userEvent.click(downloadAsImageElement);
expect(spy).toBeCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
test('Should not export to CSV if canDownload=false', async () => { test('Should not export to CSV if canDownload=false', async () => {

View File

@ -171,14 +171,14 @@ test('"Close" button should call "onHide"', async () => {
renderModal(props); renderModal(props);
await waitFor(() => { await waitFor(() => {
expect(props.onHide).toBeCalledTimes(0); expect(props.onHide).toHaveBeenCalledTimes(0);
}); });
userEvent.click(screen.getByRole('button', { name: 'Close' })); userEvent.click(screen.getByRole('button', { name: 'Close' }));
await waitFor(() => { await waitFor(() => {
expect(props.onHide).toBeCalledTimes(1); expect(props.onHide).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledTimes(0); expect(props.onSave).toHaveBeenCalledTimes(0);
}); });
}); });
@ -229,14 +229,14 @@ test('"Cancel" button should call "onHide"', async () => {
renderModal(props); renderModal(props);
await waitFor(() => { await waitFor(() => {
expect(props.onHide).toBeCalledTimes(0); expect(props.onHide).toHaveBeenCalledTimes(0);
}); });
userEvent.click(screen.getByRole('button', { name: 'Cancel' })); userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
await waitFor(() => { await waitFor(() => {
expect(props.onHide).toBeCalledTimes(1); expect(props.onHide).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledTimes(0); expect(props.onSave).toHaveBeenCalledTimes(0);
}); });
}); });
@ -244,16 +244,16 @@ test('"Save" button should call only "onSave"', async () => {
const props = createProps(); const props = createProps();
renderModal(props); renderModal(props);
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(0); expect(props.onSave).toHaveBeenCalledTimes(0);
expect(props.onHide).toBeCalledTimes(0); expect(props.onHide).toHaveBeenCalledTimes(0);
expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled(); expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled();
}); });
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onHide).toBeCalledTimes(1); expect(props.onHide).toHaveBeenCalledTimes(1);
}); });
}); });
@ -289,7 +289,7 @@ test('"Name" should not be empty', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(0); expect(props.onSave).toHaveBeenCalledTimes(0);
}); });
}); });
@ -307,8 +307,8 @@ test('"Name" should not be empty when saved', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledWith( expect(props.onSave).toHaveBeenCalledWith(
expect.objectContaining({ slice_name: 'Test chart new name' }), expect.objectContaining({ slice_name: 'Test chart new name' }),
); );
}); });
@ -328,8 +328,8 @@ test('"Cache timeout" should not be empty when saved', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledWith( expect(props.onSave).toHaveBeenCalledWith(
expect.objectContaining({ cache_timeout: '1000' }), expect.objectContaining({ cache_timeout: '1000' }),
); );
}); });
@ -349,8 +349,8 @@ test('"Description" should not be empty when saved', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledWith( expect(props.onSave).toHaveBeenCalledWith(
expect.objectContaining({ description: 'Test description' }), expect.objectContaining({ description: 'Test description' }),
); );
}); });
@ -370,8 +370,8 @@ test('"Certified by" should not be empty when saved', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledWith( expect(props.onSave).toHaveBeenCalledWith(
expect.objectContaining({ certified_by: 'Test certified by' }), expect.objectContaining({ certified_by: 'Test certified by' }),
); );
}); });
@ -393,8 +393,8 @@ test('"Certification details" should not be empty when saved', async () => {
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
await waitFor(() => { await waitFor(() => {
expect(props.onSave).toBeCalledTimes(1); expect(props.onSave).toHaveBeenCalledTimes(1);
expect(props.onSave).toBeCalledWith( expect(props.onSave).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
certification_details: 'Test certification details', certification_details: 'Test certification details',
}), }),

View File

@ -108,9 +108,12 @@ test('Should have add button', async () => {
expect( expect(
await screen.findByRole('button', { name: 'plus-large' }), await screen.findByRole('button', { name: 'plus-large' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'plus-large' })); userEvent.click(screen.getByRole('button', { name: 'plus-large' }));
expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }, undefined]); expect(props.onChange).toHaveBeenCalledWith([
{ key: 'hrYAZ5iBH' },
undefined,
]);
}); });
test('Should have remove button', async () => { test('Should have remove button', async () => {
@ -120,9 +123,9 @@ test('Should have remove button', async () => {
expect( expect(
await screen.findByRole('button', { name: 'remove-item' }), await screen.findByRole('button', { name: 'remove-item' }),
).toBeInTheDocument(); ).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'remove-item' })); userEvent.click(screen.getByRole('button', { name: 'remove-item' }));
expect(props.onChange).toBeCalledWith([]); expect(props.onChange).toHaveBeenCalledWith([]);
}); });
test('Should have SortableDragger icon', async () => { test('Should have SortableDragger icon', async () => {
@ -136,7 +139,7 @@ test('Should call Control component', async () => {
render(<CollectionControl {...props} />); render(<CollectionControl {...props} />);
expect(await screen.findByTestId('TestControl')).toBeInTheDocument(); expect(await screen.findByTestId('TestControl')).toBeInTheDocument();
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByTestId('TestControl')); userEvent.click(screen.getByTestId('TestControl'));
expect(props.onChange).toBeCalledWith([{ key: 'hrYAZ5iBH' }]); expect(props.onChange).toHaveBeenCalledWith([{ key: 'hrYAZ5iBH' }]);
}); });

View File

@ -117,16 +117,16 @@ test('Should render correct elements for disallow ad-hoc metrics', () => {
test('Clicking on "Close" should call onClose', () => { test('Clicking on "Close" should call onClose', () => {
const props = createProps(); const props = createProps();
render(<AdhocMetricEditPopover {...props} />); render(<AdhocMetricEditPopover {...props} />);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Close' })); userEvent.click(screen.getByRole('button', { name: 'Close' }));
expect(props.onClose).toBeCalledTimes(1); expect(props.onClose).toHaveBeenCalledTimes(1);
}); });
test('Clicking on "Save" should call onChange and onClose', async () => { test('Clicking on "Save" should call onChange and onClose', async () => {
const props = createProps(); const props = createProps();
render(<AdhocMetricEditPopover {...props} />); render(<AdhocMetricEditPopover {...props} />);
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
userEvent.click( userEvent.click(
screen.getByRole('combobox', { screen.getByRole('combobox', {
name: 'Select saved metrics', name: 'Select saved metrics',
@ -134,38 +134,38 @@ test('Clicking on "Save" should call onChange and onClose', async () => {
); );
await selectOption('sum'); await selectOption('sum');
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(1); expect(props.onChange).toHaveBeenCalledTimes(1);
expect(props.onClose).toBeCalledTimes(1); expect(props.onClose).toHaveBeenCalledTimes(1);
}); });
test('Clicking on "Save" should not call onChange and onClose', () => { test('Clicking on "Save" should not call onChange and onClose', () => {
const props = createProps(); const props = createProps();
render(<AdhocMetricEditPopover {...props} />); render(<AdhocMetricEditPopover {...props} />);
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
}); });
test('Clicking on "Save" should call onChange and onClose for new metric', () => { test('Clicking on "Save" should call onChange and onClose for new metric', () => {
const props = createProps(); const props = createProps();
render(<AdhocMetricEditPopover {...props} isNewMetric />); render(<AdhocMetricEditPopover {...props} isNewMetric />);
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(1); expect(props.onChange).toHaveBeenCalledTimes(1);
expect(props.onClose).toBeCalledTimes(1); expect(props.onClose).toHaveBeenCalledTimes(1);
}); });
test('Clicking on "Save" should call onChange and onClose for new title', () => { test('Clicking on "Save" should call onChange and onClose for new title', () => {
const props = createProps(); const props = createProps();
render(<AdhocMetricEditPopover {...props} isLabelModified />); render(<AdhocMetricEditPopover {...props} isLabelModified />);
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
expect(props.onClose).toBeCalledTimes(0); expect(props.onClose).toHaveBeenCalledTimes(0);
userEvent.click(screen.getByRole('button', { name: 'Save' })); userEvent.click(screen.getByRole('button', { name: 'Save' }));
expect(props.onChange).toBeCalledTimes(1); expect(props.onChange).toHaveBeenCalledTimes(1);
expect(props.onClose).toBeCalledTimes(1); expect(props.onClose).toHaveBeenCalledTimes(1);
}); });
test('Should switch to tab:Simple', () => { test('Should switch to tab:Simple', () => {
@ -180,11 +180,11 @@ test('Should switch to tab:Simple', () => {
screen.queryByRole('tabpanel', { name: 'Simple' }), screen.queryByRole('tabpanel', { name: 'Simple' }),
).not.toBeInTheDocument(); ).not.toBeInTheDocument();
expect(props.getCurrentTab).toBeCalledTimes(1); expect(props.getCurrentTab).toHaveBeenCalledTimes(1);
const tab = screen.getByRole('tab', { name: 'Simple' }).parentElement!; const tab = screen.getByRole('tab', { name: 'Simple' }).parentElement!;
userEvent.click(tab); userEvent.click(tab);
expect(props.getCurrentTab).toBeCalledTimes(2); expect(props.getCurrentTab).toHaveBeenCalledTimes(2);
expect( expect(
screen.queryByRole('tabpanel', { name: 'Saved' }), screen.queryByRole('tabpanel', { name: 'Saved' }),
@ -218,11 +218,11 @@ test('Should switch to tab:Custom SQL', () => {
screen.queryByRole('tabpanel', { name: 'Custom SQL' }), screen.queryByRole('tabpanel', { name: 'Custom SQL' }),
).not.toBeInTheDocument(); ).not.toBeInTheDocument();
expect(props.getCurrentTab).toBeCalledTimes(1); expect(props.getCurrentTab).toHaveBeenCalledTimes(1);
const tab = screen.getByRole('tab', { name: 'Custom SQL' }).parentElement!; const tab = screen.getByRole('tab', { name: 'Custom SQL' }).parentElement!;
userEvent.click(tab); userEvent.click(tab);
expect(props.getCurrentTab).toBeCalledTimes(2); expect(props.getCurrentTab).toHaveBeenCalledTimes(2);
expect( expect(
screen.queryByRole('tabpanel', { name: 'Saved' }), screen.queryByRole('tabpanel', { name: 'Saved' }),

View File

@ -91,9 +91,9 @@ test('Should send correct props to Select component - value props', async () =>
test('Should send correct props to Select component - function onChange multi:true', async () => { test('Should send correct props to Select component - function onChange multi:true', async () => {
const props = createProps(); const props = createProps();
render(<SelectAsyncControl {...props} />, { useRedux: true }); render(<SelectAsyncControl {...props} />, { useRedux: true });
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
userEvent.click(await screen.findByText('onChange')); userEvent.click(await screen.findByText('onChange'));
expect(props.onChange).toBeCalledTimes(1); expect(props.onChange).toHaveBeenCalledTimes(1);
}); });
test('Should send correct props to Select component - function onChange multi:false', async () => { test('Should send correct props to Select component - function onChange multi:false', async () => {
@ -101,7 +101,7 @@ test('Should send correct props to Select component - function onChange multi:fa
render(<SelectAsyncControl {...{ ...props, multi: false }} />, { render(<SelectAsyncControl {...{ ...props, multi: false }} />, {
useRedux: true, useRedux: true,
}); });
expect(props.onChange).toBeCalledTimes(0); expect(props.onChange).toHaveBeenCalledTimes(0);
userEvent.click(await screen.findByText('onChange')); userEvent.click(await screen.findByText('onChange'));
expect(props.onChange).toBeCalledTimes(1); expect(props.onChange).toHaveBeenCalledTimes(1);
}); });

View File

@ -247,7 +247,7 @@ describe('VizTypeControl', () => {
const visualizations = screen.getByTestId(getTestId('viz-row')); const visualizations = screen.getByTestId(getTestId('viz-row'));
userEvent.click(within(visualizations).getByText('Bar Chart')); userEvent.click(within(visualizations).getByText('Bar Chart'));
expect(defaultProps.onChange).not.toBeCalled(); expect(defaultProps.onChange).not.toHaveBeenCalled();
userEvent.dblClick(within(visualizations).getByText('Line Chart')); userEvent.dblClick(within(visualizations).getByText('Line Chart'));
expect(defaultProps.onChange).toHaveBeenCalledWith( expect(defaultProps.onChange).toHaveBeenCalledWith(

View File

@ -94,8 +94,8 @@ describe('VerifiedMetricsControl', () => {
expect(wrapper.find(MetricsControl).length).toBe(1); expect(wrapper.find(MetricsControl).length).toBe(1);
expect(verifier).toBeCalledTimes(1); expect(verifier).toHaveBeenCalledTimes(1);
expect(verifier).toBeCalledWith( expect(verifier).toHaveBeenCalledWith(
expect.objectContaining({ savedMetrics: props.savedMetrics }), expect.objectContaining({ savedMetrics: props.savedMetrics }),
); );
@ -104,8 +104,8 @@ describe('VerifiedMetricsControl', () => {
wrapper.setProps({ validMetric: ['abc'] }); wrapper.setProps({ validMetric: ['abc'] });
}); });
expect(verifier).toBeCalledTimes(2); expect(verifier).toHaveBeenCalledTimes(2);
expect(verifier).toBeCalledWith( expect(verifier).toHaveBeenCalledWith(
expect.objectContaining({ validMetric: ['abc'] }), expect.objectContaining({ validMetric: ['abc'] }),
); );
}); });
@ -123,8 +123,8 @@ describe('VerifiedMetricsControl', () => {
child.props().onChange?.(['abc']); child.props().onChange?.(['abc']);
expect(child.length).toBe(1); expect(child.length).toBe(1);
expect(mockOnChange).toBeCalledTimes(1); expect(mockOnChange).toHaveBeenCalledTimes(1);
expect(mockOnChange).toBeCalledWith(['abc'], { expect(mockOnChange).toHaveBeenCalledWith(['abc'], {
actions: defaultProps.actions, actions: defaultProps.actions,
columns: defaultProps.columns, columns: defaultProps.columns,
datasourceType: defaultProps.datasourceType, datasourceType: defaultProps.datasourceType,

View File

@ -195,7 +195,7 @@ describe('exploreUtils', () => {
const v1RequestPayload = buildV1ChartDataPayload({ const v1RequestPayload = buildV1ChartDataPayload({
formData: { ...formData, viz_type: 'my_custom_viz' }, formData: { ...formData, viz_type: 'my_custom_viz' },
}); });
expect(v1RequestPayload).hasOwnProperty('queries'); expect(v1RequestPayload.hasOwnProperty('queries')).toBeTruthy();
}); });
}); });
@ -289,7 +289,7 @@ describe('exploreUtils', () => {
exploreChart({ exploreChart({
formData: { ...formData, viz_type: 'my_custom_viz' }, formData: { ...formData, viz_type: 'my_custom_viz' },
}); });
expect(postFormSpy).toBeCalledTimes(1); expect(postFormSpy).toHaveBeenCalledTimes(1);
}); });
}); });
}); });

View File

@ -23,11 +23,11 @@ test('Should return false', () => {
const spy = jest.spyOn(Core, 'getChartMetadataRegistry'); const spy = jest.spyOn(Core, 'getChartMetadataRegistry');
const get = jest.fn(); const get = jest.fn();
spy.mockReturnValue({ get } as any); spy.mockReturnValue({ get } as any);
expect(get).toBeCalledTimes(0); expect(get).toHaveBeenCalledTimes(0);
const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' });
expect(useLegacyApi).toBe(false); expect(useLegacyApi).toBe(false);
expect(get).toBeCalledTimes(1); expect(get).toHaveBeenCalledTimes(1);
expect(get).toBeCalledWith('name_test'); expect(get).toHaveBeenCalledWith('name_test');
}); });
test('Should return true', () => { test('Should return true', () => {
@ -35,11 +35,11 @@ test('Should return true', () => {
const get = jest.fn(); const get = jest.fn();
get.mockReturnValue({ useLegacyApi: true }); get.mockReturnValue({ useLegacyApi: true });
spy.mockReturnValue({ get } as any); spy.mockReturnValue({ get } as any);
expect(get).toBeCalledTimes(0); expect(get).toHaveBeenCalledTimes(0);
const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' });
expect(useLegacyApi).toBe(true); expect(useLegacyApi).toBe(true);
expect(get).toBeCalledTimes(1); expect(get).toHaveBeenCalledTimes(1);
expect(get).toBeCalledWith('name_test'); expect(get).toHaveBeenCalledWith('name_test');
}); });
test('Should return false when useLegacyApi:false', () => { test('Should return false when useLegacyApi:false', () => {
@ -47,9 +47,9 @@ test('Should return false when useLegacyApi:false', () => {
const get = jest.fn(); const get = jest.fn();
get.mockReturnValue({ useLegacyApi: false }); get.mockReturnValue({ useLegacyApi: false });
spy.mockReturnValue({ get } as any); spy.mockReturnValue({ get } as any);
expect(get).toBeCalledTimes(0); expect(get).toHaveBeenCalledTimes(0);
const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' }); const [useLegacyApi] = getQuerySettings({ viz_type: 'name_test' });
expect(useLegacyApi).toBe(false); expect(useLegacyApi).toBe(false);
expect(get).toBeCalledTimes(1); expect(get).toHaveBeenCalledTimes(1);
expect(get).toBeCalledWith('name_test'); expect(get).toHaveBeenCalledWith('name_test');
}); });

View File

@ -37,8 +37,8 @@ describe('cacheWrapper', () => {
const returnedValue = wrappedFn(1, 2); const returnedValue = wrappedFn(1, 2);
expect(returnedValue).toEqual(fnResult); expect(returnedValue).toEqual(fnResult);
expect(fn).toBeCalledTimes(1); expect(fn).toHaveBeenCalledTimes(1);
expect(fn).toBeCalledWith(1, 2); expect(fn).toHaveBeenCalledWith(1, 2);
}); });
describe('subsequent calls', () => { describe('subsequent calls', () => {
@ -48,14 +48,14 @@ describe('cacheWrapper', () => {
expect(returnedValue1).toEqual(fnResult); expect(returnedValue1).toEqual(fnResult);
expect(returnedValue2).toEqual(fnResult); expect(returnedValue2).toEqual(fnResult);
expect(fn).toBeCalledTimes(1); expect(fn).toHaveBeenCalledTimes(1);
}); });
it('fn is called multiple times for different arguments', () => { it('fn is called multiple times for different arguments', () => {
wrappedFn(1, 2); wrappedFn(1, 2);
wrappedFn(1, 3); wrappedFn(1, 3);
expect(fn).toBeCalledTimes(2); expect(fn).toHaveBeenCalledTimes(2);
}); });
}); });
@ -77,7 +77,7 @@ describe('cacheWrapper', () => {
wrappedFn(1, 2); wrappedFn(1, 2);
wrappedFn(1, 3); wrappedFn(1, 3);
expect(fn).toBeCalledTimes(1); expect(fn).toHaveBeenCalledTimes(1);
}); });
}); });
}); });

View File

@ -94,10 +94,10 @@ describe('server', () => {
response as unknown as http.ServerResponse<http.IncomingMessage>, response as unknown as http.ServerResponse<http.IncomingMessage>,
); );
expect(writeHeadMock).toBeCalledTimes(1); expect(writeHeadMock).toHaveBeenCalledTimes(1);
expect(writeHeadMock).toHaveBeenLastCalledWith(200); expect(writeHeadMock).toHaveBeenLastCalledWith(200);
expect(endMock).toBeCalledTimes(1); expect(endMock).toHaveBeenCalledTimes(1);
expect(endMock).toHaveBeenLastCalledWith('OK'); expect(endMock).toHaveBeenLastCalledWith('OK');
}); });
@ -123,10 +123,10 @@ describe('server', () => {
response as unknown as http.ServerResponse<http.IncomingMessage>, response as unknown as http.ServerResponse<http.IncomingMessage>,
); );
expect(writeHeadMock).toBeCalledTimes(1); expect(writeHeadMock).toHaveBeenCalledTimes(1);
expect(writeHeadMock).toHaveBeenLastCalledWith(404); expect(writeHeadMock).toHaveBeenLastCalledWith(404);
expect(endMock).toBeCalledTimes(1); expect(endMock).toHaveBeenCalledTimes(1);
expect(endMock).toHaveBeenLastCalledWith('Not Found'); expect(endMock).toHaveBeenLastCalledWith('Not Found');
}); });
}); });
@ -200,16 +200,16 @@ describe('server', () => {
const sendMock = jest.spyOn(ws, 'send'); const sendMock = jest.spyOn(ws, 'send');
const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() }; const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() };
expect(statsdIncrementMock).toBeCalledTimes(0); expect(statsdIncrementMock).toHaveBeenCalledTimes(0);
server.trackClient(channelId, socketInstance); server.trackClient(channelId, socketInstance);
expect(statsdIncrementMock).toBeCalledTimes(1); expect(statsdIncrementMock).toHaveBeenCalledTimes(1);
expect(statsdIncrementMock).toHaveBeenNthCalledWith( expect(statsdIncrementMock).toHaveBeenNthCalledWith(
1, 1,
'ws_connected_client', 'ws_connected_client',
); );
server.processStreamResults(streamReturnValue); server.processStreamResults(streamReturnValue);
expect(statsdIncrementMock).toBeCalledTimes(1); expect(statsdIncrementMock).toHaveBeenCalledTimes(1);
const message1 = `{"id":"1615426152415-0","channel_id":"${channelId}","job_id":"c9b99965-8f1e-4ce5-aa43-d6fc94d6a510","user_id":"1","status":"done","errors":[],"result_url":"/superset/explore_json/data/ejr-37281682b1282cdb8f25e0de0339b386"}`; const message1 = `{"id":"1615426152415-0","channel_id":"${channelId}","job_id":"c9b99965-8f1e-4ce5-aa43-d6fc94d6a510","user_id":"1","status":"done","errors":[],"result_url":"/superset/explore_json/data/ejr-37281682b1282cdb8f25e0de0339b386"}`;
const message2 = `{"id":"1615426152516-0","channel_id":"${channelId}","job_id":"f1e5bb1f-f2f1-4f21-9b2f-c9b91dcc9b59","user_id":"1","status":"done","errors":[],"result_url":"/api/v1/chart/data/qc-64e8452dc9907dd77746cb75a19202de"}`; const message2 = `{"id":"1615426152516-0","channel_id":"${channelId}","job_id":"f1e5bb1f-f2f1-4f21-9b2f-c9b91dcc9b59","user_id":"1","status":"done","errors":[],"result_url":"/api/v1/chart/data/qc-64e8452dc9907dd77746cb75a19202de"}`;
@ -221,9 +221,9 @@ describe('server', () => {
const ws = new wsMock('localhost'); const ws = new wsMock('localhost');
const sendMock = jest.spyOn(ws, 'send'); const sendMock = jest.spyOn(ws, 'send');
expect(statsdIncrementMock).toBeCalledTimes(0); expect(statsdIncrementMock).toHaveBeenCalledTimes(0);
server.processStreamResults(streamReturnValue); server.processStreamResults(streamReturnValue);
expect(statsdIncrementMock).toBeCalledTimes(0); expect(statsdIncrementMock).toHaveBeenCalledTimes(0);
expect(sendMock).not.toHaveBeenCalled(); expect(sendMock).not.toHaveBeenCalled();
}); });
@ -236,16 +236,16 @@ describe('server', () => {
const cleanChannelMock = jest.spyOn(server, 'cleanChannel'); const cleanChannelMock = jest.spyOn(server, 'cleanChannel');
const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() }; const socketInstance = { ws: ws, channel: channelId, pongTs: Date.now() };
expect(statsdIncrementMock).toBeCalledTimes(0); expect(statsdIncrementMock).toHaveBeenCalledTimes(0);
server.trackClient(channelId, socketInstance); server.trackClient(channelId, socketInstance);
expect(statsdIncrementMock).toBeCalledTimes(1); expect(statsdIncrementMock).toHaveBeenCalledTimes(1);
expect(statsdIncrementMock).toHaveBeenNthCalledWith( expect(statsdIncrementMock).toHaveBeenNthCalledWith(
1, 1,
'ws_connected_client', 'ws_connected_client',
); );
server.processStreamResults(streamReturnValue); server.processStreamResults(streamReturnValue);
expect(statsdIncrementMock).toBeCalledTimes(2); expect(statsdIncrementMock).toHaveBeenCalledTimes(2);
expect(statsdIncrementMock).toHaveBeenNthCalledWith( expect(statsdIncrementMock).toHaveBeenNthCalledWith(
2, 2,
'ws_client_send_error', 'ws_client_send_error',