Skip to content

Commit

Permalink
Added tests for Farm roles, ability to select a language, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-robots committed Aug 30, 2023
1 parent 68d6017 commit 046accc
Show file tree
Hide file tree
Showing 9 changed files with 1,407 additions and 47 deletions.
14 changes: 10 additions & 4 deletions packages/end-to-end/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const { defineConfig } = require("cypress");
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
projectId: '45vid6',
defaultCommandTimeout: 90 * 1000,
env: {
'cypress-react-selector': {
root: '#root',
},
},
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
},
});
20 changes: 20 additions & 0 deletions packages/end-to-end/cypress/e2e/specs/01-onboarding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe.only('Onboarding', () => {
let users;

beforeEach(() => {
// Load the users fixture before the tests
cy.fixture('e2e-test-users.json').then((loadedUsers) => {
users = loadedUsers;
const user = users[Cypress.env('USER')];

cy.visit('/');
cy.get('[data-cy=email]').should('exist');
cy.get('[data-cy=continue]').should('exist');
cy.get('[data-cy=continue]').should('be.disabled');
cy.get('[data-cy=continueGoogle]').should('exist');
cy.loginOrCreateAccount(user.email, user.password, user.name, user.language);
});
});

it.only('01_Onboard new user if not already created', () => {});
});
138 changes: 138 additions & 0 deletions packages/end-to-end/cypress/e2e/specs/02-farm_people.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
describe.only('Farm People', () => {
let users;
let translation;
let roles;

beforeEach(() => {
// Load the users fixture before the tests
cy.fixture('e2e-test-users.json').then((loadedUsers) => {
users = loadedUsers;
const user = users[Cypress.env('USER')];

// Load the locale fixture by reusing translations file
cy.fixture('../../../webapp/public/locales/' + user.locale + '/translation.json').then(
(data) => {
// Use the loaded data
translation = data;
},
);

// Load the locale fixture by reusing translations file
cy.fixture('../../../webapp/public/locales/' + user.locale + '/role.json').then((data) => {
// Use the loaded data
roles = data;
});

cy.visit('/');
cy.get('[data-cy=email]', { timeout: 60 * 1000 }).should('exist');
cy.get('[data-cy=continue]').should('exist');
cy.get('[data-cy=continue]').should('be.disabled');
cy.get('[data-cy=continueGoogle]').should('exist');
cy.loginOrCreateAccount(user.email, user.password, user.name, user.language);
});
});

after(() => {});

it('InviteUserManager', () => {
const uniqueSeed = Date.now().toString();
const uniqueId = Cypress._.uniqueId(uniqueSeed);

cy.get('[data-cy=home-farmButton]')
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.get('[data-cy=navbar-option]')
.eq(2)
.contains(translation['MY_FARM']['PEOPLE'])
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.url().should('include', '/people');

cy.get('[data-cy=people-inviteUser]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=invite-fullName]').should('exist').type('Awesome Farm Manager');
cy.contains(translation['INVITE_USER']['CHOOSE_ROLE'])
.parent()
.find('input')
.type(roles['MANAGER'] + '{enter}');
cy.get('[data-cy=invite-email]')
.should('exist')
.type('farm_manager' + uniqueId + '@litefarm.com');
cy.get('[data-cy=invite-submit]').should('exist').and('not.be.disabled').click();
});

it('InviteInvalidEmail', () => {
cy.get('[data-cy=home-farmButton]')
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.get('[data-cy=navbar-option]')
.eq(2)
.contains(translation['MY_FARM']['PEOPLE'])
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.url().should('include', '/people');

cy.get('[data-cy=people-inviteUser]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=invite-fullName]').should('exist').type('Invalid Farm Manager');
cy.get('[data-cy=invite-email]').should('exist').type('Invalid email');
cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=error]')
.contains(translation['INVITE_USER']['INVALID_EMAIL_ERROR'])
.should('exist');
});

it('Duplicate email', () => {
const uniqueSeed = Date.now().toString();
const uniqueId = Cypress._.uniqueId(uniqueSeed);

cy.get('[data-cy=home-farmButton]')
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.get('[data-cy=navbar-option]')
.eq(2)
.contains(translation['MY_FARM']['PEOPLE'])
.should('exist')
.and('not.be.disabled')
.click({ force: true });
cy.url().should('include', '/people');

cy.get('[data-cy=people-inviteUser]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=invite-fullName]').should('exist').type('Awesome Farm Manager');
cy.contains(translation['INVITE_USER']['CHOOSE_ROLE'])
.parent()
.find('input')
.type(roles['MANAGER'] + '{enter}');
cy.get('[data-cy=invite-email]')
.should('exist')
.type('farm_manager' + uniqueId + '@litefarm.com');
cy.get('[data-cy=invite-submit]').should('exist').and('not.be.disabled').click();

// Invite the same user again
cy.get('[data-cy=people-inviteUser]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=invite-fullName]').should('exist').type('Awesome Farm Manager');
cy.contains(translation['INVITE_USER']['CHOOSE_ROLE'])
.parent()
.find('input')
.type(roles['MANAGER'] + '{enter}');
cy.get('[data-cy=invite-email]')
.should('exist')
.type('farm_manager' + uniqueId + '@litefarm.com');

cy.get('[data-cy=invite-fullName]').click();
cy.get('[data-cy=error]')
.contains(translation['INVITE_USER']['ALREADY_EXISTING_EMAIL_ERROR'])
.should('exist');
});
});
16 changes: 16 additions & 0 deletions packages/end-to-end/cypress/fixtures/e2e-test-users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "English User",
"email": "[email protected]",
"password": "Test123445566!",
"language": "English",
"locale": "en"
},
{
"name": "Spanish User",
"email": "[email protected]",
"password": "Test123445566!",
"language": "Spanish",
"locale": "es"
}
]
76 changes: 76 additions & 0 deletions packages/end-to-end/cypress/plugins/email-account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// cypress/plugins/email-account.js

const nodemailer = require('nodemailer');
const imaps = require('imap-simple');
const { simpleParser } = require('mailparser');

exports.makeEmailAccount = async () => {
const testAccount = await nodemailer.createTestAccount();
// use testAccount.user and testAccount.pass
// to log in into the email inbox
const emailConfig = {
imap: {
user: testAccount.user,
password: testAccount.pass,
host: 'imap.ethereal.email',
port: 993,
tls: true,
authTimeout: 10000,
},
};

console.log('created new email account %s', testAccount.user);
console.log('for debugging, the password is %s', testAccount.pass);

const userEmail = {
email: testAccount.user,
password: testAccount.pass,

/**
* Utility method for getting the last email
* for the Ethereal email account created above.
*/
async getLastEmail() {
// makes debugging very simple
console.log('getting the last email');
console.log(emailConfig);

try {
const connection = await imaps.connect(emailConfig);

// grab up to 50 emails from the inbox
await connection.openBox('INBOX');
const searchCriteria = ['1:50'];
const fetchOptions = {
bodies: [''],
};
const messages = await connection.search(searchCriteria, fetchOptions);
// and close the connection to avoid it hanging
connection.end();

if (!messages.length) {
console.log('cannot find any emails');
return null;
} else {
console.log('there are %d messages', messages.length);
// grab the last email
const mail = await simpleParser(messages[messages.length - 1].parts[0].body);
console.log(mail.subject);
console.log(mail.text);

// and returns the main fields
return {
subject: mail.subject,
text: mail.text,
html: mail.html,
};
}
} catch (e) {
console.error(e);
return null;
}
},
};

return userEmail;
};
Loading

0 comments on commit 046accc

Please sign in to comment.