Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ function renderSubject(overrides = {}) {
}

describe('<LoadingTimeout />', () => {
beforeEach(() => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

it('renders a spinner with "Loading"', () => {
const { container } = renderSubject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { fireEvent } from '@botframework-composer/test-utils';
import { PublishDialog } from '../../../src/components/BotRuntimeController/publishDialog';
import { botDisplayNameState, settingsState, dispatcherState, currentProjectIdState } from '../../../src/recoilModel';
import { renderWithRecoil } from '../../testUtils';
jest.useFakeTimers();

beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

const projectId = '12abvc.as324';
const luisConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ import { AddLanguageModal, DeleteLanguageModal } from '../../../src/components/M
const defaultLanguage = 'en-us';
const languages = ['en-us', 'zh-cn'];
const locale = 'zh-cn';

beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

describe('<AddLanguageModal />', () => {
it('should render the AddLanguageModal form, and do add language', () => {
jest.useFakeTimers();
const onSubmit = jest.fn(() => {});
const onDismiss = jest.fn(() => {});
const { getByText } = render(
Expand Down Expand Up @@ -40,7 +48,6 @@ describe('<AddLanguageModal />', () => {

describe('<DeleteLanguageModal />', () => {
it('should render the DeleteLanguageModal form, and do add language', () => {
jest.useFakeTimers();
const onSubmit = jest.fn(() => {});
const onDismiss = jest.fn(() => {});
const { getByText } = render(
Expand Down
47 changes: 26 additions & 21 deletions Composer/packages/client/__tests__/components/skill.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,38 @@ describe('Skill page', () => {

describe('<SkillForm />', () => {
it('should render the skill form, and update skill manifest url', () => {
jest.useFakeTimers();
try {
jest.useFakeTimers();

(httpClient.get as jest.Mock).mockResolvedValue({ endpoints: [] });
(httpClient.get as jest.Mock).mockResolvedValue({ endpoints: [] });

const onDismiss = jest.fn();
const onSubmit = jest.fn();
const { getByLabelText, getByText } = renderWithRecoil(
<CreateSkillModal projectId={projectId} onDismiss={onDismiss} onSubmit={onSubmit} />,
recoilInitState
);
const onDismiss = jest.fn();
const onSubmit = jest.fn();
const { getByLabelText, getByText } = renderWithRecoil(
<CreateSkillModal projectId={projectId} onDismiss={onDismiss} onSubmit={onSubmit} />,
recoilInitState
);

const urlInput = getByLabelText('Manifest url');
act(() => {
fireEvent.change(urlInput, {
target: { value: 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json' },
const urlInput = getByLabelText('Manifest url');
act(() => {
fireEvent.change(urlInput, {
target: { value: 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json' },
});
});
});

expect(urlInput.getAttribute('value')).toBe(
'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json'
);
expect(urlInput.getAttribute('value')).toBe(
'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json'
);

const submitButton = getByText('Confirm');
act(() => {
fireEvent.click(submitButton);
});
expect(onSubmit).not.toBeCalled();
const submitButton = getByText('Confirm');
act(() => {
fireEvent.click(submitButton);
});
expect(onSubmit).not.toBeCalled();
} finally {
jest.runOnlyPendingTimers();
jest.useRealTimers();
}
});

let formDataErrors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { renderWithRecoil } from '../../../../__tests__/testUtils/renderWithReco
import { NotificationCard, CardProps } from '../NotificationCard';
import Timer from '../../../utils/timer';

jest.useFakeTimers();
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

describe('<NotificationCard />', () => {
it('should render the NotificationCard', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe('<BotRuntimeStatus />', () => {
});

describe('<Poll Operations />', () => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

const updatePublishStatusMock = jest.fn();
(httpClient.get as jest.Mock).mockImplementation(() => {
updatePublishStatusMock();
Expand All @@ -53,15 +61,11 @@ describe('<BotRuntimeStatus />', () => {
});
});
});

beforeEach(() => {
jest.useFakeTimers();
updatePublishStatusMock.mockClear();
});

afterEach(() => {
jest.useRealTimers();
});

it('should not poll if bot is started', async () => {
renderWithRecoil(<BotRuntimeStatus projectId={projectId} />, ({ set }) => {
set(botStatusState(projectId), BotStatus.connected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ jest.mock('../../../utils/auth', () => {
};
});
jest.mock('jwt-decode');
jest.useFakeTimers();

beforeAll(() => {
jest.useFakeTimers();
global.Date.now = jest.fn(() => 10000000);
});

afterAll(() => {
global.Date.now = realDate;
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

const mockGetUserToken = getUserTokenFromCache as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getMac, getMacAddress } from '../../src/utility/getMacAddress';
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { networkInterfaces } from 'os';

import { getMac, getMacAddress } from '../../src/utility/getMacAddress';

jest.mock('os');

describe('getMac', () => {
Expand Down Expand Up @@ -35,10 +38,16 @@ describe('getMacAddress', () => {
});

it('throws timeout error', async () => {
(networkInterfaces as jest.Mock).mockReturnValue({});
jest.useFakeTimers();
const macAddress = getMacAddress();
jest.advanceTimersToNextTimer(10001);
expect(macAddress).rejects.toEqual('Timeout: Unable to retrieve mac address');
try {
jest.useFakeTimers();
(networkInterfaces as jest.Mock).mockReturnValue({});

const macAddress = getMacAddress();
jest.advanceTimersToNextTimer(10001);
expect(macAddress).rejects.toEqual('Timeout: Unable to retrieve mac address');
} finally {
jest.runOnlyPendingTimers();
jest.useRealTimers();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import { FunctionRefPayload, PropertyRefPayload, TemplateRefPayload } from '../.
getRandomValues: (arr: any[]) => crypto.randomBytes(arr.length),
};

jest.useFakeTimers();
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

const templatePayload: TemplateRefPayload = {
kind: 'template',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import React from 'react';

import { useDebounce } from '../useDebounce';

jest.useFakeTimers();
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

describe('useDebounce', () => {
it('put initialized value in first render', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import React from 'react';

import { DefineEntityButton } from '../DefineEntityButton';

jest.useFakeTimers();
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

describe('<DefineEntityButton />', () => {
it('Should call onDefineEntity callback when a menu item is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ const luFile: LuFile = {
isContentUnparsed: false,
};

jest.useFakeTimers();
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

describe('<InsertEntityButton />', () => {
it('Should call onInsertEntity callback when a menu item is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ const renderSelectDialog = ({ createDialog, navTo, onChange } = {}) => {
};

describe('Select Dialog', () => {
beforeEach(() => {
beforeAll(() => {
jest.useFakeTimers();
});
afterAll(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

it('should create a new dialog', async () => {
const createDialog = jest.fn().mockResolvedValue('newDialog');
Expand Down