47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import '@testing-library/jest-dom/vitest';
|
|
import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
|
|
|
|
function makeDiag(open: boolean): {
|
|
withArgs: { openAtLogin: boolean; executableWillLaunchAtLogin: boolean };
|
|
noArgs: { openAtLogin: boolean; executableWillLaunchAtLogin: boolean };
|
|
execPath: string;
|
|
} {
|
|
return {
|
|
withArgs: { openAtLogin: open, executableWillLaunchAtLogin: open },
|
|
noArgs: { openAtLogin: open, executableWillLaunchAtLogin: open },
|
|
execPath: '/path/to/exe'
|
|
};
|
|
}
|
|
|
|
vi.mock('../../src/renderer/inbox/api.js', () => ({
|
|
inboxApi: {
|
|
getAutostart: vi.fn(async () => ({ openAtLogin: true, diagnostic: makeDiag(true) })),
|
|
setAutostart: vi.fn(async (open: boolean) => ({ openAtLogin: open, diagnostic: makeDiag(open) }))
|
|
}
|
|
}));
|
|
|
|
import { AutostartSection } from '../../src/renderer/inbox/components/settings/AutostartSection';
|
|
|
|
describe('AutostartSection', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
cleanup();
|
|
});
|
|
|
|
it('renders toggle reflecting current state', async () => {
|
|
render(<AutostartSection />);
|
|
const toggle = await screen.findByRole('checkbox');
|
|
expect(toggle).toBeChecked();
|
|
});
|
|
|
|
it('clicking toggle calls setAutostart', async () => {
|
|
const { inboxApi } = await import('../../src/renderer/inbox/api.js');
|
|
render(<AutostartSection />);
|
|
const toggle = await screen.findByRole('checkbox');
|
|
fireEvent.click(toggle);
|
|
await waitFor(() => expect(inboxApi.setAutostart).toHaveBeenCalledWith(false));
|
|
});
|
|
});
|