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

Add helpers path to tsconfig #394

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { clusterParameterExists } from './navigation';
import { ensureKialiFinishedLoading } from './transition';
import { elems, nodeInfo } from './graph-pf';
import { Visualization } from '@patternfly/react-topology';
import { NodeType } from 'types/Graph';

Then('user sees details information for the remote {string} app', (name: string) => {
cy.getBySel('app-description-card').within(() => {
Expand Down Expand Up @@ -100,13 +101,26 @@ Given(
assert.isTrue(controller.hasGraph());
const { nodes } = elems(controller);

const nodeExists = nodes.some(
node =>
const nodeExists = nodes.some(node => {
const nodeOk =
node.getData().nodeType === nodeType &&
node.getData().namespace === 'bookinfo' &&
node.getData().cluster === cluster &&
node.getData().isBox === isBox
);
node.getData().isBox === isBox;
if (!nodeOk) {
return false;
}
switch (type) {
case NodeType.APP:
return node.getData().app === name;
case NodeType.SERVICE:
return node.getData().service === name;
case NodeType.WORKLOAD:
return node.getData().workload === name;
default:
return false;
}
});

assert(nodeExists, `Node ${name} of type ${type} from cluster ${cluster} not found in the graph`);
});
Expand All @@ -129,14 +143,26 @@ When(
assert.isTrue(controller.hasGraph());
const { nodes } = elems(controller);

const node = nodes.find(
node =>
const node = nodes.find(node => {
const nodeOk =
node.getData().nodeType === nodeType &&
node.getData().namespace === 'bookinfo' &&
node.getData().cluster === cluster &&
node.getData().isBox === isBox &&
!node.getData().isInaccessible
);
node.getData().isBox === isBox;
if (!nodeOk) {
return false;
}
switch (type) {
case NodeType.APP:
return node.getData().app === name;
case NodeType.SERVICE:
return node.getData().service === name;
case NodeType.WORKLOAD:
return node.getData().workload === name;
default:
return false;
}
});

assert(node, `Node ${name} of type ${type} from cluster ${cluster} not found in the graph`);

Expand Down
18 changes: 1 addition & 17 deletions plugin/cypress/integration/kiali/common/graph_display-cy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { Before, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { ensureKialiFinishedLoading } from './transition';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});

When('user graphs {string} namespaces in the cytoscape graph', (namespaces: string) => {
// Forcing "Pause" to not cause unhandled promises from the browser when cypress is testing
cy.intercept(`**/api/namespaces/graph*`).as('graphNamespaces');
Expand Down
42 changes: 15 additions & 27 deletions plugin/cypress/integration/kiali/common/graph_display-pf.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import { Before, Given, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Given, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { ensureKialiFinishedLoading } from './transition';
import { Visualization } from '@patternfly/react-topology';
import { elems, select, selectAnd, selectOr } from './graph-pf';
import { EdgeAttr, NodeAttr } from 'types/Graph';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});

When('user graphs {string} namespaces', (namespaces: string) => {
// Forcing "Pause" to not cause unhandled promises from the browser when cypress is testing
cy.intercept(`**/api/namespaces/graph*`).as('graphNamespaces');
Expand Down Expand Up @@ -449,10 +433,9 @@ Given(
.as(`istioConfigRequest-${cluster}`)
.then(response => {
expect(response.status).to.eq(200);
expect(response.body).to.have.property('gateways');
expect(response.body).to.have.property('virtualServices');
expect(response.body.gateways).to.have.length.gte(1);
expect(response.body.virtualServices).to.have.length.gte(1);
expect(response.body).to.have.property('resources');
expect(response.body.resources['networking.istio.io/v1, Kind=Gateway'].length).greaterThan(0);
expect(response.body.resources['networking.istio.io/v1, Kind=VirtualService'].length).greaterThan(0);
});
}
);
Expand All @@ -470,12 +453,15 @@ Then(
});

cy.get('@istioConfigRequest-east').then(resp => {
// Not going to check all the objects. Just the ones that probably exist while testing.
const totalObjectsEast =
resp.body.gateways.length + resp.body.virtualServices.length + resp.body.destinationRules.length;
let totalObjectsEast = 0;
Object.keys(resp.body.resources).forEach(resourceKey => {
totalObjectsEast += resp.body.resources[resourceKey].length;
});
cy.get('@istioConfigRequest-west').then(resp => {
const totalObjectsWest =
resp.body.gateways.length + resp.body.virtualServices.length + resp.body.destinationRules.length;
let totalObjectsWest = 0;
Object.keys(resp.body.resources).forEach(resourceKey => {
totalObjectsEast += resp.body.resources[resourceKey].length;
});
const totalObjects = totalObjectsEast + totalObjectsWest;
cy.get('[aria-label="Validations list"]').contains(`Istio config objects analyzed: ${totalObjects}`);
});
Expand All @@ -497,6 +483,8 @@ When('user {string} {string} traffic option', (action: string, option: string) =

Then('{int} edges appear in the graph', (graphEdges: number) => {
cy.waitForReact();
ensureKialiFinishedLoading();

cy.getReact('GraphPagePFComponent', { state: { isReady: true } })
.should('have.length', '1')
.then($graph => {
Expand Down Expand Up @@ -526,7 +514,7 @@ Then('the {string} node {string} exists', (nodeName: string, action: string) =>
const foundNode = nodes.filter(node => node.getData().workload === nodeName);

if (action === 'does') {
assert.isAtLeast(foundNode.length, 1);
assert.equal(foundNode.length, 1);
} else {
assert.equal(foundNode.length, 0);
}
Expand Down
18 changes: 1 addition & 17 deletions plugin/cypress/integration/kiali/common/graph_replay.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
import { Before, Then, When } from '@badeball/cypress-cucumber-preprocessor';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';

When('user presses the Replay button', () => {
cy.get('button[data-test="graph-replay-button"]').click();
Expand Down
18 changes: 1 addition & 17 deletions plugin/cypress/integration/kiali/common/graph_toolbar-cy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { Before, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { CytoscapeGlobalScratchData, CytoscapeGlobalScratchNamespace } from 'types/Graph';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});

When(
'user graphs {string} namespaces with refresh {string} and duration {string} in the cytoscape graph',
(namespaces: string, refresh: string, duration: string) => {
Expand Down
22 changes: 3 additions & 19 deletions plugin/cypress/integration/kiali/common/graph_toolbar-pf.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { Before, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { EdgeAttr } from 'types/Graph';
import { elems, select } from './graph-pf';
import { Visualization } from '@patternfly/react-topology';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});

When(
'user graphs {string} namespaces with refresh {string} and duration {string}',
(namespaces: string, refresh: string, duration: string) => {
Expand Down Expand Up @@ -88,9 +72,9 @@ When('user selects {string} graph type', (graphType: string) => {

Then('user {string} graph tour', (action: string) => {
if (action === 'sees') {
cy.get('div[role="dialog"]').find('span').contains('Shortcuts').should('exist');
cy.get('.pf-v5-c-popover').find('span').contains('Shortcuts').should('exist');
} else {
cy.get('div[role="dialog"]').should('not.exist');
cy.get('.pf-v5-c-popover').should('not.exist');
}
});

Expand Down
54 changes: 3 additions & 51 deletions plugin/cypress/integration/kiali/common/istio_config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { After, Given, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { colExists, getColWithRowText } from './table';
import { ensureKialiFinishedLoading } from './transition';
import { getGVKTypeString } from 'utils/IstioConfigUtils';

const CLUSTER1_CONTEXT = Cypress.env('CLUSTER1_CONTEXT');
const CLUSTER2_CONTEXT = Cypress.env('CLUSTER2_CONTEXT');
Expand All @@ -24,54 +25,6 @@ const labelsStringToJson = (labelsString: string): string => {
return `{${labelsJson}}`;
};

// This is for Istio Object Types only
const pluralize = (word: string): string => {
const endings = {
ay: 'ays',
cy: 'cies',
ry: 'ries',
ze: 'zes',
s: 'ses',
e: 'es'
};

for (const [singular, plural] of Object.entries(endings)) {
const regex = new RegExp(`${singular}$`);
if (regex.test(word)) {
return word.replace(regex, plural);
}
}

// 's' by default
return `${word}s`;
};

export const dicIstioTypeToGVKStrings: { [key: string]: string } = {
AuthorizationPolicy: 'security.istio.io/v1, Kind=AuthorizationPolicy',
PeerAuthentication: 'security.istio.io/v1, Kind=PeerAuthentication',
RequestAuthentication: 'security.istio.io/v1, Kind=RequestAuthentication',

DestinationRule: 'networking.istio.io/v1, Kind=DestinationRule',
Gateway: 'networking.istio.io/v1, Kind=Gateway',
EnvoyFilter: 'networking.istio.io/v1alpha3, Kind=EnvoyFilter',
Sidecar: 'networking.istio.io/v1, Kind=Sidecar',
ServiceEntry: 'networking.istio.io/v1, Kind=ServiceEntry',
VirtualService: 'networking.istio.io/v1, Kind=VirtualService',
WorkloadEntry: 'networking.istio.io/v1, Kind=WorkloadEntry',
WorkloadGroup: 'networking.istio.io/v1, Kind=WorkloadGroup',

WasmPlugin: 'extensions.istio.io/v1alpha1, Kind=WasmPlugin',
Telemetry: 'telemetry.istio.io/v1, Kind=Telemetry',

K8sGateway: 'gateway.networking.k8s.io/v1, Kind=Gateway',
K8sGatewayClass: 'gateway.networking.k8s.io/v1, Kind=GatewayClass',
K8sGRPCRoute: 'gateway.networking.k8s.io/v1, Kind=GRPCRoute',
K8sHTTPRoute: 'gateway.networking.k8s.io/v1, Kind=HTTPRoute',
K8sReferenceGrant: 'gateway.networking.k8s.io/v1, Kind=ReferenceGrant',
K8sTCPRoute: 'gateway.networking.k8s.io/v1alpha2, Kind=TCPRoute',
K8sTLSRoute: 'gateway.networking.k8s.io/v1alpha2, Kind=TLSRoute'
};

const minimalAuthorizationPolicy = (name: string, namespace: string): string => {
return `{
"apiVersion": "security.istio.io/v1",
Expand Down Expand Up @@ -590,14 +543,13 @@ Then('user only sees {string}', (sees: string) => {
});

Then('only {string} objects are visible in the {string} namespace', (sees: string, ns: string) => {
let lowercaseSees: string = sees.charAt(0).toLowerCase() + sees.slice(1);
let count: number;

cy.request({
method: 'GET',
url: `/api/namespaces/${ns}/istio?objects=${dicIstioTypeToGVKStrings[sees]}&validate=true`
url: `/api/namespaces/${ns}/istio?objects=${getGVKTypeString(sees)}&validate=true`
}).then(response => {
count = response.body[pluralize(lowercaseSees)].length;
count = response.body['resources'][getGVKTypeString(sees)].length;
});

cy.get('tbody').contains('tr', sees);
Expand Down
22 changes: 3 additions & 19 deletions plugin/cypress/integration/kiali/common/mesh.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import { Before, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { Visualization } from '@patternfly/react-topology';
import { MeshInfraType, MeshNodeData } from 'types/Mesh';
import { elems } from './graph-pf';

Before(() => {
// Copied from overview.ts. This prevents cypress from stopping on errors unrelated to the tests.
// There can be random failures due timeouts/loadtime/framework that throw browser errors. This
// prevents a CI failure due something like a "slow". There may be a better way to handle this.
cy.on('uncaught:exception', (err, runnable, promise) => {
// when the exception originated from an unhandled promise
// rejection, the promise is provided as a third argument
// you can turn off failing the test in this case
if (promise) {
return false;
}
// we still want to ensure there are no other unexpected
// errors, so we let them fail the test
});
});

When('user closes mesh tour', () => {
cy.waitForReact();
cy.get('div[role="dialog"]').find('button[aria-label="Close"]').click();
Expand Down Expand Up @@ -189,9 +173,9 @@ Then('user sees the istiod node connected to the dataplane nodes', () => {
Then('user {string} mesh tour', (action: string) => {
cy.waitForReact();
if (action === 'sees') {
cy.get('div[class*="pf-v5-c-popover"]').find('span').contains('Shortcuts').should('exist');
cy.get('.pf-v5-c-popover').find('span').contains('Shortcuts').should('exist');
} else {
cy.get('div[class*="pf-v5-c-popover"]').should('not.exist');
cy.get('.pf-v5-c-popover').should('not.exist');
}
});

Expand Down
Loading