From 82983694feb4723875d10f2db715172fabb01a5b Mon Sep 17 00:00:00 2001 From: chloeYue <105063779+chloeYue@users.noreply.github.com> Date: Tue, 7 Feb 2023 23:34:04 +0100 Subject: [PATCH] Add e2e test: send nft (#17638) * add e2e test send nft --- test/e2e/nft/import-nft.spec.js | 2 +- test/e2e/nft/send-nft.spec.js | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/e2e/nft/send-nft.spec.js diff --git a/test/e2e/nft/import-nft.spec.js b/test/e2e/nft/import-nft.spec.js index a890d6397..eb493dd78 100644 --- a/test/e2e/nft/import-nft.spec.js +++ b/test/e2e/nft/import-nft.spec.js @@ -62,7 +62,7 @@ describe('Import NFT', function () { ); }); - it('should not be able to import an NFT that dose not belong to user', async function () { + it('should not be able to import an NFT that does not belong to user', async function () { await withFixtures( { dapp: true, diff --git a/test/e2e/nft/send-nft.spec.js b/test/e2e/nft/send-nft.spec.js new file mode 100644 index 000000000..66e562675 --- /dev/null +++ b/test/e2e/nft/send-nft.spec.js @@ -0,0 +1,76 @@ +const { strict: assert } = require('assert'); +const { convertToHexValue, withFixtures } = require('../helpers'); +const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); +const FixtureBuilder = require('../fixture-builder'); + +describe('Send NFT', function () { + const smartContract = SMART_CONTRACTS.COLLECTIBLES; + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: convertToHexValue(25000000000000000000), + }, + ], + }; + + it('should be able to send ERC721 NFT', async function () { + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder().build(), + ganacheOptions, + smartContract, + title: this.test.title, + }, + async ({ driver, _, contractRegistry }) => { + const contractAddress = + contractRegistry.getContractAddress(smartContract); + await driver.navigate(); + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + // After login, go to NFTs tab and import an NFT + await driver.clickElement('[data-testid="home__nfts-tab"]'); + await driver.clickElement({ text: 'Import NFTs', tag: 'a' }); + + await driver.fill('[data-testid="address"]', contractAddress); + await driver.fill('[data-testid="token-id"]', '1'); + await driver.clickElement({ text: 'Add', tag: 'button' }); + + // Fill the send NFT form and confirm the transaction + await driver.clickElement('.collectibles-items__item-image'); + await driver.clickElement({ text: 'Send', tag: 'button' }); + await driver.fill( + 'input[placeholder="Search, public address (0x), or ENS"]', + '0xc427D562164062a23a5cFf596A4a3208e72Acd28', + ); + await driver.clickElement({ text: 'Next', tag: 'button' }); + await driver.clickElement({ text: 'Confirm', tag: 'button' }); + + // When transaction complete, check the send nft item is displayed in activity tab + await driver.wait(async () => { + const confirmedTxes = await driver.findElements( + '.transaction-list__completed-transactions .transaction-list-item', + ); + return confirmedTxes.length === 1; + }, 10000); + + const sendNftItem = await driver.findElement({ + css: 'h2', + text: 'Send Test Dapp Collectibles', + }); + assert.equal(await sendNftItem.isDisplayed(), true); + + // Go back to NFTs tab and check the imported NFT is shown as previously owned + await driver.clickElement('[data-testid="home__nfts-tab"]'); + const previouslyOwnedNft = await driver.findElement({ + css: 'h5', + text: 'Previously Owned', + }); + assert.equal(await previouslyOwnedNft.isDisplayed(), true); + }, + ); + }); +});