frequi_origin/cypress/integration/backtesting.spec.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-04-12 18:52:48 +00:00
function setLoginInfo() {
localStorage.setItem(
'ftAuthLoginInfo',
JSON.stringify({
'ftbot.0': {
botName: 'TestBot',
apiUrl: 'http://localhost:3000',
accessToken: 'access_token_tesst',
refreshToken: 'refresh_test',
autoRefresh: true,
},
}),
);
localStorage.setItem('ftSelectedBot', 'ftbot.0');
}
function defaultMocks() {
cy.intercept('**/api/v1/**', {
statusCode: 200,
// eslint-disable-next-line @typescript-eslint/camelcase
headers: { 'access-control-allow-origin': '*' },
}).as('RandomAPICall');
cy.intercept('GET', '**/api/v1/ping', { fixture: 'ping.json' }).as('Ping');
cy.intercept('GET', '**/api/v1/show_config', {
fixture: 'backtest/show_config_backtest.json',
}).as('ShowConf');
cy.intercept('GET', '**/api/v1/strategies', { fixture: 'backtest/strategies.json' }).as(
'Strategies',
);
}
describe('Backtesting', () => {
2022-04-13 17:55:27 +00:00
it('Starts webserver mode', () => {
2022-04-12 18:52:48 +00:00
///
defaultMocks();
setLoginInfo();
cy.visit('/backtest');
cy.wait('@Ping');
cy.wait('@ShowConf');
// cy.wait('@Strategies');
cy.get('a').should('contain', 'Backtest');
cy.contains('Run backtest');
cy.contains('Strategy');
const strategySelect = cy.get('select[id=strategy-select]');
strategySelect.should('exist');
strategySelect.select('SampleStrategy');
cy.get('option[value=SampleStrategy]').should('exist');
2022-04-13 17:55:27 +00:00
cy.get('[id=bt-analyze-btn]').should('be.disabled');
2022-04-12 18:52:48 +00:00
cy.intercept('POST', '**/api/v1/backtest', { fixture: 'backtest/backtest_post_start.json' }).as(
'BacktestStart',
);
2022-04-13 17:55:27 +00:00
cy.intercept('GET', '**/api/v1/backtest', { fixture: 'backtest/backtest_get_end.json' }).as(
'BacktestPoll',
);
2022-04-12 18:52:48 +00:00
cy.get('button[id=start-backtest]').click();
cy.wait('@BacktestStart');
2022-04-13 17:55:27 +00:00
cy.wait('@BacktestPoll');
// All buttons are now enabled
cy.get('[id=bt-analyze-btn]').should('be.enabled');
2022-04-12 18:52:48 +00:00
});
});