Skip to content

Commit 9a1f97d

Browse files
Added e2e tests
1 parent b198840 commit 9a1f97d

File tree

7 files changed

+334
-146
lines changed

7 files changed

+334
-146
lines changed

frontend/packages/dev-console/src/components/add/AddPage.tsx

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import * as React from 'react';
2-
import { Button, Alert } from '@patternfly/react-core';
2+
import { Button } from '@patternfly/react-core';
33
import { Helmet } from 'react-helmet';
44
import { useTranslation, Trans } from 'react-i18next';
55
import { match as RMatch } from 'react-router';
6-
import { Link } from 'react-router-dom';
7-
import { useK8sWatchResource } from '@console/dynamic-plugin-sdk/src/api/core-api';
86
import { withStartGuide } from '../../../../../public/components/start-guide';
9-
import { AppliedClusterResourceQuotaModel, ResourceQuotaModel } from '../../../../../public/models';
10-
import {
11-
AppliedClusterResourceQuotaKind,
12-
ResourceQuotaKind,
13-
} from '../../../../../public/module/k8s';
14-
import { checkQuotaLimit } from '../../../../topology/src/components/utils/checkResourceQuota';
157
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
168
import CreateProjectListPage from '../projects/CreateProjectListPage';
9+
import { ResourceQuotaAlert } from '../resource-quota/ResourceQuotaAlert';
1710
import AddPageLayout from './AddPageLayout';
1811

1912
export interface AddPageProps {
@@ -27,71 +20,9 @@ export const PageContents: React.FC<AddPageProps> = ({ match }) => {
2720
const { t } = useTranslation();
2821
const namespace = match.params.ns;
2922

30-
const [warningMessageFlag, setWarningMessageFlag] = React.useState<boolean>();
31-
const [resourceQuotaName, setResourceQuotaName] = React.useState<string>('');
32-
const [resourceQuotaKind, setResourceQuotaKind] = React.useState<string>('');
33-
34-
const [quotas, rqLoaded] = useK8sWatchResource<ResourceQuotaKind[]>({
35-
groupVersionKind: {
36-
kind: ResourceQuotaModel.kind,
37-
version: ResourceQuotaModel.apiVersion,
38-
},
39-
namespace,
40-
isList: true,
41-
});
42-
43-
const [clusterQuotas, acrqLoaded] = useK8sWatchResource<AppliedClusterResourceQuotaKind[]>({
44-
groupVersionKind: {
45-
kind: AppliedClusterResourceQuotaModel.kind,
46-
version: AppliedClusterResourceQuotaModel.apiVersion,
47-
group: AppliedClusterResourceQuotaModel.apiGroup,
48-
},
49-
namespace,
50-
isList: true,
51-
});
52-
53-
const [totalRQatQuota, quotaName, quotaKind] = checkQuotaLimit(quotas);
54-
const [totalACRQatQuota, clusterRQName, clusterRQKind] = checkQuotaLimit(clusterQuotas);
55-
56-
let totalResourcesAtQuota = [...totalRQatQuota, ...totalACRQatQuota];
57-
totalResourcesAtQuota = totalResourcesAtQuota.filter((resourceAtQuota) => resourceAtQuota !== 0);
58-
59-
React.useEffect(() => {
60-
if (totalResourcesAtQuota.length === 1) {
61-
setResourceQuotaName(quotaName || clusterRQName);
62-
setResourceQuotaKind(quotaKind || clusterRQKind);
63-
} else {
64-
setResourceQuotaName('');
65-
setResourceQuotaKind('');
66-
}
67-
if (totalResourcesAtQuota.length > 0) {
68-
setWarningMessageFlag(true);
69-
} else {
70-
setWarningMessageFlag(false);
71-
}
72-
}, [clusterRQKind, clusterRQName, totalResourcesAtQuota, quotaKind, quotaName]);
73-
74-
const getRedirectLink = () => {
75-
if (resourceQuotaName && resourceQuotaKind === AppliedClusterResourceQuotaModel.kind) {
76-
return `/k8s/ns/${namespace}/${AppliedClusterResourceQuotaModel.apiGroup}~${AppliedClusterResourceQuotaModel.apiVersion}~${AppliedClusterResourceQuotaModel.kind}/${resourceQuotaName}`;
77-
}
78-
if (resourceQuotaName) {
79-
return `/k8s/ns/${namespace}/${ResourceQuotaModel.plural}/${resourceQuotaName}`;
80-
}
81-
return `/k8s/ns/${namespace}/${ResourceQuotaModel.plural}`;
82-
};
83-
8423
return namespace ? (
8524
<>
86-
{warningMessageFlag && rqLoaded && acrqLoaded ? (
87-
<Alert variant="warning" title={t('devconsole~Resource quota reached')} isInline>
88-
<Link to={getRedirectLink()}>
89-
{t('devconsole~{{count}} resource reached quota', {
90-
count: totalResourcesAtQuota.reduce((a, b) => a + b, 0),
91-
})}
92-
</Link>
93-
</Alert>
94-
) : null}
25+
<ResourceQuotaAlert namespace={namespace} />
9526
<AddPageLayout title={t('devconsole~Add')} />
9627
</>
9728
) : (
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import * as React from 'react';
2+
import { Alert } from '@patternfly/react-core';
3+
import { useTranslation } from 'react-i18next';
4+
import { Link } from 'react-router-dom';
5+
import { useK8sWatchResource } from '@console/dynamic-plugin-sdk/src/api/core-api';
6+
import { AppliedClusterResourceQuotaModel, ResourceQuotaModel } from '@console/internal/models';
7+
import { AppliedClusterResourceQuotaKind, ResourceQuotaKind } from '@console/internal/module/k8s';
8+
import { checkQuotaLimit } from '@console/topology/src/components/utils/checkResourceQuota';
9+
10+
export interface ResourceQuotaAlertProps {
11+
namespace: string;
12+
}
13+
14+
export const ResourceQuotaAlert: React.FC<ResourceQuotaAlertProps> = ({ namespace }) => {
15+
const { t } = useTranslation();
16+
const [warningMessageFlag, setWarningMessageFlag] = React.useState<boolean>();
17+
const [resourceQuotaName, setResourceQuotaName] = React.useState<string>('');
18+
const [resourceQuotaKind, setResourceQuotaKind] = React.useState<string>('');
19+
20+
const [quotas, rqLoaded] = useK8sWatchResource<ResourceQuotaKind[]>({
21+
groupVersionKind: {
22+
kind: ResourceQuotaModel.kind,
23+
version: ResourceQuotaModel.apiVersion,
24+
},
25+
namespace,
26+
isList: true,
27+
});
28+
29+
const [clusterQuotas, acrqLoaded] = useK8sWatchResource<AppliedClusterResourceQuotaKind[]>({
30+
groupVersionKind: {
31+
kind: AppliedClusterResourceQuotaModel.kind,
32+
version: AppliedClusterResourceQuotaModel.apiVersion,
33+
group: AppliedClusterResourceQuotaModel.apiGroup,
34+
},
35+
namespace,
36+
isList: true,
37+
});
38+
39+
const [totalRQatQuota, quotaName, quotaKind] = checkQuotaLimit(quotas);
40+
const [totalACRQatQuota, clusterRQName, clusterRQKind] = checkQuotaLimit(clusterQuotas);
41+
42+
let totalResourcesAtQuota = [...totalRQatQuota, ...totalACRQatQuota];
43+
totalResourcesAtQuota = totalResourcesAtQuota.filter((resourceAtQuota) => resourceAtQuota !== 0);
44+
45+
React.useEffect(() => {
46+
if (totalResourcesAtQuota.length === 1) {
47+
setResourceQuotaName(quotaName || clusterRQName);
48+
setResourceQuotaKind(quotaKind || clusterRQKind);
49+
} else {
50+
setResourceQuotaName('');
51+
setResourceQuotaKind('');
52+
}
53+
if (totalResourcesAtQuota.length > 0) {
54+
setWarningMessageFlag(true);
55+
} else {
56+
setWarningMessageFlag(false);
57+
}
58+
}, [clusterRQKind, clusterRQName, totalResourcesAtQuota, quotaKind, quotaName]);
59+
60+
const getRedirectLink = () => {
61+
if (resourceQuotaName && resourceQuotaKind === AppliedClusterResourceQuotaModel.kind) {
62+
return `/k8s/ns/${namespace}/${AppliedClusterResourceQuotaModel.apiGroup}~${AppliedClusterResourceQuotaModel.apiVersion}~${AppliedClusterResourceQuotaModel.kind}/${resourceQuotaName}`;
63+
}
64+
if (resourceQuotaName) {
65+
return `/k8s/ns/${namespace}/${ResourceQuotaModel.plural}/${resourceQuotaName}`;
66+
}
67+
return `/k8s/ns/${namespace}/${ResourceQuotaModel.plural}`;
68+
};
69+
return (
70+
<>
71+
{warningMessageFlag && rqLoaded && acrqLoaded ? (
72+
<Alert variant="warning" title={t('topology~Resource quota reached')} isInline>
73+
<Link to={getRedirectLink()}>
74+
{t('topology~{{count}} resource reached quota', {
75+
count: totalResourcesAtQuota.reduce((a, b) => a + b, 0),
76+
})}
77+
</Link>
78+
</Alert>
79+
) : null}
80+
</>
81+
);
82+
};
83+
84+
export default ResourceQuotaAlert;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
"promise/catch-or-return": "off",
4+
"promise/no-nesting": "off"
5+
}
6+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@topology @add-flow @ODC6771
2+
Feature: Update user in topology and add flow if Quotas has been reached in a namespace
3+
If any resource reached resource quota limit, a warning alert will be displayed for the user in Add page and Topology page.
4+
5+
Background:
6+
Given user is at developer perspective
7+
And user has created or selected namespace "aut-topology"
8+
9+
10+
@regression
11+
Scenario: Deploy git workload with devfile from topology page: T-19-TC01
12+
Given user is at the Topology page
13+
When user right clicks on topology empty graph
14+
And user selects "Import from Git" option from Add to Project context menu
15+
And user enters Git Repo URL as "https://github.com/nodeshift-starters/devfile-sample" in Import from Git form
16+
And user enters workload name as "node-bulletin-board-1"
17+
And user clicks Create button on Add page
18+
Then user will be redirected to Topology page
19+
And user is able to see workload "node-bulletin-board-1" in topology page
20+
21+
22+
@regression
23+
Scenario: user creates a resource quota: T-19-TC02
24+
Given user clicks on import YAML button
25+
When user creates resource quota 'resourcequota1' by entering "testData/resource-quota/resource-quota.yaml" file data
26+
And user clicks on Create button
27+
Then user is redirected to resource quota details page
28+
29+
30+
@regression
31+
Scenario: check resource quota reached warning message in topology page: T-19-TC03
32+
Given user is at the Topology page
33+
When user clicks on link to view resource quota details
34+
Then user is redirected to resource quota details page
35+
36+
37+
@regression
38+
Scenario: check resource quota reached warning message in Add page: T-19-TC04
39+
Given user is at the Add page
40+
When user clicks on link to view resource quota details
41+
Then user is redirected to resource quota details page
42+
43+
44+
@regression
45+
Scenario: user creates another resource quota: T-19-TC05
46+
Given user clicks on import YAML button
47+
When user creates resource quota 'resourcequota2' by entering "testData/resource-quota/resource-quota.yaml" file data
48+
And user clicks on Create button
49+
Then user is redirected to resource quota details page
50+
51+
52+
@regression
53+
Scenario: Click on warning message link to see the resource quotas list in toplology page: T-19-TC06
54+
Given user is at the Topology page
55+
When user clicks on link to view resource quota details
56+
Then user is redirected to resource quota list page
57+
58+
59+
@regression
60+
Scenario: Click on warning message link to see the resource quotas list in Add page: T-19-TC07
61+
Given user is at the Add page
62+
When user clicks on link to view resource quota details
63+
And user is redirected to resource quota list page
64+
And user deletes resource quotas created
65+
Then user should not be able to see the resource quotas "resourcequota1" and "resourcequota2"
66+
67+
68+
@regression
69+
Scenario: Delete the application created: A-04-TC01: T-19-TC08
70+
Given user is at the Topology page
71+
When user right clicks on Application Grouping "devfile-sample-app"
72+
And user clicks on Delete application
73+
And user enters the name "devfile-sample-app" in the Delete application modal and clicks on Delete button
74+

0 commit comments

Comments
 (0)