feat: export parser sessions from the browser
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { fireEvent, render, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { OneNoteApplication } from './App.js';
|
||||
import type {
|
||||
@@ -105,6 +105,17 @@ class SuccessfulParserWorker implements WorkerPort {
|
||||
diagnostics: [],
|
||||
},
|
||||
});
|
||||
} else if (message.type === 'export-session') {
|
||||
this.respond({
|
||||
type: 'export-artifact',
|
||||
requestId: message.requestId,
|
||||
sessionId: message.sessionId,
|
||||
artifact: {
|
||||
filename: 'Project notes.zip',
|
||||
mediaType: 'application/zip',
|
||||
bytes: Uint8Array.of(0x50, 0x4b, 3, 4).buffer,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -183,6 +194,43 @@ describe('OneNoteApplication', () => {
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('downloads a worker-built export after explicit user action', async () => {
|
||||
const user = userEvent.setup();
|
||||
const worker = new SuccessfulParserWorker();
|
||||
const createObjectUrl = vi
|
||||
.spyOn(URL, 'createObjectURL')
|
||||
.mockReturnValue('blob:local-export');
|
||||
const click = vi
|
||||
.spyOn(HTMLAnchorElement.prototype, 'click')
|
||||
.mockImplementation(() => undefined);
|
||||
render(
|
||||
<OneNoteApplication
|
||||
createWorkerClient={() => new OneNoteWorkerClient(() => worker)}
|
||||
/>
|
||||
);
|
||||
|
||||
await user.upload(
|
||||
screen.getByLabelText('Choose OneNote files'),
|
||||
new File([new Uint8Array([1, 2, 3])], 'Section.one')
|
||||
);
|
||||
await screen.findByRole('heading', { name: 'First meeting' });
|
||||
await user.click(screen.getByRole('button', { name: 'Create export' }));
|
||||
|
||||
expect(
|
||||
await screen.findByText('The export download is ready.')
|
||||
).toBeVisible();
|
||||
expect(worker.lastMessage).toEqual({
|
||||
type: 'export-session',
|
||||
requestId: 'export-3',
|
||||
sessionId: 'session-one',
|
||||
format: 'static-zip',
|
||||
});
|
||||
expect(createObjectUrl).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ type: 'application/zip' })
|
||||
);
|
||||
expect(click).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('opens a dropped OneNote package through the local worker', async () => {
|
||||
const notebook: OneNotePackageDto = {
|
||||
format: 'onepkg',
|
||||
|
||||
Reference in New Issue
Block a user