Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cypress set up and working with basic tests #74

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
ignorePatterns: ['public/build/'],
settings: { 'svelte3/ignore-styles': () => true },
plugins: ['svelte3'],
extends: 'eslint:recommended',
extends: ['eslint:recommended', 'plugin:cypress/recommended'],
overrides: [
{
files: ['*.svelte'],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ $RECYCLE.BIN/
Thumbs.db
UserInterfaceState.xcuserstate
.env

cypress/old_tests
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://guest.oae.com",
"viewportWidth": 1280,
"viewportHeight": 960
}
115 changes: 115 additions & 0 deletions cypress/integration/basic.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/// <reference types="Cypress" />

import { compose, not, isEmpty } from 'ramda';

const isNotEmpty = compose(not, isEmpty);

const createTenantAdmin = () => {};
const createRegularUser = () => {};

const MOCK_USERNAME = 'miguellaginha';
const OAE = 'Open Academic Environment';

describe('Make sure the interface works', () => {
before(() => {
createTenantAdmin();
createRegularUser();
});

beforeEach(() => {
cy.visit('/');
});

it('It is up and running', () => {
cy.title().should('eq', OAE);
cy.contains(OAE);
});
});

describe('Authentication', () => {
beforeEach(() => {
cy.visit('/');
});

const fillInForm = credentials => {
cy.get('a.signIn-button').click();
cy.get('#username').click();

if (isNotEmpty(credentials.username)) {
cy.get('#username').shadow().find('input').type(credentials.username);
}
if (isNotEmpty(credentials.password)) {
cy.get('#password').shadow().find('input').type(credentials.password);
}
cy.get('#submit-button').click();
};

const assertLocationHasNotChanged = () => {
cy.location().should(location => {
expect(location.host).to.eq('guest.oae.com');
expect(location.pathname).to.eq('/');
});
};

it('rejects submit without username', () => {
fillInForm({ username: '', password: 'password' });
cy.contains('A valid username should be provided');

assertLocationHasNotChanged();
});

it('rejects submit without password', () => {
fillInForm({ username: 'username', password: '' });
cy.contains('A valid password should be provided');

assertLocationHasNotChanged();
});

it('rejects login without correct credentials', () => {
fillInForm({ username: 'username', password: 'password' });
cy.contains('Wrong credentials');

assertLocationHasNotChanged();
cy.get('#password').shadow().find('input').should('have.value', '');
});

it('login as regular user and then logout', () => {
const mockCredentials = { username: MOCK_USERNAME, password: MOCK_USERNAME };
fillInForm(mockCredentials);

cy.title().should('eq', OAE);
cy.contains('Home');
cy.contains('Upload file');
cy.contains('Create');
cy.contains('Activity Feed');
cy.contains('Library');
cy.contains('Discussions');
cy.contains('Groups');
cy.contains('Settings');

cy.location().should(location => {
expect(location.host).to.eq('guest.oae.com');
expect(location.pathname).to.eq('/dashboard');
});

cy.get('button.logout-button').click();

cy.location().should(location => {
expect(location.host).to.eq('guest.oae.com');
expect(location.pathname).to.eq('/');
});
});

it('login as regular user and check cookies', () => {
const mockCredentials = { username: MOCK_USERNAME, password: MOCK_USERNAME };
fillInForm(mockCredentials);

cy.getCookies().should('have.length', 2);

expect(cy.getCookie('session')).to.exist;
expect(cy.getCookie('session.sig')).to.exist;

cy.getCookie('loggedin_tenancies').should('eq', null);
cy.getCookie('breadcrumb').should('eq', null);
});
});
Loading