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