Skip to content

Commit d485852

Browse files
authored
test(extension): add basic tests for Custom Submit API (#1388)
1 parent 985f792 commit d485852

File tree

13 files changed

+311
-7
lines changed

13 files changed

+311
-7
lines changed

apps/browser-extension-wallet/src/views/browser-view/features/settings/components/CustomSubmitApiDrawer.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ export const CustomSubmitApiDrawer = ({
9090
popupView={popupView}
9191
>
9292
<div className={popupView ? styles.popupContainer : undefined}>
93-
<Text className={styles.drawerDescription}>
93+
<Text className={styles.drawerDescription} data-testid="custom-submit-api-description">
9494
{t('browserView.settings.wallet.customSubmitApi.description')}{' '}
95-
<a href={LEARN_SUBMIT_API_URL} target="_blank" rel="noopener noreferrer">
95+
<a
96+
href={LEARN_SUBMIT_API_URL}
97+
target="_blank"
98+
rel="noopener noreferrer"
99+
data-testid="custom-submit-api-learn-more-url"
100+
>
96101
{t('browserView.settings.wallet.customSubmitApi.descriptionLink')}
97102
</a>
98103
</Text>
99-
<Text className={styles.drawerText}>
104+
<Text className={styles.drawerText} data-testid="custom-submit-api-default-address">
100105
{t('browserView.settings.wallet.customSubmitApi.defaultAddress', { url: DEFAULT_SUBMIT_API })}
101106
</Text>
102107
<div className={styles.customApiContainer}>
@@ -106,6 +111,7 @@ export const CustomSubmitApiDrawer = ({
106111
value={customSubmitTxUrl}
107112
onChange={(event) => setCustomSubmitTxUrl(event.target.value)}
108113
disabled={isCustomApiEnabledForCurrentNetwork}
114+
data-testid="custom-submit-api-url-input"
109115
/>
110116
<Button.Primary
111117
label={
@@ -115,10 +121,11 @@ export const CustomSubmitApiDrawer = ({
115121
}
116122
icon={isCustomApiEnabledForCurrentNetwork ? <PauseIcon /> : <PlayIcon />}
117123
onClick={() => handleCustomTxSubmitEndpoint(!isCustomApiEnabledForCurrentNetwork)}
124+
data-testid={`custom-submit-button-${isCustomApiEnabledForCurrentNetwork ? 'disable' : 'enable'}`}
118125
/>
119126
</div>
120127
{isValidationError && (
121-
<Text className={styles.validationError}>
128+
<Text className={styles.validationError} data-testid="custom-submit-api-validation-error">
122129
{t('browserView.settings.wallet.customSubmitApi.validationError')}
123130
</Text>
124131
)}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import CustomSubmitApiDrawer from '../../elements/settings/CustomSubmitApiDrawer';
2+
import { t } from '../../utils/translationService';
3+
import { expect } from 'chai';
4+
import { isPopupMode } from '../../utils/pageUtils';
5+
6+
class CustomSubmitApiAssert {
7+
private LEARN_SUBMIT_API_URL = 'https://github.com/IntersectMBO/cardano-node/tree/master/cardano-submit-api';
8+
private DEFAULT_SUBMIT_API = 'http://localhost:8090/api/submit/tx';
9+
10+
async assertSeeCustomSubmitApiDrawer() {
11+
await CustomSubmitApiDrawer.drawerBody.waitForStable();
12+
await CustomSubmitApiDrawer.drawerBody.waitForClickable();
13+
await CustomSubmitApiDrawer.drawerNavigationTitle.waitForDisplayed({ reverse: await isPopupMode() });
14+
!(await isPopupMode()) &&
15+
expect(await CustomSubmitApiDrawer.drawerNavigationTitle.getText()).to.equal(
16+
await t('browserView.settings.heading')
17+
);
18+
19+
await CustomSubmitApiDrawer.drawerHeaderBackButton.waitForDisplayed({ reverse: !(await isPopupMode()) });
20+
await CustomSubmitApiDrawer.drawerHeaderCloseButton.waitForDisplayed({ reverse: await isPopupMode() });
21+
22+
await CustomSubmitApiDrawer.drawerHeaderTitle.waitForDisplayed();
23+
expect(await CustomSubmitApiDrawer.drawerHeaderTitle.getText()).to.equal(
24+
await t('browserView.settings.wallet.customSubmitApi.title')
25+
);
26+
27+
await CustomSubmitApiDrawer.description.waitForDisplayed();
28+
const expectedDescription = `${await t('browserView.settings.wallet.customSubmitApi.description')} ${await t(
29+
'browserView.settings.wallet.customSubmitApi.descriptionLink'
30+
)}`;
31+
expect(await CustomSubmitApiDrawer.description.getText()).to.equal(expectedDescription);
32+
await CustomSubmitApiDrawer.learnMoreLink.waitForDisplayed();
33+
expect(await CustomSubmitApiDrawer.learnMoreLink.getAttribute('href')).to.equal(this.LEARN_SUBMIT_API_URL);
34+
35+
await CustomSubmitApiDrawer.defaultAddress.waitForDisplayed();
36+
expect(await CustomSubmitApiDrawer.defaultAddress.getText()).to.equal(
37+
(await t('browserView.settings.wallet.customSubmitApi.defaultAddress')).replace(
38+
'{{url}}',
39+
this.DEFAULT_SUBMIT_API
40+
)
41+
);
42+
43+
await CustomSubmitApiDrawer.urlInput.waitForDisplayed();
44+
expect(await CustomSubmitApiDrawer.urlInput.getValue()).to.equal(this.DEFAULT_SUBMIT_API);
45+
await CustomSubmitApiDrawer.urlInputLabel.waitForDisplayed();
46+
expect(await CustomSubmitApiDrawer.urlInputLabel.getText()).to.equal(
47+
await t('browserView.settings.wallet.customSubmitApi.inputLabel')
48+
);
49+
}
50+
51+
async assertButtonClickable(button: 'Enable' | 'Disable') {
52+
switch (button) {
53+
case 'Enable':
54+
await CustomSubmitApiDrawer.enableButton.waitForClickable();
55+
break;
56+
case 'Disable':
57+
await CustomSubmitApiDrawer.disableButton.waitForClickable();
58+
break;
59+
default:
60+
throw new Error(`Unsupported button '${button}'`);
61+
}
62+
}
63+
64+
async assertSeeValidationError(expectedError: string) {
65+
await CustomSubmitApiDrawer.validationError.waitForDisplayed();
66+
expect(await CustomSubmitApiDrawer.validationError.getText()).to.equal(expectedError);
67+
}
68+
}
69+
70+
export default new CustomSubmitApiAssert();

packages/e2e-tests/src/assert/settings/SettingsPageAssert.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ class SettingsPageAssert {
201201
}
202202
);
203203
}
204+
205+
async assertCustomSubmitApiEnabled(isEnabled: boolean) {
206+
const expectedValue = isEnabled
207+
? await t('browserView.settings.wallet.customSubmitApi.enabled')
208+
: await t('browserView.settings.wallet.customSubmitApi.disabled');
209+
210+
await browser.waitUntil(async () => (await SettingsPage.customSubmitAPILink.addon.getText()) === expectedValue, {
211+
timeout: 3000,
212+
interval: 1000,
213+
timeoutMsg: `Failed while waiting for Custom Submit API with "${expectedValue}" state`
214+
});
215+
}
204216
}
205217

206218
export default new SettingsPageAssert();

packages/e2e-tests/src/assert/toastMessageAssert.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import ToastMessage from '../elements/toastMessage';
22
import { expect } from 'chai';
3+
import { isPopupMode } from '../utils/pageUtils';
34

45
class ToastMessageAssert {
56
async assertSeeToastMessage(expectedMessage: string, shouldBeDisplayed = true) {
67
await ToastMessage.container.waitForDisplayed({ timeout: 10_000, reverse: !shouldBeDisplayed });
78
await ToastMessage.icon.waitForDisplayed({ reverse: !shouldBeDisplayed });
8-
await ToastMessage.progressBar.waitForDisplayed({ reverse: !shouldBeDisplayed });
9+
// TODO: temporary override for LW-11313, please update when ticket is resolved
10+
if (!(await isPopupMode())) {
11+
await ToastMessage.progressBar.waitForDisplayed({ reverse: !shouldBeDisplayed });
12+
}
913
await ToastMessage.closeButton.waitForDisplayed({ reverse: !shouldBeDisplayed });
1014
await ToastMessage.messageText.waitForDisplayed({ reverse: !shouldBeDisplayed });
1115
if (shouldBeDisplayed) {

packages/e2e-tests/src/elements/menuHeader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export class MenuHeader {
180180

181181
async openSettings(): Promise<void> {
182182
await this.openUserMenu();
183+
await this.menuSettingsButton.waitForClickable();
183184
await this.menuSettingsButton.click();
184185
}
185186

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* eslint-disable no-undef */
2+
import { ChainablePromiseElement } from 'webdriverio';
3+
import CommonDrawerElements from '../CommonDrawerElements';
4+
import { setInputFieldValue } from '../../utils/inputFieldUtils';
5+
import { isPopupMode } from '../../utils/pageUtils';
6+
7+
class CustomSubmitApiDrawer extends CommonDrawerElements {
8+
private DESCRIPTION = '[data-testid="custom-submit-api-description"]';
9+
private LEARN_MORE_LINK = '[data-testid="custom-submit-api-learn-more-url"]';
10+
private DEFAULT_ADDRESS = '[data-testid="custom-submit-api-default-address"]';
11+
private URL_INPUT = '[data-testid="custom-submit-api-url-input"]';
12+
private URL_INPUT_LABEL = 'form label';
13+
private ENABLE_BUTTON = '[data-testid="custom-submit-button-enable"]';
14+
private DISABLE_BUTTON = '[data-testid="custom-submit-button-disable"]';
15+
private VALIDATION_ERROR = '[data-testid="custom-submit-api-validation-error"]';
16+
17+
get description(): ChainablePromiseElement<WebdriverIO.Element> {
18+
return $(this.DESCRIPTION);
19+
}
20+
21+
get learnMoreLink(): ChainablePromiseElement<WebdriverIO.Element> {
22+
return $(this.LEARN_MORE_LINK);
23+
}
24+
25+
get defaultAddress(): ChainablePromiseElement<WebdriverIO.Element> {
26+
return $(this.DEFAULT_ADDRESS);
27+
}
28+
29+
get urlInput(): ChainablePromiseElement<WebdriverIO.Element> {
30+
return $(this.URL_INPUT);
31+
}
32+
33+
get urlInputLabel(): ChainablePromiseElement<WebdriverIO.Element> {
34+
return $(this.URL_INPUT_LABEL);
35+
}
36+
37+
get enableButton(): ChainablePromiseElement<WebdriverIO.Element> {
38+
return $(this.ENABLE_BUTTON);
39+
}
40+
41+
get disableButton(): ChainablePromiseElement<WebdriverIO.Element> {
42+
return $(this.DISABLE_BUTTON);
43+
}
44+
45+
get validationError(): ChainablePromiseElement<WebdriverIO.Element> {
46+
return $(this.VALIDATION_ERROR);
47+
}
48+
49+
async clickLearnMoreLink(): Promise<void> {
50+
await this.learnMoreLink.waitForClickable();
51+
await this.learnMoreLink.click();
52+
}
53+
54+
async enterUrl(url: string): Promise<void> {
55+
await this.urlInput.waitForClickable();
56+
await setInputFieldValue(await this.urlInput, url);
57+
}
58+
59+
async clickEnableButton(): Promise<void> {
60+
await this.enableButton.waitForClickable();
61+
await this.enableButton.click();
62+
}
63+
64+
async clickDisableButton(): Promise<void> {
65+
await this.disableButton.waitForClickable();
66+
await this.disableButton.click();
67+
}
68+
69+
async closeDrawer(): Promise<void> {
70+
(await isPopupMode()) ? await this.clickBackDrawerButton() : await this.clickCloseDrawerButton();
71+
}
72+
}
73+
74+
export default new CustomSubmitApiDrawer();

packages/e2e-tests/src/features/SettingsPageExtended.part2.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,43 @@ Feature: General Settings - Extended Browser View
167167
Then I see LW homepage
168168
And I see a different wallet address than in my initial wallet
169169

170+
@LW-11314 @Mainnet @Testnet
171+
Scenario: Extended View - Custom submit API - open drawer
172+
When I open settings from header menu
173+
And I click on "Custom Submit API" setting
174+
Then "Custom submit API" drawer is displayed
175+
176+
@LW-11316 @Mainnet @Testnet
177+
Scenario: Extended View - Custom submit API - Learn more - click
178+
When I open settings from header menu
179+
And I click on "Custom Submit API" setting
180+
And I click on "Learn more about Cardano-submit-API" link
181+
Then New tab with url containing "https://github.com/IntersectMBO/cardano-node/tree/master/cardano-submit-api" is opened
182+
183+
@LW-11318 @Mainnet @Testnet
184+
Scenario: Extended View - Custom submit API - invalid URL
185+
When I open settings from header menu
186+
And I click on "Custom Submit API" setting
187+
And I enter "abc" into URL input on "Custom submit API" drawer
188+
And I click on "Enable" button on "Custom submit API" drawer
189+
Then "Invalid URL" error is displayed on "Custom submit API" drawer
190+
191+
@LW-11320 @Mainnet @Testnet
192+
Scenario: Extended View - Custom submit API - enable/disable
193+
When I open settings from header menu
194+
And I click on "Custom Submit API" setting
195+
And I click on "Enable" button on "Custom submit API" drawer
196+
Then I see a toast with text: "Your custom submit API is enabled..."
197+
And I close a toast message
198+
When I close "Custom submit API" drawer
199+
Then "Custom submit API" is marked as enabled on Settings page
200+
When I click on "Custom Submit API" setting
201+
And I click on "Disable" button on "Custom submit API" drawer
202+
Then I see a toast with text: "Your custom submit API is disabled..."
203+
And I close a toast message
204+
When I close "Custom submit API" drawer
205+
Then "Custom submit API" is marked as disabled on Settings page
206+
170207
# this test should be executed as the last one in this suite
171208
@LW-2521 @LW-9113 @Mainnet @Testnet
172209
Scenario: Extended View - Remove wallet and confirm

packages/e2e-tests/src/features/SettingsPagePopup.part2.feature

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,43 @@ Feature: General Settings - Popup View
109109
Given I open settings from header menu
110110
Then I see analytics option with proper description and toggle
111111

112+
@LW-11315 @Mainnet @Testnet
113+
Scenario: Popup View - Custom submit API - open drawer
114+
When I open settings from header menu
115+
And I click on "Custom Submit API" setting
116+
Then "Custom submit API" drawer is displayed
117+
118+
@LW-11317 @Mainnet @Testnet
119+
Scenario: Popup View - Custom submit API - Learn more - click
120+
When I open settings from header menu
121+
And I click on "Custom Submit API" setting
122+
And I click on "Learn more about Cardano-submit-API" link
123+
Then New tab with url containing "https://github.com/IntersectMBO/cardano-node/tree/master/cardano-submit-api" is opened
124+
125+
@LW-11319 @Mainnet @Testnet
126+
Scenario: Popup View - Custom submit API - invalid URL
127+
When I open settings from header menu
128+
And I click on "Custom Submit API" setting
129+
And I enter "abc" into URL input on "Custom submit API" drawer
130+
And I click on "Enable" button on "Custom submit API" drawer
131+
Then "Invalid URL" error is displayed on "Custom submit API" drawer
132+
133+
@LW-11321 @Mainnet @Testnet
134+
Scenario: Popup View - Custom submit API - enable/disable
135+
When I open settings from header menu
136+
And I click on "Custom Submit API" setting
137+
And I click on "Enable" button on "Custom submit API" drawer
138+
Then I see a toast with text: "Your custom submit API is enabled..."
139+
And I close a toast message
140+
When I close "Custom submit API" drawer
141+
Then "Custom submit API" is marked as enabled on Settings page
142+
When I click on "Custom Submit API" setting
143+
And I click on "Disable" button on "Custom submit API" drawer
144+
Then I see a toast with text: "Your custom submit API is disabled..."
145+
And I close a toast message
146+
When I close "Custom submit API" drawer
147+
Then "Custom submit API" is marked as disabled on Settings page
148+
112149
# this test should be executed as the last one in this suite
113150
@LW-2708 @Mainnet @Testnet
114151
Scenario: Popup View - Remove wallet and confirm

packages/e2e-tests/src/features/analytics/AnalyticsSettingsExtended.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ Feature: Analytics - Settings - Extended View
174174
Then I validate latest analytics single event "settings | wallet | hd wallet sync | sync | click"
175175
And I validate that 1 analytics event(s) have been sent
176176

177+
@LW-11322
178+
Scenario: Analytics - Extended View - Custom Submit API
179+
When I open settings from header menu
180+
And I set up request interception for posthog analytics request(s)
181+
And I click on "Custom Submit API" setting
182+
Then I validate latest analytics single event "settings | custom submit api | click"
183+
When I click on "Enable" button on "Custom submit API" drawer
184+
Then I validate latest analytics single event "settings | custom submit api | enable | click"
185+
And I validate that 2 analytics event(s) have been sent
186+
177187
# this test should be executed as the last one in this suite
178188
@LW-8559
179189
Scenario: Analytics - Extended View - Settings - Wallet removal events - Remove wallet

packages/e2e-tests/src/features/analytics/AnalyticsSettingsPopup.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ Feature: Analytics - Settings - Popup View
181181
Then I validate latest analytics single event "settings | theme | light mode | click"
182182
Then I validate that 2 analytics event(s) have been sent
183183

184+
@LW-11323
185+
Scenario: Analytics - Popup View - Custom Submit API
186+
When I open settings from header menu
187+
And I set up request interception for posthog analytics request(s)
188+
And I click on "Custom Submit API" setting
189+
Then I validate latest analytics single event "settings | custom submit api | click"
190+
When I click on "Enable" button on "Custom submit API" drawer
191+
Then I validate latest analytics single event "settings | custom submit api | enable | click"
192+
And I validate that 2 analytics event(s) have been sent
193+
184194
# this test should be executed as the last one in this suite
185195
@LW-8571
186196
Scenario: Analytics - Popup View - Settings - Wallet removal events - Remove wallet

0 commit comments

Comments
 (0)