Skip to content

Commit

Permalink
Removed some ts-ignores.
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed Jun 9, 2023
1 parent 0a8a29f commit 8568762
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const APP_ID = 'testAppId';
const LOCALSTORAGE_QUERY_PARAMS_KEY = getQueryParamsLocalStorageKey(APP_ID);
const LOCALSTORAGE_FILTER_OPTIONS_KEY = getFilterOptionsLocalStorageKey(APP_ID);

// @ts-ignore
const stringify = (parsedParams) => new URLSearchParams(parsedParams).toString();
const stringify = (parsedParams: Record<string, string>) =>
new URLSearchParams(parsedParams).toString();

describe('useAllCasesQueryParams', () => {
beforeEach(() => {
Expand Down Expand Up @@ -162,14 +162,14 @@ describe('useAllCasesQueryParams', () => {
};
const expectedUrl = { ...URL_DEFAULTS, ...nonDefaultUrlParams };

mockLocation.search = stringify(nonDefaultUrlParams);
mockLocation.search = stringify(nonDefaultUrlParams as unknown as Record<string, string>);

renderHook(() => useAllCasesState(), {
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
});

expect(useHistory().replace).toHaveBeenCalledWith({
search: stringify(expectedUrl),
search: stringify(expectedUrl as unknown as Record<string, string>),
});
});

Expand Down Expand Up @@ -209,7 +209,7 @@ describe('useAllCasesQueryParams', () => {
perPage: DEFAULT_TABLE_LIMIT + 5,
};

mockLocation.search = stringify(nonDefaultUrlParams);
mockLocation.search = stringify(nonDefaultUrlParams as unknown as Record<string, string>);

localStorage.setItem(
LOCALSTORAGE_QUERY_PARAMS_KEY,
Expand Down Expand Up @@ -261,14 +261,14 @@ describe('useAllCasesQueryParams', () => {
});

it('url perPage query param cannot be > 100', () => {
mockLocation.search = stringify({ perPage: 1000 });
mockLocation.search = stringify({ perPage: '1000' });

renderHook(() => useAllCasesState(), {
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
});

expect(useHistory().replace).toHaveBeenCalledWith({
search: stringify({ ...URL_DEFAULTS, perPage: 100 }),
search: 'perPage=100&page=1&sortField=createdAt&sortOrder=desc&severity=all&status=all',
});

mockLocation.search = '';
Expand All @@ -294,7 +294,7 @@ describe('useAllCasesQueryParams', () => {
});

expect(useHistory().replace).toHaveBeenCalledWith({
search: stringify({ ...URL_DEFAULTS }),
search: 'sortOrder=desc&page=1&perPage=10&sortField=createdAt&severity=all&status=all',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const getFilterOptionsLocalStorageKey = (appId: string) => {
return `${appId}.${filteringKey}`;
};

// @ts-ignore
const stringify = (parsedParams) => new URLSearchParams(parsedParams).toString();
const stringify = (parsedParams: Record<string, string>) =>
new URLSearchParams(parsedParams).toString();
const parse = (queryString: string) => Object.fromEntries(new URLSearchParams(queryString));

const getQueryParams = (
Expand Down Expand Up @@ -208,7 +208,10 @@ export function useAllCasesState(
try {
const newHistory = {
...location,
search: stringify({ ...parsedUrlParams, ...stateUrlParams }),
search: stringify({ ...parsedUrlParams, ...stateUrlParams } as unknown as Record<
string,
string
>),
};
history.replace(newHistory);
} catch {
Expand Down

0 comments on commit 8568762

Please sign in to comment.