Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(FE):Cypress global time test case #348

Merged
merged 8 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions frontend/cypress/CustomFunctions/Login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ROUTES from 'constants/routes';

const Login = ({ email, name }: LoginProps): void => {
const emailInput = cy.findByPlaceholderText('[email protected]');

Expand Down Expand Up @@ -29,12 +27,16 @@ const Login = ({ email, name }: LoginProps): void => {
expect(inputValue).to.be.equals(name);
});

const gettingStartedButton = cy.get('button');
const gettingStartedButton = cy.findByText('Get Started');
gettingStartedButton.click();

cy.location('pathname').then((e) => {
expect(e).to.be.equal(ROUTES.APPLICATION);
});
cy
.intercept('POST', '/api/v1/user?email*', {
statusCode: 200,
})
.as('defaultUser');

cy.wait('@defaultUser');
};

export interface LoginProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
getDefaultOption,
getOptions,
} from 'container/Header/DateTimeSelection/config';
// import { AppState } from 'store/reducers';

const CheckRouteDefaultGlobalTimeOptions = ({
route,
}: CheckRouteDefaultGlobalTimeOptionsProps): void => {
cy.visit(Cypress.env('baseUrl') + route);

const allOptions = getOptions(route);

const defaultValue = getDefaultOption(route);

const defaultSelectedOption = allOptions.find((e) => e.value === defaultValue);

expect(defaultSelectedOption).not.undefined;

cy
.findAllByTestId('dropDown')
.find('span')
.then((el) => {
const elements = el.get();

const item = elements[1];

expect(defaultSelectedOption?.label).to.be.equals(
item.innerText,
'Default option is not matching',
);
});

// cy
// .window()
// .its('store')
// .invoke('getState')
// .then((e: AppState) => {
// const { globalTime } = e;
// const { maxTime, minTime } = globalTime;
// // @TODO match the global min time and max time according to the selected option
// });
};

export interface CheckRouteDefaultGlobalTimeOptionsProps {
route: string;
}

export default CheckRouteDefaultGlobalTimeOptions;
1 change: 1 addition & 0 deletions frontend/cypress/fixtures/errorPercentage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "status": "success", "data": { "resultType": "matrix", "result": [] } }
29 changes: 29 additions & 0 deletions frontend/cypress/fixtures/requestPerSecond.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {},
"values": [
[1634741764.961, "0.9"],
[1634741824.961, "0.9"],
[1634741884.961, "0.8666666666666667"],
[1634741944.961, "1"],
[1634742004.961, "0.9166666666666666"],
[1634742064.961, "0.95"],
[1634742124.961, "0.9333333333333333"],
[1634742184.961, "0.95"],
[1634742244.961, "1.0333333333333334"],
[1634742304.961, "0.9333333333333333"],
[1634742364.961, "0.9166666666666666"],
[1634742424.961, "0.9"],
[1634742484.961, "1.0166666666666666"],
[1634742544.961, "0.8333333333333334"],
[1634742604.961, "0.9166666666666666"],
[1634742664.961, "0.95"]
]
}
]
}
}
62 changes: 62 additions & 0 deletions frontend/cypress/fixtures/serviceOverview.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"timestamp": 1634742600000000000,
"p50": 720048500,
"p95": 924409540,
"p99": 974744300,
"numCalls": 48,
"callRate": 0.8,
"numErrors": 0,
"errorRate": 0
},
{
"timestamp": 1634742540000000000,
"p50": 712614000,
"p95": 955580700,
"p99": 1045595400,
"numCalls": 59,
"callRate": 0.98333335,
"numErrors": 0,
"errorRate": 0
},
{
"timestamp": 1634742480000000000,
"p50": 720842000,
"p95": 887187600,
"p99": 943676860,
"numCalls": 53,
"callRate": 0.8833333,
"numErrors": 0,
"errorRate": 0
},
{
"timestamp": 1634742420000000000,
"p50": 712287000,
"p95": 908505540,
"p99": 976507650,
"numCalls": 58,
"callRate": 0.96666664,
"numErrors": 0,
"errorRate": 0
},
{
"timestamp": 1634742360000000000,
"p50": 697125500,
"p95": 975581800,
"p99": 1190121900,
"numCalls": 54,
"callRate": 0.9,
"numErrors": 0,
"errorRate": 0
},
{
"timestamp": 1634742300000000000,
"p50": 711592500,
"p95": 880559900,
"p99": 1100105500,
"numCalls": 40,
"callRate": 0.6666667,
"numErrors": 0,
"errorRate": 0
}
]
9 changes: 9 additions & 0 deletions frontend/cypress/fixtures/topEndPoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"p50": 710824000,
"p95": 1003231400,
"p99": 1231265500,
"numCalls": 299,
"name": "HTTP GET /dispatch"
}
]
2 changes: 0 additions & 2 deletions frontend/cypress/integration/appLayout/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ describe('App Layout', () => {
});
});
});

export {};
44 changes: 44 additions & 0 deletions frontend/cypress/integration/globalTime/default.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// <reference types="cypress" />
import ROUTES from 'constants/routes';

describe('default time', () => {
beforeEach(() => {
window.localStorage.setItem('isLoggedIn', 'yes');
});

it('Metrics Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.APPLICATION,
});
});

it('Dashboard Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.ALL_DASHBOARD,
});
});

it('Trace Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.TRACES,
});
});

it('Instrumentation Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.INSTRUMENTATION,
});
});

it('Service Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.SERVICE_MAP,
});
});

it('Settings Page default time', () => {
cy.checkDefaultGlobalOption({
route: ROUTES.SETTINGS,
});
});
});
126 changes: 126 additions & 0 deletions frontend/cypress/integration/globalTime/metricsApplication.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/// <reference types="cypress" />
import getGlobalDropDownFormatedDate from 'lib/getGlobalDropDownFormatedDate';
import { AppState } from 'store/reducers';

import topEndPoints from '../../fixtures/topEndPoints.json';

describe('Global Time Metrics Application', () => {
beforeEach(() => {
cy.visit(Cypress.env('baseUrl'));

const testEmail = '[email protected]';
const firstName = 'Test';

cy.login({
email: testEmail,
name: firstName,
});
});

it('Metrics Application', async () => {
cy
.intercept('GET', '/api/v1/services*', {
fixture: 'defaultApp.json',
})
.as('defaultApps');

cy.wait('@defaultApps');

//clicking on frontend
cy.get('tr:nth-child(1) > td:first-child').click();

cy
.intercept('GET', '/api/v1/service/top_endpoints*', {
fixture: 'topEndPoints.json',
})
.as('topEndPoints');

cy
.intercept('GET', '/api/v1/service/overview?*', {
fixture: 'serviceOverview.json',
})
.as('serviceOverview');

cy
.intercept(
'GET',
`/api/v1/query_range?query=sum(rate(signoz_latency_count*`,
{
fixture: 'requestPerSecond.json',
},
)
.as('requestPerSecond');

cy
.window()
.its('store')
.invoke('getState')
.then((e: AppState) => {
const { globalTime } = e;

const { maxTime, minTime } = globalTime;

// intercepting metrics application call

cy.wait('@topEndPoints');
cy.wait('@serviceOverview');
//TODO add errorPercentage also
// cy.wait('@errorPercentage');
cy.wait('@requestPerSecond');

cy
.get('tbody tr:first-child td:first-child')
.then((el) => {
const elements = el.get();

expect(elements.length).to.be.equals(1);

const element = elements[0];

expect(element.innerText).to.be.equals(topEndPoints[0].name);
})
.click();

cy
.findAllByTestId('dropDown')
.find('span.ant-select-selection-item')
.then((e) => {
const elements = e;

const element = elements[0];

const customSelectedTime = element.innerText;

const startTime = new Date(minTime / 1000000);
const endTime = new Date(maxTime / 1000000);

const startString = getGlobalDropDownFormatedDate(startTime);
const endString = getGlobalDropDownFormatedDate(endTime);

const result = `${startString} - ${endString}`;

expect(customSelectedTime).to.be.equals(result);
});

cy
.findByTestId('dropDown')
.click()
.then(() => {
cy.findByTitle('Last 30 min').click();
});

cy
.findByTestId('dropDown')
.find('span.ant-select-selection-item')
.then((e) => {
const elements = e;

const element = elements[0];

const selectedTime = element.innerText;

expect(selectedTime).to.be.equals('Last 30 min');
});
});
});
});
Loading