Skip to content

Commit

Permalink
Merge pull request #3100 from LiteFarmOrg/LF-4026-get-cypress-tests-p…
Browse files Browse the repository at this point in the history
…assing-on-current-state-of-integration

LF-4026 Get Cypress tests passing on current state of integration
  • Loading branch information
Duncan-Brain committed Jan 31, 2024
2 parents 9c9afc5 + 76adf26 commit 1892333
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 369 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Run cypress happy path test

on:
workflow_dispatch:
pull_request:
merge_group:
branches:
- e2e_test_mika
- integration

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions packages/end-to-end/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.nyc_output
1 change: 1 addition & 0 deletions packages/end-to-end/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = defineConfig({
'cypress-react-selector': {
root: '#root',
},
USER: 0, // for local use; in CI the CYPRESS_USER variable defined in the GitHub workflow will override this, see docs.cypress.io/guides/guides/environment-variables#Option-3-CYPRESS_
},
e2e: {
baseUrl: 'http://localhost:3000',
Expand Down
141 changes: 65 additions & 76 deletions packages/end-to-end/cypress/e2e/crops.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,70 @@
/*
* Copyright 2023, 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/>.
*/

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['SLIDE_MENU']['CROPS'],
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('AddCropVariety', () => {
it('should successfully add a crop variety and crop plan', () => {
const uniqueSeed = Date.now().toString();
const uniqueId = Cypress._.uniqueId(uniqueSeed);

// Add a crop variety
cy.get('[data-cy=navbar-hamburger]').should('exist').click();
cy.contains(translation['SLIDE_MENU']['CROPS']).should('exist').click();
cy.contains(translation['MENU']['CROPS']).should('exist').click();
cy.url().should('include', '/crop_catalogue');

cy.get('[data-cy=crop-addLink]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_ADD_LINK).should('exist').and('not.be.disabled').click();

cy.url().should('include', '/crop/new');
cy.get('[data-cy=crop-cropName]')
cy.get(Selectors.CROP_CROP_NAME)
.should('exist')
.type('New Crop' + uniqueId);
// cy.contains(translation['INVITE_USER']['CHOOSE_ROLE'])
cy.get('[data-cy="react-select')
cy.get(Selectors.REACT_SELECT)
.find('input')
.type(crops['CEREALS'] + '{enter}');

cy.get('[type="radio"]').first().check({ force: true });
cy.get(Selectors.RADIO).first().check({ force: true });

cy.get('[data-cy=crop-submit]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_SUBMIT).should('exist').and('not.be.disabled').click();
cy.url().should('include', '/crop/new/add_crop_variety');
cy.get('[data-cy=crop-variety]').should('exist').type('New Variety');
cy.get('[data-cy=crop-supplier]').should('exist').type('New Supplier');
cy.get('[data-cy=crop-annual]').should('exist').check({ force: true });
cy.get('[data-cy=variety-submit]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_VARIETY).should('exist').type('New Variety');
cy.get(Selectors.CROP_SUPPLIER).should('exist').type('New Supplier');
cy.get(Selectors.CROP_ANNUAL).should('exist').check({ force: true });
cy.get(Selectors.VARIETY_SUBMIT).should('exist').and('not.be.disabled').click();
cy.url().should('include', '/crop/new/add_crop_variety/compliance');
cy.get('[data-cy=compliance-newVarietySave]').should('exist').and('be.disabled');
cy.get('[data-cy=compliance-seed]').eq(1).should('exist').check({ force: true });
cy.get('[data-cy=compliance-seed]').eq(1).should('exist').check({ force: true });
cy.get('[data-cy=compliance-seedAvailability]').eq(1).should('exist').check({ force: true });
cy.get('[data-cy=compliance-seedEngineered]').eq(0).should('exist').check({ force: true });
cy.get('[data-cy=compliance-seedTreated]').eq(2).should('exist').check({ force: true });
cy.get('[data-cy=compliance-newVarietySave]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.COMPLIANCE_NEW_VARIETY_SAVE).should('exist').and('be.disabled');
cy.get(Selectors.COMPLIANCE_SEED).eq(1).should('exist').check({ force: true });
cy.get(Selectors.COMPLIANCE_SEED).eq(1).should('exist').check({ force: true });
cy.get(Selectors.COMPLIANCE_SEED_AVAILABILITY).eq(1).should('exist').check({ force: true });
cy.get(Selectors.COMPLIANCE_SEED_ENGINEERED).eq(0).should('exist').check({ force: true });
cy.get(Selectors.COMPLIANCE_SEED_TREATED).eq(2).should('exist').check({ force: true });
cy.get(Selectors.COMPLIANCE_NEW_VARIETY_SAVE).should('exist').and('not.be.disabled').click();

// Check if spotlight was shown
cy.window()
Expand All @@ -85,50 +74,50 @@ describe('Crops', () => {
.then((managementPlanCreation) => {
if (!managementPlanCreation) {
// Checks if the value is false
cy.get('[data-cy=spotlight-next]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy=spotlight-next]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.SPOTLIGHT_NEXT).should('exist').and('not.be.disabled').click();
cy.get(Selectors.SPOTLIGHT_NEXT).should('exist').and('not.be.disabled').click();
}
});

// Add Management Plan
cy.contains(translation['CROP_DETAIL']['ADD_PLAN']).click();
cy.get('[type="radio"]').first().check();
cy.get('[data-cy=cropPlan-submit]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy="cropPlan-transplantSubmit"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.RADIO).first().check();
cy.get(Selectors.CROP_PLAN_SUBMIT).should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_PLAN_TRANSPLANT_SUBMIT).should('exist').and('not.be.disabled').click();

const date = new Date();
date.setDate(date.getDate() + 1);
const getDateInputFormat = (date) => moment(date).format('YYYY-MM-DD');
const dueDate = getDateInputFormat(date);
cy.get('[data-cy="cropPlan-plantDate"]').should('exist').type(dueDate);
cy.get('[data-cy="cropPlan-seedGermination"]').should('exist').type('15');
cy.get('[data-cy="cropPlan-plantHarvest"]').should('exist').type('30');
cy.get('[data-cy="plantDate-submit"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_PLAN_PLANT_DATE).should('exist').type(dueDate);
cy.get(Selectors.CROP_PLAN_SEED_GERMINATION).should('exist').type('15');
cy.get(Selectors.CROP_PLAN_PLANT_HARVEST).should('exist').type('30');
cy.get(Selectors.PLANT_DATE_SUBMIT).should('exist').and('not.be.disabled').click();

// Select field
cy.contains('First Field').should('be.visible');
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(500, { log: false });
cy.get('[data-cy=map-selectLocation]').click({ force: false });
cy.get('[data-cy="cropPlan-locationSubmit"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.MAP_SELECT_LOCATION).click({ force: false });
cy.get(Selectors.CROP_PLAN_LOCATION_SUBMIT).should('exist').and('not.be.disabled').click();

// Planning Method
cy.get('[type="radio"]').first().check();
cy.get('[data-cy="plantingMethod-submit"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.RADIO).first().check();
cy.get(Selectors.PLANTING_METHOD_SUBMIT).should('exist').and('not.be.disabled').click();

// Row length
cy.get('[data-cy=rowMethod-equalLength]').first().check();
cy.get(Selectors.ROW_METHOD_EQUAL_LENGTH).first().check();

cy.get('[data-cy="rowMethod-rows"]').should('exist').type('15{enter}');
cy.get('[data-cy="rowMethod-length"]').should('exist').type('15{enter}');
cy.get('[data-cy="rowMethod-spacing"]').should('exist').type('15{enter}');
cy.get(Selectors.ROW_METHOD_ROWS).should('exist').type('15{enter}');
cy.get(Selectors.ROW_METHOD_LENGTH).should('exist').type('15{enter}');
cy.get(Selectors.ROW_METHOD_SPACING).should('exist').type('15{enter}');
cy.contains(translation['MANAGEMENT_PLAN']['PLANT_SPACING']).click({ force: true });
cy.get('[data-cy="rowMethod-yield"]').should('exist').type('15');
cy.get(Selectors.ROW_METHOD_YIELD).should('exist').type('15');
cy.contains(translation['MANAGEMENT_PLAN']['PLANT_SPACING']).click({ force: true });
cy.get('[data-cy="rowMethod-submit"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.ROW_METHOD_SUBMIT).should('exist').and('not.be.disabled').click();

cy.get('[data-cy="planGuidance-submit"]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy="cropPlan-save"]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.PLAN_GUIDANCE_SUBMIT).should('exist').and('not.be.disabled').click();
cy.get(Selectors.CROP_PLAN_SAVE).should('exist').and('not.be.disabled').click();

// Check if spotlight was shown
cy.window()
Expand All @@ -138,8 +127,8 @@ describe('Crops', () => {
.then((managementPlanCreation) => {
if (!managementPlanCreation) {
// Checks if the value is false
cy.get('[data-cy=spotlight-next]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy=spotlight-next]').should('exist').and('not.be.disabled').click();
cy.get(Selectors.SPOTLIGHT_NEXT).should('exist').and('not.be.disabled').click();
cy.get(Selectors.SPOTLIGHT_NEXT).should('exist').and('not.be.disabled').click();
}
});
});
Expand Down

0 comments on commit 1892333

Please sign in to comment.