Skip to content

Commit

Permalink
fix(core): wrong fetch injected to snapshot downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Dec 31, 2024
1 parent 9dc1b5e commit e8549a4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ const Dialog = ({
loading={disabled}
disabled={disabled}
onClick={handleImportToSelectedWorkspace}
data-testid="import-template-to-workspace-btn"
>
{selectedWorkspaceName &&
t['com.affine.import-template.dialog.createDocToWorkspace']({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ export const Component = () => {
const [searchParams] = useSearchParams();
const { jumpToIndex } = useNavigateHelper();
useEffect(() => {
globalDialogService.open('import-template', {
const id = globalDialogService.open('import-template', {
templateName: searchParams.get('name') ?? '',
templateMode: (searchParams.get('mode') as DocMode) ?? 'page',
snapshotUrl: searchParams.get('snapshotUrl') ?? '',
});

return () => {
globalDialogService.close(id);
};
}, [globalDialogService, jumpToIndex, searchParams]);
// no ui for this route, just open the dialog
return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/core/src/modules/import-template/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Framework } from '@toeverything/infra';

import { FetchService } from '../cloud';
import { RawFetchProvider } from '../cloud';
import { WorkspacesService } from '../workspace';
import { ImportTemplateDialog } from './entities/dialog';
import { TemplateDownloader } from './entities/downloader';
Expand All @@ -16,6 +16,6 @@ export function configureImportTemplateModule(framework: Framework) {
.entity(ImportTemplateDialog)
.service(TemplateDownloaderService)
.entity(TemplateDownloader, [TemplateDownloaderStore])
.store(TemplateDownloaderStore, [FetchService])
.store(TemplateDownloaderStore, [RawFetchProvider])
.service(ImportTemplateService, [WorkspacesService]);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Store } from '@toeverything/infra';

import type { FetchService } from '../../cloud';
import type { RawFetchProvider } from '../../cloud';

export class TemplateDownloaderStore extends Store {
constructor(private readonly fetchService: FetchService) {
constructor(private readonly fetchProvider: RawFetchProvider) {
super();
}

async download(snapshotUrl: string) {
const response = await this.fetchService.fetch(snapshotUrl, {
const response = await this.fetchProvider.fetch(snapshotUrl, {
priority: 'high',
} as any);
const arrayBuffer = await response.arrayBuffer();
Expand Down
33 changes: 33 additions & 0 deletions tests/affine-cloud/e2e/template.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test } from '@affine-test/kit/playwright';
import { createRandomUser, loginUser } from '@affine-test/kit/utils/cloud';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';

test.beforeEach(async ({ page }) => {
const user = await createRandomUser();
await loginUser(page, user);
});

test('import from template should work', async ({ page }) => {
await page.goto('https://affine.pro/templates', { waitUntil: 'load' });

await page.click('.template-list > a:first-child');
const importLink = page.getByText('Use this template');

const href = await importLink.evaluate((el: HTMLElement) => {
const a = el.closest('a');
if (!a) {
throw new Error('Import link not found');
}
return a.href;
});

const url = new URL(href);

await page.goto(url.pathname + url.search);

const btn = page.getByTestId('import-template-to-workspace-btn');

await btn.isVisible();
btn.click();
await waitForEditorLoad(page);
});

0 comments on commit e8549a4

Please sign in to comment.