Skip to content

Commit 833604a

Browse files
authored
refactor: replace click overloads with click() and clickRedirectsTo() (#8)
* refactor: replace click overloads with click() and clickRedirectsTo() * refactor: replace click overloads with click() and clickRedirectsTo()
1 parent fb5b00d commit 833604a

29 files changed

Lines changed: 55 additions & 49 deletions

src/controls/html-element.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@ export class HTMLElement implements IHTMLElement {
5151
/**
5252
*
5353
* Schedules a command to click on this element
54+
* @return {*} {Promise<void>}
55+
* @memberof HTMLElement
56+
*/
57+
async click(): Promise<void> {
58+
return await this.callIfMethodExists('click');
59+
}
60+
/**
61+
*
62+
* Schedules a command to click on this element and return a new page object
5463
* @template TPage
55-
* @param {new () => TPage} [page]
56-
* @return {*} {Promise<any>}
64+
* @param {new () => TPage} page
65+
* @return {*} {Promise<TPage>}
5766
* @memberof HTMLElement
5867
*/
59-
click(): Promise<void>;
60-
click<TPage>(page: new () => TPage): Promise<TPage>;
61-
async click<TPage>(page?: new () => TPage): Promise<any> {
62-
if (page) {
63-
return await this.callIfMethodExists('click', [page]);
64-
} else {
65-
return await this.callIfMethodExists('click');
66-
}
68+
async clickRedirectsTo<TPage>(page: new () => TPage): Promise<TPage> {
69+
return await this.callIfMethodExists('clickRedirectsTo', [page]);
6770
}
6871
/**
6972
*

src/flask/pages/onboarding/experimental-area.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export class ExperimentalArea extends PageObject {
2727
* @memberof ExperimentalArea
2828
*/
2929
async iAccept(): Promise<Welcome> {
30-
return await this.iAcceptButton.click<Welcome>(Welcome);
30+
return await this.iAcceptButton.clickRedirectsTo<Welcome>(Welcome);
3131
}
3232
}

src/interface/controls/html-element.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { IConfirmation } from '../wallet/confirmation';
33

44
export interface IHTMLElement {
55
click(): Promise<void>;
6-
click<TPage>(page: new () => TPage): Promise<TPage>;
7-
click<TPage>(page?: new () => TPage): Promise<any>;
6+
clickRedirectsTo<TPage>(page: new () => TPage): Promise<TPage>;
87
clickAndSwitchToWindow<TPage extends IConfirmation | IPageObject>(page: new () => TPage): Promise<TPage>;
98
clickAndWait(duration: number): Promise<void>;
109
getAttribute(attribute: string): Promise<string | null>;

src/metamask/pages/onboarding/confirm-recovery-phrase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ export class ConfirmRecoveryPhrase extends PageObject {
6060
*/
6161
async confirm(): Promise<Metametrics> {
6262
await this.confirmButton.click();
63-
return await this.modalButton.click<Metametrics>(Metametrics);
63+
return await this.modalButton.clickRedirectsTo<Metametrics>(Metametrics);
6464
}
6565
}

src/metamask/pages/onboarding/create-password.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class CreatePassword extends PageObject {
6565
* @memberof CreatePassword
6666
*/
6767
async importWallet(): Promise<Metametrics> {
68-
return await this.submitButton.click<Metametrics>(Metametrics);
68+
return await this.submitButton.clickRedirectsTo<Metametrics>(Metametrics);
6969
}
7070
/**
7171
*
@@ -74,6 +74,6 @@ export class CreatePassword extends PageObject {
7474
* @memberof CreatePassword
7575
*/
7676
async createWallet(): Promise<ReviewRecoveryPhrase> {
77-
return await this.submitButton.click<ReviewRecoveryPhrase>(ReviewRecoveryPhrase);
77+
return await this.submitButton.clickRedirectsTo<ReviewRecoveryPhrase>(ReviewRecoveryPhrase);
7878
}
7979
}

src/metamask/pages/onboarding/import-with-recory-phrase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ export class ImportWithRecoveryPhrase extends PageObject {
4646
* @memberof ImportWithRecoveryPhrase
4747
*/
4848
async confirmSecretRecoveryPhrase(): Promise<CreatePassword> {
49-
return await this.confirmButton.click<CreatePassword>(CreatePassword);
49+
return await this.confirmButton.clickRedirectsTo<CreatePassword>(CreatePassword);
5050
}
5151
}

src/metamask/pages/onboarding/metametrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export class Metametrics extends PageObject {
2727
* @memberof Metametrics
2828
*/
2929
async continue(): Promise<Completion> {
30-
return await this.iAgreeButton.click<Completion>(Completion);
30+
return await this.iAgreeButton.clickRedirectsTo<Completion>(Completion);
3131
}
3232
}

src/metamask/pages/onboarding/review-recovery-phrase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export class ReviewRecoveryPhrase extends PageObject {
3939
* @memberof ReviewRecoveryPhrase
4040
*/
4141
async next(): Promise<ConfirmRecoveryPhrase> {
42-
return await this.nextButton.click<ConfirmRecoveryPhrase>(ConfirmRecoveryPhrase);
42+
return await this.nextButton.clickRedirectsTo<ConfirmRecoveryPhrase>(ConfirmRecoveryPhrase);
4343
}
4444
}

src/metamask/pages/onboarding/welcome.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Welcome extends PageObject {
3737
*/
3838
async createANewWallet(): Promise<CreatePassword> {
3939
await this.createANewWalletButton.click();
40-
return await this.createWithSRPButton.click<CreatePassword>(CreatePassword);
40+
return await this.createWithSRPButton.clickRedirectsTo<CreatePassword>(CreatePassword);
4141
}
4242
/**
4343
*
@@ -47,6 +47,6 @@ export class Welcome extends PageObject {
4747
*/
4848
async iHaveAnExistingWallet(): Promise<ImportWithRecoveryPhrase> {
4949
await this.importAnExistingWalletButton.click();
50-
return await this.importWithSRPButton.click<ImportWithRecoveryPhrase>(ImportWithRecoveryPhrase);
50+
return await this.importWithSRPButton.clickRedirectsTo<ImportWithRecoveryPhrase>(ImportWithRecoveryPhrase);
5151
}
5252
}

src/playwright/html-element.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export class PlaywrightHTMLElement implements IHTMLElement {
3131
return locator;
3232
}
3333

34-
async click<TPage>(page?: new () => TPage): Promise<any> {
34+
async click(): Promise<void> {
3535
await this.webElement.click({ timeout: this.timeout });
36-
if (page) {
37-
return await DappDriver.getPage<TPage>(page);
38-
}
36+
}
37+
38+
async clickRedirectsTo<TPage>(page: new () => TPage): Promise<TPage> {
39+
await this.webElement.click({ timeout: this.timeout });
40+
return await DappDriver.getPage<TPage>(page);
3941
}
4042

4143
async clickAndWait(duration: number): Promise<void> {

0 commit comments

Comments
 (0)