Skip to content

Commit

Permalink
Add Field and task creation to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-robots committed Oct 5, 2023
1 parent 72dede9 commit 9957088
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
87 changes: 87 additions & 0 deletions packages/end-to-end/cypress/e2e/specs/04-tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import moment from 'moment';

describe.only('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.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,
translation['SLIDE_MENU']['CROPS'],
);
},
);

// 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;
});
});
});

after(() => {});

it('CheckTasksNavigation', () => {
// Add a crop variety
cy.get('[data-cy=navbar-hamburger]').should('exist').click();
cy.contains(translation['SLIDE_MENU']['TASKS']).should('exist').click();
cy.contains(translation['TASK']['ADD_TASK']).should('exist').and('not.be.disabled');
cy.visit('/');

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

cy.contains(translation['TASK']['ADD_TASK']).should('exist').and('not.be.disabled');
cy.visit('/');
});

it('CreateCleanTask', () => {
cy.get('[data-cy=navbar-hamburger]').should('exist').click();
cy.contains(translation['SLIDE_MENU']['TASKS']).should('exist').click();

cy.contains(translation['TASK']['ADD_TASK']).should('exist').and('not.be.disabled').click();

cy.contains(tasks['CLEANING_TASK']).should('exist').click();

//Create an unassigned cleaning task due tomorrow
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=addTask-taskDate]').should('exist').type(dueDate);

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

cy.contains('First Field').should('be.visible');
cy.get('[data-cy=map-selectLocation]').trigger('mousedown');
cy.get('[data-cy=map-selectLocation]').trigger('mouseup');
cy.get('[data-cy=map-selectLocation]').click(530, 216, {
force: false,
});

cy.get('[data-cy=addTask-locationContinue]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy=addTask-detailsContinue]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy=addTask-assignmentSave]').should('exist').and('not.be.disabled').click();
cy.waitForReact();
});
});
55 changes: 55 additions & 0 deletions packages/end-to-end/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ Cypress.Commands.add(
cy.addFarm('UBC FARM', '49.250833, -123.2410777');
cy.onboardCompleteQuestions('Manager');
cy.acceptSlideMenuSpotlights(crop_menu_name);

cy.createFirstLocation();
} else {
cy.get('[data-cy=enterPassword-password]').type(password);
cy.get('[data-cy=enterPassword-submit]').should('exist').and('be.enabled').click();

cy.get('[data-cy=chooseFarm-proceed]').should('exist').and('be.enabled').click();
}
cy.get('[data-cy=home-farmButton]').should('exist').and('not.be.disabled');
cy.visit('/');
});
},
);
Expand Down Expand Up @@ -142,6 +146,57 @@ Cypress.Commands.add('onboardCompleteQuestions', (role) => {
cy.get('[data-cy=outro-finish]').should('exist').and('not.be.disabled').click();
});

Cypress.Commands.add('createFirstLocation', () => {
cy.get('[data-cy=home-farmButton]').should('exist').and('not.be.disabled').click({ force: true });
cy.get('[data-cy=navbar-option]')
.eq(1)
.should('exist')
.and('not.be.disabled')
.click({ force: true });

//arrive at farm map page and draw a field
cy.url().should('include', '/map');
cy.get('[data-cy=spotlight-next]', { timeout: 60 * 1000 })
.should('exist')
.and('not.be.disabled')
.click();
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('[data-cy=map-addFeature]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy="map-selection"]').should('be.visible');

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

cy.get('[data-cy=map-mapContainer]', { timeout: 60 * 1000 })
.find('button', { timeout: 60 * 1000 })
.eq(2)
.should('exist')
.and('be.visible');
cy.get('[data-cy=mapTutorial-continue]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=map-mapContainer]').click(500, 300);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(300, { log: false });
cy.get('[data-cy=map-mapContainer]').click(700, 300);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(300, { log: false });
cy.get('[data-cy=map-mapContainer]').click(700, 400);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(300, { log: false });
cy.get('[data-cy=map-mapContainer]').click(500, 400);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(300, { log: false });
cy.get('[data-cy=map-mapContainer]').click(500, 300);
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(300, { log: false });
cy.get('[data-cy=mapTutorial-continue]').should('exist').and('not.be.disabled').click();
cy.get('[data-cy=map-drawCompleteContinue]').should('exist').and('not.be.disabled').click();

cy.get('[data-cy=areaDetails-name]').should('exist').type('First Field');
cy.get('[data-cy=createField-save]').should('exist').and('not.be.disabled').click();
});

Cypress.Commands.add('acceptSlideMenuSpotlights', (crop_menu_name) => {
// Check the spotlights
cy.get('[data-cy=spotlight-next]').should('exist').and('not.be.disabled').click();
Expand Down

0 comments on commit 9957088

Please sign in to comment.