From 77080849cba9f15f6569d062051aa6869852bf48 Mon Sep 17 00:00:00 2001 From: David Cho-Lerat Date: Tue, 31 Oct 2023 16:33:06 +0100 Subject: [PATCH] [NO JIRA] Fix some code smells on new code --- .../src/main/js/helpers/testSelector.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/server/sonar-web/src/main/js/helpers/testSelector.ts b/server/sonar-web/src/main/js/helpers/testSelector.ts index b4f8adcdf90..1e4b9af3dde 100644 --- a/server/sonar-web/src/main/js/helpers/testSelector.ts +++ b/server/sonar-web/src/main/js/helpers/testSelector.ts @@ -130,6 +130,10 @@ abstract class ChainingQuery implements ReactTestingQuery { byDisplayValue(...args: Parameters>): ReactTestingQuery { return this.by(new DispatchByDisplayValue(args)); } + + byTitle(...args: Parameters>): ReactTestingQuery { + return this.by(new DispatchByTitle(args)); + } } class ChainDispatch extends ChainingQuery { @@ -341,6 +345,45 @@ class DispatchByTestId extends ChainingQuery { } } +class DispatchByTitle extends ChainingQuery { + readonly args: Parameters>; + + constructor(args: Parameters>) { + super(); + this.args = args; + } + + find( + container?: HTMLElement, + waitForOptions?: waitForOptions, + ) { + return maybeScreen(container).findByTitle(...this.args, waitForOptions); + } + + findAll( + container?: HTMLElement, + waitForOptions?: waitForOptions, + ) { + return maybeScreen(container).findAllByTitle(...this.args, waitForOptions); + } + + get(container?: HTMLElement) { + return maybeScreen(container).getByTitle(...this.args); + } + + getAll(container?: HTMLElement) { + return maybeScreen(container).getAllByTitle(...this.args); + } + + query(container?: HTMLElement) { + return maybeScreen(container).queryByTitle(...this.args); + } + + queryAll(container?: HTMLElement) { + return maybeScreen(container).queryAllByTitle(...this.args); + } +} + class DispatchByDisplayValue extends ChainingQuery { readonly args: Parameters>; @@ -439,6 +482,10 @@ export function byTestId(...args: Parameters> return new DispatchByTestId(args); } +export function byTitle(...args: Parameters>) { + return new DispatchByTitle(args); +} + export function byDisplayValue(...args: Parameters>) { return new DispatchByDisplayValue(args); } -- 2.39.5