Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type Handler<T = any> = {
url: string;
response?: T;
icebergResponse?: T;
headers?: HeadersInit;
statusText?: string;
type?: ResponseType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { screen, waitFor, waitForOptions } from '@testing-library/react';
import {
Matcher,
SelectorMatcherOptions,
screen,
waitFor,
waitForOptions as WaitForOptions,
} from '@testing-library/react';
import { WAIT_FOR_DEFAULT_OPTIONS } from './common.constants';

export const assertTextVisibility = async (text: string): Promise<void> =>
export const assertTextVisibility = async (
text: Matcher,
options?: SelectorMatcherOptions,
waitForOptions = WAIT_FOR_DEFAULT_OPTIONS,
): Promise<void> =>
waitFor(
() => expect(screen.getByText(text)).toBeVisible(),
WAIT_FOR_DEFAULT_OPTIONS,
() => expect(screen.getByText(text, options)).toBeVisible(),
waitForOptions,
);

export const assertElementVisibility = (
Expand All @@ -19,7 +29,7 @@ export const assertElementLabel = ({
}: {
element: HTMLElement;
label: string;
} & waitForOptions): Promise<void> =>
} & WaitForOptions): Promise<void> =>
waitFor(() => expect(element).toHaveAttribute('label', label), {
...WAIT_FOR_DEFAULT_OPTIONS,
...options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const toMswHandlers = (handlers: Handler[] = []): RequestHandler[] =>
delay: delayTime = 1000,
status = 200,
response,
icebergResponse,
responseText,
api = 'v6',
baseUrl,
Expand All @@ -30,10 +31,24 @@ export const toMswHandlers = (handlers: Handler[] = []): RequestHandler[] =>
if (responseText) {
return HttpResponse.text(responseText);
}
const json =
typeof response === 'function'
? await response(request, params, cookies)
: response;
const requestHeaders = new Headers(request?.headers);
const isIceberg =
requestHeaders.get('X-Pagination-Size') ||
requestHeaders.get('x-pagination-mode');

let json;
if (isIceberg && icebergResponse) {
json =
typeof icebergResponse === 'function'
? await icebergResponse(request, params, cookies)
: icebergResponse;
} else {
json =
typeof response === 'function'
? await response(request, params, cookies)
: response;
}

return HttpResponse.json(json, {
status,
headers,
Expand Down
Loading