test(trading): 6004-CHAR-chart e2e tests (#4179)

This commit is contained in:
Ben 2023-06-29 09:14:54 +01:00 committed by GitHub
parent ed2c82487d
commit 45b7c2ad4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 417 additions and 25 deletions

View File

@ -1,28 +1,180 @@
describe('chart', { tags: '@smoke' }, () => {
beforeEach(() => {
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
cy.wait('@Markets');
});
it('config should persist', () => {
cy.getByTestId('Chart').click();
cy.get('[data-testid="tab-chart"] button').as('control-buttons');
cy.get('@control-buttons').each(($button) => {
cy.wrap($button).click();
cy.get(
'[role="menuitemradio"]:first, [role="menuitemcheckbox"]:first'
).click();
});
cy.getByTestId('Depth').click();
cy.getByTestId('Chart').click();
cy.get('@control-buttons').each(($button) => {
cy.wrap($button).click();
cy.get('[role="menuitemradio"]:first, [role="menuitemcheckbox"]:first')
.within(($lastMenuItem) => {
expect($lastMenuItem.data('state')).to.equal('checked');
})
.click();
interface ItemInfoType {
name: string;
infoText: string;
}
type CheckMenuItemsFnType = (
triggerSelector: string,
validTexts: string[],
clickItem?: string
) => void;
type CheckMenuItemCheckboxFnType = (
buttonText: string,
items: ItemInfoType[]
) => void;
const menuItemRadio = 'div[role="menuitemradio"]';
const menuItemCheckbox = 'div[role="menuitemcheckbox"]';
const button = 'button';
const indicatorInfo = '.indicator-info-wrapper';
const checkMenuItems: CheckMenuItemsFnType = (
triggerSelector,
validTexts,
clickItem
) => {
cy.get(triggerSelector).click();
cy.get(menuItemRadio)
.should('have.length', validTexts.length)
.each(($el, index) => {
const text = $el.text().trim();
expect(text).to.equal(validTexts[index]);
});
if (clickItem) {
cy.contains(menuItemRadio, clickItem).click();
cy.get(triggerSelector).click();
cy.get(`${menuItemRadio}[data-state="checked"]`)
.invoke('text')
.then((text: string) => {
expect(text.trim()).to.equal(clickItem);
});
}
};
const checkMenuItemCheckbox: CheckMenuItemCheckboxFnType = (
buttonText,
items
) => {
items.forEach((item) => {
cy.contains(button, buttonText).click();
cy.contains(menuItemCheckbox, item.name).click();
});
cy.contains(button, buttonText).click();
cy.get(menuItemCheckbox)
.should('have.length', items.length)
.each(($el, index) => {
const text = $el.text();
expect(text).to.equal(items[index].name);
});
items.forEach((item, index) => {
cy.get(indicatorInfo)
.eq(index + 1)
.invoke('text')
.should('eq', item.infoText);
});
cy.contains(button, buttonText).click({ force: true });
};
function getButtonSelectorByText(text: string): string {
return `${button}[aria-haspopup="menu"]:contains(${text})`;
}
beforeEach(() => {
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
cy.wait('@Markets');
});
describe(
'chart display options',
{ tags: '@smoke', testIsolation: true },
() => {
it('change time interval', () => {
// 6004-CHAR-001
checkMenuItems(
getButtonSelectorByText('Interval:'),
['1m', '5m', '15m', '1H', '6H', '1D'],
'1m'
);
});
it('change display type', () => {
// 6004-CHAR-002
// 6004-CHAR-003
checkMenuItems(
'[aria-label$="chart icon"]',
['Mountain', 'Candlestick', 'Line', 'OHLC'],
'Mountain'
);
});
it('Overlays', () => {
// 6004-CHAR-004
// 6004-CHAR-008
// 6004-CHAR-009
// 6004-CHAR-034
// 6004-CHAR-037
// 6004-CHAR-039
// 6004-CHAR-041
const overlayInfo: ItemInfoType[] = [
{
name: 'Bollinger bands',
infoText: 'Bollinger: Upper 174.78590Lower 173.38014',
},
{
name: 'Envelope',
infoText: 'Envelope: Upper 191.29000Lower 156.51000',
},
{ name: 'EMA', infoText: 'EMA: 174.06793' },
{ name: 'Moving average', infoText: 'Moving average: 174.08302' },
{
name: 'Price monitoring bounds',
infoText: 'Price Monitoring Bounds: Min -Max -Reference -',
},
];
checkMenuItemCheckbox('Overlays', overlayInfo);
});
it('Studies', () => {
// 6004-CHAR-005
// 6004-CHAR-006
// 6004-CHAR-007
// 6004-CHAR-042
// 6004-CHAR-045
// 6004-CHAR-047
// 6004-CHAR-049
// 6004-CHAR-051
const studyInfo: ItemInfoType[] = [
{
name: 'Eldar-ray',
infoText: 'Eldar-ray: Bull -0.08376Bear -0.58376',
},
{ name: 'Force index', infoText: 'Force index: 987.48858' },
{ name: 'MACD', infoText: 'MACD: S -0.06420D 0.00359MACD -0.06062' },
{ name: 'RSI', infoText: 'RSI: 47.08648' },
{ name: 'Volume', infoText: 'Volume: 55,000.00000' },
];
cy.get(indicatorInfo).eq(1).realHover();
cy.get('.close-button-module_closeButton__2ifkl').click({ force: true });
cy.get(indicatorInfo).should('have.length', 1);
checkMenuItemCheckbox('Studies', studyInfo);
});
it('price details', () => {
// 6004-CHAR-010
const expectedDateRegex = new RegExp(
/^\d{2}:\d{2} \d{2} [A-Za-z]{3} \d{4}$/
);
const expectedOhlc = `O 173.60000H 174.00000L 173.50000C 173.90000Change 0.60000(0.34%)`;
cy.get(indicatorInfo)
.eq(0)
.invoke('text')
.then((text) => {
const actualDate = text.slice(0, -67);
console.log(actualDate);
const actualOhlc = text.slice(-67);
assert.isTrue(expectedDateRegex.test(actualDate));
assert.strictEqual(actualOhlc, expectedOhlc);
});
});
}
);

View File

@ -78,4 +78,244 @@ const candles: CandleFieldsFragment[] = [
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:00:00Z',
lastUpdateInPeriod: '2022-04-06T09:01:00Z',
high: '17481092',
low: '17403651',
open: '17458833',
close: '17446470',
volume: '82721',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:10:00Z',
lastUpdateInPeriod: '2022-04-06T09:11:00Z',
high: '17491202',
low: '17361138',
open: '17446470',
close: '17367174',
volume: '62637',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:20:00Z',
lastUpdateInPeriod: '2022-04-06T09:21:00Z',
high: '17424522',
low: '17337719',
open: '17367174',
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:30:00Z',
lastUpdateInPeriod: '2022-04-06T09:31:00Z',
high: '17500000',
low: '17300000',
open: '17380000',
close: '17450000',
volume: '70000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:40:00Z',
lastUpdateInPeriod: '2022-04-06T09:41:00Z',
high: '17400000',
low: '17350000',
open: '17360000',
close: '17390000',
volume: '55000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:50:00Z',
lastUpdateInPeriod: '2022-04-06T09:51:00Z',
high: '17481092',
low: '17403651',
open: '17458833',
close: '17446470',
volume: '82721',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T10:00:00Z',
lastUpdateInPeriod: '2022-04-06T10:01:00Z',
high: '17491202',
low: '17361138',
open: '17446470',
close: '17367174',
volume: '62637',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T10:10:00Z',
lastUpdateInPeriod: '2022-04-06T10:11:00Z',
high: '17424522',
low: '17337719',
open: '17367174',
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T10:20:00Z',
lastUpdateInPeriod: '2022-04-06T10:21:00Z',
high: '17500000',
low: '17300000',
open: '17380000',
close: '17450000',
volume: '70000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T10:30:00Z',
lastUpdateInPeriod: '2022-04-06T10:31:00Z',
high: '17400000',
low: '17350000',
open: '17360000',
close: '17390000',
volume: '55000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T01:00:00Z',
lastUpdateInPeriod: '2022-04-06T09:01:00Z',
high: '17481092',
low: '17403651',
open: '17458833',
close: '17446470',
volume: '82721',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:10:00Z',
lastUpdateInPeriod: '2022-04-06T09:11:00Z',
high: '17491202',
low: '17361138',
open: '17446470',
close: '17367174',
volume: '62637',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:20:00Z',
lastUpdateInPeriod: '2022-04-06T09:21:00Z',
high: '17424522',
low: '17337719',
open: '17367174',
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:30:00Z',
lastUpdateInPeriod: '2022-04-06T09:31:00Z',
high: '17500000',
low: '17300000',
open: '17380000',
close: '17450000',
volume: '70000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:40:00Z',
lastUpdateInPeriod: '2022-04-06T09:41:00Z',
high: '17400000',
low: '17350000',
open: '17360000',
close: '17390000',
volume: '55000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T09:50:00Z',
lastUpdateInPeriod: '2022-04-06T09:51:00Z',
high: '17481092',
low: '17403651',
open: '17458833',
close: '17446470',
volume: '82721',
},
{
__typename: 'Candle',
periodStart: '2022-04-05T20:00:00Z',
lastUpdateInPeriod: '2022-04-05T20:01:00Z',
high: '17491202',
low: '17361138',
open: '17446470',
close: '17367174',
volume: '62637',
},
{
__typename: 'Candle',
periodStart: '2022-04-05T22:10:00Z',
lastUpdateInPeriod: '2022-04-05T24:11:00Z',
high: '17424522',
low: '17337719',
open: '17367174',
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-05T21:20:00Z',
lastUpdateInPeriod: '2022-04-05T21:21:00Z',
high: '17500000',
low: '17300000',
open: '17380000',
close: '17450000',
volume: '70000',
},
{
__typename: 'Candle',
periodStart: '2022-04-05T21:30:00Z',
lastUpdateInPeriod: '2022-04-05T21:31:00Z',
high: '17400000',
low: '17350000',
open: '17360000',
close: '17390000',
volume: '55000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T02:00:00Z',
lastUpdateInPeriod: '2022-04-06T02:01:00Z',
high: '17491202',
low: '17361138',
open: '17446470',
close: '17367174',
volume: '62637',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T03:03:00Z',
lastUpdateInPeriod: '2022-04-06T03:11:00Z',
high: '17424522',
low: '17337719',
open: '17367174',
close: '17376455',
volume: '60259',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T00:20:00Z',
lastUpdateInPeriod: '2022-04-06T00:21:00Z',
high: '17500000',
low: '17300000',
open: '17380000',
close: '17450000',
volume: '70000',
},
{
__typename: 'Candle',
periodStart: '2022-04-06T01:30:00Z',
lastUpdateInPeriod: '2022-04-06T01:31:00Z',
high: '17400000',
low: '17350000',
open: '17360000',
close: '17390000',
volume: '55000',
},
];