Skip to content

Commit

Permalink
LF-4026 PR #2931 feedback - remove empty functions and refactor out b…
Browse files Browse the repository at this point in the history
…eforeEach setup
  • Loading branch information
kathyavini committed Jan 30, 2024
1 parent 15b6692 commit 8b6684e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 104 deletions.
42 changes: 7 additions & 35 deletions packages/end-to-end/cypress/e2e/crops.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,21 @@

import moment from 'moment';
import * as Selectors from '../support/selectorConstants.ts';
import { loadTranslationsAndConfigureUserFarm } from '../support/utilities.js';

describe('Crops', () => {
let users;
let translation;
let crops;

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;

cy.visit('/');
cy.loginOrCreateAccount(
user.email,
user.password,
user.name,
user.language,
translation['MENU']['CROPS'],
translation['MENU']['MAP'],
translation['FARM_MAP']['MAP_FILTER']['GARDEN'],
);
},
);

// Load the locale fixture by reusing translations file
cy.fixture('../../../webapp/public/locales/' + user.locale + '/crop_group.json').then(
(data) => {
// Use the loaded data
crops = data;
},
);
});
loadTranslationsAndConfigureUserFarm({ additionalTranslation: 'crop_group' }).then(
([baseTranslation, additionalTranslation]) => {
translation = baseTranslation;
crops = additionalTranslation;
},
);
});

after(() => {});

it('should successfully add a crop variety and crop plan', () => {
cy.intercept('GET', '**/maps.googleapis.com/maps/api/**').as('googleMapsApiCall');

Expand Down
40 changes: 7 additions & 33 deletions packages/end-to-end/cypress/e2e/farm_people.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,21 @@
*/

import * as Selectors from '../support/selectorConstants.ts';
import { loadTranslationsAndConfigureUserFarm } from '../support/utilities.js';

describe('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;

cy.visit('/');
cy.loginOrCreateAccount(
user.email,
user.password,
user.name,
user.language,
translation['MENU']['CROPS'],
translation['MENU']['MAP'],
translation['FARM_MAP']['MAP_FILTER']['GARDEN'],
);
},
);

// 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;
});
});
loadTranslationsAndConfigureUserFarm({ additionalTranslation: 'role' }).then(
([baseTranslation, additionalTranslation]) => {
translation = baseTranslation;
roles = additionalTranslation;
},
);
});

after(() => {});

it('should invite a manager user', () => {
const uniqueSeed = Date.now().toString();
const uniqueId = Cypress._.uniqueId(uniqueSeed);
Expand Down
46 changes: 10 additions & 36 deletions packages/end-to-end/cypress/e2e/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import moment from 'moment';
import * as Selectors from '../support/selectorConstants.ts';
import { loadTranslationsAndConfigureUserFarm } from '../support/utilities.js';

// Utility function to check Redux state with a retry mechanism
const checkReduxState = (endTime) => {
Expand All @@ -26,48 +27,21 @@ const checkReduxState = (endTime) => {
};

describe('Tasks', () => {
let users;
let translation;
let tasks;

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;

cy.visit('/');
cy.loginOrCreateAccount(
user.email,
user.password,
user.name,
user.language,
translation['MENU']['CROPS'],
translation['MENU']['MAP'],
translation['FARM_MAP']['MAP_FILTER']['GARDEN'],
);

const endTime = new Date().getTime() + 15000; // Set the end time to 15 seconds from now
checkReduxState(endTime);
},
);

// Load the locale fixture by reusing translations file
cy.fixture('../../../webapp/public/locales/' + user.locale + '/task.json').then((data) => {
// Use the loaded data
tasks = data;
});
});
loadTranslationsAndConfigureUserFarm({ additionalTranslation: 'task' }).then(
([baseTranslation, additionalTranslation]) => {
translation = baseTranslation;
tasks = additionalTranslation;

const endTime = new Date().getTime() + 15000; // Set the end time to 15 seconds from now
checkReduxState(endTime);
},
);
});

after(() => {});

it('it should successfully create a cleaning task', () => {
// Confirm that location exists
cy.contains(translation['MENU']['MAP'])
Expand Down
45 changes: 45 additions & 0 deletions packages/end-to-end/cypress/support/utilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2024 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

export const loadTranslationsAndConfigureUserFarm = ({ additionalTranslation }) => {
return cy.fixture('e2e-test-users.json').then((loadedUsers) => {
const users = loadedUsers;
const user = users[Cypress.env('USER')];

return cy
.fixture('../../../webapp/public/locales/' + user.locale + '/translation.json')
.then((translation) => {
cy.visit('/');

cy.loginOrCreateAccount(
user.email,
user.password,
user.name,
user.language,
translation['MENU']['CROPS'],
translation['MENU']['MAP'],
translation['FARM_MAP']['MAP_FILTER']['GARDEN'],
);

return cy
.fixture(
'../../../webapp/public/locales/' + user.locale + `/${additionalTranslation}.json`,
)
.then((additionalTranslationData) => {
return [translation, additionalTranslationData];
});
});
});
};

0 comments on commit 8b6684e

Please sign in to comment.