Skip to content

Commit

Permalink
deps: upgrade vite to 5.2.11 HP-2436
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkojamG committed May 23, 2024
1 parent 8397a05 commit c748e9a
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 156 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^12.1.4",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react-hooks": "^8.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/dompurify": "^2.2.2",
"@types/file-saver": "^2.0.1",
Expand Down Expand Up @@ -69,12 +69,12 @@
"typescript": "4.9.5",
"uuid": "^8.1.0",
"validator": "^13.7.0",
"vite": "^5.1.7",
"vite": "^5.2.11",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.6.0",
"vitest": "^1.5.2",
"vitest-fetch-mock": "^0.2.2",
"yup": "^0.32.5"
},
Expand Down Expand Up @@ -111,7 +111,7 @@
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/typescript": "^4.0.6",
"@graphql-codegen/typescript-operations": "^4.2.0",
"@vitest/coverage-istanbul": "^1.6.0",
"@vitest/coverage-istanbul": "^1.3.1",
"cross-env": "^7.0.3",
"helsinki-utils": "City-of-Helsinki/helsinki-utils-js#0.1.0",
"husky": "^9.0.11",
Expand Down
201 changes: 96 additions & 105 deletions src/profile/hooks/__tests__/useProfileLoadTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,18 @@ describe('useProfileLoader.ts ', () => {
};

const waitForProfileLoadToEnd = async (renderHookResult: RenderResult) =>
waitFor(() => {
waitFor(async () => {
const currentHookProps = renderHookResult.result.current;

if (currentHookProps.isProfileLoadComplete() === false) {
advanceTimers();
renderHookResult.rerender();
advanceTimers();
throw new Error('Profile load is not complete');
}
});

// Function for advancing straight to point where
// profile loading is complete (success / failure)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const proceedToProfileLoadCompleteState = async ({
loadSuccess,
profileExist,
Expand All @@ -130,21 +129,15 @@ describe('useProfileLoader.ts ', () => {
addAllowedGraphQLError: boolean;
}) => {
const renderHookResult = await initTests();

const result = profileExist
? { data: loadSuccess ? getMyProfile() : undefined }
: { data: { myProfile: null } };

const errorObj = addAllowedGraphQLError
? createApolloErrorWithAllowedPermissionError()
: (({} as unknown) as ApolloError);

const error = loadSuccess ? undefined : errorObj;

mockProfileLoadProcess({ ...result, error });

await waitForProfileLoadToEnd(renderHookResult);

return { renderHookResult };
};

Expand Down Expand Up @@ -191,9 +184,9 @@ describe('useProfileLoader.ts ', () => {
});

it(`Profile should not be loaded at all, if context has an error. In this case
- hook.hasExistingProfile() returns false
- hook.didProfileLoadFail() returns true
- hook.isProfileLoadComplete() returns true`, async () => {
- hook.hasExistingProfile() returns false
- hook.didProfileLoadFail() returns true
- hook.isProfileLoadComplete() returns true`, async () => {
await act(async () => {
updateMockUseProfileQueryResult({
error: {} as ApolloError,
Expand All @@ -208,104 +201,102 @@ describe('useProfileLoader.ts ', () => {
});
});

// it(`When profile load is successful and profile exists
// - hook.hasExistingProfile() returns true
// - hook.didProfileLoadFail() returns false
// - hook.isProfileLoadComplete() returns true.
// Response can include an allowed graphQL error.`, async () => {
// await act(async () => {
// const { renderHookResult } = await proceedToProfileLoadCompleteState({
// loadSuccess: true,
// profileExist: true,
// addAllowedGraphQLError: true,
// });

// const currentHookProps = renderHookResult.result.current;

// expect(currentHookProps.hasExistingProfile()).toBeTruthy();
// expect(currentHookProps.didProfileLoadFail()).toBeFalsy();
// expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
// expect(fetchProfileMock).toHaveBeenCalledTimes(1);
// });
// });
it(`When profile load is successful and profile exists
- hook.hasExistingProfile() returns true
- hook.didProfileLoadFail() returns false
- hook.isProfileLoadComplete() returns true.
Response can include an allowed graphQL error.`, async () => {
await act(async () => {
const { renderHookResult } = await proceedToProfileLoadCompleteState({
loadSuccess: true,
profileExist: true,
addAllowedGraphQLError: true,
});
const currentHookProps = renderHookResult.result.current;
expect(currentHookProps.hasExistingProfile()).toBeTruthy();
expect(currentHookProps.didProfileLoadFail()).toBeFalsy();
expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
expect(fetchProfileMock).toHaveBeenCalledTimes(1);
});
});

// it(`When profile load is successful, but profile does not exist,
// - hook.hasExistingProfile() returns false
// - hook.didProfileLoadFail() returns false
// - hook.isProfileLoadComplete() returns true`, async () => {
// await act(async () => {
// const { renderHookResult } = await proceedToProfileLoadCompleteState({
// loadSuccess: true,
// profileExist: false,
// addAllowedGraphQLError: false,
// });
// const currentHookProps = renderHookResult.result.current;
// expect(currentHookProps.hasExistingProfile()).toBeFalsy();
// expect(currentHookProps.didProfileLoadFail()).toBeFalsy();
// expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
// expect(fetchProfileMock).toHaveBeenCalledTimes(1);
// });
// });
it(`When profile load is successful, but profile does not exist,
- hook.hasExistingProfile() returns false
- hook.didProfileLoadFail() returns false
- hook.isProfileLoadComplete() returns true`, async () => {
await act(async () => {
const { renderHookResult } = await proceedToProfileLoadCompleteState({
loadSuccess: true,
profileExist: false,
addAllowedGraphQLError: false,
});
const currentHookProps = renderHookResult.result.current;
expect(currentHookProps.hasExistingProfile()).toBeFalsy();
expect(currentHookProps.didProfileLoadFail()).toBeFalsy();
expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
expect(fetchProfileMock).toHaveBeenCalledTimes(1);
});
});

// it(`When profile load fails
// - hook.hasExistingProfile() returns false
// - hook.didProfileLoadFail() returns true
// - hook.isProfileLoadComplete() returns true`, async () => {
// await act(async () => {
// const { renderHookResult } = await proceedToProfileLoadCompleteState({
// loadSuccess: false,
// profileExist: true,
// addAllowedGraphQLError: false,
// });
// const currentHookProps = renderHookResult.result.current;
// expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
// expect(currentHookProps.didProfileLoadFail()).toBeTruthy();
// expect(currentHookProps.hasExistingProfile()).toBeFalsy();
// expect(fetchProfileMock).toHaveBeenCalledTimes(1);
// });
// });
it(`When profile load fails
- hook.hasExistingProfile() returns false
- hook.didProfileLoadFail() returns true
- hook.isProfileLoadComplete() returns true`, async () => {
await act(async () => {
const { renderHookResult } = await proceedToProfileLoadCompleteState({
loadSuccess: false,
profileExist: true,
addAllowedGraphQLError: false,
});
const currentHookProps = renderHookResult.result.current;
expect(currentHookProps.isProfileLoadComplete()).toBeTruthy();
expect(currentHookProps.didProfileLoadFail()).toBeTruthy();
expect(currentHookProps.hasExistingProfile()).toBeFalsy();
expect(fetchProfileMock).toHaveBeenCalledTimes(1);
});
});

// it(`Hook provides a reloadProfile() function for refetching profile when
// - load fails
// - profile is fetched after it is created for first time.`, async () => {
// await act(async () => {
// const { renderHookResult } = await proceedToProfileLoadCompleteState({
// loadSuccess: false,
// profileExist: true,
// addAllowedGraphQLError: false,
// });
// const currentHookProps = renderHookResult.result.current;
// expect(currentHookProps.didProfileLoadFail()).toBeTruthy();
// expect(currentHookProps.hasExistingProfile()).toBeFalsy();
// updateMockUseProfileQueryResult({
// error: undefined,
// loading: true,
// data: undefined,
// });
// mockProfileLoadProcess({
// ...successfulProfileLoadData,
// });
// currentHookProps.reloadProfile();
it(`Hook provides a reloadProfile() function for refetching profile when
- load fails
- profile is fetched after it is created for first time.`, async () => {
await act(async () => {
const { renderHookResult } = await proceedToProfileLoadCompleteState({
loadSuccess: false,
profileExist: true,
addAllowedGraphQLError: false,
});
const currentHookProps = renderHookResult.result.current;
expect(currentHookProps.didProfileLoadFail()).toBeTruthy();
expect(currentHookProps.hasExistingProfile()).toBeFalsy();
updateMockUseProfileQueryResult({
error: undefined,
loading: true,
data: undefined,
});
mockProfileLoadProcess({
...successfulProfileLoadData,
});
currentHookProps.reloadProfile();

// await waitForProfileLoadToEnd(renderHookResult);
// const updatedHookProps = renderHookResult.result.current;
// expect(updatedHookProps.didProfileLoadFail()).toBeFalsy();
// expect(updatedHookProps.hasExistingProfile()).toBeTruthy();
await waitForProfileLoadToEnd(renderHookResult);
const updatedHookProps = renderHookResult.result.current;
expect(updatedHookProps.didProfileLoadFail()).toBeFalsy();
expect(updatedHookProps.hasExistingProfile()).toBeTruthy();

// expect(fetchProfileMock).toHaveBeenCalledTimes(1);
// expect(refetchProfileMock).toHaveBeenCalledTimes(1);
// });
// });
expect(fetchProfileMock).toHaveBeenCalledTimes(1);
expect(refetchProfileMock).toHaveBeenCalledTimes(1);
});
});

// it('Hook.hasExistingProfile() throws, when used before profile load is complete', async () => {
// await act(async () => {
// const renderHookResult = await initTests();
// const currentHookProps = renderHookResult.result.current;
// expect(() => currentHookProps.hasExistingProfile()).toThrow();
// mockProfileLoadProcess(successfulProfileLoadData);
// await waitForProfileLoadToEnd(renderHookResult);
// expect(() => currentHookProps.hasExistingProfile()).not.toThrow();
// });
// });
it('Hook.hasExistingProfile() throws, when used before profile load is complete', async () => {
await act(async () => {
const renderHookResult = await initTests();
const currentHookProps = renderHookResult.result.current;
expect(() => currentHookProps.hasExistingProfile()).toThrow();
mockProfileLoadProcess(successfulProfileLoadData);
await waitForProfileLoadToEnd(renderHookResult);
expect(() => currentHookProps.hasExistingProfile()).not.toThrow();
});
});
});
});
5 changes: 5 additions & 0 deletions src/profile/hooks/useProfileLoadTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export function useProfileLoadTracker(): useProfileLoaderHookReturnType {
const statusRef = useRef<Status>(STATUS_WAITING);

const updateStatus = useCallback((updatedStatus?: Status): Status => {
console.log('Updating status to', updatedStatus);

if (!updatedStatus) {
return statusRef.current;
}
Expand All @@ -87,10 +89,13 @@ export function useProfileLoadTracker(): useProfileLoaderHookReturnType {
}, []);

const newStatus = resolveChangedStatus(statusRef.current, profileContext);

updateStatus(newStatus);

useEffect(() => {
console.log('Effect running with newStatus', newStatus);
if (shouldLoad(newStatus)) {
console.log('Starting to load');
updateStatus(STATUS_LOADING);
profileContext.fetch();
}
Expand Down
Loading

0 comments on commit c748e9a

Please sign in to comment.