Skip to content

Commit 499ef7f

Browse files
authored
Feat add gc (#545)
Signed-off-by: zhaoxinxin <1186037180@qq.com>
1 parent 192567e commit 499ef7f

36 files changed

+3827
-62
lines changed

cypress/e2e/gc/audit.cy.ts

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
import config from '../../fixtures/gc/config.json';
2+
import history from '../../fixtures/gc/history.json';
3+
import executeGC from '../../fixtures/gc/execute-gc.json';
4+
import updateConfig from '../../fixtures/gc/update-config.json';
5+
6+
describe('audit', () => {
7+
beforeEach(() => {
8+
cy.signin();
9+
10+
cy.intercept(
11+
{
12+
method: 'GET',
13+
url: '/api/v1/configs?page=1&per_page=10000000',
14+
},
15+
(req) => {
16+
req.reply((res: any) => {
17+
res.send(200, config);
18+
});
19+
},
20+
);
21+
22+
cy.intercept(
23+
{
24+
method: 'GET',
25+
url: '/api/v1/jobs?page=1&per_page=10000000&type=gc',
26+
},
27+
(req) => {
28+
req.reply((res: any) => {
29+
res.send(200, history);
30+
});
31+
},
32+
);
33+
34+
cy.viewport(1440, 1080);
35+
cy.visit('/gc/audit');
36+
});
37+
38+
it('when data is loaded', () => {
39+
cy.get('#audit-ttl').should('have.text', '3 Days');
40+
41+
cy.get('#history').should('have.text', '11');
42+
cy.get('#pagination').should('exist');
43+
44+
cy.get('#trigger-119').should('have.text', 'Manual');
45+
46+
cy.get('.MuiPagination-ul > :nth-child(3) > .MuiButtonBase-root').click();
47+
48+
cy.get('#id-97').should('have.text', 97);
49+
});
50+
51+
it('when no data is loaded', () => {
52+
cy.intercept(
53+
{
54+
method: 'GET',
55+
url: '/api/v1/configs?page=1&per_page=10000000',
56+
},
57+
(req) => {
58+
req.reply({ statusCode: 200, body: [] });
59+
},
60+
);
61+
62+
cy.intercept(
63+
{
64+
method: 'GET',
65+
url: '/api/v1/jobs?page=1&per_page=10000000&type=gc',
66+
},
67+
(req) => {
68+
req.reply({ statusCode: 200, body: [] });
69+
},
70+
);
71+
72+
cy.get('#audit-ttl').should('have.text', '-');
73+
cy.get('#history').should('have.text', '0');
74+
cy.get('#last-completed').should('have.text', '-');
75+
76+
cy.get('#pagination').should('not.exist');
77+
78+
// no history.
79+
cy.get('#no-history').should('have.text', `You don't have GC history.`);
80+
});
81+
82+
it('can execute GC', () => {
83+
cy.get('#execute-gc').click();
84+
cy.get('#execute').should('exist');
85+
86+
// Click cancel button.
87+
cy.get('#cancel-execute').click();
88+
cy.get('#execute').should('not.exist');
89+
90+
cy.get('#execute-gc').click();
91+
92+
cy.intercept(
93+
{
94+
method: 'POST',
95+
url: '/api/v1/jobs',
96+
},
97+
async (req) => {
98+
await new Promise((resolve) => setTimeout(resolve, 2000));
99+
req.reply({
100+
statusCode: 200,
101+
body: executeGC,
102+
});
103+
},
104+
);
105+
106+
// Click execute button.
107+
cy.get('#save-execute').click();
108+
109+
cy.get('#execute-loading').should('exist');
110+
111+
cy.wait(1000);
112+
cy.get('#success-execute-gc').should('exist');
113+
114+
// Show number of recycled audit log.
115+
cy.get('.MuiAlert-message').should('have.text', 'You have successfully recycled 10 audit logs!');
116+
117+
cy.get('#close-execut-icon').click();
118+
119+
cy.get('#execute').should('not.exist');
120+
});
121+
122+
it('can not execute GC', () => {
123+
cy.get('#execute-gc').click();
124+
cy.get('#execute').should('exist');
125+
126+
cy.intercept(
127+
{
128+
method: 'POST',
129+
url: '/api/v1/jobs',
130+
},
131+
async (req) => {
132+
req.reply({
133+
forceNetworkError: true,
134+
});
135+
},
136+
);
137+
138+
// Click execute button.
139+
cy.get('#save-execute').click();
140+
141+
cy.get('#execute-error').should('exist');
142+
});
143+
144+
it('should handle API error response', () => {
145+
cy.intercept(
146+
{
147+
method: 'GET',
148+
url: '/api/v1/configs?page=1&per_page=10000000',
149+
},
150+
(req) => {
151+
req.reply({ forceNetworkError: true });
152+
},
153+
);
154+
155+
cy.intercept(
156+
{
157+
method: 'GET',
158+
url: '/api/v1/jobs?page=1&per_page=10000000&type=gc',
159+
},
160+
(req) => {
161+
req.reply({ forceNetworkError: true });
162+
},
163+
);
164+
165+
// Show error message.
166+
cy.get('.MuiAlert-message').should('be.visible').and('contain', 'Failed to fetch');
167+
168+
// Close error message.
169+
cy.get('.MuiAlert-action > .MuiButtonBase-root').click();
170+
cy.get('.MuiAlert-message').should('not.exist');
171+
});
172+
173+
it('can update ttl', () => {
174+
cy.get('#audit-ttl').should('have.text', '3 Days');
175+
cy.get('#update').click();
176+
177+
cy.get('#audit-ttl-input').clear();
178+
cy.get('#audit-ttl-input').type('1');
179+
180+
cy.intercept(
181+
{
182+
method: 'PATCH',
183+
url: '/api/v1/configs/1',
184+
},
185+
async (req) => {
186+
req.reply({
187+
statusCode: 200,
188+
body: {},
189+
});
190+
},
191+
);
192+
193+
cy.intercept(
194+
{
195+
method: 'GET',
196+
url: '/api/v1/configs?page=1&per_page=10000000',
197+
},
198+
(req) => {
199+
req.reply((res: any) => {
200+
res.send(200, updateConfig);
201+
});
202+
},
203+
);
204+
205+
cy.get('#save-ttl').click();
206+
207+
cy.get('.MuiAlert-message').should('have.text', 'Submission successful!');
208+
209+
cy.get('#audit-ttl').should('have.text', '21 Days');
210+
});
211+
212+
it('can no update ttl', () => {
213+
cy.get('#audit-ttl').should('have.text', '3 Days');
214+
cy.get('#update').click();
215+
216+
cy.get('#audit-ttl-input').clear();
217+
cy.get('#audit-ttl-input').type('1');
218+
219+
cy.intercept(
220+
{
221+
method: 'PATCH',
222+
url: '/api/v1/configs/1',
223+
},
224+
async (req) => {
225+
req.reply({
226+
forceNetworkError: true,
227+
});
228+
},
229+
);
230+
231+
cy.get('#save-ttl').click();
232+
233+
// Show error message.
234+
cy.get('.MuiAlert-message').should('be.visible').and('contain', 'Failed to fetch');
235+
});
236+
});

0 commit comments

Comments
 (0)