mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Improve a11y (#1841)
Improve accessibility by removing unnecessary tags without hrefs. Also remove many eslint errors and warnings.
This commit is contained in:
@@ -36,7 +36,7 @@ describe("ApiProvider tests", () => {
|
||||
|
||||
it("should register QueryClient", () => {
|
||||
const { result } = renderHook(() => useQueryClient(), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
expect(result.current).toBeDefined();
|
||||
});
|
||||
@@ -48,7 +48,7 @@ describe("ApiProvider tests", () => {
|
||||
};
|
||||
|
||||
const { result } = renderHook(() => useLegacyContext(), {
|
||||
wrapper: createWrapper({ onIndexFetched })
|
||||
wrapper: createWrapper({ onIndexFetched }),
|
||||
});
|
||||
|
||||
if (result.current?.onIndexFetched) {
|
||||
|
||||
@@ -31,9 +31,9 @@ import { reset } from "./reset";
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false
|
||||
}
|
||||
}
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
type Props = LegacyContext & {
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("LegacyContext tests", () => {
|
||||
|
||||
it("should return provided context", () => {
|
||||
const { result } = renderHook(() => useLegacyContext(), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
expect(result.current).toBeDefined();
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ describe("Test admin hooks", () => {
|
||||
it("should get update info", async () => {
|
||||
const updateInfo: UpdateInfo = {
|
||||
latestVersion: "x.y.z",
|
||||
link: "http://heartofgold@hitchhiker.com/x.y.z"
|
||||
link: "http://heartofgold@hitchhiker.com/x.y.z",
|
||||
};
|
||||
fetchMock.getOnce("/api/v2/updateInfo", updateInfo);
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("Test admin hooks", () => {
|
||||
setIndexLink(queryClient, "updateInfo", "/updateInfo");
|
||||
|
||||
const { result, waitFor } = renderHook(() => useUpdateInfo(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
|
||||
@@ -45,9 +45,9 @@ describe("error handling tests", () => {
|
||||
context: [
|
||||
{
|
||||
type: "planet",
|
||||
id: "earth"
|
||||
}
|
||||
]
|
||||
id: "earth",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -55,9 +55,9 @@ describe("error handling tests", () => {
|
||||
fetchMock.restore();
|
||||
});
|
||||
|
||||
it("should create a normal error, if the content type is not scmm-error", done => {
|
||||
it("should create a normal error, if the content type is not scmm-error", (done) => {
|
||||
fetchMock.getOnce("/api/v2/error", {
|
||||
status: 404
|
||||
status: 404,
|
||||
});
|
||||
|
||||
apiClient.get("/error").catch((err: Error) => {
|
||||
@@ -67,13 +67,13 @@ describe("error handling tests", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should create an backend error, if the content type is scmm-error", done => {
|
||||
it("should create an backend error, if the content type is scmm-error", (done) => {
|
||||
fetchMock.getOnce("/api/v2/error", {
|
||||
status: 404,
|
||||
headers: {
|
||||
"Content-Type": "application/vnd.scmm-error+json;v=2"
|
||||
"Content-Type": "application/vnd.scmm-error+json;v=2",
|
||||
},
|
||||
body: earthNotFoundError
|
||||
body: earthNotFoundError,
|
||||
});
|
||||
|
||||
apiClient.get("/error").catch((err: BackendError) => {
|
||||
@@ -87,8 +87,8 @@ describe("error handling tests", () => {
|
||||
expect(err.context).toEqual([
|
||||
{
|
||||
type: "planet",
|
||||
id: "earth"
|
||||
}
|
||||
id: "earth",
|
||||
},
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
isBackendError,
|
||||
TOKEN_EXPIRED_ERROR_CODE,
|
||||
TokenExpiredError,
|
||||
UnauthorizedError
|
||||
UnauthorizedError,
|
||||
} from "./errors";
|
||||
|
||||
type SubscriptionEvent = {
|
||||
@@ -62,12 +62,7 @@ type SubscriptionArgument = MessageListeners | SubscriptionContext;
|
||||
|
||||
type Cancel = () => void;
|
||||
|
||||
const sessionId = (
|
||||
Date.now().toString(36) +
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substr(2, 5)
|
||||
).toUpperCase();
|
||||
const sessionId = (Date.now().toString(36) + Math.random().toString(36).substr(2, 5)).toUpperCase();
|
||||
|
||||
const extractXsrfTokenFromJwt = (jwt: string) => {
|
||||
const parts = jwt.split(".");
|
||||
@@ -102,7 +97,7 @@ const createRequestHeaders = () => {
|
||||
// identify the web interface
|
||||
"X-SCM-Client": "WUI",
|
||||
// identify the window session
|
||||
"X-SCM-Session-ID": sessionId
|
||||
"X-SCM-Session-ID": sessionId,
|
||||
};
|
||||
|
||||
const xsrf = extractXsrfToken();
|
||||
@@ -112,10 +107,10 @@ const createRequestHeaders = () => {
|
||||
return headers;
|
||||
};
|
||||
|
||||
const applyFetchOptions: (p: RequestInit) => RequestInit = o => {
|
||||
const applyFetchOptions: (p: RequestInit) => RequestInit = (o) => {
|
||||
if (o.headers) {
|
||||
o.headers = {
|
||||
...createRequestHeaders()
|
||||
...createRequestHeaders(),
|
||||
};
|
||||
} else {
|
||||
o.headers = createRequestHeaders();
|
||||
@@ -174,9 +169,7 @@ class ApiClient {
|
||||
requestListeners: RequestListener[] = [];
|
||||
|
||||
get = (url: string): Promise<Response> => {
|
||||
return this.request(url, applyFetchOptions({}))
|
||||
.then(handleFailure)
|
||||
.catch(this.notifyAndRethrow);
|
||||
return this.request(url, applyFetchOptions({})).then(handleFailure).catch(this.notifyAndRethrow);
|
||||
};
|
||||
|
||||
post = (
|
||||
@@ -203,7 +196,7 @@ class ApiClient {
|
||||
const options: RequestInit = {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: additionalHeaders
|
||||
headers: additionalHeaders,
|
||||
};
|
||||
return this.httpRequestWithBinaryBody(options, url);
|
||||
};
|
||||
@@ -214,22 +207,18 @@ class ApiClient {
|
||||
|
||||
head = (url: string) => {
|
||||
let options: RequestInit = {
|
||||
method: "HEAD"
|
||||
method: "HEAD",
|
||||
};
|
||||
options = applyFetchOptions(options);
|
||||
return this.request(url, options)
|
||||
.then(handleFailure)
|
||||
.catch(this.notifyAndRethrow);
|
||||
return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
|
||||
};
|
||||
|
||||
delete = (url: string): Promise<Response> => {
|
||||
let options: RequestInit = {
|
||||
method: "DELETE"
|
||||
method: "DELETE",
|
||||
};
|
||||
options = applyFetchOptions(options);
|
||||
return this.request(url, options)
|
||||
.then(handleFailure)
|
||||
.catch(this.notifyAndRethrow);
|
||||
return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
|
||||
};
|
||||
|
||||
httpRequestWithJSONBody = (
|
||||
@@ -241,7 +230,7 @@ class ApiClient {
|
||||
): Promise<Response> => {
|
||||
const options: RequestInit = {
|
||||
method: method,
|
||||
headers: additionalHeaders
|
||||
headers: additionalHeaders,
|
||||
};
|
||||
if (payload) {
|
||||
options.body = JSON.stringify(payload);
|
||||
@@ -257,7 +246,7 @@ class ApiClient {
|
||||
) => {
|
||||
const options: RequestInit = {
|
||||
method: method,
|
||||
headers: additionalHeaders
|
||||
headers: additionalHeaders,
|
||||
};
|
||||
options.body = payload;
|
||||
return this.httpRequestWithBinaryBody(options, url, "text/plain");
|
||||
@@ -273,14 +262,12 @@ class ApiClient {
|
||||
options.headers["Content-Type"] = contentType;
|
||||
}
|
||||
|
||||
return this.request(url, options)
|
||||
.then(handleFailure)
|
||||
.catch(this.notifyAndRethrow);
|
||||
return this.request(url, options).then(handleFailure).catch(this.notifyAndRethrow);
|
||||
};
|
||||
|
||||
subscribe(url: string, argument: SubscriptionArgument): Cancel {
|
||||
const es = new EventSource(createUrlWithIdentifiers(url), {
|
||||
withCredentials: true
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
let listeners: MessageListeners;
|
||||
@@ -321,11 +308,11 @@ class ApiClient {
|
||||
};
|
||||
|
||||
private notifyRequestListeners = (url: string, options: RequestInit) => {
|
||||
this.requestListeners.forEach(requestListener => requestListener(url, options));
|
||||
this.requestListeners.forEach((requestListener) => requestListener(url, options));
|
||||
};
|
||||
|
||||
private notifyAndRethrow = (error: Error): never => {
|
||||
this.errorListeners.forEach(errorListener => errorListener(error));
|
||||
this.errorListeners.forEach((errorListener) => errorListener(error));
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("Test base api hooks", () => {
|
||||
describe("useIndex tests", () => {
|
||||
fetchMock.get("/api/v2/", {
|
||||
version: "x.y.z",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
|
||||
it("should return index", async () => {
|
||||
@@ -48,9 +48,9 @@ describe("Test base api hooks", () => {
|
||||
it("should call onIndexFetched of LegacyContext", async () => {
|
||||
let index: IndexResources;
|
||||
const context: LegacyContext = {
|
||||
onIndexFetched: fetchedIndex => {
|
||||
onIndexFetched: (fetchedIndex) => {
|
||||
index = fetchedIndex;
|
||||
}
|
||||
},
|
||||
};
|
||||
const { result, waitFor } = renderHook(() => useIndex(), { wrapper: createWrapper(context) });
|
||||
await waitFor(() => {
|
||||
@@ -70,10 +70,10 @@ describe("Test base api hooks", () => {
|
||||
const queryClient = new QueryClient();
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
const { result } = renderHook(() => useIndexLink("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
@@ -86,17 +86,17 @@ describe("Test base api hooks", () => {
|
||||
spaceships: [
|
||||
{
|
||||
name: "heartOfGold",
|
||||
href: "/spaceships/heartOfGold"
|
||||
href: "/spaceships/heartOfGold",
|
||||
},
|
||||
{
|
||||
name: "razorCrest",
|
||||
href: "/spaceships/razorCrest"
|
||||
}
|
||||
]
|
||||
}
|
||||
href: "/spaceships/razorCrest",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const { result } = renderHook(() => useIndexLink("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
@@ -107,12 +107,12 @@ describe("Test base api hooks", () => {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
spaceships: {
|
||||
href: "/api/spaceships"
|
||||
}
|
||||
}
|
||||
href: "/api/spaceships",
|
||||
},
|
||||
},
|
||||
});
|
||||
const { result } = renderHook(() => useIndexLink("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.current).toBe("/api/spaceships");
|
||||
});
|
||||
@@ -130,12 +130,12 @@ describe("Test base api hooks", () => {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
spaceships: {
|
||||
href: "/api/spaceships"
|
||||
}
|
||||
}
|
||||
href: "/api/spaceships",
|
||||
},
|
||||
},
|
||||
});
|
||||
const { result } = renderHook(() => useIndexLinks(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect((result.current!.spaceships as Link).href).toBe("/api/spaceships");
|
||||
});
|
||||
@@ -150,10 +150,10 @@ describe("Test base api hooks", () => {
|
||||
it("should return version", () => {
|
||||
const queryClient = new QueryClient();
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z"
|
||||
version: "x.y.z",
|
||||
});
|
||||
const { result } = renderHook(() => useVersion(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.current).toBe("x.y.z");
|
||||
});
|
||||
@@ -164,10 +164,10 @@ describe("Test base api hooks", () => {
|
||||
const queryClient = new QueryClient();
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
const { result } = renderHook(() => useRequiredIndexLink("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.error).toBeDefined();
|
||||
});
|
||||
@@ -178,12 +178,12 @@ describe("Test base api hooks", () => {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
spaceships: {
|
||||
href: "/api/spaceships"
|
||||
}
|
||||
}
|
||||
href: "/api/spaceships",
|
||||
},
|
||||
},
|
||||
});
|
||||
const { result } = renderHook(() => useRequiredIndexLink("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
expect(result.current).toBe("/api/spaceships");
|
||||
});
|
||||
@@ -196,19 +196,19 @@ describe("Test base api hooks", () => {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
spaceships: {
|
||||
href: "/spaceships"
|
||||
}
|
||||
}
|
||||
href: "/spaceships",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const spaceship = {
|
||||
name: "heartOfGold"
|
||||
name: "heartOfGold",
|
||||
};
|
||||
|
||||
fetchMock.get("/api/v2/spaceships", spaceship);
|
||||
|
||||
const { result, waitFor } = renderHook(() => useIndexJsonResource<typeof spaceship>("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -223,11 +223,11 @@ describe("Test base api hooks", () => {
|
||||
const queryClient = new QueryClient();
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useIndexJsonResource<{}>("spaceships"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
|
||||
@@ -60,9 +60,9 @@ describe("Test config hooks", () => {
|
||||
skipFailedAuthenticators: false,
|
||||
_links: {
|
||||
update: {
|
||||
href: "/config"
|
||||
}
|
||||
}
|
||||
href: "/config",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -75,7 +75,7 @@ describe("Test config hooks", () => {
|
||||
setIndexLink(queryClient, "config", "/config");
|
||||
fetchMock.get("/api/v2/config", config);
|
||||
const { result, waitFor } = renderHook(() => useConfig(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(config);
|
||||
@@ -89,15 +89,15 @@ describe("Test config hooks", () => {
|
||||
|
||||
const newConfig = {
|
||||
...config,
|
||||
baseUrl: "/hog"
|
||||
baseUrl: "/hog",
|
||||
};
|
||||
|
||||
fetchMock.putOnce("/api/v2/config", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useUpdateConfig(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
|
||||
@@ -30,20 +30,20 @@ import { requiredLink } from "./links";
|
||||
|
||||
export const useConfig = (): ApiResult<Config> => {
|
||||
const indexLink = useIndexLink("config");
|
||||
return useQuery<Config, Error>("config", () => apiClient.get(indexLink!).then(response => response.json()), {
|
||||
enabled: !!indexLink
|
||||
return useQuery<Config, Error>("config", () => apiClient.get(indexLink!).then((response) => response.json()), {
|
||||
enabled: !!indexLink,
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateConfig = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { mutate, isLoading, error, data, reset } = useMutation<unknown, Error, Config>(
|
||||
config => {
|
||||
(config) => {
|
||||
const updateUrl = requiredLink(config, "update");
|
||||
return apiClient.put(updateUrl, config, "application/vnd.scmm-config+json;v=2");
|
||||
},
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("config")
|
||||
onSuccess: () => queryClient.invalidateQueries("config"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
@@ -51,6 +51,6 @@ export const useUpdateConfig = () => {
|
||||
isLoading,
|
||||
error,
|
||||
isUpdated: !!data,
|
||||
reset
|
||||
reset,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -50,26 +50,25 @@ describe("Test diff", () => {
|
||||
content: "0",
|
||||
type: "insert",
|
||||
lineNumber: 1,
|
||||
isInsert: true
|
||||
}
|
||||
]
|
||||
}
|
||||
isInsert: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
_links: {
|
||||
lines: {
|
||||
href:
|
||||
"/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
||||
templated: true
|
||||
}
|
||||
}
|
||||
}
|
||||
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
||||
templated: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
partial: false,
|
||||
_links: {
|
||||
self: {
|
||||
href: "/api/v2/diff"
|
||||
}
|
||||
}
|
||||
href: "/api/v2/diff",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const partialDiff1: Diff = {
|
||||
@@ -93,29 +92,28 @@ describe("Test diff", () => {
|
||||
content: "0",
|
||||
type: "insert",
|
||||
lineNumber: 1,
|
||||
isInsert: true
|
||||
}
|
||||
]
|
||||
}
|
||||
isInsert: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
_links: {
|
||||
lines: {
|
||||
href:
|
||||
"/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
||||
templated: true
|
||||
}
|
||||
}
|
||||
}
|
||||
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/0.txt?start={start}&end={end}",
|
||||
templated: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
partial: true,
|
||||
_links: {
|
||||
self: {
|
||||
href: "/diff"
|
||||
href: "/diff",
|
||||
},
|
||||
next: {
|
||||
href: "/diff?offset=1&limit=1"
|
||||
}
|
||||
}
|
||||
href: "/diff?offset=1&limit=1",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const partialDiff2: Diff = {
|
||||
@@ -139,26 +137,25 @@ describe("Test diff", () => {
|
||||
content: "1",
|
||||
type: "insert",
|
||||
lineNumber: 1,
|
||||
isInsert: true
|
||||
}
|
||||
]
|
||||
}
|
||||
isInsert: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
_links: {
|
||||
lines: {
|
||||
href:
|
||||
"/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/1.txt?start={start}&end={end}",
|
||||
templated: true
|
||||
}
|
||||
}
|
||||
}
|
||||
href: "/api/v2/repositories/scmadmin/HeartOfGold-git/content/one_to_onehundred/1.txt?start={start}&end={end}",
|
||||
templated: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
partial: false,
|
||||
_links: {
|
||||
self: {
|
||||
href: "/diff"
|
||||
}
|
||||
}
|
||||
href: "/diff",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -168,10 +165,10 @@ describe("Test diff", () => {
|
||||
it("should return simple parsed diff", async () => {
|
||||
fetchMock.getOnce("/api/v2/diff", {
|
||||
body: simpleDiff,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" }
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff"), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(simpleDiff);
|
||||
@@ -188,10 +185,10 @@ describe("Test diff", () => {
|
||||
+i am new!
|
||||
\\ No newline at end of file
|
||||
`,
|
||||
headers: { "Content-Type": "text/plain" }
|
||||
headers: { "Content-Type": "text/plain" },
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff"), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data?.files).toHaveLength(1);
|
||||
@@ -200,14 +197,14 @@ describe("Test diff", () => {
|
||||
it("should return parsed diff in multiple chunks", async () => {
|
||||
fetchMock.getOnce("/api/v2/diff?limit=1", {
|
||||
body: partialDiff1,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" }
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
||||
});
|
||||
fetchMock.getOnce("/api/v2/diff?offset=1&limit=1", {
|
||||
body: partialDiff2,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" }
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
||||
});
|
||||
const { result, waitFor, waitForNextUpdate } = renderHook(() => useDiff("/diff?limit=1"), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(partialDiff1);
|
||||
@@ -226,10 +223,10 @@ describe("Test diff", () => {
|
||||
it("should append query parameters to url which has already query params", async () => {
|
||||
fetchMock.getOnce("/api/v2/diff?format=GIT&limit=25", {
|
||||
body: simpleDiff,
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" }
|
||||
headers: { "Content-Type": "application/vnd.scmm-diffparsed+json;v=2" },
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useDiff("/diff?format=GIT", { limit: 25 }), {
|
||||
wrapper: createWrapper()
|
||||
wrapper: createWrapper(),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(simpleDiff);
|
||||
|
||||
@@ -32,10 +32,10 @@ describe("test createBackendError", () => {
|
||||
context: [
|
||||
{
|
||||
type: "planet",
|
||||
id: "earth"
|
||||
}
|
||||
id: "earth",
|
||||
},
|
||||
],
|
||||
violations: []
|
||||
violations: [],
|
||||
};
|
||||
|
||||
it("should return a default backend error", () => {
|
||||
|
||||
@@ -40,21 +40,21 @@ describe("Test group hooks", () => {
|
||||
type: "xml",
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/groups/jedis"
|
||||
href: "/groups/jedis",
|
||||
},
|
||||
update: {
|
||||
href: "/groups/jedis"
|
||||
}
|
||||
href: "/groups/jedis",
|
||||
},
|
||||
},
|
||||
_embedded: {
|
||||
members: []
|
||||
}
|
||||
members: [],
|
||||
},
|
||||
};
|
||||
|
||||
const jedisCollection = {
|
||||
_embedded: {
|
||||
groups: [jedis]
|
||||
}
|
||||
groups: [jedis],
|
||||
},
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -67,7 +67,7 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
fetchMock.get("/api/v2/groups", jedisCollection);
|
||||
const { result, waitFor } = renderHook(() => useGroups(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(jedisCollection);
|
||||
@@ -78,11 +78,11 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
fetchMock.get("/api/v2/groups", jedisCollection, {
|
||||
query: {
|
||||
page: "42"
|
||||
}
|
||||
page: "42",
|
||||
},
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useGroups({ page: 42 }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(jedisCollection);
|
||||
@@ -93,11 +93,11 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
fetchMock.get("/api/v2/groups", jedisCollection, {
|
||||
query: {
|
||||
q: "jedis"
|
||||
}
|
||||
q: "jedis",
|
||||
},
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useGroups({ search: "jedis" }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(jedisCollection);
|
||||
@@ -108,7 +108,7 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
fetchMock.get("/api/v2/groups", jedisCollection);
|
||||
const { result, waitFor } = renderHook(() => useGroups(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(queryClient.getQueryData(["group", "jedis"])).toEqual(jedis);
|
||||
@@ -121,7 +121,7 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
fetchMock.get("/api/v2/groups/jedis", jedis);
|
||||
const { result, waitFor } = renderHook(() => useGroup("jedis"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(jedis);
|
||||
@@ -136,14 +136,14 @@ describe("Test group hooks", () => {
|
||||
fetchMock.postOnce("/api/v2/groups", {
|
||||
status: 201,
|
||||
headers: {
|
||||
Location: "/groups/jedis"
|
||||
}
|
||||
Location: "/groups/jedis",
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/groups/jedis", jedis);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateGroup(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -160,13 +160,13 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
|
||||
fetchMock.postOnce("/api/v2/groups", {
|
||||
status: 201
|
||||
status: 201,
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/groups/jedis", jedis);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateGroup(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -185,11 +185,11 @@ describe("Test group hooks", () => {
|
||||
setIndexLink(queryClient, "groups", "/groups");
|
||||
|
||||
fetchMock.deleteOnce("/api/v2/groups/jedis", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useDeleteGroup(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -212,17 +212,17 @@ describe("Test group hooks", () => {
|
||||
|
||||
const newJedis = {
|
||||
...jedis,
|
||||
description: "may the 4th be with you"
|
||||
description: "may the 4th be with you",
|
||||
};
|
||||
|
||||
fetchMock.putOnce("/api/v2/groups/jedis", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/groups/jedis", newJedis);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useUpdateGroup(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
|
||||
@@ -29,9 +29,9 @@ describe("requireLink tests", () => {
|
||||
{
|
||||
_links: {
|
||||
spaceship: {
|
||||
href: "/v2/ship"
|
||||
}
|
||||
}
|
||||
href: "/v2/ship",
|
||||
},
|
||||
},
|
||||
},
|
||||
"spaceship"
|
||||
);
|
||||
@@ -49,14 +49,14 @@ describe("requireLink tests", () => {
|
||||
spaceship: [
|
||||
{
|
||||
name: "one",
|
||||
href: "/v2/one"
|
||||
href: "/v2/one",
|
||||
},
|
||||
{
|
||||
name: "two",
|
||||
href: "/v2/two"
|
||||
}
|
||||
]
|
||||
}
|
||||
href: "/v2/two",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() => requiredLink(object, "spaceship")).toThrowError();
|
||||
});
|
||||
@@ -67,14 +67,14 @@ describe("requireLink tests", () => {
|
||||
spaceship: [
|
||||
{
|
||||
name: "one",
|
||||
href: "/v2/one"
|
||||
href: "/v2/one",
|
||||
},
|
||||
{
|
||||
name: "two",
|
||||
href: "/v2/two"
|
||||
}
|
||||
]
|
||||
}
|
||||
href: "/v2/two",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(requiredLink(object, "spaceship", "one")).toBe("/v2/one");
|
||||
});
|
||||
@@ -85,14 +85,14 @@ describe("requireLink tests", () => {
|
||||
spaceship: [
|
||||
{
|
||||
name: "one",
|
||||
href: "/v2/one"
|
||||
href: "/v2/one",
|
||||
},
|
||||
{
|
||||
name: "two",
|
||||
href: "/v2/two"
|
||||
}
|
||||
]
|
||||
}
|
||||
href: "/v2/two",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(() => requiredLink(object, "spaceship", "three")).toThrowError();
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ describe("Test login hooks", () => {
|
||||
name: "tricia",
|
||||
displayName: "Tricia",
|
||||
groups: [],
|
||||
_links: {}
|
||||
_links: {},
|
||||
};
|
||||
|
||||
describe("useMe tests", () => {
|
||||
@@ -45,7 +45,7 @@ describe("Test login hooks", () => {
|
||||
name: "tricia",
|
||||
displayName: "Tricia",
|
||||
groups: [],
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
|
||||
it("should return me", async () => {
|
||||
@@ -65,9 +65,9 @@ describe("Test login hooks", () => {
|
||||
|
||||
let me: Me;
|
||||
const context: LegacyContext = {
|
||||
onMeFetched: fetchedMe => {
|
||||
onMeFetched: (fetchedMe) => {
|
||||
me = fetchedMe;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const { result, waitFor } = renderHook(() => useMe(), { wrapper: createWrapper(context, queryClient) });
|
||||
@@ -130,7 +130,7 @@ describe("Test login hooks", () => {
|
||||
name: "_anonymous",
|
||||
displayName: "Anonymous",
|
||||
groups: [],
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
const { result } = renderHook(() => useSubject(), { wrapper: createWrapper(undefined, queryClient) });
|
||||
|
||||
@@ -158,8 +158,8 @@ describe("Test login hooks", () => {
|
||||
cookie: true,
|
||||
grant_type: "password",
|
||||
username: "tricia",
|
||||
password: "hitchhikersSecret!"
|
||||
}
|
||||
password: "hitchhikersSecret!",
|
||||
},
|
||||
});
|
||||
|
||||
// required because we invalidate the whole cache and react-query refetches the index
|
||||
@@ -167,13 +167,13 @@ describe("Test login hooks", () => {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
login: {
|
||||
href: "/second/login"
|
||||
}
|
||||
}
|
||||
href: "/second/login",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useLogin(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
const { login } = result.current;
|
||||
expect(login).toBeDefined();
|
||||
@@ -194,7 +194,7 @@ describe("Test login hooks", () => {
|
||||
queryClient.setQueryData("me", tricia);
|
||||
|
||||
const { result } = renderHook(() => useLogin(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
expect(result.current.login).toBeUndefined();
|
||||
@@ -209,7 +209,7 @@ describe("Test login hooks", () => {
|
||||
fetchMock.deleteOnce("/api/v2/logout", {});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useLogout(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
const { logout } = result.current;
|
||||
expect(logout).toBeDefined();
|
||||
@@ -229,7 +229,7 @@ describe("Test login hooks", () => {
|
||||
setEmptyIndex(queryClient);
|
||||
|
||||
const { result } = renderHook(() => useLogout(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
const { logout } = result.current;
|
||||
|
||||
@@ -32,13 +32,13 @@ import { useReset } from "./reset";
|
||||
export const useMe = (): ApiResult<Me> => {
|
||||
const legacy = useLegacyContext();
|
||||
const link = useIndexLink("me");
|
||||
return useQuery<Me, Error>("me", () => apiClient.get(link!).then(response => response.json()), {
|
||||
return useQuery<Me, Error>("me", () => apiClient.get(link!).then((response) => response.json()), {
|
||||
enabled: !!link,
|
||||
onSuccess: me => {
|
||||
onSuccess: (me) => {
|
||||
if (legacy.onMeFetched) {
|
||||
legacy.onMeFetched(me);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ export const useSubject = () => {
|
||||
isAnonymous,
|
||||
isLoading,
|
||||
error,
|
||||
me
|
||||
me,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -75,9 +75,9 @@ export const useLogin = () => {
|
||||
const link = useIndexLink("login");
|
||||
const reset = useReset();
|
||||
const { mutate, isLoading, error } = useMutation<unknown, Error, Credentials>(
|
||||
credentials => apiClient.post(link!, credentials),
|
||||
(credentials) => apiClient.post(link!, credentials),
|
||||
{
|
||||
onSuccess: reset
|
||||
onSuccess: reset,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -91,7 +91,7 @@ export const useLogin = () => {
|
||||
return {
|
||||
login: link ? login : undefined,
|
||||
isLoading,
|
||||
error
|
||||
error,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -104,14 +104,14 @@ export const useLogout = () => {
|
||||
const reset = useReset();
|
||||
|
||||
const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(
|
||||
() => apiClient.delete(link!).then(r => (r.status === 200 ? r.json() : {})),
|
||||
() => apiClient.delete(link!).then((r) => (r.status === 200 ? r.json() : {})),
|
||||
{
|
||||
onSuccess: response => {
|
||||
onSuccess: (response) => {
|
||||
if (response?.logoutRedirect) {
|
||||
window.location.assign(response.logoutRedirect);
|
||||
}
|
||||
return reset();
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -122,6 +122,6 @@ export const useLogout = () => {
|
||||
return {
|
||||
logout: link && !data ? logout : undefined,
|
||||
isLoading,
|
||||
error
|
||||
error,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -38,14 +38,14 @@ describe("Test namespace hooks", () => {
|
||||
namespaces: [
|
||||
{
|
||||
namespace: "spaceships",
|
||||
_links: {}
|
||||
}
|
||||
]
|
||||
}
|
||||
_links: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const { result, waitFor } = renderHook(() => useNamespaces(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
@@ -61,11 +61,11 @@ describe("Test namespace hooks", () => {
|
||||
fetchMock.get("/api/v2/ns", {
|
||||
current: "awesome",
|
||||
available: [],
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
|
||||
const { result, waitFor } = renderHook(() => useNamespaceStrategies(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
@@ -80,11 +80,11 @@ describe("Test namespace hooks", () => {
|
||||
setIndexLink(queryClient, "namespaces", "/ns");
|
||||
fetchMock.get("/api/v2/ns/awesome", {
|
||||
namespace: "awesome",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
|
||||
const { result, waitFor } = renderHook(() => useNamespace("awesome"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
|
||||
@@ -34,7 +34,7 @@ export const useNamespaces = () => {
|
||||
export const useNamespace = (name: string): ApiResult<Namespace> => {
|
||||
const namespacesLink = useRequiredIndexLink("namespaces");
|
||||
return useQuery<Namespace, Error>(["namespace", name], () =>
|
||||
apiClient.get(concat(namespacesLink, name)).then(response => response.json())
|
||||
apiClient.get(concat(namespacesLink, name)).then((response) => response.json())
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -40,26 +40,28 @@ const waitForRestartAfter = (
|
||||
const endTime = Number(new Date()) + 60000;
|
||||
let started = false;
|
||||
|
||||
const executor = <T = any>(data: T) => (resolve: (result: T) => void, reject: (error: Error) => void) => {
|
||||
// we need some initial delay
|
||||
if (!started) {
|
||||
started = true;
|
||||
setTimeout(executor(data), initialDelay, resolve, reject);
|
||||
} else {
|
||||
apiClient
|
||||
.get("")
|
||||
.then(() => resolve(data))
|
||||
.catch(() => {
|
||||
if (Number(new Date()) < endTime) {
|
||||
setTimeout(executor(data), timeout, resolve, reject);
|
||||
} else {
|
||||
reject(new Error("timeout reached"));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
const executor =
|
||||
<T = any>(data: T) =>
|
||||
(resolve: (result: T) => void, reject: (error: Error) => void) => {
|
||||
// we need some initial delay
|
||||
if (!started) {
|
||||
started = true;
|
||||
setTimeout(executor(data), initialDelay, resolve, reject);
|
||||
} else {
|
||||
apiClient
|
||||
.get("")
|
||||
.then(() => resolve(data))
|
||||
.catch(() => {
|
||||
if (Number(new Date()) < endTime) {
|
||||
setTimeout(executor(data), timeout, resolve, reject);
|
||||
} else {
|
||||
reject(new Error("timeout reached"));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return promise.then(data => new Promise<void>(executor(data)));
|
||||
return promise.then((data) => new Promise<void>(executor(data)));
|
||||
};
|
||||
|
||||
export type UseAvailablePluginsOptions = {
|
||||
@@ -70,10 +72,10 @@ export const useAvailablePlugins = ({ enabled }: UseAvailablePluginsOptions = {}
|
||||
const indexLink = useRequiredIndexLink("availablePlugins");
|
||||
return useQuery<PluginCollection, Error>(
|
||||
["plugins", "available"],
|
||||
() => apiClient.get(indexLink).then(response => response.json()),
|
||||
() => apiClient.get(indexLink).then((response) => response.json()),
|
||||
{
|
||||
enabled,
|
||||
retry: 3
|
||||
retry: 3,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -86,10 +88,10 @@ export const useInstalledPlugins = ({ enabled }: UseInstalledPluginsOptions = {}
|
||||
const indexLink = useRequiredIndexLink("installedPlugins");
|
||||
return useQuery<PluginCollection, Error>(
|
||||
["plugins", "installed"],
|
||||
() => apiClient.get(indexLink).then(response => response.json()),
|
||||
() => apiClient.get(indexLink).then((response) => response.json()),
|
||||
{
|
||||
enabled,
|
||||
retry: 3
|
||||
retry: 3,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -98,10 +100,10 @@ export const usePendingPlugins = (): ApiResult<PendingPlugins> => {
|
||||
const indexLink = useIndexLink("pendingPlugins");
|
||||
return useQuery<PendingPlugins, Error>(
|
||||
["plugins", "pending"],
|
||||
() => apiClient.get(indexLink!).then(response => response.json()),
|
||||
() => apiClient.get(indexLink!).then((response) => response.json()),
|
||||
{
|
||||
enabled: !!indexLink,
|
||||
retry: 3
|
||||
retry: 3,
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -133,19 +135,19 @@ export const useInstallPlugin = () => {
|
||||
return promise;
|
||||
},
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins")
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
install: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
|
||||
mutate({
|
||||
plugin,
|
||||
restartOptions
|
||||
restartOptions,
|
||||
}),
|
||||
isLoading,
|
||||
error,
|
||||
data,
|
||||
isInstalled: !!data
|
||||
isInstalled: !!data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -160,18 +162,18 @@ export const useUninstallPlugin = () => {
|
||||
return promise;
|
||||
},
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins")
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
uninstall: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
|
||||
mutate({
|
||||
plugin,
|
||||
restartOptions
|
||||
restartOptions,
|
||||
}),
|
||||
isLoading,
|
||||
error,
|
||||
isUninstalled: !!data
|
||||
isUninstalled: !!data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -194,18 +196,18 @@ export const useUpdatePlugins = () => {
|
||||
return promise;
|
||||
},
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins")
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
update: (plugin: Plugin | PluginCollection, restartOptions: RestartOptions = {}) =>
|
||||
mutate({
|
||||
plugins: plugin,
|
||||
restartOptions
|
||||
restartOptions,
|
||||
}),
|
||||
isLoading,
|
||||
error,
|
||||
isUpdated: !!data
|
||||
isUpdated: !!data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -220,7 +222,7 @@ export const useExecutePendingPlugins = () => {
|
||||
({ pending, restartOptions }) =>
|
||||
waitForRestartAfter(apiClient.post(requiredLink(pending, "execute")), restartOptions),
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins")
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
@@ -228,22 +230,22 @@ export const useExecutePendingPlugins = () => {
|
||||
mutate({ pending, restartOptions }),
|
||||
isLoading,
|
||||
error,
|
||||
isExecuted: !!data
|
||||
isExecuted: !!data,
|
||||
};
|
||||
};
|
||||
|
||||
export const useCancelPendingPlugins = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { mutate, isLoading, error, data } = useMutation<unknown, Error, PendingPlugins>(
|
||||
pending => apiClient.post(requiredLink(pending, "cancel")),
|
||||
(pending) => apiClient.post(requiredLink(pending, "cancel")),
|
||||
{
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins")
|
||||
onSuccess: () => queryClient.invalidateQueries("plugins"),
|
||||
}
|
||||
);
|
||||
return {
|
||||
update: (pending: PendingPlugins) => mutate(pending),
|
||||
isLoading,
|
||||
error,
|
||||
isCancelled: !!data
|
||||
isCancelled: !!data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -32,8 +32,9 @@ import { act } from "react-test-renderer";
|
||||
import {
|
||||
useCreateRepositoryRole,
|
||||
useDeleteRepositoryRole,
|
||||
useRepositoryRole, useRepositoryRoles,
|
||||
useUpdateRepositoryRole
|
||||
useRepositoryRole,
|
||||
useRepositoryRoles,
|
||||
useUpdateRepositoryRole,
|
||||
} from "./repository-roles";
|
||||
|
||||
describe("Test repository-roles hooks", () => {
|
||||
@@ -43,12 +44,12 @@ describe("Test repository-roles hooks", () => {
|
||||
verbs: ["rocking"],
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/repositoryRoles/theroleingstones"
|
||||
href: "/repositoryRoles/theroleingstones",
|
||||
},
|
||||
update: {
|
||||
href: "/repositoryRoles/theroleingstones"
|
||||
}
|
||||
}
|
||||
href: "/repositoryRoles/theroleingstones",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const roleCollection: RepositoryRoleCollection = {
|
||||
@@ -56,8 +57,8 @@ describe("Test repository-roles hooks", () => {
|
||||
pageTotal: 0,
|
||||
_links: {},
|
||||
_embedded: {
|
||||
repositoryRoles: [role]
|
||||
}
|
||||
repositoryRoles: [role],
|
||||
},
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -70,7 +71,7 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
fetchMock.get("/api/v2/repositoryRoles", roleCollection);
|
||||
const { result, waitFor } = renderHook(() => useRepositoryRoles(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(roleCollection);
|
||||
@@ -81,11 +82,11 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
fetchMock.get("/api/v2/repositoryRoles", roleCollection, {
|
||||
query: {
|
||||
page: "42"
|
||||
}
|
||||
page: "42",
|
||||
},
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useRepositoryRoles({ page: 42 }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(roleCollection);
|
||||
@@ -96,7 +97,7 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
fetchMock.get("/api/v2/repositoryRoles", roleCollection);
|
||||
const { result, waitFor } = renderHook(() => useRepositoryRoles(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(queryClient.getQueryData(["repositoryRole", roleName])).toEqual(role);
|
||||
@@ -109,7 +110,7 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
fetchMock.get("/api/v2/repositoryRoles/" + roleName, role);
|
||||
const { result, waitFor } = renderHook(() => useRepositoryRole(roleName), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(role);
|
||||
@@ -124,14 +125,14 @@ describe("Test repository-roles hooks", () => {
|
||||
fetchMock.postOnce("/api/v2/repositoryRoles", {
|
||||
status: 201,
|
||||
headers: {
|
||||
Location: "/repositoryRoles/" + roleName
|
||||
}
|
||||
Location: "/repositoryRoles/" + roleName,
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/repositoryRoles/" + roleName, role);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateRepositoryRole(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -148,13 +149,13 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
|
||||
fetchMock.postOnce("/api/v2/repositoryRoles", {
|
||||
status: 201
|
||||
status: 201,
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/repositoryRoles/" + roleName, role);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateRepositoryRole(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -173,11 +174,11 @@ describe("Test repository-roles hooks", () => {
|
||||
setIndexLink(queryClient, "repositoryRoles", "/repositoryRoles");
|
||||
|
||||
fetchMock.deleteOnce("/api/v2/repositoryRoles/" + roleName, {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useDeleteRepositoryRole(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -200,15 +201,15 @@ describe("Test repository-roles hooks", () => {
|
||||
|
||||
const newRole: RepositoryRole = {
|
||||
...role,
|
||||
name: "newname"
|
||||
name: "newname",
|
||||
};
|
||||
|
||||
fetchMock.putOnce("/api/v2/repositoryRoles/" + roleName, {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useUpdateRepositoryRole(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
|
||||
@@ -25,7 +25,7 @@ import { QueryClient, useQueryClient } from "react-query";
|
||||
|
||||
export const reset = (queryClient: QueryClient) => {
|
||||
queryClient.removeQueries({
|
||||
predicate: ({ queryKey }) => queryKey !== "index"
|
||||
predicate: ({ queryKey }) => queryKey !== "index",
|
||||
});
|
||||
return queryClient.invalidateQueries("index");
|
||||
};
|
||||
|
||||
@@ -35,9 +35,9 @@ describe("Test sources hooks", () => {
|
||||
type: "git",
|
||||
_links: {
|
||||
sources: {
|
||||
href: "/src"
|
||||
}
|
||||
}
|
||||
href: "/src",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const readmeMd: File = {
|
||||
@@ -49,8 +49,8 @@ describe("Test sources hooks", () => {
|
||||
description: "Awesome readme",
|
||||
_links: {},
|
||||
_embedded: {
|
||||
children: []
|
||||
}
|
||||
children: [],
|
||||
},
|
||||
};
|
||||
|
||||
const rootDirectory: File = {
|
||||
@@ -60,8 +60,8 @@ describe("Test sources hooks", () => {
|
||||
revision: "abc",
|
||||
_links: {},
|
||||
_embedded: {
|
||||
children: [readmeMd]
|
||||
}
|
||||
children: [readmeMd],
|
||||
},
|
||||
};
|
||||
|
||||
const sepecialMd: File = {
|
||||
@@ -73,20 +73,20 @@ describe("Test sources hooks", () => {
|
||||
description: "Awesome special file",
|
||||
_links: {},
|
||||
_embedded: {
|
||||
children: []
|
||||
}
|
||||
children: [],
|
||||
},
|
||||
};
|
||||
|
||||
const sepecialMdPartial: File = {
|
||||
...sepecialMd,
|
||||
partialResult: true,
|
||||
computationAborted: false
|
||||
computationAborted: false,
|
||||
};
|
||||
|
||||
const sepecialMdComputationAborted: File = {
|
||||
...sepecialMd,
|
||||
partialResult: true,
|
||||
computationAborted: true
|
||||
computationAborted: true,
|
||||
};
|
||||
|
||||
const mainDirectoryTruncated: File = {
|
||||
@@ -97,20 +97,20 @@ describe("Test sources hooks", () => {
|
||||
truncated: true,
|
||||
_links: {
|
||||
proceed: {
|
||||
href: "src/2"
|
||||
}
|
||||
href: "src/2",
|
||||
},
|
||||
},
|
||||
_embedded: {
|
||||
children: []
|
||||
}
|
||||
children: [],
|
||||
},
|
||||
};
|
||||
|
||||
const mainDirectory: File = {
|
||||
...mainDirectoryTruncated,
|
||||
truncated: false,
|
||||
_embedded: {
|
||||
children: [sepecialMd]
|
||||
}
|
||||
children: [sepecialMd],
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -128,7 +128,7 @@ describe("Test sources hooks", () => {
|
||||
const queryClient = createInfiniteCachingClient();
|
||||
fetchMock.getOnce("/api/v2/src", rootDirectory);
|
||||
const { result, waitFor } = renderHook(() => useSources(puzzle42), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(rootDirectory);
|
||||
@@ -138,7 +138,7 @@ describe("Test sources hooks", () => {
|
||||
const queryClient = createInfiniteCachingClient();
|
||||
fetchMock.getOnce("/api/v2/src/abc/README.md", readmeMd);
|
||||
const { result, waitFor } = renderHook(() => useSources(puzzle42, { revision: "abc", path: "README.md" }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(readmeMd);
|
||||
@@ -149,7 +149,7 @@ describe("Test sources hooks", () => {
|
||||
fetchMock.getOnce("/api/v2/src", mainDirectoryTruncated);
|
||||
fetchMock.getOnce("/api/v2/src/2", mainDirectory);
|
||||
const { result, waitFor, waitForNextUpdate } = renderHook(() => useSources(puzzle42), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
|
||||
@@ -172,11 +172,11 @@ describe("Test sources hooks", () => {
|
||||
{
|
||||
...mainDirectory,
|
||||
_embedded: {
|
||||
children: [sepecialMdPartial]
|
||||
}
|
||||
children: [sepecialMdPartial],
|
||||
},
|
||||
},
|
||||
{
|
||||
repeat: 1
|
||||
repeat: 1,
|
||||
}
|
||||
);
|
||||
fetchMock.get(
|
||||
@@ -184,17 +184,17 @@ describe("Test sources hooks", () => {
|
||||
{
|
||||
...mainDirectory,
|
||||
_embedded: {
|
||||
children: [sepecialMd]
|
||||
}
|
||||
children: [sepecialMd],
|
||||
},
|
||||
},
|
||||
{
|
||||
repeat: 1,
|
||||
overwriteRoutes: false
|
||||
overwriteRoutes: false,
|
||||
}
|
||||
);
|
||||
|
||||
const { result, waitFor } = renderHook(() => useSources(puzzle42, { refetchPartialInterval: 100 }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await waitFor(() => !!firstChild(result.current.data));
|
||||
@@ -210,23 +210,23 @@ describe("Test sources hooks", () => {
|
||||
// should never be called
|
||||
fetchMock.getOnce("/api/v2/src/abc/main/special.md", sepecialMd, {
|
||||
repeat: 1,
|
||||
overwriteRoutes: false
|
||||
overwriteRoutes: false,
|
||||
});
|
||||
const { result, waitFor } = renderHook(
|
||||
() =>
|
||||
useSources(puzzle42, {
|
||||
revision: "abc",
|
||||
path: "main/special.md",
|
||||
refetchPartialInterval: 100
|
||||
refetchPartialInterval: 100,
|
||||
}),
|
||||
{
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
}
|
||||
);
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(sepecialMdComputationAborted);
|
||||
|
||||
await new Promise(r => setTimeout(r, 200));
|
||||
await new Promise((r) => setTimeout(r, 200));
|
||||
expect(result.current.data).toEqual(sepecialMdComputationAborted);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,25 +37,25 @@ export type UseSourcesOptions = {
|
||||
|
||||
const UseSourcesDefaultOptions: UseSourcesOptions = {
|
||||
enabled: true,
|
||||
refetchPartialInterval: 3000
|
||||
refetchPartialInterval: 3000,
|
||||
};
|
||||
|
||||
export const useSources = (repository: Repository, opts: UseSourcesOptions = UseSourcesDefaultOptions) => {
|
||||
const options = {
|
||||
...UseSourcesDefaultOptions,
|
||||
...opts
|
||||
...opts,
|
||||
};
|
||||
const link = createSourcesLink(repository, options);
|
||||
const { isLoading, error, data, isFetchingNextPage, fetchNextPage, refetch } = useInfiniteQuery<File, Error, File>(
|
||||
repoQueryKey(repository, "sources", options.revision || "", options.path || ""),
|
||||
({ pageParam }) => {
|
||||
return apiClient.get(pageParam || link).then(response => response.json());
|
||||
return apiClient.get(pageParam || link).then((response) => response.json());
|
||||
},
|
||||
{
|
||||
enabled: options.enabled,
|
||||
getNextPageParam: lastPage => {
|
||||
getNextPageParam: (lastPage) => {
|
||||
return (lastPage._links.proceed as Link)?.href;
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ export const useSources = (repository: Repository, opts: UseSourcesOptions = Use
|
||||
const intervalId = setInterval(() => {
|
||||
if (isPartial(file)) {
|
||||
refetch({
|
||||
throwOnError: true
|
||||
throwOnError: true,
|
||||
});
|
||||
}
|
||||
}, options.refetchPartialInterval);
|
||||
@@ -79,7 +79,7 @@ export const useSources = (repository: Repository, opts: UseSourcesOptions = Use
|
||||
fetchNextPage: () => {
|
||||
// wrapped because we do not want to leak react-query types in our api
|
||||
fetchNextPage();
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -108,8 +108,8 @@ const merge = (files?: File[]): File | undefined => {
|
||||
...lastPage,
|
||||
_embedded: {
|
||||
...lastPage._embedded,
|
||||
children
|
||||
}
|
||||
children,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ describe("Test Tag hooks", () => {
|
||||
type: "git",
|
||||
_links: {
|
||||
tags: {
|
||||
href: "/hog/tags"
|
||||
}
|
||||
}
|
||||
href: "/hog/tags",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const changeset: Changeset = {
|
||||
@@ -46,14 +46,14 @@ describe("Test Tag hooks", () => {
|
||||
description: "Awesome change",
|
||||
date: new Date(),
|
||||
author: {
|
||||
name: "Arthur Dent"
|
||||
name: "Arthur Dent",
|
||||
},
|
||||
_embedded: {},
|
||||
_links: {
|
||||
tag: {
|
||||
href: "/hog/tag"
|
||||
}
|
||||
}
|
||||
href: "/hog/tag",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const tagOneDotZero = {
|
||||
@@ -61,17 +61,17 @@ describe("Test Tag hooks", () => {
|
||||
revision: "42",
|
||||
signatures: [],
|
||||
_links: {
|
||||
"delete": {
|
||||
href: "/hog/tags/1.0"
|
||||
}
|
||||
}
|
||||
delete: {
|
||||
href: "/hog/tags/1.0",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const tags: TagCollection = {
|
||||
_embedded: {
|
||||
tags: [tagOneDotZero]
|
||||
tags: [tagOneDotZero],
|
||||
},
|
||||
_links: {}
|
||||
_links: {},
|
||||
};
|
||||
|
||||
const queryClient = createInfiniteCachingClient();
|
||||
@@ -87,7 +87,7 @@ describe("Test Tag hooks", () => {
|
||||
fetchMock.getOnce("/api/v2/hog/tags", tags);
|
||||
|
||||
const { result, waitFor } = renderHook(() => useTags(repository), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
@@ -114,7 +114,7 @@ describe("Test Tag hooks", () => {
|
||||
fetchMock.getOnce("/api/v2/hog/tags/1.0", tagOneDotZero);
|
||||
|
||||
const { result, waitFor } = renderHook(() => useTag(repository, "1.0"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => {
|
||||
return !!result.current.data;
|
||||
@@ -141,14 +141,14 @@ describe("Test Tag hooks", () => {
|
||||
fetchMock.postOnce("/api/v2/hog/tag", {
|
||||
status: 201,
|
||||
headers: {
|
||||
Location: "/hog/tags/1.0"
|
||||
}
|
||||
Location: "/hog/tags/1.0",
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/hog/tags/1.0", tagOneDotZero);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateTag(repository, changeset), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -195,11 +195,11 @@ describe("Test Tag hooks", () => {
|
||||
|
||||
it("should fail without location header", async () => {
|
||||
fetchMock.postOnce("/api/v2/hog/tag", {
|
||||
status: 201
|
||||
status: 201,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateTag(repository, changeset), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -215,11 +215,11 @@ describe("Test Tag hooks", () => {
|
||||
describe("useDeleteTags tests", () => {
|
||||
const deleteTag = async () => {
|
||||
fetchMock.deleteOnce("/api/v2/hog/tags/1.0", {
|
||||
status: 204
|
||||
status: 204,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useDeleteTag(repository), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
|
||||
@@ -28,9 +28,9 @@ const createInfiniteCachingClient = () => {
|
||||
return new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: Infinity
|
||||
}
|
||||
}
|
||||
staleTime: Infinity,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -22,22 +22,22 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { QueryClient} from "react-query";
|
||||
import { QueryClient } from "react-query";
|
||||
|
||||
export const setIndexLink = (queryClient: QueryClient, name: string, href: string) => {
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z",
|
||||
_links: {
|
||||
[name]: {
|
||||
href: href
|
||||
}
|
||||
}
|
||||
href: href,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const setEmptyIndex = (queryClient: QueryClient) => {
|
||||
queryClient.setQueryData("index", {
|
||||
version: "x.y.z",
|
||||
_links: {}
|
||||
_links: {},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -22,12 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import {
|
||||
concat,
|
||||
getNamespaceAndPageFromMatch,
|
||||
getQueryStringFromLocation,
|
||||
withEndingSlash
|
||||
} from "./urls";
|
||||
import { concat, getNamespaceAndPageFromMatch, getQueryStringFromLocation, withEndingSlash } from "./urls";
|
||||
|
||||
describe("tests for withEndingSlash", () => {
|
||||
it("should append missing slash", () => {
|
||||
@@ -50,7 +45,7 @@ describe("concat tests", () => {
|
||||
describe("tests for getNamespaceAndPageFromMatch", () => {
|
||||
function createMatch(namespace?: string, page?: string) {
|
||||
return {
|
||||
params: { namespace, page }
|
||||
params: { namespace, page },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,7 +83,7 @@ describe("tests for getNamespaceAndPageFromMatch", () => {
|
||||
describe("tests for getQueryStringFromLocation", () => {
|
||||
function createLocation(search: string) {
|
||||
return {
|
||||
search
|
||||
search,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import {
|
||||
useDeleteUser,
|
||||
useUpdateUser,
|
||||
useUser,
|
||||
useUsers
|
||||
useUsers,
|
||||
} from "./users";
|
||||
|
||||
describe("Test user hooks", () => {
|
||||
@@ -48,21 +48,21 @@ describe("Test user hooks", () => {
|
||||
name: "yoda",
|
||||
_links: {
|
||||
delete: {
|
||||
href: "/users/yoda"
|
||||
href: "/users/yoda",
|
||||
},
|
||||
update: {
|
||||
href: "/users/yoda"
|
||||
href: "/users/yoda",
|
||||
},
|
||||
convertToInternal: {
|
||||
href: "/users/yoda/convertToInternal"
|
||||
href: "/users/yoda/convertToInternal",
|
||||
},
|
||||
convertToExternal: {
|
||||
href: "/users/yoda/convertToExternal"
|
||||
}
|
||||
href: "/users/yoda/convertToExternal",
|
||||
},
|
||||
},
|
||||
_embedded: {
|
||||
members: []
|
||||
}
|
||||
members: [],
|
||||
},
|
||||
};
|
||||
|
||||
const userCollection: UserCollection = {
|
||||
@@ -70,8 +70,8 @@ describe("Test user hooks", () => {
|
||||
page: 0,
|
||||
pageTotal: 0,
|
||||
_embedded: {
|
||||
users: [yoda]
|
||||
}
|
||||
users: [yoda],
|
||||
},
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
@@ -84,7 +84,7 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
fetchMock.get("/api/v2/users", userCollection);
|
||||
const { result, waitFor } = renderHook(() => useUsers(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(userCollection);
|
||||
@@ -95,11 +95,11 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
fetchMock.get("/api/v2/users", userCollection, {
|
||||
query: {
|
||||
page: "42"
|
||||
}
|
||||
page: "42",
|
||||
},
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useUsers({ page: 42 }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(userCollection);
|
||||
@@ -110,11 +110,11 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
fetchMock.get("/api/v2/users", userCollection, {
|
||||
query: {
|
||||
q: "yoda"
|
||||
}
|
||||
q: "yoda",
|
||||
},
|
||||
});
|
||||
const { result, waitFor } = renderHook(() => useUsers({ search: "yoda" }), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(userCollection);
|
||||
@@ -125,7 +125,7 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
fetchMock.get("/api/v2/users", userCollection);
|
||||
const { result, waitFor } = renderHook(() => useUsers(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(queryClient.getQueryData(["user", "yoda"])).toEqual(yoda);
|
||||
@@ -138,7 +138,7 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
fetchMock.get("/api/v2/users/yoda", yoda);
|
||||
const { result, waitFor } = renderHook(() => useUser("yoda"), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
await waitFor(() => !!result.current.data);
|
||||
expect(result.current.data).toEqual(yoda);
|
||||
@@ -153,14 +153,14 @@ describe("Test user hooks", () => {
|
||||
fetchMock.postOnce("/api/v2/users", {
|
||||
status: 201,
|
||||
headers: {
|
||||
Location: "/users/yoda"
|
||||
}
|
||||
Location: "/users/yoda",
|
||||
},
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/users/yoda", yoda);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateUser(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -177,13 +177,13 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
|
||||
fetchMock.postOnce("/api/v2/users", {
|
||||
status: 201
|
||||
status: 201,
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/users/yoda", yoda);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useCreateUser(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -202,11 +202,11 @@ describe("Test user hooks", () => {
|
||||
setIndexLink(queryClient, "users", "/users");
|
||||
|
||||
fetchMock.deleteOnce("/api/v2/users/yoda", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useDeleteUser(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -229,17 +229,17 @@ describe("Test user hooks", () => {
|
||||
|
||||
const newJedis = {
|
||||
...yoda,
|
||||
description: "may the 4th be with you"
|
||||
description: "may the 4th be with you",
|
||||
};
|
||||
|
||||
fetchMock.putOnce("/api/v2/users/yoda", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
fetchMock.getOnce("/api/v2/users/yoda", newJedis);
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useUpdateUser(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -261,11 +261,11 @@ describe("Test user hooks", () => {
|
||||
const queryClient = createInfiniteCachingClient();
|
||||
|
||||
fetchMock.putOnce("/api/v2/users/yoda/convertToInternal", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useConvertToInternal(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
@@ -287,11 +287,11 @@ describe("Test user hooks", () => {
|
||||
const queryClient = createInfiniteCachingClient();
|
||||
|
||||
fetchMock.putOnce("/api/v2/users/yoda/convertToExternal", {
|
||||
status: 200
|
||||
status: 200,
|
||||
});
|
||||
|
||||
const { result, waitForNextUpdate } = renderHook(() => useConvertToExternal(), {
|
||||
wrapper: createWrapper(undefined, queryClient)
|
||||
wrapper: createWrapper(undefined, queryClient),
|
||||
});
|
||||
|
||||
await act(() => {
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
export const createQueryString = (params: Record<string, string>) => {
|
||||
return Object.keys(params)
|
||||
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
|
||||
.map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
|
||||
.join("&");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user