|
|
@@ -26,6 +26,7 @@ import {
|
|
|
pageNotFoundAtom,
|
|
|
remoteRevisionBodyAtom,
|
|
|
} from '~/states/page/internal-atoms';
|
|
|
+import { useSWRxPageInfo } from '~/stores/page';
|
|
|
|
|
|
// Mock Next.js router
|
|
|
const mockRouter = mockDeep<NextRouter>();
|
|
|
@@ -37,6 +38,13 @@ vi.mock('next/router', () => ({
|
|
|
vi.mock('~/client/util/apiv3-client');
|
|
|
const mockedApiv3Get = vi.spyOn(apiv3Client, 'apiv3Get');
|
|
|
|
|
|
+// Mock useSWRxPageInfo
|
|
|
+vi.mock('~/stores/page', () => ({
|
|
|
+ useSWRxPageInfo: vi.fn(),
|
|
|
+}));
|
|
|
+const mockedUseSWRxPageInfo = vi.mocked(useSWRxPageInfo);
|
|
|
+const mockMutatePageInfo = vi.fn();
|
|
|
+
|
|
|
const mockUser: IUserHasId = {
|
|
|
_id: 'user1',
|
|
|
name: 'Test User',
|
|
|
@@ -133,6 +141,16 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockRouter.pathname = '/[[...path]]';
|
|
|
(useRouter as ReturnType<typeof vi.fn>).mockReturnValue(mockRouter);
|
|
|
|
|
|
+ // Mock useSWRxPageInfo to return a mutate function
|
|
|
+ mockMutatePageInfo.mockClear();
|
|
|
+ mockedUseSWRxPageInfo.mockReturnValue({
|
|
|
+ mutate: mockMutatePageInfo,
|
|
|
+ data: undefined,
|
|
|
+ error: undefined,
|
|
|
+ isLoading: false,
|
|
|
+ isValidating: false,
|
|
|
+ } as ReturnType<typeof useSWRxPageInfo>);
|
|
|
+
|
|
|
// Default API response
|
|
|
const defaultPageData = createPageDataMock(
|
|
|
'defaultPageId',
|
|
|
@@ -738,6 +756,7 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
store.set(remoteRevisionBodyAtom, 'remote body');
|
|
|
|
|
|
// Mock API rejection with ErrorV3 like object
|
|
|
+ // Note: error.args must have isNotFound property for isIPageNotFoundInfo check
|
|
|
const notFoundError = {
|
|
|
code: 'not_found',
|
|
|
message: 'Page not found',
|