|
@@ -8,7 +8,7 @@ import type {
|
|
|
PageGrant,
|
|
PageGrant,
|
|
|
PageStatus,
|
|
PageStatus,
|
|
|
} from '@growi/core/dist/interfaces';
|
|
} from '@growi/core/dist/interfaces';
|
|
|
-import { renderHook, waitFor } from '@testing-library/react';
|
|
|
|
|
|
|
+import { act, renderHook, waitFor } from '@testing-library/react';
|
|
|
// biome-ignore lint/style/noRestrictedImports: import only types
|
|
// biome-ignore lint/style/noRestrictedImports: import only types
|
|
|
import type { AxiosResponse } from 'axios';
|
|
import type { AxiosResponse } from 'axios';
|
|
|
import { createStore, Provider } from 'jotai';
|
|
import { createStore, Provider } from 'jotai';
|
|
@@ -180,7 +180,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/new/page' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/new/page' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: Wait for state updates
|
|
// Assert: Wait for state updates
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -211,7 +213,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/same/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/same/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
// Use a short timeout to ensure no fetch is initiated
|
|
// Use a short timeout to ensure no fetch is initiated
|
|
@@ -231,7 +235,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ pageId: 'page123' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ pageId: 'page123' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -261,9 +267,11 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({
|
|
|
|
|
- path: '/same/path',
|
|
|
|
|
- revisionId: 'rev_different',
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: '/same/path',
|
|
|
|
|
+ revisionId: 'rev_different',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
@@ -294,9 +302,11 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({
|
|
|
|
|
- path: '/same/path',
|
|
|
|
|
- revisionId: currentRevisionId,
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: '/same/path',
|
|
|
|
|
+ revisionId: currentRevisionId,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
@@ -327,9 +337,11 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({
|
|
|
|
|
- path: '/same/path',
|
|
|
|
|
- revisionId: 'rev_old',
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: '/same/path',
|
|
|
|
|
+ revisionId: 'rev_old',
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
@@ -367,7 +379,12 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/same/path', force: true });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: '/same/path',
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -405,7 +422,12 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ pageId: 'pageId123', force: true });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ pageId: 'pageId123',
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -444,9 +466,11 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({
|
|
|
|
|
- path: `/${permalinkId}`,
|
|
|
|
|
- force: true,
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: `/${permalinkId}`,
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
@@ -475,7 +499,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockResolvedValue(mockApiResponse(regularPageData));
|
|
mockedApiv3Get.mockResolvedValue(mockApiResponse(regularPageData));
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/some/page' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/some/page' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(store.get(currentPageEntityIdAtom)).toBe('regularPageId');
|
|
expect(store.get(currentPageEntityIdAtom)).toBe('regularPageId');
|
|
@@ -491,7 +517,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockResolvedValue(mockApiResponse(rootPageData));
|
|
mockedApiv3Get.mockResolvedValue(mockApiResponse(rootPageData));
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
- await result.current.fetchCurrentPage({ path: '/' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: Navigation to root works
|
|
// Assert: Navigation to root works
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -516,7 +544,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: encodedPath });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: encodedPath });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -540,7 +570,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: permalink });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: permalink });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -567,7 +599,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: permalinkPath });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: permalinkPath });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -604,9 +638,11 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({
|
|
|
|
|
- path: permalinkPath,
|
|
|
|
|
- pageId: explicitPageId,
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({
|
|
|
|
|
+ path: permalinkPath,
|
|
|
|
|
+ pageId: explicitPageId,
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
@@ -640,7 +676,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: regularPath });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: regularPath });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -674,7 +712,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: permalinkWithHash });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: permalinkWithHash });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -733,7 +773,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: testCase.input });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: testCase.input });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -769,7 +811,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockRejectedValueOnce([notFoundError]);
|
|
mockedApiv3Get.mockRejectedValueOnce([notFoundError]);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/will/not/found' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/will/not/found' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert
|
|
// Assert
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -794,7 +838,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockRejectedValueOnce(unknownError);
|
|
mockedApiv3Get.mockRejectedValueOnce(unknownError);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
const err = store.get(pageErrorAtom);
|
|
const err = store.get(pageErrorAtom);
|
|
@@ -813,7 +859,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockRejectedValueOnce([]);
|
|
mockedApiv3Get.mockRejectedValueOnce([]);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
const err = store.get(pageErrorAtom);
|
|
const err = store.get(pageErrorAtom);
|
|
@@ -836,7 +884,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockRejectedValueOnce([nonErrorV3]);
|
|
mockedApiv3Get.mockRejectedValueOnce([nonErrorV3]);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/any/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
expect(store.get(pageLoadingAtom)).toBe(false);
|
|
expect(store.get(pageLoadingAtom)).toBe(false);
|
|
@@ -870,7 +920,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockResolvedValueOnce(notFoundResponseWithEmptyPage);
|
|
mockedApiv3Get.mockResolvedValueOnce(notFoundResponseWithEmptyPage);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/empty/page' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/empty/page' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: emptyPageId should be set from meta
|
|
// Assert: emptyPageId should be set from meta
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -902,7 +954,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
mockedApiv3Get.mockResolvedValueOnce(notFoundResponseWithoutEmptyPage);
|
|
mockedApiv3Get.mockResolvedValueOnce(notFoundResponseWithoutEmptyPage);
|
|
|
|
|
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/regular/not/found' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/regular/not/found' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: emptyPageId should be undefined
|
|
// Assert: emptyPageId should be undefined
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -930,7 +984,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/success/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/success/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: emptyPageId should be reset to undefined
|
|
// Assert: emptyPageId should be reset to undefined
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -945,7 +1001,6 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
it('should handle path with encoded Japanese characters', async () => {
|
|
it('should handle path with encoded Japanese characters', async () => {
|
|
|
// Arrange: Path with Japanese characters
|
|
// Arrange: Path with Japanese characters
|
|
|
const japanesePath = '/日本語/ページ';
|
|
const japanesePath = '/日本語/ページ';
|
|
|
- const encodedPath = encodeURIComponent(japanesePath);
|
|
|
|
|
const pageData = createPageDataMock(
|
|
const pageData = createPageDataMock(
|
|
|
'japanesePageId',
|
|
'japanesePageId',
|
|
|
japanesePath,
|
|
japanesePath,
|
|
@@ -955,7 +1010,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: japanesePath });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: japanesePath });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: Path should be properly decoded and sent to API
|
|
// Assert: Path should be properly decoded and sent to API
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
@@ -978,7 +1035,9 @@ describe('useFetchCurrentPage - Integration Test', () => {
|
|
|
|
|
|
|
|
// Act
|
|
// Act
|
|
|
const { result } = renderHookWithProvider();
|
|
const { result } = renderHookWithProvider();
|
|
|
- await result.current.fetchCurrentPage({ path: '/test/path' });
|
|
|
|
|
|
|
+ await act(async () => {
|
|
|
|
|
+ await result.current.fetchCurrentPage({ path: '/test/path' });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// Assert: mutatePageInfo should be called to refetch metadata
|
|
// Assert: mutatePageInfo should be called to refetch metadata
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|