-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Error when deleting local changes. (#13669)
Co-authored-by: Michael Queyrichon <michael.queyrichon@digdir.no>
- Loading branch information
1 parent
aae8aef
commit d2b2fba
Showing
8 changed files
with
79 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
frontend/app-development/hooks/mutations/useAddXsdMutation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { waitFor } from '@testing-library/react'; | ||
import { renderHookWithProviders } from '../../test/mocks'; | ||
import { useAddXsdMutation } from './useAddXsdMutation'; | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { app, org } from '@studio/testing/testids'; | ||
|
||
// Test data: | ||
const modelPath: string = 'modelPath'; | ||
|
||
describe('useAddXsdMutation', () => { | ||
it('Calls useAddXsdMutation with correct arguments', async () => { | ||
const addDataModelXsd = renderHookWithProviders()(() => useAddXsdMutation()).renderHookResult | ||
.result; | ||
await addDataModelXsd.current.mutateAsync(modelPath); | ||
await waitFor(() => expect(addDataModelXsd.current.isSuccess).toBe(true)); | ||
|
||
expect(queriesMock.addXsdFromRepo).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.addXsdFromRepo).toHaveBeenCalledWith(org, app, modelPath); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
frontend/app-development/hooks/mutations/useAddXsdMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
import { StringUtils } from '@studio/pure-functions'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
|
||
export const useAddXsdMutation = () => { | ||
const { addXsdFromRepo } = useServicesContext(); | ||
const queryClient = useQueryClient(); | ||
const { org, app } = useStudioEnvironmentParams(); | ||
|
||
return useMutation({ | ||
mutationFn: (modelPath: string) => | ||
addXsdFromRepo(org, app, StringUtils.removeStart(modelPath, '/')), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: [QueryKey.DataModelsJson, org, app] }).then(); | ||
queryClient.invalidateQueries({ queryKey: [QueryKey.DataModelsXsd, org, app] }).then(); | ||
queryClient.invalidateQueries({ queryKey: [QueryKey.JsonSchema, org, app] }).then(); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters