// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors

import { Toast } from '@blueprintjs/core';
import { act } from '@testing-library/react';
import React from 'react';
import { testRender } from '../../../test';
import { dfuError } from './DfuError';

it('should dismiss when close is clicked', async () => {
    const callback = jest.fn();
    const toast = dfuError(callback, undefined as never);

    const [user, message] = testRender(<Toast {...toast} />);

    await act(() => user.click(message.getByRole('button', { name: /close/i })));

    expect(callback).toHaveBeenCalledWith('dismiss');
});

it('should try again when clicked', async () => {
    const callback = jest.fn();
    const toast = dfuError(callback, undefined as never);

    const [user, message] = testRender(<Toast {...toast} />);

    await act(() => user.click(message.getByRole('button', { name: /again/i })));

    expect(callback).toHaveBeenCalledWith('tryAgain');
});
