fix: close module access lifecycle gaps
This commit is contained in:
1 parent
d16922f18c
commit
ebe55ba17a
8 files changed
+289
-19
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { MemoryRouter, Outlet } from 'react-router-dom';
|
||||
import App from '@/App';
|
||||
@@ -27,6 +27,10 @@ vi.mock('@/pages/ModuleSelection', () => ({
|
||||
ModuleSelection: () => <div>Module chooser</div>,
|
||||
}));
|
||||
|
||||
vi.mock('@/pages/Settings', () => ({
|
||||
Settings: () => <div>Global settings</div>,
|
||||
}));
|
||||
|
||||
describe('App programming provider initialization gate', () => {
|
||||
const initProviders = vi.fn();
|
||||
|
||||
@@ -84,6 +88,37 @@ describe('App programming provider initialization gate', () => {
|
||||
await waitFor(() => expect(initProviders).toHaveBeenCalledTimes(1));
|
||||
});
|
||||
|
||||
it('waits for the startup module policy before initializing programming providers', async () => {
|
||||
useAuthStore.setState({
|
||||
initialized: false,
|
||||
moduleAccess: {
|
||||
programming: true,
|
||||
design: true,
|
||||
learning: true,
|
||||
robot: true,
|
||||
},
|
||||
});
|
||||
|
||||
await renderAt('/opencode-chat');
|
||||
|
||||
expect(initProviders).not.toHaveBeenCalled();
|
||||
|
||||
act(() => {
|
||||
useAuthStore.setState({
|
||||
initialized: true,
|
||||
moduleAccess: {
|
||||
programming: false,
|
||||
design: true,
|
||||
learning: true,
|
||||
robot: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
expect(await screen.findByText('Module chooser')).toBeInTheDocument();
|
||||
expect(initProviders).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
['/opencode-chat', 'programming'],
|
||||
['/image-canvas', 'design'],
|
||||
@@ -107,4 +142,20 @@ describe('App programming provider initialization gate', () => {
|
||||
expect(initProviders).not.toHaveBeenCalled();
|
||||
}
|
||||
});
|
||||
|
||||
it('keeps global settings available when Programming is disabled', async () => {
|
||||
useAuthStore.setState({
|
||||
moduleAccess: {
|
||||
programming: false,
|
||||
design: true,
|
||||
learning: true,
|
||||
robot: true,
|
||||
},
|
||||
});
|
||||
|
||||
await renderAt('/settings');
|
||||
|
||||
expect(await screen.findByText('Global settings')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Module chooser')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user