-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
141 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
import { Page } from '@playwright/test'; | ||
import { SwapCryptoAssetSelectors } from '@tests/selectors/swap.selectors'; | ||
import { Locator, Page } from '@playwright/test'; | ||
import { SwapSelectors } from '@tests/selectors/swap.selectors'; | ||
import { createTestSelector } from '@tests/utils'; | ||
|
||
export class SwapPage { | ||
readonly page: Page; | ||
readonly chooseAssetList: Locator; | ||
readonly chooseAssetListItem: Locator; | ||
readonly selectAssetBtn: Locator; | ||
readonly swapAmountInput: Locator; | ||
readonly swapBtn: Locator; | ||
readonly swapDetailsAmount: Locator; | ||
readonly swapDetailsProtocol: Locator; | ||
readonly swapDetailsSymbol: Locator; | ||
readonly swapReviewBtn: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.chooseAssetList = page.getByTestId(SwapSelectors.ChooseAssetList); | ||
this.chooseAssetListItem = page.getByTestId(SwapSelectors.ChooseAssetListItem); | ||
this.selectAssetBtn = page.getByTestId(SwapSelectors.SelectAssetTriggerBtn); | ||
this.swapAmountInput = page.getByTestId(SwapSelectors.SwapAmountInput); | ||
this.swapBtn = page.getByTestId(SwapSelectors.SwapBtn); | ||
this.swapDetailsAmount = page.getByTestId(SwapSelectors.SwapDetailsAmount); | ||
this.swapDetailsProtocol = page.getByTestId(SwapSelectors.SwapDetailsProtocol); | ||
this.swapDetailsSymbol = page.getByTestId(SwapSelectors.SwapDetailsSymbol); | ||
this.swapReviewBtn = page.getByTestId(SwapSelectors.SwapReviewBtn); | ||
} | ||
|
||
async waitForSendPageReady() { | ||
await this.page.waitForSelector(createTestSelector(SwapCryptoAssetSelectors.SwapPageReady), { | ||
async waitForSwapPageReady() { | ||
await this.page.waitForSelector(createTestSelector(SwapSelectors.SwapPageReady), { | ||
state: 'attached', | ||
}); | ||
} | ||
|
||
async selectAssetToReceive() { | ||
const swapAssetSelectors = await this.selectAssetBtn.all(); | ||
await swapAssetSelectors[1].click(); | ||
await this.chooseAssetList.waitFor(); | ||
const swapAssets = await this.chooseAssetListItem.all(); | ||
await swapAssets[0].click(); | ||
await this.swapReviewBtn.click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
export enum SwapCryptoAssetSelectors { | ||
export enum SwapSelectors { | ||
ChooseAssetList = 'choose-asset-list', | ||
ChooseAssetListItem = 'choose-asset-list-item', | ||
SelectAssetTriggerBtn = 'select-asset-trigger-btn', | ||
SwapAmountInput = 'swap-amount-input', | ||
SwapBtn = 'swap-btn', | ||
SwapDetailsAmount = 'swap-details-amount', | ||
SwapDetailsProtocol = 'swap-details-protocol', | ||
SwapDetailsSymbol = 'swap-details-symbol', | ||
SwapPageReady = 'swap-page-ready', | ||
SwapReviewBtn = 'swap-review-btn', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
import { test } from '../../fixtures/fixtures'; | ||
|
||
test.describe('swap', () => { | ||
const alexSdkPostRoute = 'https://gql.alexlab.co/v1/graphql'; | ||
|
||
test.describe('Swaps', () => { | ||
test.beforeEach(async ({ extensionId, globalPage, homePage, onboardingPage, swapPage }) => { | ||
await globalPage.setupAndUseApiCalls(extensionId); | ||
await onboardingPage.signInWithTestAccount(extensionId); | ||
await homePage.enableTestMode(); | ||
await homePage.swapButton.click(); | ||
await swapPage.waitForSendPageReady(); | ||
await swapPage.waitForSwapPageReady(); | ||
}); | ||
|
||
test('that it defaults to swapping STX', async ({ swapPage }) => { | ||
test.expect(swapPage.page.getByText('STX')).toBeTruthy(); | ||
}); | ||
|
||
// Skip tests until feature is live | ||
test.skip('that it shows swap page', async ({ swapPage }) => { | ||
await test.expect(swapPage.page.getByText('Swap')).toBeVisible(); | ||
test('that it shows correct swap review details', async ({ swapPage }) => { | ||
const swapAmountInputs = await swapPage.swapAmountInput.all(); | ||
await swapAmountInputs[0].fill('1'); | ||
await swapPage.selectAssetToReceive(); | ||
|
||
const swapProtocol = await swapPage.swapDetailsProtocol.innerText(); | ||
test.expect(swapProtocol).toEqual('ALEX'); | ||
|
||
const swapAssets = await swapPage.swapDetailsSymbol.all(); | ||
const swapAssetFrom = await swapAssets[0].innerText(); | ||
const swapAssetTo = await swapAssets[1].innerText(); | ||
test.expect(swapAssetFrom).toEqual('STX'); | ||
test.expect(swapAssetTo).toEqual('ALEX'); | ||
|
||
const swapAmounts = await swapPage.swapDetailsAmount.all(); | ||
const swapAmountFrom = await swapAmounts[0].innerText(); | ||
test.expect(swapAmountFrom).toEqual('1'); | ||
|
||
test.expect(swapPage.page.getByText('Sponsored')).toBeTruthy(); | ||
}); | ||
|
||
test('that the swap is broadcast', async ({ swapPage }) => { | ||
const requestPromise = swapPage.page.waitForRequest(alexSdkPostRoute); | ||
|
||
await swapPage.page.route(alexSdkPostRoute, async route => { | ||
await route.abort(); | ||
}); | ||
|
||
const swapAmountInputs = await swapPage.swapAmountInput.all(); | ||
await swapAmountInputs[0].fill('1'); | ||
await swapPage.selectAssetToReceive(); | ||
|
||
await swapPage.swapBtn.click(); | ||
|
||
const request = await requestPromise; | ||
const requestBody = request.postDataBuffer(); | ||
test.expect(requestBody).toBeDefined(); | ||
}); | ||
}); |