mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-21 13:58:49 +00:00
Cypress: prettier code (#743)
Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com>
This commit is contained in:
parent
fd64c1bb14
commit
20fcc8e163
@ -3,6 +3,7 @@ import {resizeToHugeMizu, resizeToNormalMizu} from "../testHelpers/TrafficHelper
|
|||||||
const greenFilterColor = 'rgb(210, 250, 210)';
|
const greenFilterColor = 'rgb(210, 250, 210)';
|
||||||
const redFilterColor = 'rgb(250, 214, 220)';
|
const redFilterColor = 'rgb(250, 214, 220)';
|
||||||
const refreshWaitTimeout = 10000;
|
const refreshWaitTimeout = 10000;
|
||||||
|
const bodyJsonClass = '.hljs';
|
||||||
|
|
||||||
it('opening mizu', function () {
|
it('opening mizu', function () {
|
||||||
cy.visit(Cypress.env('testUrl'));
|
cy.visit(Cypress.env('testUrl'));
|
||||||
@ -192,11 +193,12 @@ function checkFilter(filterDetails){
|
|||||||
if (!applyByEnter)
|
if (!applyByEnter)
|
||||||
cy.get('[type="submit"]').click();
|
cy.get('[type="submit"]').click();
|
||||||
|
|
||||||
// only one entry in DOM after filtering, checking all four checks on it
|
// only one entry in DOM after filtering, checking all checks on it
|
||||||
leftTextCheck(totalEntries - 1, leftSidePath, leftSideExpectedText);
|
leftTextCheck(totalEntries - 1, leftSidePath, leftSideExpectedText);
|
||||||
leftOnHoverCheck(totalEntries - 1, leftSidePath, name);
|
leftOnHoverCheck(totalEntries - 1, leftSidePath, name);
|
||||||
rightTextCheck(rightSidePath, rightSideExpectedText);
|
rightTextCheck(rightSidePath, rightSideExpectedText);
|
||||||
rightOnHoverCheck(rightSidePath, name);
|
rightOnHoverCheck(rightSidePath, name);
|
||||||
|
checkRightSideResponseBody();
|
||||||
|
|
||||||
cy.get('[title="Fetch old records"]').click();
|
cy.get('[title="Fetch old records"]').click();
|
||||||
resizeToHugeMizu();
|
resizeToHugeMizu();
|
||||||
@ -227,7 +229,7 @@ function deeperChcek(leftSidePath, rightSidePath, filterName, leftSideExpectedTe
|
|||||||
cy.get(`#list #entry-${entryNum}`).click();
|
cy.get(`#list #entry-${entryNum}`).click();
|
||||||
rightTextCheck(rightSidePath, rightSideExpectedText);
|
rightTextCheck(rightSidePath, rightSideExpectedText);
|
||||||
rightOnHoverCheck(rightSidePath, filterName);
|
rightOnHoverCheck(rightSidePath, filterName);
|
||||||
checkRightSide();
|
checkRightSideResponseBody();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,13 +251,12 @@ function rightOnHoverCheck(path, expectedText) {
|
|||||||
cy.get(`.TrafficPage-Container > :nth-child(2) .Queryable-Tooltip`).should('have.text', expectedText);
|
cy.get(`.TrafficPage-Container > :nth-child(2) .Queryable-Tooltip`).should('have.text', expectedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkRightSide() {
|
|
||||||
const jsonClass = '.hljs';
|
|
||||||
|
|
||||||
|
function checkRightSideResponseBody() {
|
||||||
cy.contains('Response').click();
|
cy.contains('Response').click();
|
||||||
clickCheckbox('Decode Base64');
|
clickCheckbox('Decode Base64');
|
||||||
|
|
||||||
cy.get(`${jsonClass}`).then(value => {
|
cy.get(`${bodyJsonClass}`).then(value => {
|
||||||
const encodedBody = value.text();
|
const encodedBody = value.text();
|
||||||
cy.log(encodedBody);
|
cy.log(encodedBody);
|
||||||
|
|
||||||
@ -264,25 +265,25 @@ function checkRightSide() {
|
|||||||
|
|
||||||
const expectdJsonBody = {
|
const expectdJsonBody = {
|
||||||
args: RegExp({}),
|
args: RegExp({}),
|
||||||
url: RegExp("http://.*/get"),
|
url: RegExp('http://.*/get'),
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": RegExp('[REDACTED]'),
|
"User-Agent": RegExp('[REDACTED]'),
|
||||||
"Accept-Encoding": RegExp('gzip'),
|
"Accept-Encoding": RegExp('gzip'),
|
||||||
"X-Forwarded-Uri": RegExp("/api/v1/namespaces/.*/services/.*/proxy/get")
|
"X-Forwarded-Uri": RegExp('/api/v1/namespaces/.*/services/.*/proxy/get')
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
expect(responseBody.args).to.match(expectdJsonBody.args);
|
expect(responseBody.args).to.match(expectdJsonBody.args);
|
||||||
expect(responseBody.url).to.match(expectdJsonBody.url);
|
expect(responseBody.url).to.match(expectdJsonBody.url);
|
||||||
expect(responseBody.headers["User-Agent"]).to.match(expectdJsonBody.headers["User-Agent"]);
|
expect(responseBody.headers['User-Agent']).to.match(expectdJsonBody.headers['User-Agent']);
|
||||||
expect(responseBody.headers["Accept-Encoding"]).to.match(expectdJsonBody.headers["Accept-Encoding"]);
|
expect(responseBody.headers['Accept-Encoding']).to.match(expectdJsonBody.headers['Accept-Encoding']);
|
||||||
expect(responseBody.headers["X-Forwarded-Uri"]).to.match(expectdJsonBody.headers["X-Forwarded-Uri"]);
|
expect(responseBody.headers['X-Forwarded-Uri']).to.match(expectdJsonBody.headers['X-Forwarded-Uri']);
|
||||||
|
|
||||||
cy.get('.hljs').should('have.text', encodedBody);
|
cy.get(`${bodyJsonClass}`).should('have.text', encodedBody);
|
||||||
clickCheckbox('Decode Base64');
|
clickCheckbox('Decode Base64');
|
||||||
|
|
||||||
cy.get('.hljs > ').its('length').should('be.gt', 1).then(linesNum => {
|
cy.get(`${bodyJsonClass} > `).its('length').should('be.gt', 1).then(linesNum => {
|
||||||
cy.get('.hljs > >').its('length').should('be.gt', linesNum).then(jsonItemsNum => {
|
cy.get(`${bodyJsonClass} > >`).its('length').should('be.gt', linesNum).then(jsonItemsNum => {
|
||||||
checkPrettyAndLineNums(jsonItemsNum, decodedBody);
|
checkPrettyAndLineNums(jsonItemsNum, decodedBody);
|
||||||
|
|
||||||
clickCheckbox('Line numbers');
|
clickCheckbox('Line numbers');
|
||||||
@ -304,7 +305,7 @@ function clickCheckbox(type) {
|
|||||||
|
|
||||||
function checkPrettyAndLineNums(jsonItemsLen, decodedBody) {
|
function checkPrettyAndLineNums(jsonItemsLen, decodedBody) {
|
||||||
decodedBody = decodedBody.replaceAll(' ', '');
|
decodedBody = decodedBody.replaceAll(' ', '');
|
||||||
cy.get('.hljs >').then(elements => {
|
cy.get(`${bodyJsonClass} >`).then(elements => {
|
||||||
const lines = Object.values(elements);
|
const lines = Object.values(elements);
|
||||||
lines.forEach((line, index) => {
|
lines.forEach((line, index) => {
|
||||||
if (line.getAttribute) {
|
if (line.getAttribute) {
|
||||||
@ -324,13 +325,13 @@ function getCleanLine(lineElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkPrettyOrNothing(jsonItems, decodedBody) {
|
function checkPrettyOrNothing(jsonItems, decodedBody) {
|
||||||
cy.get('.hljs > ').should('have.length', jsonItems).then(text => {
|
cy.get(`${bodyJsonClass} > `).should('have.length', jsonItems).then(text => {
|
||||||
const json = text.text();
|
const json = text.text();
|
||||||
expect(json).to.equal(decodedBody);
|
expect(json).to.equal(decodedBody);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkOnlyLineNumberes(jsonItems, decodedText) {
|
function checkOnlyLineNumberes(jsonItems, decodedText) {
|
||||||
cy.get('.hljs >').should('have.length', 1).and('have.text', decodedText);
|
cy.get(`${bodyJsonClass} >`).should('have.length', 1).and('have.text', decodedText);
|
||||||
cy.get('.hljs > >').should('have.length', jsonItems)
|
cy.get(`${bodyJsonClass} > >`).should('have.length', jsonItems)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user