addons/isl/src/__tests__/toasts.test.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {act, fireEvent, render, screen} from '@testing-library/react';
b69ab319import App from '../App';
b69ab3110import platform from '../platform';
b69ab3111import {
b69ab3112 TEST_COMMIT_HISTORY,
b69ab3113 expectMessageSentToServer,
b69ab3114 resetTestMessages,
b69ab3115 simulateCommits,
b69ab3116} from '../testUtils';
b69ab3117
b69ab3118describe('toasts', () => {
b69ab3119 beforeEach(() => {
b69ab3120 resetTestMessages();
b69ab3121 render(<App />);
b69ab3122 act(() => {
b69ab3123 expectMessageSentToServer({
b69ab3124 type: 'subscribe',
b69ab3125 kind: 'smartlogCommits',
b69ab3126 subscriptionID: expect.anything(),
b69ab3127 });
b69ab3128 simulateCommits({
b69ab3129 value: TEST_COMMIT_HISTORY,
b69ab3130 });
b69ab3131 });
b69ab3132 });
b69ab3133
b69ab3134 it('shows toast when copying commit hash', () => {
b69ab3135 const copySpy = jest.spyOn(platform, 'clipboardCopy').mockImplementation(() => {});
b69ab3136 fireEvent.contextMenu(screen.getByTestId('commit-e'));
b69ab3137 fireEvent.click(screen.getByText('Copy Commit Hash "e"'));
b69ab3138 expect(screen.getByText('Copied e')).toBeInTheDocument();
b69ab3139 expect(copySpy).toHaveBeenCalledWith('e', undefined);
b69ab3140 });
b69ab3141});