Skip to content

Commit

Permalink
added method-style rule for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
rsun19 committed Jun 3, 2024
1 parent 4aa0a8c commit be332ac
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 527 deletions.
1 change: 1 addition & 0 deletions frontend/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"always",
{ "exceptAfterSingleLine": false }
],
"@typescript-eslint/method-signature-style": "error",
"@typescript-eslint/naming-convention": [
"error",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,79 @@ declare global {
* @param url the URL to visit
* @param credentials login credentials
*/
visitWithLogin(
visitWithLogin: (
url: string,
credentials?: { username: string; password: string; provider?: string },
): Cypress.Chainable<void>;
) => Cypress.Chainable<void>;

/**
* Find a patternfly kebab toggle button.
*
* @param isDropdownToggle - True to indicate that it is a dropdown toggle instead of table kebab actions
*/
findKebab(isDropdownToggle?: boolean): Cypress.Chainable<JQuery>;
findKebab: (isDropdownToggle?: boolean) => Cypress.Chainable<JQuery>;

/**
* Finds a patternfly kebab toggle button, opens the menu, and finds the action.
*
* @param name the name of the action in the kebeb menu
* @param isDropdownToggle - True to indicate that it is a dropdown toggle instead of table kebab actions
*/
findKebabAction(name: string | RegExp, isDropdownToggle?: boolean): Cypress.Chainable<JQuery>;
findKebabAction: (
name: string | RegExp,
isDropdownToggle?: boolean,
) => Cypress.Chainable<JQuery>;

/**
* Finds a patternfly dropdown item by first opening the dropdown if not already opened.
*
* @param name the name of the item
*/
findDropdownItem(name: string | RegExp): Cypress.Chainable<JQuery>;
findDropdownItem: (name: string | RegExp) => Cypress.Chainable<JQuery>;

/**
* Finds a patternfly dropdown item by data-testid, first opening the dropdown if not already opened.
*
* @param testId the name of the item
*/
findDropdownItemByTestId(testId: string): Cypress.Chainable<JQuery>;
findDropdownItemByTestId: (testId: string) => Cypress.Chainable<JQuery>;
/**
* Finds a patternfly select option by first opening the select menu if not already opened.
*
* @param name the name of the option
*/
findSelectOption(name: string | RegExp): Cypress.Chainable<JQuery>;
findSelectOption: (name: string | RegExp) => Cypress.Chainable<JQuery>;

/**
* Shortcut to first clear the previous value and then type text into DOM element.
*
* @see https://on.cypress.io/type
*/
fill(
fill: (
text: string,
options?: Partial<Cypress.TypeOptions> | undefined,
): Cypress.Chainable<unknown>;
) => Cypress.Chainable<unknown>;

/**
* Returns a PF Switch label for clickable actions.
*
* @param dataId - the data test id you provided to the PF Switch
*/
pfSwitch(dataId: string): Cypress.Chainable<JQuery>;
pfSwitch: (dataId: string) => Cypress.Chainable<JQuery>;

/**
* Returns a PF Switch input behind the checkbox to compare .should('be.checked') like ops
*
* @param dataId
*/
pfSwitchValue(dataId: string): Cypress.Chainable<JQuery>;
pfSwitchValue: (dataId: string) => Cypress.Chainable<JQuery>;

/**
* The bottom two functions, findByTestId and findAllByTestId have the disabled rule
* method-signature-style because they are overwrites.
* Thus, we cannot change it to use the property signature for functions.
* https://typescript-eslint.io/rules/method-signature-style/
*/

/**
* Overwrite `findByTestId` to support an array of Matchers.
Expand All @@ -85,6 +95,7 @@ declare global {
* cy.findByTestId(['card', 'my-id']);
* cy.findByTestId('card my-id');
*/
// eslint-disable-next-line @typescript-eslint/method-signature-style
findByTestId(id: Matcher | Matcher[], options?: MatcherOptions): Chainable<JQuery>;

/**
Expand All @@ -97,6 +108,7 @@ declare global {
* cy.findAllByTestId(['card']);
* cy.findAllByTestId('card my-id');
*/
// eslint-disable-next-line @typescript-eslint/method-signature-style
findAllByTestId(id: Matcher | Matcher[], options?: MatcherOptions): Chainable<JQuery>;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'cypress-axe';
declare global {
namespace Cypress {
interface Chainable {
testA11y(context?: Parameters<cy['checkA11y']>[0]): void;
testA11y: (context?: Parameters<cy['checkA11y']>[0]) => void;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ declare global {
namespace Cypress {
interface Chainable {
interceptSnapshot: InterceptSnapshot;
waitSnapshot(alias: string): Chainable<Interception>;
readSnapshot(path: string): Cypress.Chainable<{ [key: string]: Snapshot }>;
waitSnapshot: (alias: string) => Chainable<Interception>;
readSnapshot: (path: string) => Cypress.Chainable<{ [key: string]: Snapshot }>;
}
}
}
Expand Down
55 changes: 27 additions & 28 deletions frontend/src/__tests__/cypress/cypress/support/commands/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ declare global {
* By default all the URL will include the namespace but not the name of the provided resource.
* This results in the default behavior tailored to listing resources.
*/
wsK8s<K extends K8sResourceCommon>(
wsK8s: <K extends K8sResourceCommon>(
type: 'ADDED' | 'DELETED' | 'MODIFIED',
modelOrOptions: K8sModelCommon | WsOptions,
resource: K,
): Cypress.Chainable<undefined>;
) => Cypress.Chainable<undefined>;

/**
* Simplified variant of equivalent function for GET method.
*/
interceptK8s<K extends K8sResourceCommon>(
interceptK8s: (<K extends K8sResourceCommon>(
modelOrOptions: K8sModelCommon | K8sOptions,
response?:
| K
Expand All @@ -53,29 +53,28 @@ declare global {
| string
| GenericStaticResponse<string, K | K8sStatus | Patch[] | string>
| RouteHandlerController,
): Chainable<null>;

/**
* Intercept command for K8s resource.
* Provides equivalent functionality to `cy.intercept` where the URL is constructed from the given model and options.
*
* The default URL will include the name and namespace extracted from the supplied resource.
* This can be overridden by supplying options.
*
* If a payload other than a K8s resource is supplied, ensure that the appropriate options include the resource
* name and namespace, if required.
*/
interceptK8s<K extends K8sResourceCommon>(
method: 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT',
modelOrOptions: K8sModelCommon | K8sOptions,
response?:
| K
| K8sStatus
| Patch[]
| string
| GenericStaticResponse<string, K | K8sStatus | Patch[] | string>
| RouteHandlerController,
): Chainable<null>;
) => Chainable<null>) &
/**
* Intercept command for K8s resource.
* Provides equivalent functionality to `cy.intercept` where the URL is constructed from the given model and options.
*
* The default URL will include the name and namespace extracted from the supplied resource.
* This can be overridden by supplying options.
*
* If a payload other than a K8s resource is supplied, ensure that the appropriate options include the resource
* name and namespace, if required.
*/
(<K extends K8sResourceCommon>(
method: 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT',
modelOrOptions: K8sModelCommon | K8sOptions,
response?:
| K
| K8sStatus
| Patch[]
| string
| GenericStaticResponse<string, K | K8sStatus | Patch[] | string>
| RouteHandlerController,
) => Chainable<null>);

/**
* Intercept command for listing K8s resources.
Expand All @@ -87,13 +86,13 @@ declare global {
* If a payload other than a list containing at least one K8s resource is supplied, ensure that the appropriate
* options include the resource name and namespace, if required.
*/
interceptK8sList<K extends K8sResourceCommon>(
interceptK8sList: <K extends K8sResourceCommon>(
modelOrOptions: K8sModelCommon | K8sOptions,
resource:
| K8sResourceListResult<K>
| GenericStaticResponse<string, K8sResourceListResult<K> | K8sStatus>
| RouteHandlerController,
): Chainable<null>;
) => Chainable<null>;
}
}
}
Expand Down
Loading

0 comments on commit be332ac

Please sign in to comment.