Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ module.exports = defineConfig({
e2e: {
baseUrl: process.env.CYPRESS_BASE_URL || 'http://localhost:3000',
chromeWebSecurity: false, // Required for OIDC testing
setupNodeEvents(on, config) {
on("task", {
log(message) {
console.log(message);
return null;
}
})
}
},
});
121 changes: 73 additions & 48 deletions cypress/e2e/repo.cy.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,82 @@
describe('Repo', () => {
beforeEach(() => {
let repoName;
let cloneURL;
let csrfToken;
let cookies;

before(() => {
cy.login('admin', 'admin');

cy.visit('/dashboard/repo');
// Create a new repo
cy.getCSRFToken().then((csrfToken) => {
repoName = `${Date.now()}`;
cloneURL = `http://localhost:8000/cypress-test/${repoName}.git`;

// prevent failures on 404 request and uncaught promises
cy.on('uncaught:exception', () => false);
cy.request({
method: 'POST',
url: 'http://localhost:8080/api/v1/repo',
body: {
project: 'cypress-test',
name: repoName,
url: `https://github.com/cypress-test/${repoName}.git`
},
headers: {
cookie: cookies?.join('; ') || '',
'X-CSRF-TOKEN': csrfToken
}
}).then((res) => {
expect(res.status).to.eq(200);
});
});
});

describe('Code button for repo row', () => {
it('Opens tooltip with correct content and can copy', () => {
const cloneURL = 'http://localhost:8000/finos/git-proxy.git';
const tooltipQuery = 'div[role="tooltip"]';

cy
// tooltip isn't open to start with
.get(tooltipQuery)
.should('not.exist');

cy
// find the entry for finos/git-proxy
.get('a[href="/dashboard/repo/git-proxy"]')
// take it's parent row
.closest('tr')
// find the nearby span containing Code we can click to open the tooltip
.find('span')
.contains('Code')
.should('exist')
.click();

cy
// find the newly opened tooltip
.get(tooltipQuery)
.should('exist')
.find('span')
// check it contains the url we expect
.contains(cloneURL)
.should('exist')
.parent()
// find the adjacent span that contains the svg
.find('span')
.next()
// check it has the copy icon first and click it
.get('svg.octicon-copy')
.should('exist')
.click()
// check the icon has changed to the check icon
.get('svg.octicon-copy')
.should('not.exist')
.get('svg.octicon-check')
.should('exist');

// failed to successfully check the clipboard
after(() => {
// Delete the repo
cy.getCSRFToken().then((csrfToken) => {
cy.request({
method: 'DELETE',
url: `http://localhost:8080/api/v1/repo/${repoName}/delete`,
headers: {
cookie: cookies?.join('; ') || '',
'X-CSRF-TOKEN': csrfToken
}
});
});
});

it('Opens tooltip with correct content and can copy', () => {
cy.visit('/dashboard/repo');
cy.on('uncaught:exception', () => false);

const tooltipQuery = 'div[role="tooltip"]';

// Check the tooltip isn't open to start with
cy.get(tooltipQuery)
.should('not.exist');

// Find the repo's Code button and click it
cy.get(`a[href="/dashboard/repo/${repoName}"]`)
.closest('tr')
.find('span')
.contains('Code')
.should('exist')
.click();

// Check tooltip is open and contains the correct clone URL
cy.get(tooltipQuery)
.should('exist')
.find('span')
.contains(cloneURL)
.should('exist')
.parent()
.find('span')
.next()
.get('svg.octicon-copy')
.should('exist')
.click()
.get('svg.octicon-copy')
.should('not.exist')
.get('svg.octicon-check')
.should('exist');
});
});
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ Cypress.Commands.add('login', (username, password) => {
cy.url().should('include', '/dashboard/repo');
});
});

Cypress.Commands.add('getCSRFToken', () => {
return cy.request('GET', 'http://localhost:8080/api/v1/repo').then((res) => {
const cookies = res.headers['set-cookie'];
const csrfCookie = cookies.find(c => c.startsWith('csrf='));
const token = decodeURIComponent(csrfCookie.split('=')[1].split(';')[0]);
Comment thread
jescalada marked this conversation as resolved.
Outdated
return cy.wrap(token);
});
});
4 changes: 2 additions & 2 deletions src/ui/services/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const getRepos = async (
setIsLoading(true);
await axios(url.toString(), config)
.then((response) => {
const data = response.data;
setData(data);
const sortedRepos = response.data.sort((a, b) => a.name.localeCompare(b.name));
setData(sortedRepos);
})
.catch((error) => {
setIsError(true);
Expand Down
7 changes: 3 additions & 4 deletions test/addRepoTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ describe('add new repo', async () => {
after(async function () {
await service.httpServer.close();

// don't clean up data as cypress tests rely on it being present
// await db.deleteRepo('test-repo');
// await db.deleteUser('u1');
// await db.deleteUser('u2');
await db.deleteRepo('test-repo');
await db.deleteUser('u1');
await db.deleteUser('u2');
});
});
Loading