Improve modal test util types (#3435)

This commit is contained in:
Opender Singh 2021-06-03 10:52:38 +12:00
parent fa23003de7
commit 83f6c2051c

View File

@ -1,16 +1,14 @@
import * as modals from './ui/components/modals';
import type { ErrorModalOptions } from './ui/components/modals/error-modal';
import { PromptModalOptions } from './ui/components/modals/prompt-modal';
import { showAlert, showError, showModal, showPrompt } from './ui/components/modals';
export const getAndClearShowPromptMockArgs = (): PromptModalOptions => {
const mockFn = modals.showPrompt as jest.Mock;
const options = mockFn.mock.calls[0][0] as PromptModalOptions;
export const getAndClearShowPromptMockArgs = () => {
const mockFn = showPrompt as jest.Mock<typeof showPrompt, Parameters<typeof showPrompt>>;
const options = mockFn.mock.calls[0][0];
mockFn.mockClear();
return options;
};
export const getAndClearShowAlertMockArgs = () => {
const mockFn = modals.showAlert as jest.Mock;
const mockFn = showAlert as jest.Mock<typeof showAlert, Parameters<typeof showAlert>>;
const { title, okLabel, addCancel, message, onConfirm } = mockFn.mock.calls[0][0];
mockFn.mockClear();
return {
@ -22,15 +20,15 @@ export const getAndClearShowAlertMockArgs = () => {
};
};
export const getAndClearShowErrorMockArgs = (): ErrorModalOptions => {
const mockFn = modals.showError as jest.Mock;
const options: ErrorModalOptions = mockFn.mock.calls[0][0];
export const getAndClearShowErrorMockArgs = () => {
const mockFn = showError as jest.Mock<typeof showError, Parameters<typeof showError>>;
const options = mockFn.mock.calls[0][0];
mockFn.mockClear();
return options;
};
export const getAndClearShowModalMockArgs = () => {
const mockFn = modals.showModal as jest.Mock;
const mockFn = showModal as jest.Mock<typeof showModal, Parameters<typeof showModal>>;
const args = mockFn.mock.calls[0][1];
mockFn.mockClear();
return args;