Skip to content

Commit

Permalink
feat(RHINENG-8253): Update risk label in cluster page (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsToNlele committed Mar 21, 2024
1 parent 273f87a commit 3f21e6e
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 7 deletions.
1 change: 0 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ module.exports = defineConfig({
return config;
},
},
retries: 2,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"predictions": [
{
"cluster_id": "e488c993-821c-4915-bd08-5a51ed7aa3a2",
"last_checked_at": "2011-15-04T00:05:23Z",
"prediction_status": "ok",
"upgrade_recommended": true,
"upgrade_risks_predictors": {
"alerts": [
{
"name": "SomeCriticalAlert",
"namespace": "openshift-kube-apiserver",
"severity": "critical",
"url": "https://some_url.com/monitoring/alerts?orderBy=asc&sortBy=Severity&alert-name=SomeCriticalAlert"
}
],
"operator_conditions": [
{
"condition": "Degraded",
"name": "authentication",
"reason": "AsExpected",
"url": "https://some_url.com/k8s/cluster/config.openshift.io~v1~ClusterOperator/authentication"
}
]
}
},
{
"cluster_id": "bbbbbbb",
"prediction_status": "No data for the cluster"
}
],
"status": "ok"
}
113 changes: 113 additions & 0 deletions cypress/utils/interceptors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import singleClusterPageReport from '../fixtures/api/insights-results-aggregator/v2/cluster/dcb95bbf-8673-4f3a-a63c-12d4a530aa6f/reports-disabled-false.json';
import updateRisksFixtures from '../fixtures/api/insights-results-aggregator/v2/cluster/dcb95bbf-8673-4f3a-a63c-12d4a530aa6f/upgrade-risks-prediction.json';
import clusterInfoFixtures from '../fixtures/api/insights-results-aggregator/v2/cluster/dcb95bbf-8673-4f3a-a63c-12d4a530aa6f/info.json';
import clustersUpdateRisks from '../fixtures/api/insights-results-aggregator/v2/upgrade-risks-prediction.json';
import _ from 'lodash';

export const clusterReportsInterceptors = {
Expand Down Expand Up @@ -184,3 +185,115 @@ export const featureFlagsInterceptors = {
}).as('getOcpWorkloadsFlag');
},
};

export const clustersUpdateRisksInterceptors = {
successful: () => {
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
(req) => {
const fixtureWithOneUpdateRisk = req?.body?.clusters.map(
(item, index) => {
return index === 0
? {
...clustersUpdateRisks.predictions[0],
cluster_id: item,
}
: {
...clustersUpdateRisks.predictions[1],
cluster_id: item,
};
}
);
req.continue((res) => {
res.send({
statusCode: 200,
body: { predictions: fixtureWithOneUpdateRisk, status: 'ok' },
});
});
}
);
},
'successful, two labels': () => {
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
(req) => {
const fixtureWithTwoUpdateRisks = req?.body?.clusters.map(
(item, index) => {
return index === 0 || index === 3
? {
...clustersUpdateRisks.predictions[0],
cluster_id: item,
}
: {
...clustersUpdateRisks.predictions[1],
cluster_id: item,
};
}
);
req.continue((res) => {
res.send({
statusCode: 200,
body: { predictions: fixtureWithTwoUpdateRisks, status: 'ok' },
});
});
}
);
},
'successful, no labels': () => {
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
(req) => {
const fixtureWithOneUpdateRisk = req?.body?.clusters.map((item) => ({
...clustersUpdateRisks.predictions[1],
cluster_id: item,
}));
req.continue((res) => {
res.send({
statusCode: 200,
body: { predictions: fixtureWithOneUpdateRisk, status: 'ok' },
});
});
}
);
},
'error, status not ok': () =>
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
{
statusCode: 200,
body: {
status: 'not ok',
},
}
),
'error, not found': () =>
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
{
statusCode: 404,
}
),
'error, other': () =>
cy.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
{
statusCode: 500,
}
),
'long responding': () =>
cy
.intercept(
'POST',
/\/api\/insights-results-aggregator\/v2\/upgrade-risks-prediction/,
{
delay: 4200,
}
)
.as('clustersUpdateRisksLong'),
};
5 changes: 5 additions & 0 deletions cypress/utils/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function checkFiltering(
checkEmptyState(emptyStateTitle);
checkTableHeaders(tableHeaders);
} else {
cy.get('[data-ouia-component-id=loading-skeleton]').should('not.exist');
cy.get(`td[data-label="${columnName}"]`)
.should('have.length', values.length)
.then(($els) => {
return _.map(Cypress.$.makeArray($els), 'innerText');
})
Expand Down Expand Up @@ -197,7 +199,10 @@ function checkSorting(
),
dataField
);
cy.get('[data-ouia-component-id=loading-skeleton]').should('not.exist');
const expectedLength = sortedValues.slice(0, nExpectedRows).length;
cy.get(`td[data-label="${columnField}"]`)
.should('have.length', expectedLength)
.then(($els) => {
return _.map(Cypress.$.makeArray($els), 'innerText');
})
Expand Down
142 changes: 142 additions & 0 deletions src/Components/ClustersListTable/ClustersListTable.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ import {
VERSION_COMBINATIONS,
applyFilters,
} from '../../../cypress/utils/filters';
import { clustersUpdateRisksInterceptors } from '../../../cypress/utils/interceptors';

const lessClusters = {
data: [...clusters.data.slice(0, 28)],
meta: {
count: 28,
},
status: 'ok',
};

// add property name to clusters
let values = _.cloneDeep(clusters['data']);
Expand Down Expand Up @@ -216,6 +225,7 @@ const urlParamsList = [
urlParamsList.forEach((urlParams, index) => {
describe(`pre-filled url search parameters ${index}`, () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, status not ok']();
cy.mount(
<MemoryRouter
initialEntries={[`/openshift/insights/advisor/clusters?${urlParams}`]}
Expand Down Expand Up @@ -270,6 +280,7 @@ urlParamsList.forEach((urlParams, index) => {

describe('clusters list table', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, status not ok']();
cy.mount(
<MemoryRouter
initialEntries={['/openshift/insights/advisor/clusters']}
Expand Down Expand Up @@ -395,6 +406,9 @@ describe('clusters list table', () => {
).forEach(([category, label]) => {
SORTING_ORDERS.forEach((order) => {
it(`${order} by ${label}`, () => {
cy.get('[data-ouia-component-id=loading-skeleton]').should(
'not.exist'
);
let sortingParameter = category;
// modify sortingParameters for certain values

Expand Down Expand Up @@ -563,6 +577,7 @@ describe('clusters list table', () => {

describe('cluster list Empty state rendering', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, status not ok']();
cy.mount(
<MemoryRouter
initialEntries={['/openshift/insights/advisor/clusters']}
Expand Down Expand Up @@ -609,4 +624,131 @@ describe('cluster list Empty state rendering', () => {
});
});

describe('update risk', () => {
const mountLessClusters = () => {
cy.mount(
<MemoryRouter
initialEntries={['/openshift/insights/advisor/clusters']}
initialIndex={0}
>
<Intl>
<Provider store={getStore()}>
<ClustersListTable
query={{
isError: false,
isFetching: false,
isUninitialized: false,
isSuccess: true,
data: lessClusters,
refetch: cy.stub(),
}}
/>
</Provider>
</Intl>
</MemoryRouter>
);
};

describe('one label', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['successful']();
mountLessClusters();
});

it('displays one label', () => {
cy.get(
'span[class=pf-v5-c-label__content]:contains("Update risk")'
).should('have.length', 1);
});
});

describe('two labels', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['successful, two labels']();
mountLessClusters();
});

it('displays two labels', () => {
cy.get(
'span[class=pf-v5-c-label__content]:contains("Update risk")'
).should('have.length', 2);
});
});

describe('no labels', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['successful, no labels']();
mountLessClusters();
});

it('displays no labels', () => {
cy.get(
'span[class=pf-v5-c-label__content]:contains("Update risk")'
).should('have.length', 0);
});
});

describe('no labels', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['successful, no labels']();
mountLessClusters();
});

it('displays no labels', () => {
cy.get(
'span[class=pf-v5-c-label__content]:contains("Update risk")'
).should('have.length', 0);
});
});

describe('status not ok', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, status not ok']();
mountLessClusters();
});

it("don't block table rendering on error", () => {
cy.ouiaId('loading-skeleton').should('not.exist');
expect(filterData()).to.have.length.gte(1);
});
});

describe('error not found', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, not found']();
mountLessClusters();
});

it("don't block table rendering on error", () => {
cy.ouiaId('loading-skeleton').should('not.exist');
expect(filterData()).to.have.length.gte(1);
});
});

describe('error other', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['error, other']();
mountLessClusters();
});

it("don't block table rendering on error", () => {
cy.ouiaId('loading-skeleton').should('not.exist');
expect(filterData()).to.have.length.gte(1);
});
});

describe('long responding', () => {
beforeEach(() => {
clustersUpdateRisksInterceptors['long responding']();
mountLessClusters();
});

it("don't block table rendering on ", () => {
cy.wait('@clustersUpdateRisksLong');
cy.ouiaId('loading-skeleton').should('not.exist');
expect(filterData()).to.have.length.gte(1);
});
});
});

// TODO tests for URL parameters and chips as in RecsListTable

0 comments on commit 3f21e6e

Please sign in to comment.