209 lines
7.6 KiB
JavaScript

/// <reference types="Cypress" />
// import userMutoid from '../../fixtures/userMutoid';
var Mutoid;
describe('As a visitor, I am able to log in', function () {
beforeEach(function () {
cy.visit("/online");
})
it('Ckeck that the login page is accessible', function () {
// Asset
cy.url().should('include', '?action=login');
})
it('Check that the login tab is active by default', function () {
// Asset
cy.get('.menu-reg').first().find('a[href$="action=login"]').should('have.class', 'active');
})
});
describe('As a visitor, I can only create an account the right way.', function () {
before(function () {
cy.fixture("userMutoid.json").as("Mutoid").then(() => {
expect(this.Mutoid.email).to.exist;
expect(this.Mutoid.password).to.exist;
Mutoid = this.Mutoid;
});
});
beforeEach(', go to the login webpage.', function () {
cy.visit("/online");
});
it('Check that the Create Account tab is accessible', function () {
// Assert
cy.get('.menu-reg').first().find('a[href$="action=register"]')
.should('be.visible');
});
it('Check that the Create Account tab shows a form to fill when active', function () {
// Act : Visiter le formulaire pour s'inscrire.
cy.get('.menu-reg').find('a[href$="action=register"]').click();
// Assert
cy.url().should('include', '?action=register');
// L'onglet "Create accout" possède la classe "active".
cy.get('.menu-reg').find('a[href$="action=register"]').should('have.class', 'active')
// Les formulaires existent et sont visible
cy.get('input#register-email')
.should('be.visible');
cy.get('input#register-password')
.should('be.visible');
// Le bouton "Create Account" existe.
cy.get('#register-form').find(":submit");
});
it('Allow to land directly on the Register page', function () {
//Act
cy.visit('/online/#/welcome/?action=register')
//Assert
cy.get('.menu-reg').first().find('a[href$="action=register"]').should('have.class', 'active');
})
it('Prevent to create an account with empty fields', function () {
// Arrange
cy.get('.menu-reg').first().find('a[href$="action=register"]').click();
cy.get('input#register-email').should('have.not.class', 'input_error');
cy.get('input#register-password').should('have.not.class', 'input_error');
// Act
cy.get('#register-form').find(":submit").click();
// Assert
cy.get('div#register-error') // Message d'erreur
.should('have.class', 'register__error')
.and('be.not.visible');
cy.get('input#register-email').should('have.class', 'input_error'); // Champs surlignés
cy.get('input#register-password').should('have.class', 'input_error');
})
it('Prevent to create an account with an already existing account', function () {
// Arrange
cy.get('.menu-reg').first().find('a[href$="action=register"]').click();
// Act
cy.get('input#register-email').type(Mutoid.email);
cy.get('input#register-password').type(Mutoid.password);
cy.get('#register-form').find(":submit").click();
// Assert
cy.get('input#register-email').should('have.class', 'input_error');
cy.get('input#register-password').should('have.class', 'input_error');
cy.get('div#register-error')
.should('be.visible')
.and('contain', 'This email is already registered, please choose another one.')
})
});
describe.only("As a user, I can only log in and out the right way", function () {
before(function () {
cy.fixture("users.json").as("users").then((users) => {
Mutoid = users["Mutoid"];
expect(Mutoid.email).to.exist;
expect(Mutoid.password).to.exist;
expect(Mutoid.type).eq("user");
});
})
beforeEach(function () {
cy.visit("/online");
})
it('Prevent to log in with empty credentials', function () {
// Act
cy.get('form#login-form').find(':submit').click();
// Assert
cy.url().should('include', '?action=login'); // Pas de redirection
cy.get('div#login-error')
.should('have.class', 'login__error')
.and('be.visible')
.and('contain', "Please fill the email and password fields"); // Message d'erreur de l'API
// Champs éclairés
cy.get('input#login-email').should('have.class', 'input_error');
cy.get('input#login-password').should('have.class', 'input_error');
})
it('Prevent to log in with just the email', function () {
// Act
cy.get("#login-email").type(Mutoid.email);
cy.get('form#login-form').find(':submit').click();
// Assert
cy.url().should('include', '?action=login'); // Pas de redirection
cy.get('div#login-error')
.should('have.class', 'login__error')
.and('be.visible'); // Message d'erreur
// Champs éclairés
cy.get('input#login-email').should('have.class', 'input_error');
cy.get('input#login-password').should('have.class', 'input_error');
})
it('Prevent to log in with just the password', function () {
// Act
cy.get("#login-password").type(Mutoid.password)
cy.get('form#login-form').find(':submit').click();
// Assert
cy.url().should('include', '?action=login'); // Pas de redirection
cy.get('div#login-error')
.should('have.class', 'login__error')
.and('be.visible'); // Message d'erreur
// Champs éclairés
cy.get('input#login-email').should('have.class', 'input_error');
cy.get('input#login-password').should('have.class', 'input_error');
})
it('Prevent to log in Mutoid with an invalid password', function () {
// Act
cy.get("#login-email").type(Mutoid.email)
cy.get("#login-password").type(Mutoid.email)
cy.get('form#login-form').find(':submit').click();
// Assert
cy.url().should('include', '?action=login'); // Pas de redirection
cy.get('div#login-error')
.should('have.class', 'login__error')
.and('be.visible'); // Message d'erreur
// Champs éclairés
cy.get('input#login-email').should('have.class', 'input_error');
cy.get('input#login-password').should('have.class', 'input_error');
})
it('Logs Mutoid in.', function () {
// Act
cy.get("#login-email").type(Mutoid.email)
cy.get("#login-password").type(Mutoid.password)
cy.get("#login-form").find(":submit").click()
// Assert
cy.url().should('contain', '/online/#/reader/category/all/')
cy.get("div#user").find("a.user__settings").click();
cy.logout();
});
it('Logs Mutoid in via API', function () {
// act
cy.login(Mutoid);
cy.visit("/online");
// assert
cy.getCookie('session').should('exist');
});
it('Logs Mutoid out.', function () {
// Arrange
cy.login(Mutoid)
cy.visit('/online');
// act
cy.get("div#user").find("a.user__settings").click();
cy.get("div#user-menu").find('.logout').click();
//assert
cy.url().should('include', '?action=login');
cy.get('.menu-reg').first().find('a[href$="action=login"]')
.should('have.class', 'active');
cy.getCookie('session').should('not.exist');
})
})