Skip to content

Commit

Permalink
QA-59 | E2E | Limit Oder - Add tests (#2314)
Browse files Browse the repository at this point in the history
Add limit order tests
  • Loading branch information
ltthienn authored Oct 20, 2023
1 parent 411361f commit f4c826b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cypress/e2e/pages/limit-order.po.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const LimitOder = {
cy.getContent(LimitOrderLocators.dropdownTokenBuy, text)
},

setAmountIn(value: string) {
cy.get(LimitOrderLocators.txtTokenSellAmount).type(value)
},

setSellingRate(text: string) {
cy.get(LimitOrderLocators.txtSellingRate).click().type(text)
},
Expand All @@ -30,5 +34,13 @@ export const LimitOder = {
return cy.get(LimitOrderLocators.txtSellingRate).invoke('val').then(value => {
return value
})
},

getBalanceIn(text: myCallbackType<string>) {
cy.getContent(LimitOrderLocators.lblBalanceIn, text)
},

getInsufficientErrorMessage() {
return cy.get(LimitOrderLocators.lblErrorMessage)
}
}
5 changes: 4 additions & 1 deletion cypress/e2e/selectors/selectors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ export const SwapPageLocators = {
}

export const LimitOrderLocators = {
txtTokenSellAmount: '[data-testid=limit-order-input-tokena] [data-testid=token-amount-input]',
dropdownTokenSell: '[data-testid=limit-order-input-tokena] [data-testid=token-symbol-container]',
dropdownTokenBuy: '[data-testid=limit-order-input-tokenb] [data-testid=token-symbol-container]',
btnLimit: '[data-testid=limit-button]',
txtSellingRate: '[data-testid=input-selling-rate]'
txtSellingRate: '[data-testid=input-selling-rate]',
lblBalanceIn: '[data-testid=limit-order-input-tokena] [data-testid=balance]',
lblErrorMessage: '[data-testid=error-message]'
}

export const WalletLocators = {
Expand Down
11 changes: 10 additions & 1 deletion cypress/e2e/specs/limit-order.e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const tokenSymbols = TOKEN_SYMBOLS[NETWORK]
const tokenCatalog = new TokenCatalog();


describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
describe(`Limit Order on ${NETWORK}`, { tags: TAG.regression }, () => {
beforeEach(() => {
SwapPage.open(DEFAULT_URL)
SwapPage.goToLimitOrder()
Expand Down Expand Up @@ -88,4 +88,13 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
})
})
})

describe('Messages', () => {
it('Verify error message when insufficient balance', () => {
LimitOder.getBalanceIn((text) => {
LimitOder.setAmountIn(String(Number(text) + 1))
LimitOder.getInsufficientErrorMessage().should('be.visible')
})
})
})
})
2 changes: 2 additions & 0 deletions cypress/e2e/specs/swap-page.e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
it('Should be removed tokenIn from favorite tokens list', () => {
SwapPage.selectTokenIn().getFavoriteTokens((arr) => {
tokenCatalog.removeFavoriteToken(arr[1])
cy.wait(2000)
tokenCatalog.getFavoriteTokens((list) => {
expect(list).not.to.include.members([arr[1]])
})
Expand All @@ -56,6 +57,7 @@ describe(`Token Catalog on ${NETWORK}`, { tags: TAG.regression }, () => {
it('Should be removed tokenOut from favorite tokens list', () => {
SwapPage.selectTokenOut().getFavoriteTokens((arr) => {
tokenCatalog.removeFavoriteToken(arr[2])
cy.wait(2000)
tokenCatalog.getFavoriteTokens((list) => {
expect(list).not.to.include.members([arr[2]])
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/CurrencyInputPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default function CurrencyInputPanel({
)}
<Flex onClick={onMax ?? undefined} style={{ cursor: onMax ? 'pointer' : undefined }} alignItems="center">
<Wallet color={theme.subText} />
<Text fontWeight={500} color={theme.subText} marginLeft="4px">
<Text fontWeight={500} color={theme.subText} marginLeft="4px" data-testid="balance">
{customBalanceText || selectedCurrencyBalance?.toSignificant(10) || balanceRef.current || 0}
</Text>
</Flex>
Expand All @@ -319,6 +319,7 @@ export default function CurrencyInputPanel({
<NumericalInput
error={error}
className="token-amount-input"
data-testid="token-amount-input"
value={value}
disabled={disabledInput}
maxLength={maxLength}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface TooltipProps extends Omit<PopoverProps, 'content'> {
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>
children?: React.ReactNode
dataTestId?: string
}

export default function Tooltip({
Expand All @@ -45,6 +46,7 @@ export default function Tooltip({
onMouseEnter,
onMouseLeave,
show,
dataTestId,
...rest
}: TooltipProps) {
return (
Expand All @@ -57,6 +59,7 @@ export default function Tooltip({
size={size}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
data-testid={dataTestId}
>
{text}
</TooltipContainer>
Expand Down
9 changes: 8 additions & 1 deletion src/components/swapv2/LimitOrder/LimitOrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,14 @@ const LimitOrderForm = forwardRef<LimitOrderFormHandle, Props>(function LimitOrd
return (
<>
<Flex flexDirection={'column'} style={{ gap: '1rem' }}>
<Tooltip text={inputError} show={!!inputError} placement="top" style={styleTooltip} width="fit-content">
<Tooltip
text={inputError}
show={!!inputError}
placement="top"
style={styleTooltip}
width="fit-content"
dataTestId="error-message"
>
<CurrencyInputPanel
error={!!inputError}
value={inputAmount}
Expand Down

0 comments on commit f4c826b

Please sign in to comment.