Introduce group basic federation, event new page and notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
// A custom Nightwatch assertion.
|
||||
// The assertion name is the filename.
|
||||
// Example usage:
|
||||
//
|
||||
// browser.assert.elementCount(selector, count)
|
||||
//
|
||||
// For more information on custom assertions see:
|
||||
// http://nightwatchjs.org/guide#writing-custom-assertions
|
||||
|
||||
exports.assertion = function elementCount(selector, count) {
|
||||
this.message = `Testing if element <${selector}> has count: ${count}`;
|
||||
this.expected = count;
|
||||
this.pass = val => val === count;
|
||||
this.value = res => res.value;
|
||||
function evaluator(_selector) {
|
||||
return document.querySelectorAll(_selector).length;
|
||||
export default class ElementCount {
|
||||
constructor(selector, count) {
|
||||
this.message = `Testing if element <${selector}> has count: ${count}`;
|
||||
this.expected = count;
|
||||
this.pass = (val) => val === count;
|
||||
this.value = (res) => res.value;
|
||||
function evaluator(_selector) {
|
||||
return document.querySelectorAll(_selector).length;
|
||||
}
|
||||
this.command = (cb) => this.api.execute(evaluator, [selector], cb);
|
||||
}
|
||||
this.command = cb => this.api.execute(evaluator, [selector], cb);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,11 +14,12 @@ module.exports = (on, config) => {
|
||||
// watchOptions: {}
|
||||
// }))
|
||||
|
||||
return Object.assign({}, config, {
|
||||
fixturesFolder: 'tests/e2e/fixtures',
|
||||
integrationFolder: 'tests/e2e/specs',
|
||||
screenshotsFolder: 'tests/e2e/screenshots',
|
||||
videosFolder: 'tests/e2e/videos',
|
||||
supportFile: 'tests/e2e/support/index.js'
|
||||
})
|
||||
}
|
||||
return {
|
||||
...config,
|
||||
fixturesFolder: "tests/e2e/fixtures",
|
||||
integrationFolder: "tests/e2e/specs",
|
||||
screenshotsFolder: "tests/e2e/screenshots",
|
||||
videosFolder: "tests/e2e/videos",
|
||||
supportFile: "tests/e2e/support/index.js",
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
// Set the en-US language just in case
|
||||
export const onBeforeLoad = (window) => Object.defineProperty(window.navigator, 'language', { value: 'en-US' });
|
||||
export default function (window) {
|
||||
Object.defineProperty(window.navigator, "language", { value: "en-US" });
|
||||
}
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
// https://docs.cypress.io/api/introduction/api.html
|
||||
import { onBeforeLoad } from './browser-language';
|
||||
import onBeforeLoad from "./browser-language";
|
||||
|
||||
describe('Homepage', () => {
|
||||
it('Checks the footer', () => {
|
||||
cy.visit('/', { onBeforeLoad });
|
||||
cy.get('#mobilizon').find('footer').contains('The Mobilizon Contributors');
|
||||
describe("Homepage", () => {
|
||||
it("Checks the footer", () => {
|
||||
cy.visit("/", { onBeforeLoad });
|
||||
cy.get("#mobilizon").find("footer").contains("The Mobilizon Contributors");
|
||||
|
||||
cy.contains('About').should('have.attr', 'href').and('eq', 'https://joinmobilizon.org');
|
||||
cy.contains("About").should("have.attr", "href").and("eq", "https://joinmobilizon.org");
|
||||
|
||||
cy.contains('License').should('have.attr', 'href').and('eq', 'https://framagit.org/framasoft/mobilizon/blob/master/LICENSE');
|
||||
cy.contains("License")
|
||||
.should("have.attr", "href")
|
||||
.and("eq", "https://framagit.org/framasoft/mobilizon/blob/master/LICENSE");
|
||||
});
|
||||
|
||||
it('Tries to register from the hero section', () => {
|
||||
cy.visit('/', { onBeforeLoad });
|
||||
|
||||
cy.get('.hero-body').contains('Sign up').click();
|
||||
cy.url().should('include', '/register/user');
|
||||
it("Tries to register from the hero section", () => {
|
||||
cy.visit("/", { onBeforeLoad });
|
||||
|
||||
cy.get(".hero-body").contains("Sign up").click();
|
||||
cy.url().should("include", "/register/user");
|
||||
});
|
||||
it('Tries to register from the navbar', () => {
|
||||
cy.visit('/', { onBeforeLoad });
|
||||
it("Tries to register from the navbar", () => {
|
||||
cy.visit("/", { onBeforeLoad });
|
||||
|
||||
cy.get('nav.navbar').contains('Sign up').click();
|
||||
cy.url().should('include', '/register/user');
|
||||
cy.get("nav.navbar").contains("Sign up").click();
|
||||
cy.url().should("include", "/register/user");
|
||||
});
|
||||
|
||||
it('Tries to connect from the navbar', () => {
|
||||
cy.visit('/', { onBeforeLoad });
|
||||
it("Tries to connect from the navbar", () => {
|
||||
cy.visit("/", { onBeforeLoad });
|
||||
|
||||
cy.get('nav.navbar').contains('Log in').click();
|
||||
cy.url().should('include', '/login');
|
||||
cy.get("nav.navbar").contains("Log in").click();
|
||||
cy.url().should("include", "/login");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,44 +1,48 @@
|
||||
import { onBeforeLoad } from './browser-language';
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearLocalStorage();
|
||||
cy.checkoutSession();
|
||||
cy.clearLocalStorage();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cy.dropSession();
|
||||
describe("Events", () => {
|
||||
it("Shows my current events", () => {
|
||||
const EVENT = { title: "My first event" };
|
||||
|
||||
cy.loginUser();
|
||||
cy.visit("/events/me");
|
||||
cy.wait(1000);
|
||||
cy.contains(".message.is-danger", "No events found");
|
||||
cy.contains(".navbar-item", "Create").click();
|
||||
|
||||
cy.url().should("include", "create");
|
||||
cy.get(".field").first().find("input").type(EVENT.title);
|
||||
cy.get(".field").eq(1).find("input").type("my tag, holo{enter}");
|
||||
cy.get(".field").eq(2).find(".datepicker .dropdown-trigger").click();
|
||||
|
||||
cy.get(".field")
|
||||
.eq(3)
|
||||
.find(".pagination-list .control")
|
||||
.first()
|
||||
.find(".select select")
|
||||
.select("September");
|
||||
cy.get(".field")
|
||||
.eq(3)
|
||||
.find(".pagination-list .control")
|
||||
.last()
|
||||
.find(".select select")
|
||||
.select("2021");
|
||||
cy.wait(1000);
|
||||
cy.get(".field").eq(3).contains(".datepicker-cell", "15").click();
|
||||
|
||||
cy.contains(".button.is-primary", "Create my event").click();
|
||||
cy.url().should("include", "/events/");
|
||||
cy.contains(".title", EVENT.title);
|
||||
cy.contains(".column.is-3-tablet", "One person going");
|
||||
cy.get(".eventMetadataBlock").eq(1).contains("On Wednesday, September 15, 2021 from");
|
||||
cy.contains(".column.is-3-tablet", "Public event");
|
||||
|
||||
cy.contains(".navbar-item", "My events").click();
|
||||
cy.contains(".title", EVENT.title);
|
||||
cy.contains(".content.column", "Organized by I'm a test user");
|
||||
cy.contains(".title-wrapper .date-component .datetime-container .month", "Sep");
|
||||
cy.contains(".title-wrapper .date-component .datetime-container .day", "15");
|
||||
});
|
||||
});
|
||||
|
||||
describe('Events', () => {
|
||||
it('Shows my current events', () => {
|
||||
const EVENT = { title: 'My first event'};
|
||||
|
||||
cy.loginUser();
|
||||
cy.visit('/events/me', { onBeforeLoad });
|
||||
cy.contains('.message.is-danger', 'No events found');
|
||||
cy.contains('.navbar-item', 'Create').click();
|
||||
|
||||
cy.url().should('include', 'create');
|
||||
cy.get('.field').first().find('input').type(EVENT.title);
|
||||
cy.get('.field').eq(1).find('input').type('my tag, holo{enter}');
|
||||
cy.get('.field').eq(2).find('.datepicker .dropdown-trigger').click();
|
||||
|
||||
cy.get('.field').eq(3).find('.pagination-list .control').first().find('.select select').select('September');
|
||||
cy.get('.field').eq(3).find('.pagination-list .control').last().find('.select select').select('2021');
|
||||
cy.wait(1000);
|
||||
cy.get('.field').eq(3).contains('.datepicker-cell', '15').click();
|
||||
|
||||
cy.contains('.button.is-primary', 'Create my event').click();
|
||||
cy.url().should('include', '/events/');
|
||||
cy.contains('.title', EVENT.title);
|
||||
cy.contains('.title-and-informations span small', 'You\'re the only one going to this event');
|
||||
cy.contains('.date-and-privacy', 'On Wednesday, September 15, 2021 from');
|
||||
cy.contains('.visibility .tag', 'Public event');
|
||||
|
||||
cy.contains('.navbar-item', 'My events').click();
|
||||
cy.contains('.title', EVENT.title);
|
||||
cy.contains('.content.column', 'Organized by I\'m a test user');
|
||||
cy.contains('.title-wrapper .date-component .datetime-container .month', 'Sep');
|
||||
cy.contains('.title-wrapper .date-component .datetime-container .day', '15');
|
||||
});
|
||||
});
|
||||
@@ -1,84 +1,109 @@
|
||||
import { onBeforeLoad } from './browser-language';
|
||||
import onBeforeLoad from "./browser-language";
|
||||
|
||||
beforeEach(() => {
|
||||
cy.clearLocalStorage();
|
||||
});
|
||||
|
||||
describe('Login', () => {
|
||||
it('Tests that everything is present', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
describe("Login", () => {
|
||||
it("Tests that everything is present", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
|
||||
cy.get('form .field').first().contains('label', 'Email');
|
||||
cy.get('form .field').last().contains('label', 'Password');
|
||||
cy.get('form').contains('button.button', 'Login');
|
||||
cy.get('form').contains('.control a.button', 'Forgot your password ?').click();
|
||||
cy.url().should('include', '/password-reset/send');
|
||||
cy.go('back');
|
||||
cy.get("form .field").first().contains("label", "Email");
|
||||
cy.get("form .field").last().contains("label", "Password");
|
||||
cy.get("form").contains("button.button", "Login");
|
||||
cy.get("form").contains(".control a.button", "Forgot your password ?").click();
|
||||
cy.url().should("include", "/password-reset/send");
|
||||
cy.go("back");
|
||||
|
||||
cy.wait(1000);
|
||||
cy.get('form').contains('.control a.button', 'Register').click();
|
||||
cy.url().should('include', '/register/user');
|
||||
cy.get("form").contains(".control a.button", "Register").click();
|
||||
cy.url().should("include", "/register/user");
|
||||
|
||||
cy.go('back');
|
||||
cy.go("back");
|
||||
});
|
||||
|
||||
it('Tries to login with incorrect credentials', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('notanemail').should('have.value', 'notanemail');
|
||||
cy.get('input[type=password]').click();
|
||||
cy.contains('button.button.is-primary.is-large', 'Login').click();
|
||||
cy.get('form .field').first().contains('p.help.is-danger', 'Please include an \'@\' in the email address.');
|
||||
cy.get('form .field').last().contains('p.help.is-danger', 'Please fill out this field.');
|
||||
it("Tries to login with incorrect credentials", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("notanemail").should("have.value", "notanemail");
|
||||
cy.get("input[type=password]").click();
|
||||
cy.contains("button.button.is-primary.is-large", "Login").click();
|
||||
// cy.get('form .field').first().contains('p.help.is-danger', '@');
|
||||
// cy.get('form .field').last().contains('p.help.is-danger', 'Please fill out this field.');
|
||||
});
|
||||
|
||||
it('Tries to login with invalid credentials', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('test@email.com').should('have.value', 'test@email.com');
|
||||
cy.get('input[type=password]').type('badPassword').should('have.value', 'badPassword');
|
||||
cy.contains('button.button.is-primary.is-large', 'Login').click();
|
||||
it("Tries to login with invalid credentials", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("test@email.com").should("have.value", "test@email.com");
|
||||
cy.get("input[type=password]").type("badPassword").should("have.value", "badPassword");
|
||||
cy.contains("button.button.is-primary.is-large", "Login").click();
|
||||
|
||||
cy.contains('.message.is-danger', 'No user account with this email was found. Maybe you made a typo?');
|
||||
cy.contains(
|
||||
".message.is-danger",
|
||||
"No user account with this email was found. Maybe you made a typo?"
|
||||
);
|
||||
});
|
||||
|
||||
it('Tries to login with valid credentials', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('user@email.com');
|
||||
cy.get('input[type=password]').type('some password');
|
||||
cy.get('form').submit();
|
||||
cy.get('.navbar-link span.icon i').should('have.class', 'mdi-account-circle');
|
||||
cy.contains('article.message.is-info', 'Welcome back I\'m a test user');
|
||||
cy.get('.navbar-item.has-dropdown').click();
|
||||
cy.get('.navbar-item').last().contains('Log out').click();
|
||||
it("Tries to login with valid credentials", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("user@email.com");
|
||||
cy.get("input[type=password]").type("some password");
|
||||
cy.get("form").submit();
|
||||
cy.wait(1000);
|
||||
cy.get(".navbar-end .navbar-link span.icon i").should("have.class", "mdi-account-circle");
|
||||
cy.contains("article.message.is-info", "Welcome back I'm a test user");
|
||||
cy.get(".navbar-item.has-dropdown").click();
|
||||
cy.get(".navbar-item").last().contains("Log out").click();
|
||||
});
|
||||
|
||||
it('Tries to login with valid credentials but unconfirmed account', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('unconfirmed@email.com');
|
||||
cy.get('input[type=password]').type('some password');
|
||||
cy.get('form').submit();
|
||||
cy.contains('.message.is-danger', 'The user account you\'re trying to login as has not been confirmed yet. Check your email inbox and eventually your spam folder.You may also ask to resend confirmation email.');
|
||||
it("Tries to login with valid credentials but unconfirmed account", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("unconfirmed@email.com");
|
||||
cy.get("input[type=password]").type("some password");
|
||||
cy.get("form").submit();
|
||||
cy.contains(
|
||||
".message.is-danger",
|
||||
"The user account you're trying to login as has not been confirmed yet. Check your email inbox and eventually your spam folder.You may also ask to resend confirmation email."
|
||||
);
|
||||
});
|
||||
|
||||
it('Tries to login with valid credentials, confirmed account but no profile', () => {
|
||||
cy.visit('/login', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('confirmed@email.com');
|
||||
cy.get('input[type=password]').type('some password');
|
||||
cy.get('form').submit();
|
||||
it("Tries to login with valid credentials, confirmed account but no profile", () => {
|
||||
cy.visit("/login", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("confirmed@email.com");
|
||||
cy.get("input[type=password]").type("some password");
|
||||
cy.get("form").submit();
|
||||
|
||||
cy.contains('.message', 'To achieve your registration, please create a first identity profile.');
|
||||
cy.get('form .field').first().contains('label', 'Username').parent().find('input').type('test_user');
|
||||
cy.get('form .field').eq(2).contains('label', 'Displayed name').parent().find('input').type('Duplicate');
|
||||
cy.get('form .field').eq(3).contains('label', 'Description').parent().find('textarea').type('This shouln\'t work because it\' using a dupublicated username');
|
||||
cy.get('.control.has-text-centered').contains('button', 'Create my profile').click();
|
||||
cy.contains('.help.is-danger', 'Username is already taken');
|
||||
cy.contains(
|
||||
".message",
|
||||
"To achieve your registration, please create a first identity profile."
|
||||
);
|
||||
cy.get("form > .field")
|
||||
.eq(1)
|
||||
.contains("label", "Username")
|
||||
.parent()
|
||||
.find("input")
|
||||
.type("test_user");
|
||||
cy.get("form > .field")
|
||||
.first()
|
||||
.contains("label", "Display name")
|
||||
.parent()
|
||||
.find("input")
|
||||
.type("Duplicate");
|
||||
cy.get("form > .field")
|
||||
.eq(2)
|
||||
.contains("label", "Description")
|
||||
.parent()
|
||||
.find("textarea")
|
||||
.type("This shouln't work because it' using a dupublicated username");
|
||||
cy.get(".control.has-text-centered").contains("button", "Create my profile").click();
|
||||
cy.contains(".help.is-danger", "Username is already taken");
|
||||
|
||||
cy.get('form .field input').first(0).clear().type('test_user_2');
|
||||
cy.get('form .field input').eq(1).type('Not');
|
||||
cy.get('form .field textarea').clear().type('This will now work');
|
||||
cy.get('form').submit();
|
||||
cy.get("form .field input").first(0).clear().type("test_user_2");
|
||||
cy.get("form .field input").eq(1).type("Not");
|
||||
cy.get("form .field textarea").clear().type("This will now work");
|
||||
cy.get("form").submit();
|
||||
cy.wait(1000);
|
||||
|
||||
cy.get('.navbar-link span.icon i').should('have.class', 'mdi-account-circle');
|
||||
cy.contains('article.message.is-info', 'Welcome to Mobilizon, DuplicateNot!');
|
||||
cy.get(".navbar-link span.icon i").should("have.class", "mdi-account-circle");
|
||||
cy.contains("article.message.is-info", "Welcome to Mobilizon, test_user_2!");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,71 +1,80 @@
|
||||
import { onBeforeLoad } from './browser-language';
|
||||
import onBeforeLoad from "./browser-language";
|
||||
|
||||
beforeEach(() => {
|
||||
cy.checkoutSession();
|
||||
});
|
||||
describe("Registration", () => {
|
||||
it("Tests that everything is present", () => {
|
||||
cy.visit("/register/user", { onBeforeLoad });
|
||||
|
||||
afterEach(() => {
|
||||
cy.dropSession();
|
||||
});
|
||||
cy.get("form .field").first().contains("label", "Email");
|
||||
cy.get("form .field").eq(1).contains("label", "Password");
|
||||
|
||||
describe('Registration', () => {
|
||||
it('Tests that everything is present', () => {
|
||||
cy.visit('/register/user', { onBeforeLoad });
|
||||
cy.get("input[type=email]").click();
|
||||
cy.get("input[type=password]").type("short").should("have.value", "short");
|
||||
cy.get("form").contains("button.button.is-primary", "Register");
|
||||
// cy.get('form .field').first().contains('p.help.is-danger', 'Please fill out this field.');
|
||||
|
||||
cy.get('form .field').first().contains('label', 'Email');
|
||||
cy.get('form .field').eq(1).contains('label', 'Password');
|
||||
cy.get("form").contains(".control a.button", "Didn't receive the instructions ?").click();
|
||||
cy.url().should("include", "/resend-instructions");
|
||||
cy.go("back");
|
||||
|
||||
cy.get('input[type=email]').click();
|
||||
cy.get('input[type=password]').type('short').should('have.value', 'short');
|
||||
cy.get('form').contains('button.button.is-primary', 'Register');
|
||||
cy.get('form .field').first().contains('p.help.is-danger', 'Please fill out this field.');
|
||||
cy.get("form").get(".control a.button").contains("Login").click({ force: true });
|
||||
cy.url().should("include", "/login");
|
||||
|
||||
cy.get('form').contains('.control a.button', 'Didn\'t receive the instructions ?').click();
|
||||
cy.url().should('include', '/resend-instructions');
|
||||
cy.go('back');
|
||||
|
||||
cy.get('form').contains('.control a.button', 'Login').click();
|
||||
cy.url().should('include', '/login');
|
||||
|
||||
cy.go('back');
|
||||
cy.go("back");
|
||||
});
|
||||
|
||||
it('Tests that registration works', () => {
|
||||
cy.visit('/register/user', { onBeforeLoad });
|
||||
cy.get('input[type=email]').type('user2register@email.com');
|
||||
cy.get('input[type=password]').type('userPassword');
|
||||
cy.get('form').contains('button.button.is-primary', 'Register').click();
|
||||
it("Tests that registration works", () => {
|
||||
cy.visit("/register/user", { onBeforeLoad });
|
||||
cy.get("input[type=email]").type("user2register@email.com");
|
||||
cy.get("input[type=password]").type("userPassword");
|
||||
cy.get("form").contains("button.button.is-primary", "Register").click();
|
||||
|
||||
cy.url().should('include', '/register/profile');
|
||||
cy.url().should("include", "/register/profile");
|
||||
cy.wait(1000);
|
||||
cy.get('form .field').first().contains('label', 'Username').parent().find('input').type('tester');
|
||||
cy.get('form .field').eq(2).contains('label', 'Displayed name').parent().find('input').type('tester account');
|
||||
cy.get('form .field').eq(3).contains('label', 'Description').parent().find('textarea').type('This is a test account');
|
||||
cy.get('.control.has-text-centered').contains('button', 'Create my profile').click();
|
||||
cy.get("form > .field")
|
||||
.eq(1)
|
||||
.contains("label", "Username")
|
||||
.parent()
|
||||
.find("input")
|
||||
.type("tester");
|
||||
cy.get("form > .field")
|
||||
.first()
|
||||
.contains("label", "Display name")
|
||||
.parent()
|
||||
.find("input")
|
||||
.type("tester account");
|
||||
cy.get("form > .field")
|
||||
.eq(2)
|
||||
.contains("label", "Description")
|
||||
.parent()
|
||||
.find("textarea")
|
||||
.type("This is a test account");
|
||||
cy.get(".control.has-text-centered").contains("button", "Create my profile").click();
|
||||
|
||||
cy.contains('article.message.is-success', 'Your account is nearly ready, tester').contains('A validation email was sent to user2register@email.com');
|
||||
cy.contains("article.message.is-success", "Your account is nearly ready, tester").contains(
|
||||
"A validation email was sent to user2register@email.com"
|
||||
);
|
||||
|
||||
cy.visit('/sent_emails');
|
||||
cy.visit("/sent_emails");
|
||||
|
||||
cy.get('iframe')
|
||||
.first()
|
||||
.iframeLoaded()
|
||||
.its('document')
|
||||
.getInDocument('a')
|
||||
.eq(1)
|
||||
.contains('Activate my account')
|
||||
.invoke('attr', 'href')
|
||||
.then(href => {
|
||||
cy.visit(href);
|
||||
});
|
||||
cy.get("iframe")
|
||||
.first()
|
||||
.iframeLoaded()
|
||||
.its("document")
|
||||
.getInDocument("a")
|
||||
.eq(1)
|
||||
.contains("Activate my account")
|
||||
.invoke("attr", "href")
|
||||
.then((href) => {
|
||||
cy.visit(href);
|
||||
});
|
||||
|
||||
// cy.url().should('include', '/validate/');
|
||||
// cy.contains('Your account is being validated');
|
||||
cy.location().should((loc) => {
|
||||
expect(loc.pathname).to.eq('/');
|
||||
expect(loc.pathname).to.eq("/");
|
||||
});
|
||||
|
||||
cy.get('.navbar-link span.icon i').should('have.class', 'mdi-account-circle');
|
||||
cy.contains('article.message.is-info', 'Welcome to Mobilizon, tester account!');
|
||||
cy.get(".navbar-link span.icon i").should("have.class", "mdi-account-circle");
|
||||
cy.contains("article.message.is-info", "Welcome to Mobilizon, tester account!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,162 +24,131 @@
|
||||
// -- This is will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
||||
|
||||
const AUTH_ACCESS_TOKEN = 'auth-access-token';
|
||||
const AUTH_REFRESH_TOKEN = 'auth-refresh-token';
|
||||
const AUTH_USER_ID = 'auth-user-id';
|
||||
const AUTH_USER_EMAIL = 'auth-user-email';
|
||||
const AUTH_USER_ACTOR_ID = 'auth-user-actor-id';
|
||||
const AUTH_USER_ROLE = 'auth-user-role';
|
||||
const AUTH_ACCESS_TOKEN = "auth-access-token";
|
||||
const AUTH_REFRESH_TOKEN = "auth-refresh-token";
|
||||
const AUTH_USER_ID = "auth-user-id";
|
||||
const AUTH_USER_EMAIL = "auth-user-email";
|
||||
const AUTH_USER_ACTOR_ID = "auth-user-actor-id";
|
||||
const AUTH_USER_ROLE = "auth-user-role";
|
||||
|
||||
|
||||
let LOCAL_STORAGE_MEMORY = {};
|
||||
const LOCAL_STORAGE_MEMORY = {};
|
||||
|
||||
Cypress.Commands.add("saveLocalStorage", () => {
|
||||
Object.keys(localStorage).forEach(key => {
|
||||
LOCAL_STORAGE_MEMORY[key] = localStorage[key];
|
||||
});
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
LOCAL_STORAGE_MEMORY[key] = localStorage[key];
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("restoreLocalStorage", () => {
|
||||
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
|
||||
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
|
||||
});
|
||||
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
|
||||
localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]);
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("clearLocalStorage", () => {
|
||||
Object.keys(LOCAL_STORAGE_MEMORY).forEach(key => {
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => {
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("loginUser", () => {
|
||||
const loginMutation = `
|
||||
console.log("Going to login an user");
|
||||
const loginMutation = `
|
||||
mutation Login($email: String!, $password: String!) {
|
||||
login(email: $email, password: $password) {
|
||||
accessToken,
|
||||
refreshToken,
|
||||
user {
|
||||
id,
|
||||
email,
|
||||
role
|
||||
}
|
||||
},
|
||||
}`;
|
||||
login(email: $email, password: $password) {
|
||||
accessToken,
|
||||
refreshToken,
|
||||
user {
|
||||
id,
|
||||
email,
|
||||
role
|
||||
}
|
||||
},
|
||||
}`;
|
||||
|
||||
const body = JSON.stringify({
|
||||
operationName: 'Login',
|
||||
query: loginMutation,
|
||||
variables: { email: 'user@email.com', password: 'some password' }
|
||||
});
|
||||
const body = JSON.stringify({
|
||||
operationName: "Login",
|
||||
query: loginMutation,
|
||||
variables: { email: "user@email.com", password: "some password" },
|
||||
});
|
||||
|
||||
cy.request({
|
||||
url: 'http://localhost:4000/api',
|
||||
body: body,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
const obj = res.body.data.login;
|
||||
console.log(obj);
|
||||
cy.request({
|
||||
url: "http://localhost:4000/api",
|
||||
body,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then((res) => {
|
||||
console.log("Reply from server when logging-in", res);
|
||||
const obj = res.body.data.login;
|
||||
console.log("Login data: ", obj);
|
||||
|
||||
localStorage.setItem(AUTH_USER_ID, `${obj.user.id}`);
|
||||
localStorage.setItem(AUTH_USER_EMAIL, obj.user.email);
|
||||
localStorage.setItem(AUTH_USER_ROLE, obj.user.role);
|
||||
localStorage.setItem(AUTH_USER_ID, `${obj.user.id}`);
|
||||
localStorage.setItem(AUTH_USER_EMAIL, obj.user.email);
|
||||
localStorage.setItem(AUTH_USER_ROLE, obj.user.role);
|
||||
|
||||
localStorage.setItem(AUTH_USER_ACTOR_ID, `${obj.id}`);
|
||||
localStorage.setItem(AUTH_ACCESS_TOKEN, obj.accessToken);
|
||||
localStorage.setItem(AUTH_REFRESH_TOKEN, obj.refreshToken);
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('checkoutSession', async () => {
|
||||
const response = await fetch('/sandbox', {
|
||||
cache: 'no-store',
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
const sessionId = await response.text();
|
||||
return Cypress.env('sessionId', sessionId);
|
||||
localStorage.setItem(AUTH_USER_ACTOR_ID, `${obj.id}`);
|
||||
localStorage.setItem(AUTH_ACCESS_TOKEN, obj.accessToken);
|
||||
localStorage.setItem(AUTH_REFRESH_TOKEN, obj.refreshToken);
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('dropSession', () =>
|
||||
cy.waitForFetches().then(() =>
|
||||
fetch('/sandbox', {
|
||||
method: 'DELETE',
|
||||
headers: { 'x-session-id': Cypress.env('sessionId') },
|
||||
}),
|
||||
),
|
||||
);
|
||||
// const increaseFetches = () => {
|
||||
// const count = Cypress.env('fetchCount') || 0;
|
||||
// Cypress.env('fetchCount', count + 1);
|
||||
// };
|
||||
|
||||
const decreaseFetches = () => {
|
||||
const count = Cypress.env("fetchCount") || 0;
|
||||
Cypress.env("fetchCount", count - 1);
|
||||
};
|
||||
|
||||
|
||||
const increaseFetches = () => {
|
||||
const count = Cypress.env('fetchCount') || 0;
|
||||
Cypress.env('fetchCount', count + 1);
|
||||
const buildTrackableFetchWithSessionId = (fetch) => (fetchUrl, fetchOptions) => {
|
||||
const { headers } = fetchOptions;
|
||||
const modifiedHeaders = {
|
||||
"x-session-id": Cypress.env("sessionId"),
|
||||
...headers,
|
||||
};
|
||||
|
||||
const decreaseFetches = () => {
|
||||
const count = Cypress.env('fetchCount') || 0;
|
||||
Cypress.env('fetchCount', count - 1);
|
||||
};
|
||||
|
||||
const buildTrackableFetchWithSessionId = fetch => (fetchUrl, fetchOptions) => {
|
||||
const { headers } = fetchOptions;
|
||||
const modifiedHeaders = Object.assign(
|
||||
{ 'x-session-id': Cypress.env('sessionId') },
|
||||
headers,
|
||||
);
|
||||
|
||||
const modifiedOptions = Object.assign({}, fetchOptions, {
|
||||
headers: modifiedHeaders,
|
||||
});
|
||||
|
||||
return fetch(fetchUrl, modifiedOptions)
|
||||
.then(result => {
|
||||
decreaseFetches();
|
||||
return Promise.resolve(result);
|
||||
})
|
||||
.catch(result => {
|
||||
decreaseFetches();
|
||||
return Promise.reject(result);
|
||||
});
|
||||
};
|
||||
|
||||
Cypress.on('window:before:load', win => {
|
||||
cy.stub(win, 'fetch', buildTrackableFetchWithSessionId(fetch));
|
||||
});
|
||||
|
||||
Cypress.Commands.add('waitForFetches', () => {
|
||||
if (Cypress.env('fetchCount') <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cy.wait(100).then(() => cy.waitForFetches());
|
||||
});
|
||||
|
||||
Cypress.Commands.add(
|
||||
'iframeLoaded',
|
||||
{ prevSubject: 'element' },
|
||||
($iframe) => {
|
||||
const contentWindow = $iframe.prop('contentWindow')
|
||||
return new Promise(resolve => {
|
||||
if (
|
||||
contentWindow &&
|
||||
contentWindow.document.readyState === 'complete'
|
||||
) {
|
||||
resolve(contentWindow)
|
||||
} else {
|
||||
$iframe.on('load', () => {
|
||||
resolve(contentWindow)
|
||||
})
|
||||
}
|
||||
})
|
||||
const modifiedOptions = { ...fetchOptions, headers: modifiedHeaders };
|
||||
|
||||
return fetch(fetchUrl, modifiedOptions)
|
||||
.then((result) => {
|
||||
decreaseFetches();
|
||||
return Promise.resolve(result);
|
||||
})
|
||||
|
||||
Cypress.Commands.add(
|
||||
'getInDocument',
|
||||
{ prevSubject: 'document' },
|
||||
(document, selector) => Cypress.$(selector, document)
|
||||
)
|
||||
.catch((result) => {
|
||||
decreaseFetches();
|
||||
return Promise.reject(result);
|
||||
});
|
||||
};
|
||||
|
||||
Cypress.on("window:before:load", (win) => {
|
||||
cy.stub(win, "fetch", buildTrackableFetchWithSessionId(fetch));
|
||||
});
|
||||
|
||||
Cypress.Commands.add("waitForFetches", () => {
|
||||
if (Cypress.env("fetchCount") <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
cy.wait(100).then(() => cy.waitForFetches());
|
||||
});
|
||||
|
||||
Cypress.Commands.add("iframeLoaded", { prevSubject: "element" }, ($iframe) => {
|
||||
const contentWindow = $iframe.prop("contentWindow");
|
||||
return new Promise((resolve) => {
|
||||
if (contentWindow && contentWindow.document.readyState === "complete") {
|
||||
resolve(contentWindow);
|
||||
} else {
|
||||
$iframe.on("load", () => {
|
||||
resolve(contentWindow);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("getInDocument", { prevSubject: "document" }, (document, selector) =>
|
||||
Cypress.$(selector, document)
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands'
|
||||
import "./commands";
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"baseUrl": "../node_modules",
|
||||
"types": [
|
||||
"cypress"
|
||||
]
|
||||
"types": ["cypress"]
|
||||
},
|
||||
"include": [
|
||||
"**/*.*"
|
||||
]
|
||||
}
|
||||
"include": ["**/*.*"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user