Skip to content

Commit 866a772

Browse files
authored
Tests: Add assets tests (#5053)
1 parent 9e1422a commit 866a772

File tree

10 files changed

+163
-20
lines changed

10 files changed

+163
-20
lines changed

apps/web/cypress/e2e/pages/assets.pages.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import * as main from './main.page'
22
import * as addressbook from '../pages/address_book.page'
33
import * as createTx from '../pages/create_tx.pages'
44
import { tableRow } from '../pages/address_book.page'
5+
import { assetsSwapBtn } from '../pages/swaps.pages'
6+
import { nftsRow } from '../pages/nfts.pages'
7+
58

69
let etherscanLinkSepolia = 'a[aria-label="View on sepolia.etherscan.io"]'
710
export const balanceSingleRow = '[aria-labelledby="tableTitle"] > tbody tr'
@@ -15,6 +18,7 @@ const paginationPageList = 'ul[role="listbox"]'
1518
const currencyDropDown = 'div[id="currency"]'
1619
export const tokenListTable = 'table[aria-labelledby="tableTitle"]'
1720
const tokenListDropdown = 'div[id="tokenlist-select"]'
21+
export const tablePaginationContainer = '[data-testid="table-pagination"]'
1822

1923
const hiddenTokenSaveBtn = 'span[data-track="assets: Save hide dialog"]'
2024
const hiddenTokenCancelBtn = 'span[data-track="assets: Cancel hide dialog"]'
@@ -25,6 +29,7 @@ const currencyItem = '[data-testid="currency-item"]'
2529
const tokenAmountFld = '[data-testid="token-amount-field"]'
2630
const tokenBalance = '[data-testid="token-balance"]'
2731
const tokenItem = '[data-testid="token-item"]'
32+
const sendBtn = '[data-testid="send-button"]'
2833

2934
const hideTokenDefaultString = 'Hide tokens'
3035
const assetNameSortBtnStr = 'Asset'
@@ -110,6 +115,41 @@ export const currentcyGnosisFormat = '< 0.00001 GNO'
110115
export const currencyOx = /^0x$/
111116
export const currentcyOxFormat = '1.003 ZRX'
112117

118+
export function checkNftAddressFormat() {
119+
cy.get(nftsRow).each(($el) => {
120+
cy.wrap($el)
121+
.invoke('text')
122+
.should('match', /0x[a-fA-F0-9]{4}\.\.\.[a-fA-F0-9]{4}/);
123+
});
124+
}
125+
126+
export function checkNftCopyIconAndLink() {
127+
cy.get(nftsRow).each(($el) => {
128+
cy.wrap($el)
129+
.within(() => {
130+
cy.get(createTx.copyIcon, { timeout: 5000 })
131+
.should('exist');
132+
});
133+
cy.wrap($el)
134+
.within(() => {
135+
cy.get(createTx.explorerBtn, { timeout: 5000 })
136+
.should('exist');
137+
});
138+
});
139+
}
140+
141+
export function showSendBtn() {
142+
return cy.get(sendBtn)
143+
.invoke('css', 'opacity', '1')
144+
.should('have.css', 'opacity', '1');
145+
}
146+
147+
export function showSwapBtn() {
148+
return cy.get(assetsSwapBtn)
149+
.invoke('css', 'opacity', '1')
150+
.should('have.css', 'opacity', '1');
151+
}
152+
113153
export function enterAmount(amount) {
114154
cy.get(tokenAmountFld).find('input').clear().type(amount)
115155
}
@@ -166,13 +206,6 @@ export function clickOnExecuteBtn(index) {
166206
})
167207
}
168208

169-
export function showSendBtn(index) {
170-
cy.get('button')
171-
.contains(sendBtnStr)
172-
.then((elements) => {
173-
cy.wrap(elements[index]).invoke('css', 'opacity', 100).trigger('mouseover', { force: true })
174-
})
175-
}
176209

177210
export function VerifySendButtonIsDisabled() {
178211
cy.get('button').contains(sendBtnStr).should('be.disabled')
@@ -234,6 +267,14 @@ export function checkTokenCounter(value) {
234267
})
235268
}
236269

270+
export function checkNFTCounter(value) {
271+
cy.get(hiddenTokenIcon)
272+
.parent()
273+
.within(() => {
274+
cy.get('p').should('include.text', value)
275+
})
276+
}
277+
237278
export function checkHiddenTokenBtnCounter(value) {
238279
cy.get(hiddeTokensBtn).within(() => {
239280
cy.get('p').should('include.text', value)

apps/web/cypress/e2e/pages/create_tx.pages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const relayExecMethod = '[data-testid="relay-execution-method"]'
1818
export const payNowExecMethod = '[data-testid="pay-now-execution-method"]'
1919
export const addToBatchBtn = '[data-track="batching: Add to batch"]'
2020
const accordionDetails = '[data-testid="accordion-details"]'
21-
const copyIcon = '[data-testid="copy-btn-icon"]'
21+
export const copyIcon = '[data-testid="copy-btn-icon"]'
22+
export const explorerBtn = '[data-testid="explorer-btn"]'
2223
const transactionSideList = '[data-testid="transaction-actions-list"]'
2324
const confirmationVisibilityBtn = '[data-testid="confirmation-visibility-btn"]'
2425
const expandAllBtn = '[data-testid="expande-all-btn"]'

apps/web/cypress/e2e/pages/nfts.pages.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ const nftModal = modal.modal
77

88
const nftModalCloseBtn = main.modalDialogCloseBtn
99
const recipientInput = 'input[name="recipient"]'
10-
const nftsRow = '[data-testid^="nfts-table-row"]'
10+
export const nftsRow = '[data-testid^="nfts-table-row"]'
1111
const inactiveNftIcon = '[data-testid="nft-icon-border"]'
1212
const activeNftIcon = '[data-testid="nft-icon-primary"]'
1313
const nftCheckBox = (index) => `[data-testid="nft-checkbox-${index}"] > input`
14+
const selectAllNFTsCheckbox = 'span[title="Select all"] > input'
1415
const activeSendNFTBtn = '[data-testid="nft-send-btn-false"]'
1516
const disabledSendNFTBtn = '[data-testid="nft-send-btn-true"]'
1617
const modalTitle = '[data-testid="modal-title"]'
@@ -105,6 +106,14 @@ export function selectNFTs(numberOfNFTs) {
105106
cy.get(nftCheckBox(i)).click()
106107
cy.contains(`${i} NFT${i > 1 ? 's' : ''} selected`)
107108
}
109+
checkSelectedNFTsNumberIs(numberOfNFTs)
110+
}
111+
112+
export function selectAllNFTs() {
113+
cy.get(selectAllNFTsCheckbox).click()
114+
}
115+
116+
export function checkSelectedNFTsNumberIs(numberOfNFTs) {
108117
cy.contains('button', `Send ${numberOfNFTs} NFT${numberOfNFTs > 1 ? 's' : ''}`)
109118
}
110119

apps/web/cypress/e2e/pages/swaps.pages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ export const swapTxs = {
142142
export const tokenBlockLabels = {
143143
sell: 'Sell',
144144
buy: 'Buy exactly',
145+
}
145146

147+
export function verifySwapBtnIsVisible() {
148+
cy.get(assetsSwapBtn).should('be.visible')
146149
}
150+
147151
export function checkInputCurrencyPreviewValue(value) {
148152
cy.get(inputCurrencyPreview).should('contain.text', value)
149153
}

apps/web/cypress/e2e/regression/assets.cy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Assets tests', () => {
3030
assets.clickOnSendBtn(0)
3131
})
3232

33-
it('[SMOKE] Verify that Token list dropdown down options show/hide spam tokens', () => {
33+
it('Verify that Token list dropdown shows options "Default tokens" and "All tokens"', () => {
3434
let spamTokens = [
3535
assets.currencyAave,
3636
assets.currencyTestTokenA,
@@ -40,7 +40,10 @@ describe('Assets tests', () => {
4040
assets.currencyDaiCap,
4141
]
4242

43+
assets.selectTokenList(assets.tokenListOptions.default)
44+
main.verifyValuesExist(assets.tokenListTable, [constants.tokenNames.sepoliaEther])
4345
main.verifyValuesDoNotExist(assets.tokenListTable, spamTokens)
46+
4447
assets.selectTokenList(assets.tokenListOptions.allTokens)
4548
spamTokens.push(constants.tokenNames.sepoliaEther)
4649
main.verifyValuesExist(assets.tokenListTable, spamTokens)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import * as constants from '../../support/constants.js'
2+
import * as assets from '../pages/assets.pages.js'
3+
import { getSafes, CATEGORIES } from '../../support/safes/safesHandler.js'
4+
import * as wallet from '../../support/utils/wallet.js'
5+
import * as main from '../pages/main.page.js'
6+
import * as navigation from '../pages/navigation.page'
7+
import * as nfts from '../pages/nfts.pages.js'
8+
import { clickOnAssetSwapBtn } from "../pages/swaps.pages.js";
9+
10+
let staticSafes = []
11+
12+
const walletCredentials = JSON.parse(Cypress.env('CYPRESS_WALLET_CREDENTIALS'))
13+
const signer = walletCredentials.OWNER_1_PRIVATE_KEY
14+
const signer2 = walletCredentials.OWNER_4_PRIVATE_KEY
15+
16+
describe('Assets 2 tests', () => {
17+
before(async () => {
18+
staticSafes = await getSafes(CATEGORIES.static)
19+
})
20+
21+
22+
it('Verify no pagination shows at the bottom if there are less than 25 rows', () => {
23+
cy.visit(constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_2)
24+
let spamTokens = [
25+
assets.currencyAave,
26+
assets.currencyTestTokenA,
27+
assets.currencyTestTokenB,
28+
assets.currencyUSDC,
29+
assets.currencyLink,
30+
assets.currencyDaiCap,
31+
]
32+
33+
assets.selectTokenList(assets.tokenListOptions.allTokens)
34+
main.verifyValuesExist(assets.tokenListTable, spamTokens)
35+
main.verifyElementsCount(assets.tablePaginationContainer, 0)
36+
})
37+
38+
it('Verify Proposers have the Send and Swap buttons enabled', () => {
39+
cy.visit(constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_31)
40+
wallet.connectSigner(signer)
41+
assets.selectTokenList(assets.tokenListOptions.default)
42+
main.verifyValuesExist(assets.tokenListTable, [constants.tokenNames.sepoliaEther])
43+
assets.showSendBtn().should('be.enabled')
44+
assets.showSwapBtn().should('be.enabled')
45+
navigation.clickOnWalletExpandMoreIcon()
46+
navigation.clickOnDisconnectBtn()
47+
})
48+
49+
it('Verify that Send and Swap buttons are enabled for spending limit users', () => {
50+
cy.visit(constants.BALANCE_URL + staticSafes.SEP_STATIC_SAFE_8)
51+
wallet.connectSigner(signer2)
52+
assets.selectTokenList(assets.tokenListOptions.default)
53+
main.verifyValuesExist(assets.tokenListTable, [constants.tokenNames.sepoliaEther])
54+
assets.showSendBtn().should('be.enabled')
55+
assets.showSwapBtn().should('be.enabled')
56+
navigation.clickOnWalletExpandMoreIcon()
57+
navigation.clickOnDisconnectBtn()
58+
})
59+
60+
it('Verify the counter at the top is updated for every selected token', () => {
61+
cy.visit(constants.balanceNftsUrl + staticSafes.SEP_STATIC_SAFE_2)
62+
nfts.waitForNftItems(5)
63+
nfts.selectNFTs(1)
64+
})
65+
66+
it.only('Verify the "select all" checkbox does checks all the nfts', () => {
67+
cy.visit(constants.balanceNftsUrl + staticSafes.SEP_STATIC_SAFE_2)
68+
nfts.waitForNftItems(5)
69+
nfts.selectAllNFTs()
70+
nfts.checkSelectedNFTsNumberIs(10)
71+
})
72+
73+
it('Verify every NFT has its shorten address', () => {
74+
cy.visit(constants.balanceNftsUrl + staticSafes.SEP_STATIC_SAFE_2)
75+
nfts.waitForNftItems(5)
76+
assets.checkNftAddressFormat()
77+
})
78+
79+
it('Verify every NFT has the copy-to-clipboard and blockexplorer button', () => {
80+
cy.visit(constants.balanceNftsUrl + staticSafes.SEP_STATIC_SAFE_2)
81+
nfts.waitForNftItems(5)
82+
assets.checkNftCopyIconAndLink()
83+
})
84+
})

apps/web/cypress/e2e/regression/tx_details_createtx.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('Transaction details create tests', { defaultCommandTimeout: 30000 }, (
7676
getBody().findByText(safeapps.createBatchStr).click()
7777
getBody().findByText(safeapps.sendBatchStr).click()
7878
})
79+
cy.wait(2000)
7980
safeapps.clickOnAdvancedDetails()
8081
safeapps.verifyUntrustedHandllerWarningDoesNotExist()
8182
})

apps/web/cypress/e2e/smoke/assets.cy.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('[SMOKE] Assets tests', () => {
2525
assets.verifyTokensTabIsSelected('true')
2626
})
2727

28-
it('[SMOKE] Verify that Token list dropdown down options show/hide spam tokens', () => {
28+
it('[SMOKE] Verify that Token list dropdown shows options "Default tokens" and "All tokens"', () => {
2929
let spamTokens = [
3030
assets.currencyAave,
3131
assets.currencyTestTokenA,
@@ -35,14 +35,12 @@ describe('[SMOKE] Assets tests', () => {
3535
assets.currencyDaiCap,
3636
]
3737

38-
cy.wrap(null)
39-
.then(() => main.addToLocalStorage(constants.localStorageKeys.SAFE_v2__settings, ls.safeSettings.slimitSettings))
40-
.then(() => {
41-
cy.reload()
42-
main.verifyValuesDoNotExist(assets.tokenListTable, spamTokens)
43-
assets.selectTokenList(assets.tokenListOptions.allTokens)
44-
spamTokens.push(constants.tokenNames.sepoliaEther)
45-
main.verifyValuesExist(assets.tokenListTable, spamTokens)
46-
})
38+
assets.selectTokenList(assets.tokenListOptions.default)
39+
main.verifyValuesExist(assets.tokenListTable, [constants.tokenNames.sepoliaEther])
40+
main.verifyValuesDoNotExist(assets.tokenListTable, spamTokens)
41+
42+
assets.selectTokenList(assets.tokenListOptions.allTokens)
43+
spamTokens.push(constants.tokenNames.sepoliaEther)
44+
main.verifyValuesExist(assets.tokenListTable, spamTokens)
4745
})
4846
})

apps/web/src/components/balances/AssetsTable/SendButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const SendButton = ({ tokenInfo, isOutlined }: { tokenInfo: TokenInfo; isOutline
2222
{(isOk) => (
2323
<Track {...ASSETS_EVENTS.SEND}>
2424
<Button
25+
data-testid="send-button"
2526
variant={isOutlined ? 'outlined' : 'contained'}
2627
color="primary"
2728
size="small"

apps/web/src/components/common/EnhancedTable/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function EnhancedTable({ rows, headCells, mobileVariant }: EnhancedTableProps) {
180180

181181
{rows.length > pagedRows.length && (
182182
<TablePagination
183+
data-testid="table-pagination"
183184
rowsPerPageOptions={pageSizes}
184185
component="div"
185186
count={rows.length}

0 commit comments

Comments
 (0)