|
1 | 1 | describe('Repo', () => { |
2 | | - beforeEach(() => { |
| 2 | + let repoName; |
| 3 | + let cloneURL; |
| 4 | + let csrfToken; |
| 5 | + let cookies; |
| 6 | + let repoId; |
| 7 | + |
| 8 | + before(() => { |
3 | 9 | cy.login('admin', 'admin'); |
4 | 10 |
|
5 | | - cy.visit('/dashboard/repo'); |
| 11 | + // Create a new repo |
| 12 | + cy.getCSRFToken().then((csrfToken) => { |
| 13 | + repoName = `${Date.now()}`; |
| 14 | + cloneURL = `http://localhost:8000/github.com/cypress-test/${repoName}.git`; |
| 15 | + |
| 16 | + cy.request({ |
| 17 | + method: 'POST', |
| 18 | + url: 'http://localhost:8080/api/v1/repo', |
| 19 | + body: { |
| 20 | + project: 'cypress-test', |
| 21 | + name: repoName, |
| 22 | + url: `https://github.com/cypress-test/${repoName}.git` |
| 23 | + }, |
| 24 | + headers: { |
| 25 | + cookie: cookies?.join('; ') || '', |
| 26 | + 'X-CSRF-TOKEN': csrfToken |
| 27 | + } |
| 28 | + }).then((res) => { |
| 29 | + expect(res.status).to.eq(200); |
| 30 | + repoId = res.body._id; |
| 31 | + }); |
| 32 | + }); |
| 33 | + }); |
6 | 34 |
|
7 | | - // prevent failures on 404 request and uncaught promises |
| 35 | + it('Opens tooltip with correct content and can copy', () => { |
| 36 | + cy.visit('/dashboard/repo'); |
8 | 37 | cy.on('uncaught:exception', () => false); |
| 38 | + |
| 39 | + const tooltipQuery = 'div[role="tooltip"]'; |
| 40 | + |
| 41 | + // Check the tooltip isn't open to start with |
| 42 | + cy.get(tooltipQuery) |
| 43 | + .should('not.exist'); |
| 44 | + |
| 45 | + // Find the repo's Code button and click it |
| 46 | + cy.get(`a[href="/dashboard/repo/${repoId}"]`) |
| 47 | + .closest('tr') |
| 48 | + .find('span') |
| 49 | + .contains('Code') |
| 50 | + .should('exist') |
| 51 | + .click(); |
| 52 | + |
| 53 | + // Check tooltip is open and contains the correct clone URL |
| 54 | + cy.get(tooltipQuery) |
| 55 | + .should('exist') |
| 56 | + .find('span') |
| 57 | + .contains(cloneURL) |
| 58 | + .should('exist') |
| 59 | + .parent() |
| 60 | + .find('span') |
| 61 | + .next() |
| 62 | + .get('svg.octicon-copy') |
| 63 | + .should('exist') |
| 64 | + .click() |
| 65 | + .get('svg.octicon-copy') |
| 66 | + .should('not.exist') |
| 67 | + .get('svg.octicon-check') |
| 68 | + .should('exist'); |
9 | 69 | }); |
10 | 70 |
|
11 | | - describe('Code button for repo row', () => { |
12 | | - it('Opens tooltip with correct content and can copy', () => { |
13 | | - const cloneURLRegex = /http:\/\/localhost:8000\/(?:[^\/]+\/).+\.git/; |
14 | | - const tooltipQuery = 'div[role="tooltip"]'; |
15 | | - |
16 | | - cy |
17 | | - // tooltip isn't open to start with |
18 | | - .get(tooltipQuery) |
19 | | - .should('not.exist'); |
20 | | - |
21 | | - cy |
22 | | - // find a table row for a repo (any will do) |
23 | | - .get('table#RepoListTable>tbody>tr') |
24 | | - // find the nearby span containing Code we can click to open the tooltip |
25 | | - .find('span') |
26 | | - .contains('Code') |
27 | | - .should('exist') |
28 | | - .click(); |
29 | | - |
30 | | - cy |
31 | | - // find the newly opened tooltip |
32 | | - .get(tooltipQuery) |
33 | | - .should('exist') |
34 | | - .find('span') |
35 | | - // check it contains the url we expect |
36 | | - .contains(cloneURLRegex) |
37 | | - .should('exist') |
38 | | - .parent() |
39 | | - // find the adjacent span that contains the svg |
40 | | - .find('span') |
41 | | - .next() |
42 | | - // check it has the copy icon first and click it |
43 | | - .get('svg.octicon-copy') |
44 | | - .should('exist') |
45 | | - .click() |
46 | | - // check the icon has changed to the check icon |
47 | | - .get('svg.octicon-copy') |
48 | | - .should('not.exist') |
49 | | - .get('svg.octicon-check') |
50 | | - .should('exist'); |
51 | | - |
52 | | - // failed to successfully check the clipboard |
| 71 | + after(() => { |
| 72 | + // Delete the repo |
| 73 | + cy.getCSRFToken().then((csrfToken) => { |
| 74 | + cy.request({ |
| 75 | + method: 'DELETE', |
| 76 | + url: `http://localhost:8080/api/v1/repo/${repoName}/delete`, |
| 77 | + headers: { |
| 78 | + cookie: cookies?.join('; ') || '', |
| 79 | + 'X-CSRF-TOKEN': csrfToken |
| 80 | + } |
| 81 | + }); |
53 | 82 | }); |
54 | 83 | }); |
55 | 84 | }); |
0 commit comments