From 138bd4d726b76330466ac261558da21fbd5e37a8 Mon Sep 17 00:00:00 2001 From: alinasytnik Date: Sat, 19 Nov 2022 00:28:36 +0100 Subject: [PATCH] feat: test init --- source/components/AssetItem/index.jsx | 3 + .../Views/AddToken/components/SearchToken.jsx | 4 +- .../Views/AddToken/hooks/useSteps.jsx | 4 +- tests/e2e/custom-token.test.js | 87 +++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/custom-token.test.js diff --git a/source/components/AssetItem/index.jsx b/source/components/AssetItem/index.jsx index f8c5faa6..cd799ea0 100644 --- a/source/components/AssetItem/index.jsx +++ b/source/components/AssetItem/index.jsx @@ -94,6 +94,8 @@ const AssetItem = ({ buttonVariant="danger" onClick={handleRemoveAssetDisplay} onClose={handleModalClose} + cancelButtonProps={{ 'data-testid': 'cancel-button' }} + submitButtonProps={{ 'data-testid': 'delete-token-button' }} />
@@ -155,6 +157,7 @@ const AssetItem = ({ setOpenDelete(true)} alt="delete-token" + data-testid="delete-token-button" src={DeleteIcon} />
diff --git a/source/views/Extension/Views/AddToken/components/SearchToken.jsx b/source/views/Extension/Views/AddToken/components/SearchToken.jsx index 13cb910a..026b60d1 100644 --- a/source/views/Extension/Views/AddToken/components/SearchToken.jsx +++ b/source/views/Extension/Views/AddToken/components/SearchToken.jsx @@ -60,6 +60,7 @@ const SearchToken = ({ handleChangeSelectedToken, handleChangeTab }) => { @@ -94,7 +95,7 @@ const SearchToken = ({ handleChangeSelectedToken, handleChangeTab }) => { && } - {ft.name} ({ft.symbol}) + {ft.name} ({ft.symbol}) ))}
@@ -112,6 +113,7 @@ const SearchToken = ({ handleChangeSelectedToken, handleChangeTab }) => { style={{ marginTop: 6 }} value={t('addToken.addCustomToken')} onClick={() => handleChangeTab(1)} + data-testid="add-custom-token-button" />
diff --git a/source/views/Extension/Views/AddToken/hooks/useSteps.jsx b/source/views/Extension/Views/AddToken/hooks/useSteps.jsx index 894f964c..4d680582 100644 --- a/source/views/Extension/Views/AddToken/hooks/useSteps.jsx +++ b/source/views/Extension/Views/AddToken/hooks/useSteps.jsx @@ -21,8 +21,8 @@ const useSteps = () => { const handleChangeStep = (index) => setStep(index); const handleClose = () => navigator.navigate('home'); - const leftButton = (onClick) => ; - const rightButton = handleClose()} />; + const leftButton = (onClick) => ; + const rightButton = handleClose()} />; const steps = [ { diff --git a/tests/e2e/custom-token.test.js b/tests/e2e/custom-token.test.js new file mode 100644 index 00000000..b2bf2fca --- /dev/null +++ b/tests/e2e/custom-token.test.js @@ -0,0 +1,87 @@ +// Clicks +async function pressKey(page, key, numberOfPresses = 4) { + const array = Array.from(Array(numberOfPresses).keys()); + + // eslint-disable-next-line no-unused-vars + for (const _ of array) { + await page.keyboard.press(key); + } +} + +const clickFoundElement = async (page, testId) => { + const element = await page.getByTestId(testId, true); + await element.click(); + + return element; +}; + +const addButtonClick = (page) => clickFoundElement(page, 'add-button'); +const addCustomTokenButtonClick = (page) => clickFoundElement(page, 'add-custom-token-button'); +const tokenSearchInputClick = (page) => clickFoundElement(page, 'token-search-input'); +const searchTabClick = (page) => clickFoundElement(page, 'tab-item-Search'); +const foundTokenClick = (page, name) => clickFoundElement(page, `custom-token-${name}`); +const deleteTokenButtonClick = (page) => clickFoundElement(page, 'delete-token-button'); +const cancelButtonClick = (page) => clickFoundElement(page, 'cancel-button'); +const closeButtonClick = (page) => clickFoundElement(page, 'close-button'); +const backButtonClick = (page) => clickFoundElement(page, 'back-button'); + +describe('Add Custom NFT', () => { + let browser; + let page; + + beforeAll(async () => { + browser = await setupChrome(); + + // Importing and unlocking the accoun + page = await utils.createNewPage(browser); + + await optionsPageUtils.importAccount(page, secrets.seedphrase, secrets.password); + await optionsPageUtils.unlock(page, secrets.password); + + await page.close(); + }); + + beforeEach(async () => { + page = await utils.createNewPage(browser); + await page.goto(chromeData.popupUrl); + await addButtonClick(page); + await addCustomTokenButtonClick(page); + }); + + afterEach(async () => { + await page.close(); + }); + + afterAll(async () => { + await browser.close(); + }); + + test('canceling custom token adding', async () => { + await closeButtonClick(page); + await addButtonClick(page); + }); + + test('back to the main flow', async () => { + await backButtonClick(page); + await addButtonClick(page); + }); + + test('checking search custom token flow', async () => { + await tokenSearchInputClick(page); + await page.keyboard.type('pp'); + await addCustomTokenButtonClick(page); + await page.waitForTestIdSelector('token-canister-id-input'); + + await searchTabClick(page); + await tokenSearchInputClick(page); + await page.keyboard.type('d'); + await pressKey(page, 'Backspace', 1); + await page.keyboard.type('d'); + await foundTokenClick(page, 'BOXY DUDE'); + await addButtonClick(page); + await page.waitForTestIdSelector('asset-name-BOX Token'); + await deleteTokenButtonClick(page); + await deleteTokenButtonClick(page); + await page.waitForTestIdSelector('asset-name-BOX Token', { hidden: true }); + }); +});