feat: unify plugin workspace navigation
This commit is contained in:
83
tests/unit/plugin-workspace-controller.test.ts
Normal file
83
tests/unit/plugin-workspace-controller.test.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
dispatchPluginWorkspaceCommand,
|
||||
settlePluginWorkspaceLoads,
|
||||
type PluginWorkspaceDispatchDependencies,
|
||||
} from '@/pages/Plugins/plugin-workspace-controller';
|
||||
import type { PluginWorkspaceCommand } from '@/pages/Plugins/plugin-workspace-model';
|
||||
|
||||
function dependencies() {
|
||||
return {
|
||||
marketplace: {
|
||||
acquire: vi.fn().mockResolvedValue(undefined),
|
||||
remove: vi.fn().mockResolvedValue(undefined),
|
||||
install: vi.fn().mockResolvedValue(undefined),
|
||||
installBeta: vi.fn().mockResolvedValue(undefined),
|
||||
update: vi.fn().mockResolvedValue(undefined),
|
||||
uninstall: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
device: {
|
||||
setEnabled: vi.fn().mockResolvedValue(undefined),
|
||||
uninstall: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
project: {
|
||||
setEnabled: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
navigate: vi.fn(),
|
||||
openSettings: vi.fn(),
|
||||
} satisfies PluginWorkspaceDispatchDependencies;
|
||||
}
|
||||
|
||||
describe('plugin workspace controller', () => {
|
||||
it('dispatches every command to exactly one existing authority action', async () => {
|
||||
const deps = dependencies();
|
||||
const commands = [
|
||||
{ kind: 'acquire', pluginId: 'a' },
|
||||
{ kind: 'reacquire', pluginId: 'b' },
|
||||
{ kind: 'remove_from_library', pluginId: 'c' },
|
||||
{ kind: 'install_stable', pluginId: 'd' },
|
||||
{ kind: 'install_beta', pluginId: 'e' },
|
||||
{ kind: 'update_official', pluginId: 'f' },
|
||||
{ kind: 'remove_official_device_package', pluginId: 'g' },
|
||||
{ kind: 'enable_project', projectId: 'project-a', pluginId: 'h' },
|
||||
{ kind: 'disable_project', projectId: 'project-a', pluginId: 'i' },
|
||||
{ kind: 'enable_local', packageId: 'j' },
|
||||
{ kind: 'disable_local', packageId: 'k' },
|
||||
{ kind: 'remove_local', packageId: 'l' },
|
||||
{ kind: 'open_agent_assignment', projectId: 'project-a', pluginId: 'm' },
|
||||
{ kind: 'open_settings', projectId: 'project-a', pluginId: 'n' },
|
||||
] satisfies readonly PluginWorkspaceCommand[];
|
||||
|
||||
for (const command of commands) await dispatchPluginWorkspaceCommand(command, deps);
|
||||
|
||||
expect(deps.marketplace.acquire.mock.calls).toEqual([['a'], ['b']]);
|
||||
expect(deps.marketplace.remove).toHaveBeenCalledExactlyOnceWith('c');
|
||||
expect(deps.marketplace.install).toHaveBeenCalledExactlyOnceWith('d');
|
||||
expect(deps.marketplace.installBeta).toHaveBeenCalledExactlyOnceWith('e');
|
||||
expect(deps.marketplace.update).toHaveBeenCalledExactlyOnceWith('f');
|
||||
expect(deps.marketplace.uninstall).toHaveBeenCalledExactlyOnceWith('g');
|
||||
expect(deps.project.setEnabled.mock.calls).toEqual([
|
||||
['project-a', 'h', true],
|
||||
['project-a', 'i', false],
|
||||
]);
|
||||
expect(deps.device.setEnabled.mock.calls).toEqual([['j', true], ['k', false]]);
|
||||
expect(deps.device.uninstall).toHaveBeenCalledExactlyOnceWith('l');
|
||||
expect(deps.navigate).toHaveBeenCalledExactlyOnceWith('/project-config');
|
||||
expect(deps.openSettings).toHaveBeenCalledExactlyOnceWith();
|
||||
});
|
||||
|
||||
it('starts every available source load even when one source rejects', async () => {
|
||||
const catalog = vi.fn().mockRejectedValue(new Error('catalog offline'));
|
||||
const library = vi.fn().mockResolvedValue(undefined);
|
||||
const device = vi.fn().mockResolvedValue(undefined);
|
||||
const project = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
const results = await settlePluginWorkspaceLoads({ catalog, library, device, project });
|
||||
|
||||
expect(catalog).toHaveBeenCalledOnce();
|
||||
expect(library).toHaveBeenCalledOnce();
|
||||
expect(device).toHaveBeenCalledOnce();
|
||||
expect(project).toHaveBeenCalledOnce();
|
||||
expect(results.map(({ status }) => status)).toEqual(['rejected', 'fulfilled', 'fulfilled', 'fulfilled']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user