chore(trading): deal ticket order tests move (#4927)
This commit is contained in:
parent
ccb22f02c3
commit
18f1fbd56d
@ -1,134 +0,0 @@
|
||||
import {
|
||||
orderPriceField,
|
||||
orderSizeField,
|
||||
orderTIFDropDown,
|
||||
placeOrderBtn,
|
||||
toggleLimit,
|
||||
toggleMarket,
|
||||
} from '../support/deal-ticket';
|
||||
|
||||
describe('deal ticker order validation', { tags: '@smoke' }, () => {
|
||||
before(() => {
|
||||
cy.setVegaWallet();
|
||||
cy.mockTradingPage();
|
||||
cy.mockSubscription();
|
||||
cy.visit('/#/markets/market-0');
|
||||
cy.wait('@Markets');
|
||||
|
||||
cy.get('[data-testid="deal-ticket-form"]').then(($form) => {
|
||||
if (!$form.length) {
|
||||
cy.getByTestId('Order').click();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
cy.mockTradingPage();
|
||||
cy.getByTestId('deal-ticket-fee-margin-required').click();
|
||||
});
|
||||
|
||||
describe('limit order', () => {
|
||||
before(() => {
|
||||
cy.getByTestId(toggleLimit).click();
|
||||
});
|
||||
|
||||
it('must see the price unit', function () {
|
||||
// 7002-SORD-018
|
||||
cy.getByTestId(orderPriceField).next().should('have.text', 'DAI');
|
||||
});
|
||||
|
||||
it('must see warning when placing an order with expiry date in past', () => {
|
||||
const expiresAt = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
const expiresAtInputValue = expiresAt.toISOString().substring(0, 16);
|
||||
cy.getByTestId(toggleLimit).click();
|
||||
cy.getByTestId(orderPriceField).clear().type('0.1');
|
||||
cy.getByTestId(orderSizeField).clear().type('1');
|
||||
cy.getByTestId(orderTIFDropDown).select('TIME_IN_FORCE_GTT');
|
||||
|
||||
cy.log('choosing yesterday');
|
||||
cy.getByTestId('date-picker-field').type(expiresAtInputValue);
|
||||
|
||||
cy.getByTestId(placeOrderBtn).click();
|
||||
|
||||
cy.getByTestId('deal-ticket-error-message-expiry').should(
|
||||
'have.text',
|
||||
'The expiry date that you have entered appears to be in the past'
|
||||
);
|
||||
});
|
||||
|
||||
it('must see warning if price has too many digits after decimal place', function () {
|
||||
// 7002-SORD-059
|
||||
cy.getByTestId(toggleLimit).click();
|
||||
cy.getByTestId(orderTIFDropDown).select('TIME_IN_FORCE_GTC');
|
||||
cy.getByTestId(orderSizeField).clear().type('1');
|
||||
cy.getByTestId(orderPriceField).clear().type('1.123456');
|
||||
cy.getByTestId(placeOrderBtn).click();
|
||||
cy.getByTestId('deal-ticket-error-message-price').should(
|
||||
'have.text',
|
||||
'Price accepts up to 5 decimal places'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('market order', () => {
|
||||
before(() => {
|
||||
cy.getByTestId(toggleMarket).click();
|
||||
cy.getByTestId(placeOrderBtn).click();
|
||||
});
|
||||
|
||||
it('must not see the price unit', function () {
|
||||
// 7002-SORD-019
|
||||
cy.getByTestId(orderPriceField).should('not.exist');
|
||||
});
|
||||
|
||||
it('must warn if order size input has too many digits after the decimal place', function () {
|
||||
// 7002-SORD-016
|
||||
cy.getByTestId(orderSizeField).clear().type('1.234');
|
||||
// 7002-SORD-060
|
||||
cy.getByTestId(placeOrderBtn).should('be.enabled');
|
||||
cy.getByTestId('deal-ticket-error-message-size').should(
|
||||
'have.text',
|
||||
'Size must be whole numbers for this market'
|
||||
);
|
||||
});
|
||||
|
||||
it('must warn if order size is set to 0', function () {
|
||||
cy.getByTestId(orderSizeField).clear().type('0');
|
||||
cy.getByTestId(placeOrderBtn).should('be.enabled');
|
||||
cy.getByTestId('deal-ticket-error-message-size').should(
|
||||
'have.text',
|
||||
'Size cannot be lower than 1'
|
||||
);
|
||||
});
|
||||
|
||||
it('must have total margin available', () => {
|
||||
// 7001-COLL-011
|
||||
cy.getByTestId('deal-ticket-fee-total-margin-available').within(() => {
|
||||
cy.get('[data-state="closed"]').should(
|
||||
'have.text',
|
||||
'Total margin available100.01 tDAI'
|
||||
);
|
||||
});
|
||||
cy.getByTestId('deal-ticket-fee-margin-required').click();
|
||||
});
|
||||
|
||||
it('must have current margin allocation', () => {
|
||||
cy.getByTestId('deal-ticket-fee-current-margin-allocation').within(() => {
|
||||
cy.get('[data-state="closed"]:first').should(
|
||||
'have.text',
|
||||
'Current margin allocation'
|
||||
);
|
||||
});
|
||||
cy.getByTestId('deal-ticket-fee-margin-required').click();
|
||||
});
|
||||
|
||||
it('should open usage breakdown dialog when clicked on current margin allocation', () => {
|
||||
cy.getByTestId('deal-ticket-fee-current-margin-allocation').within(() => {
|
||||
cy.get('button').click();
|
||||
});
|
||||
cy.getByTestId('usage-breakdown').should('exist');
|
||||
cy.getByTestId('dialog-close').click();
|
||||
cy.getByTestId('deal-ticket-fee-margin-required').click();
|
||||
});
|
||||
});
|
||||
});
|
@ -156,6 +156,44 @@ describe('DealTicket', () => {
|
||||
expect(screen.getByTestId('order-tif')).toHaveValue(
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_GTC
|
||||
);
|
||||
// 7002-SORD-018
|
||||
expect(screen.getByTestId('order-price').nextSibling).toHaveTextContent(
|
||||
'BTC'
|
||||
);
|
||||
});
|
||||
|
||||
it('market order should not display price', async () => {
|
||||
render(generateJsx());
|
||||
await userEvent.click(screen.getByTestId('order-type-Market'));
|
||||
// 7002-SORD-018ß
|
||||
expect(screen.queryByTestId('order-price')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('market order must warn for whole numbers', async () => {
|
||||
const marketOverrides = { positionDecimalPlaces: 0 };
|
||||
render(generateJsx([], marketOverrides));
|
||||
await userEvent.click(screen.getByTestId('order-type-Market'));
|
||||
await userEvent.click(screen.getByTestId('place-order'));
|
||||
await userEvent.type(screen.getByTestId('order-size'), '1.231');
|
||||
// 7002-SORD-060
|
||||
expect(screen.queryByTestId('place-order')).toBeEnabled();
|
||||
// 7002-SORD-016
|
||||
expect(
|
||||
screen.queryByTestId('deal-ticket-error-message-size')
|
||||
).toHaveTextContent('Size must be whole numbers for this market');
|
||||
});
|
||||
|
||||
it('market order must warn if order size set to 0', async () => {
|
||||
render(generateJsx());
|
||||
await userEvent.click(screen.getByTestId('order-type-Market'));
|
||||
await userEvent.click(screen.getByTestId('place-order'));
|
||||
await userEvent.type(screen.getByTestId('order-size'), '0');
|
||||
// 7002-SORD-060
|
||||
expect(screen.queryByTestId('place-order')).toBeEnabled();
|
||||
// 7002-SORD-016
|
||||
expect(
|
||||
screen.queryByTestId('deal-ticket-error-message-size')
|
||||
).toHaveTextContent('Size cannot be lower than 0.1');
|
||||
});
|
||||
|
||||
it('should use local storage state for initial values', () => {
|
||||
@ -686,7 +724,6 @@ describe('DealTicket', () => {
|
||||
new Date(screen.getByTestId<HTMLInputElement>(datePicker).value).getTime()
|
||||
).toEqual(now);
|
||||
});
|
||||
|
||||
describe('market states not accepting orders', () => {
|
||||
const states = [
|
||||
Schema.MarketState.STATE_REJECTED,
|
||||
@ -715,4 +752,80 @@ describe('DealTicket', () => {
|
||||
expect(screen.getByTestId('place-order')).toBeEnabled();
|
||||
});
|
||||
});
|
||||
it('must see warning if price has too many digits after decimal place', async () => {
|
||||
// 7002-SORD-059
|
||||
// Render component
|
||||
render(generateJsx());
|
||||
|
||||
// Elements
|
||||
const toggleLimit = screen.getByTestId('order-type-Limit');
|
||||
const orderTIFDropDown = screen.getByTestId('order-tif');
|
||||
const orderSizeField = screen.getByTestId('order-price');
|
||||
const orderPriceField = screen.getByTestId('order-price');
|
||||
const placeOrderBtn = screen.getByTestId('place-order');
|
||||
|
||||
// Actions
|
||||
await userEvent.click(toggleLimit);
|
||||
await userEvent.selectOptions(orderTIFDropDown, 'TIME_IN_FORCE_GTC');
|
||||
await userEvent.clear(orderSizeField);
|
||||
await userEvent.type(orderSizeField, '1');
|
||||
await userEvent.clear(orderPriceField);
|
||||
await userEvent.type(orderPriceField, '1.123456');
|
||||
await userEvent.click(placeOrderBtn);
|
||||
|
||||
// Expectations
|
||||
await waitFor(() => {
|
||||
const errorMessage = screen.getByTestId(
|
||||
'deal-ticket-error-message-price'
|
||||
);
|
||||
expect(errorMessage).toHaveTextContent(
|
||||
'Price accepts up to 2 decimal places'
|
||||
);
|
||||
});
|
||||
});
|
||||
it('must see warning when placing an order with expiry date in past', async () => {
|
||||
// Render component
|
||||
render(generateJsx());
|
||||
|
||||
const now = Date.now();
|
||||
jest.spyOn(global.Date, 'now').mockImplementation(() => now);
|
||||
// Elements
|
||||
const toggleLimit = screen.getByTestId('order-type-Limit');
|
||||
const orderPriceField = screen.getByTestId('order-price');
|
||||
const orderSizeField = screen.getByTestId('order-price');
|
||||
const orderTIFDropDown = screen.getByTestId('order-tif');
|
||||
const datePicker = 'date-picker-field';
|
||||
const placeOrderBtn = screen.getByTestId('place-order');
|
||||
|
||||
// Actions
|
||||
userEvent.click(toggleLimit);
|
||||
userEvent.clear(orderPriceField);
|
||||
userEvent.type(orderPriceField, '0.1');
|
||||
userEvent.clear(orderSizeField);
|
||||
userEvent.type(orderSizeField, '1');
|
||||
await userEvent.selectOptions(
|
||||
orderTIFDropDown,
|
||||
Schema.OrderTimeInForce.TIME_IN_FORCE_GTT
|
||||
);
|
||||
|
||||
// Set date to past
|
||||
const expiresAt = new Date(now - 24 * 60 * 60 * 1000);
|
||||
const expiresAtInputValue = formatForInput(expiresAt);
|
||||
fireEvent.change(screen.getByTestId(datePicker), {
|
||||
target: { value: expiresAtInputValue },
|
||||
});
|
||||
|
||||
// Place order
|
||||
userEvent.click(placeOrderBtn);
|
||||
|
||||
// Expectations
|
||||
await waitFor(() => {
|
||||
const errorMessage = screen.getByTestId(
|
||||
'deal-ticket-error-message-expiry'
|
||||
);
|
||||
expect(errorMessage).toHaveTextContent(
|
||||
'The expiry date that you have entered appears to be in the past'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user