Skip to content

Commit 8675ef3

Browse files
committed
test: add cypress e2e tests for tag push
1 parent ddfae87 commit 8675ef3

2 files changed

Lines changed: 206 additions & 0 deletions

File tree

cypress/e2e/tagPush.cy.js

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/**
2+
* Copyright 2026 GitProxy Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
describe('Tag Push Functionality', () => {
18+
beforeEach(() => {
19+
cy.login('admin', 'admin');
20+
cy.on('uncaught:exception', () => false);
21+
22+
// Create test data for tag pushes
23+
cy.createTestTagPush();
24+
});
25+
26+
describe('Tag Push Display in PushesTable', () => {
27+
it('can navigate to push dashboard and view push table', () => {
28+
cy.visit('/dashboard/push');
29+
30+
// Wait for API call to complete
31+
cy.wait('@getPushes');
32+
33+
// Check that we can see the basic table structure
34+
cy.get('table', { timeout: 10000 }).should('exist');
35+
cy.get('thead').should('exist');
36+
cy.get('tbody').should('exist');
37+
38+
// Now we should have test data, so we can check for rows
39+
cy.get('tbody tr').should('have.length.at.least', 1);
40+
41+
// Check the structure of the first row
42+
cy.get('tbody tr')
43+
.first()
44+
.within(() => {
45+
cy.get('td').should('have.length.at.least', 6); // We know there are multiple columns
46+
// Check for tag-specific content
47+
cy.contains('v1.0.0').should('exist'); // Tag name
48+
cy.contains('test-tagger').should('exist'); // Tagger
49+
});
50+
});
51+
52+
it('has search functionality', () => {
53+
cy.visit('/dashboard/push');
54+
cy.wait('@getPushes');
55+
56+
// Check search input exists
57+
cy.get('input[type="text"]').first().should('exist');
58+
59+
// Test searching for tag name
60+
cy.get('input[type="text"]').first().type('v1.0.0');
61+
cy.get('tbody tr').should('have.length.at.least', 1);
62+
});
63+
64+
it('can interact with push table entries', () => {
65+
cy.visit('/dashboard/push');
66+
cy.wait('@getPushes');
67+
68+
cy.get('tbody tr').should('have.length.at.least', 1);
69+
70+
// Check for clickable elements in the first row
71+
cy.get('tbody tr')
72+
.first()
73+
.within(() => {
74+
// Should have links and buttons
75+
cy.get('a').should('have.length.at.least', 1); // Repository links, etc.
76+
cy.get('button').should('have.length.at.least', 1); // Action button
77+
});
78+
});
79+
});
80+
81+
describe('Tag Push Details Page', () => {
82+
it('can access push details page structure', () => {
83+
// Try to access a push details page directly
84+
cy.visit('/dashboard/push/test-push-id', { failOnStatusCode: false });
85+
86+
// Check basic page structure exists (regardless of whether push exists)
87+
cy.get('body').should('exist'); // Basic content check
88+
89+
// If we end up redirected, that's also acceptable behavior
90+
cy.url().should('include', '/dashboard');
91+
});
92+
});
93+
94+
describe('Basic UI Navigation', () => {
95+
it('can navigate between dashboard pages', () => {
96+
cy.visit('/dashboard/push');
97+
cy.wait('@getPushes');
98+
cy.get('table', { timeout: 10000 }).should('exist');
99+
100+
// Test navigation to repo dashboard
101+
cy.visit('/dashboard/repo');
102+
cy.get('table', { timeout: 10000 }).should('exist');
103+
104+
// Test navigation to user management if it exists
105+
cy.visit('/dashboard/user');
106+
cy.get('body').should('exist');
107+
});
108+
});
109+
110+
describe('Application Robustness', () => {
111+
it('handles navigation to non-existent push gracefully', () => {
112+
// Try to visit a non-existent push detail page
113+
cy.visit('/dashboard/push/non-existent-push-id', { failOnStatusCode: false });
114+
115+
// Should either redirect or show error page, but not crash
116+
cy.get('body').should('exist');
117+
});
118+
119+
it('maintains functionality after page refresh', () => {
120+
cy.visit('/dashboard/push');
121+
cy.wait('@getPushes');
122+
cy.get('table', { timeout: 10000 }).should('exist');
123+
124+
// Refresh the page
125+
cy.reload();
126+
// Wait for API call again after reload
127+
cy.wait('@getPushes');
128+
129+
// Wait for page to reload and check basic functionality
130+
cy.get('body').should('exist');
131+
132+
// Give more time for table to load after refresh, or check if redirected
133+
cy.url().then((url) => {
134+
if (url.includes('/dashboard/push')) {
135+
cy.get('table', { timeout: 15000 }).should('exist');
136+
} else {
137+
// If redirected (e.g., to login), that's also acceptable behavior
138+
cy.get('body').should('exist');
139+
}
140+
});
141+
});
142+
});
143+
});

cypress/support/commands.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,66 @@ Cypress.Commands.add('getCSRFToken', () => {
8181
return cy.wrap(decodeURIComponent(token));
8282
});
8383
});
84+
85+
Cypress.Commands.add('createTestTagPush', (pushData = {}) => {
86+
const defaultTagPush = {
87+
id: `test-tag-push-${Date.now()}`,
88+
steps: [],
89+
error: false,
90+
blocked: true,
91+
allowPush: false,
92+
authorised: false,
93+
canceled: false,
94+
rejected: false,
95+
autoApproved: false,
96+
autoRejected: false,
97+
type: 'push',
98+
method: 'get',
99+
timestamp: Date.now(),
100+
project: 'cypress-test',
101+
repoName: 'test-repo.git',
102+
url: 'https://github.com/cypress-test/test-repo.git',
103+
repo: 'cypress-test/test-repo.git',
104+
user: 'test-tagger',
105+
userEmail: 'test-tagger@test.com',
106+
branch: 'refs/heads/main',
107+
tag: 'refs/tags/v1.0.0',
108+
commitFrom: '0000000000000000000000000000000000000000',
109+
commitTo: 'abcdef1234567890abcdef1234567890abcdef12',
110+
lastStep: null,
111+
blockedMessage: '\n\n\nGitProxy has received your tag push\n\n\n',
112+
_id: null,
113+
attestation: null,
114+
tagData: [
115+
{
116+
tagName: 'v1.0.0',
117+
type: 'annotated',
118+
tagger: 'test-tagger',
119+
message: 'Release version 1.0.0\n\nThis is a test tag release for Cypress testing.',
120+
timestamp: Math.floor(Date.now() / 1000),
121+
},
122+
],
123+
commitData: [
124+
{
125+
commitTs: Math.floor(Date.now() / 1000) - 300,
126+
commitTimestamp: Math.floor(Date.now() / 1000) - 300,
127+
message: 'feat: add new tag push feature',
128+
committer: 'test-committer',
129+
author: 'test-author',
130+
authorEmail: 'test-author@test.com',
131+
},
132+
],
133+
diff: {
134+
content: '+++ test tag push implementation',
135+
},
136+
...pushData,
137+
};
138+
139+
// For now, intercept the push API calls and return our test data
140+
cy.intercept('GET', '**/api/v1/push*', {
141+
statusCode: 200,
142+
body: [defaultTagPush],
143+
}).as('getPushes');
144+
145+
return cy.wrap(defaultTagPush);
146+
});

0 commit comments

Comments
 (0)