Skip to content

Commit d38eff3

Browse files
authored
test(extension): add tests for Sign Message feature (#1441)
1 parent a59aaa2 commit d38eff3

17 files changed

+472
-13
lines changed

apps/browser-extension-wallet/src/views/browser-view/features/sign-message/SignMessageDrawer.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,31 @@ export const SignMessageDrawer: React.FC = () => {
6767

6868
const renderInitialState = () => (
6969
<>
70-
<Text.Body.Large weight="$bold">{t('core.signMessage.instructions')}</Text.Body.Large>
71-
<Text.Body.Normal className={styles.subtitle}>{t('core.signMessage.subtitle')}</Text.Body.Normal>
70+
<Text.Body.Large weight="$bold" data-testid={'drawer-header-title'}>
71+
{t('core.signMessage.instructions')}
72+
</Text.Body.Large>
73+
<Text.Body.Normal className={styles.subtitle} data-testid={'drawer-header-subtitle'}>
74+
{t('core.signMessage.subtitle')}
75+
</Text.Body.Normal>
7276
{isHardwareWallet && hardwareWalletError && (
7377
<div className={styles.errorMessage}>
7478
<Text.Body.Normal color="error">{hardwareWalletError}</Text.Body.Normal>
7579
</div>
7680
)}
7781
<div className={styles.inputGroup}>
78-
<Text.Body.Normal weight="$medium">{t('core.signMessage.addressLabel')}</Text.Body.Normal>
82+
<Text.Body.Normal weight="$medium" data-testid={'address-label'}>
83+
{t('core.signMessage.addressLabel')}
84+
</Text.Body.Normal>
7985
<WalletOwnAddressDropdown
8086
addresses={usedAddresses}
8187
onSelect={setSelectedAddress}
8288
placeholder={t('core.signMessage.selectAddress')}
8389
/>
8490
</div>
8591
<div className={styles.inputGroup}>
86-
<Text.Body.Normal weight="$medium">{t('core.signMessage.messageLabel')}</Text.Body.Normal>
92+
<Text.Body.Normal weight="$medium" data-testid={'message-to-sign-label'}>
93+
{t('core.signMessage.messageLabel')}
94+
</Text.Body.Normal>
8795
<TextArea
8896
placeholder={t('core.signMessage.messagePlaceholder')}
8997
value={message}
@@ -98,12 +106,16 @@ export const SignMessageDrawer: React.FC = () => {
98106

99107
const renderPasswordPrompt = () => (
100108
<>
101-
<Text.Body.Large weight="$bold">{t('core.signMessage.passwordTitle')}</Text.Body.Large>
102-
<Text.Body.Normal className={styles.subtitle}>{t('core.signMessage.passwordSubtitle')}</Text.Body.Normal>
109+
<Text.Body.Large weight="$bold" data-testid={'drawer-header-title'}>
110+
{t('core.signMessage.passwordTitle')}
111+
</Text.Body.Large>
112+
<Text.Body.Normal className={styles.subtitle} data-testid={'drawer-header-subtitle'}>
113+
{t('core.signMessage.passwordSubtitle')}
114+
</Text.Body.Normal>
103115
<PasswordInput
104116
onChange={setPassword}
105117
label={t('core.signMessage.passwordLabel')}
106-
dataTestId="sign-message-password-input"
118+
dataTestId="password-input"
107119
error={!!error}
108120
errorMessage={error}
109121
wrapperClassName={styles.passwordWrapper}

apps/browser-extension-wallet/src/views/browser-view/features/sign-message/useDrawerConfiguration.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,19 @@ export const useDrawerConfiguration = ({
4747
if (signatureObject?.signature && !error) {
4848
return (
4949
<CopyToClipboard text={signatureObject.signature}>
50-
<Button onClick={handleCopy}>
50+
<Button onClick={handleCopy} data-testid={'copy-button'}>
5151
{t('core.signMessage.copyToClipboard')}
5252
<CopyToClipboardImg className={styles.newFolderIcon} />
5353
</Button>
5454
</CopyToClipboard>
5555
);
5656
}
5757
return (
58-
<Button onClick={handleSign} disabled={!selectedAddress || !message || isSigningInProgress}>
58+
<Button
59+
onClick={handleSign}
60+
disabled={!selectedAddress || !message || isSigningInProgress}
61+
data-testid={'sign-message-button'}
62+
>
5963
{getActionButtonLabel()}
6064
</Button>
6165
);
@@ -84,6 +88,7 @@ export const useDrawerConfiguration = ({
8488
closeDrawer();
8589
clearSecrets();
8690
}}
91+
data-testid={'close-button'}
8792
>
8893
{t('core.signMessage.closeButton')}
8994
</Button>

packages/core/src/ui/components/WalletOwnAddressesDropdown/WalletOwnAddressDropdown.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ export const WalletOwnAddressDropdown = ({
4949

5050
return (
5151
<Dropdown menu={menuProps} trigger={['click']}>
52-
<Button variant="outlined" color="secondary" className={cn(styles.dropdownBtn)}>
52+
<Button
53+
variant="outlined"
54+
color="secondary"
55+
className={cn(styles.dropdownBtn)}
56+
data-testid="select-address-button"
57+
>
5358
<span className={styles.content}>{selectedAddress}</span>
5459
</Button>
5560
</Dropdown>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import MessageSigningAllDoneDrawer from '../../elements/settings/MessageSigningAllDoneDrawer';
2+
import { expect } from 'chai';
3+
import { t } from '../../utils/translationService';
4+
import clipboard from 'clipboardy';
5+
6+
class MessageSigningAllDoneDrawerAssert {
7+
async assertSeeAllDoneDrawer() {
8+
await MessageSigningAllDoneDrawer.drawerHeaderCloseButton.waitForClickable();
9+
await MessageSigningAllDoneDrawer.drawerNavigationTitle.waitForDisplayed();
10+
expect(await MessageSigningAllDoneDrawer.drawerNavigationTitle.getText()).to.equal(
11+
await t('core.signMessage.title')
12+
);
13+
14+
await MessageSigningAllDoneDrawer.image.waitForDisplayed();
15+
await MessageSigningAllDoneDrawer.title.waitForDisplayed();
16+
expect(await MessageSigningAllDoneDrawer.title.getText()).to.equal(await t('core.signMessage.successTitle'));
17+
await MessageSigningAllDoneDrawer.description.waitForDisplayed();
18+
expect(await MessageSigningAllDoneDrawer.description.getText()).to.equal(
19+
await t('core.signMessage.successDescription')
20+
);
21+
await MessageSigningAllDoneDrawer.signature.waitForDisplayed();
22+
expect(await MessageSigningAllDoneDrawer.signature.getText()).to.not.be.empty;
23+
24+
await MessageSigningAllDoneDrawer.copyButton.waitForClickable();
25+
expect(await MessageSigningAllDoneDrawer.copyButton.getText()).to.equal(
26+
await t('core.signMessage.copyToClipboard')
27+
);
28+
await MessageSigningAllDoneDrawer.closeButton.waitForClickable();
29+
expect(await MessageSigningAllDoneDrawer.closeButton.getText()).to.equal(await t('core.signMessage.closeButton'));
30+
}
31+
32+
async assertSignatureInClipboardIsCorrect() {
33+
const displayedSignature = await MessageSigningAllDoneDrawer.signature.getText();
34+
const signatureFromClipboard = await clipboard.read();
35+
expect(signatureFromClipboard).to.equal(displayedSignature);
36+
}
37+
}
38+
39+
export default new MessageSigningAllDoneDrawerAssert();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect } from 'chai';
2+
import { t } from '../../utils/translationService';
3+
import MessageSigningSignConfirmationDrawer from '../../elements/settings/MessageSigningConfirmationDrawer';
4+
5+
class MessageSigningConfirmationDrawerAssert {
6+
async assertSeeSignConfirmationDrawer() {
7+
await MessageSigningSignConfirmationDrawer.drawerHeaderCloseButton.waitForClickable();
8+
await MessageSigningSignConfirmationDrawer.drawerNavigationTitle.waitForDisplayed();
9+
expect(await MessageSigningSignConfirmationDrawer.drawerNavigationTitle.getText()).to.equal(
10+
await t('core.signMessage.title')
11+
);
12+
13+
await MessageSigningSignConfirmationDrawer.drawerHeaderTitle.waitForDisplayed();
14+
expect(await MessageSigningSignConfirmationDrawer.drawerHeaderTitle.getText()).to.equal(
15+
await t('core.signMessage.passwordTitle')
16+
);
17+
await MessageSigningSignConfirmationDrawer.drawerHeaderSubtitle.waitForDisplayed();
18+
expect(await MessageSigningSignConfirmationDrawer.drawerHeaderSubtitle.getText()).to.equal(
19+
await t('core.signMessage.passwordSubtitle')
20+
);
21+
22+
await MessageSigningSignConfirmationDrawer.passwordInput.waitForEnabled();
23+
24+
await MessageSigningSignConfirmationDrawer.signMessageButton.waitForEnabled();
25+
expect(await MessageSigningSignConfirmationDrawer.signMessageButton.getText()).to.equal(
26+
await t('core.signMessage.signButton')
27+
);
28+
29+
await MessageSigningSignConfirmationDrawer.closeButton.waitForDisplayed();
30+
expect(await MessageSigningSignConfirmationDrawer.closeButton.getText()).to.equal(
31+
await t('core.signMessage.closeButton')
32+
);
33+
}
34+
}
35+
36+
export default new MessageSigningConfirmationDrawerAssert();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import MessageSigningInputDrawer from '../../elements/settings/MessageSigningInputDrawer';
2+
import { expect } from 'chai';
3+
import { t } from '../../utils/translationService';
4+
5+
class MessageSigningInputDrawerAssert {
6+
async assertSeeMessageSigningInputDrawer() {
7+
await MessageSigningInputDrawer.drawerHeaderCloseButton.waitForClickable();
8+
await MessageSigningInputDrawer.drawerNavigationTitle.waitForDisplayed();
9+
expect(await MessageSigningInputDrawer.drawerNavigationTitle.getText()).to.equal(await t('core.signMessage.title'));
10+
11+
await MessageSigningInputDrawer.drawerHeaderTitle.waitForDisplayed();
12+
expect(await MessageSigningInputDrawer.drawerHeaderTitle.getText()).to.equal(
13+
await t('core.signMessage.instructions')
14+
);
15+
await MessageSigningInputDrawer.drawerHeaderSubtitle.waitForDisplayed();
16+
expect(await MessageSigningInputDrawer.drawerHeaderSubtitle.getText()).to.equal(
17+
await t('core.signMessage.subtitle')
18+
);
19+
20+
await MessageSigningInputDrawer.addressLabel.waitForDisplayed();
21+
expect(await MessageSigningInputDrawer.addressLabel.getText()).to.equal(await t('core.signMessage.addressLabel'));
22+
await MessageSigningInputDrawer.selectAddressButton.waitForDisplayed();
23+
expect(await MessageSigningInputDrawer.selectAddressButton.getText()).to.equal(
24+
await t('core.signMessage.selectAddress')
25+
);
26+
27+
await MessageSigningInputDrawer.messageToSignLabel.waitForDisplayed();
28+
expect(await MessageSigningInputDrawer.messageToSignLabel.getText()).to.equal(
29+
await t('core.signMessage.messageLabel')
30+
);
31+
await MessageSigningInputDrawer.messageInput.waitForDisplayed();
32+
expect(await MessageSigningInputDrawer.messageInput.getAttribute('placeholder')).to.equal(
33+
await t('core.signMessage.messagePlaceholder')
34+
);
35+
36+
await MessageSigningInputDrawer.signMessageButton.waitForDisplayed();
37+
expect(await MessageSigningInputDrawer.signMessageButton.getText()).to.equal(
38+
await t('core.signMessage.signButton')
39+
);
40+
41+
await MessageSigningInputDrawer.closeButton.waitForDisplayed();
42+
expect(await MessageSigningInputDrawer.closeButton.getText()).to.equal(await t('core.signMessage.closeButton'));
43+
}
44+
45+
async assertSeeFollowingAddressesOnTheDropdownMenu(expectedAddresses: string[]) {
46+
await MessageSigningInputDrawer.addressMenu.waitForClickable();
47+
const actualAddresses = await (
48+
await MessageSigningInputDrawer.addresses
49+
).map(async (address) => await address.getText());
50+
51+
expect(actualAddresses).to.deep.equal(expectedAddresses);
52+
}
53+
54+
async assertSeeSelectedAddress(expectedAddress: string) {
55+
await MessageSigningInputDrawer.selectAddressButton.waitForDisplayed();
56+
const actualAddress = await MessageSigningInputDrawer.selectAddressButton.getText();
57+
expect(actualAddress).to.equal(expectedAddress);
58+
}
59+
}
60+
61+
export default new MessageSigningInputDrawerAssert();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class MenuHeader {
1616
private MENU_ADDRESS_BOOK_BUTTON = '//li[@data-testid="header-menu-address-book"]';
1717
private MENU_ADD_NEW_WALLET_BUTTON = '[data-testid="header-menu-new-wallet"]';
1818
private MENU_SETTINGS_BUTTON = '//li[@data-testid="header-menu-settings"]';
19+
private MENU_SIGN_MESSAGE_BUTTON = '//li[@data-testid="header-menu-sign-message"]';
1920
private MENU_LOCK_BUTTON = '//li[@data-testid="header-menu-lock"]';
2021
private MENU_WALLET_OPTION_ITEM = '//button[@data-testid="wallet-option-item"]';
2122
private MENU_WALLET_OPTION_NAME = '//span[@data-testid="wallet-option-title"]';
@@ -103,6 +104,10 @@ export class MenuHeader {
103104
return $(this.MENU_SETTINGS_BUTTON);
104105
}
105106

107+
get menuSignMessageButton(): ChainablePromiseElement<WebdriverIO.Element> {
108+
return $(this.MENU_SIGN_MESSAGE_BUTTON);
109+
}
110+
106111
get menuLockButton(): ChainablePromiseElement<WebdriverIO.Element> {
107112
return $(this.MENU_LOCK_BUTTON);
108113
}
@@ -198,6 +203,11 @@ export class MenuHeader {
198203
await this.menuSettingsButton.click();
199204
}
200205

206+
async clickSignMessageButton(): Promise<void> {
207+
await this.menuSignMessageButton.waitForClickable();
208+
await this.menuSignMessageButton.click();
209+
}
210+
201211
async clickAddressBookOption(): Promise<void> {
202212
await this.menuAddressBookButton.click();
203213
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* eslint-disable no-undef */
2+
import CommonDrawerElements from '../CommonDrawerElements';
3+
import type { ChainablePromiseElement } from 'webdriverio';
4+
5+
class MessageSigningAllDoneDrawer extends CommonDrawerElements {
6+
private IMAGE = '[data-testid="result-message-img"]';
7+
private TITLE = '[data-testid="result-message-title"]';
8+
private DESCRIPTION = '[data-testid="result-message-description"]';
9+
private SIGNATURE = '[data-testid="sign-message-signature"]';
10+
private COPY_BUTTON = '[data-testid="copy-button"]';
11+
private CLOSE_BUTTON = '[data-testid="close-button"]';
12+
13+
get image(): ChainablePromiseElement<WebdriverIO.Element> {
14+
return $(this.IMAGE);
15+
}
16+
17+
get title(): ChainablePromiseElement<WebdriverIO.Element> {
18+
return $(this.TITLE);
19+
}
20+
21+
get description(): ChainablePromiseElement<WebdriverIO.Element> {
22+
return $(this.DESCRIPTION);
23+
}
24+
25+
get signature(): ChainablePromiseElement<WebdriverIO.Element> {
26+
return $(this.SIGNATURE);
27+
}
28+
29+
get copyButton(): ChainablePromiseElement<WebdriverIO.Element> {
30+
return $(this.COPY_BUTTON);
31+
}
32+
33+
get closeButton(): ChainablePromiseElement<WebdriverIO.Element> {
34+
return $(this.CLOSE_BUTTON);
35+
}
36+
37+
async clickOnCopySignatureToClipboardButton(): Promise<void> {
38+
await this.copyButton.waitForClickable();
39+
await this.copyButton.click();
40+
}
41+
42+
async clickOnCloseButton(): Promise<void> {
43+
await this.closeButton.waitForClickable();
44+
await this.closeButton.click();
45+
}
46+
}
47+
48+
export default new MessageSigningAllDoneDrawer();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable no-undef */
2+
import CommonDrawerElements from '../CommonDrawerElements';
3+
import type { ChainablePromiseElement } from 'webdriverio';
4+
5+
class MessageSigningConfirmationDrawer extends CommonDrawerElements {
6+
private PASSWORD_INPUT = '[data-testid="password-input"]';
7+
private SIGN_MESSAGE_BUTTON = '[data-testid="sign-message-button"]';
8+
private CLOSE_BUTTON = '[data-testid="close-button"]';
9+
10+
get passwordInput(): ChainablePromiseElement<WebdriverIO.Element> {
11+
return $(this.PASSWORD_INPUT);
12+
}
13+
14+
get signMessageButton(): ChainablePromiseElement<WebdriverIO.Element> {
15+
return $(this.SIGN_MESSAGE_BUTTON);
16+
}
17+
18+
get closeButton(): ChainablePromiseElement<WebdriverIO.Element> {
19+
return $(this.CLOSE_BUTTON);
20+
}
21+
}
22+
23+
export default new MessageSigningConfirmationDrawer();

0 commit comments

Comments
 (0)