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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
package-lock.json


# Diagnostic reports (https://nodejs.org/api/report.html)
Expand Down
148 changes: 105 additions & 43 deletions cypress/e2e/repo.cy.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,119 @@
describe('Repo', () => {
beforeEach(() => {
cy.login('admin', 'admin');

cy.visit('/dashboard/repo');

// prevent failures on 404 request and uncaught promises
cy.on('uncaught:exception', () => false);
});

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"]';
describe('Anonymous users', () => {
it('Prevents anonymous users from adding repos', () => {
cy.get('[data-testid="repo-list-view"]')
.find('[data-testid="add-repo-button"]')
.should('not.exist');
});

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
});
});
});

describe('Regular users', () => {
beforeEach(() => {
cy.login('user', 'user');

cy
// tooltip isn't open to start with
.get(tooltipQuery)
cy.visit('/dashboard/repo');
});

after(() => {
cy.logout();
});

it('Prevents regular users from adding repos', () => {
cy.get('[data-testid="repo-list-view"]')
.find('[data-testid="add-repo-button"]')
.should('not.exist');
});
});

describe('Admin users', () => {
beforeEach(() => {
cy.login('admin', 'admin');

cy.visit('/dashboard/repo');
});

it('Admin users can add repos', () => {
cy.get('[data-testid="repo-list-view"]').find('[data-testid="add-repo-button"]').click();

cy.get('[data-testid="add-repo-dialog"]').within(() => {
cy.get('[data-testid="repo-project-input"]').type('uuidjs');
cy.get('[data-testid="repo-name-input"]').type('uuidjs');
cy.get('[data-testid="repo-url-input"]').type('https://github.com/uuidjs/uuid.git');
cy.get('[data-testid="add-repo-button"]').click();
});

cy.get('a[href="/dashboard/repo/uuidjs"]', { timeout: 10000 }).click();

cy.get('[data-testid="delete-repo-button"]').click();
});

it('Prevents adding an existing repo', () => {
cy.get('[data-testid="repo-list-view"]').find('[data-testid="add-repo-button"]').click();

cy.get('[data-testid="add-repo-dialog"]').within(() => {
cy.get('[data-testid="repo-project-input"]').type('finos');
cy.get('[data-testid="repo-name-input"]').type('git-proxy');
cy.get('[data-testid="repo-url-input"]').type('https://github.com/finos/git-proxy.git');
cy.get('[data-testid="add-repo-button"]').click();
});

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
cy.get('[data-testid="repo-error"]')
.should('be.visible')
.and('contain.text', 'Repository already exists!');
});
});
});
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Cypress.Commands.add('login', (username, password) => {
cy.url().should('include', '/dashboard/repo');
});
});

Cypress.Commands.add('logout', () => {
Cypress.session.clearAllSavedSessions();
});
Loading
Loading