Skip to content

Commit

Permalink
feat: 1700 parent tree calculation part 1 (#1709)
Browse files Browse the repository at this point in the history
Co-authored-by: mgaseta <105936322+mgaseta@users.noreply.github.com>
  • Loading branch information
ngunner15 and mgaseta authored Nov 19, 2024
1 parent e4ac30a commit 894450a
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontend/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export default defineConfig({
'**/a-class-seedlot-reg-form-extraction.cy.ts',
'**/a-class-seedlot-reg-form-parent-tree-part-1.cy.ts',
'**/a-class-seedlot-reg-form-parent-tree-part-2.cy.ts',
'**/a-class-seedlot-reg-form-parent-tree-part-3.cy.ts'
'**/a-class-seedlot-reg-form-parent-tree-part-3.cy.ts',
'**/create-a-class-seedlot-fdi.cy.ts',
'**/a-class-seedlot-reg-form-parent-tree-calculations-part-1.cy.ts'
],
chromeWebSecurity: false,
retries: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import prefix from '../../../src/styles/classPrefix';

describe('A Class Seedlot Registration form, Parent Tree Calculations Part 1', () => {
let seedlotNum: string;
const speciesKey = 'fdi';
let totalParentTrees: number = 0;
let totalConeCount: number = 0;
let totalPollenCount: number = 0;
let effectivePopulationSize: number = 0;
let firstConeValue: number = 0;
let firstPollenValue: number = 0;

beforeEach(() => {
// Login
cy.login();

cy.fixture('aclass-seedlot').then((fData) => {
cy.task('getData', fData[speciesKey].species).then((sNumber) => {
seedlotNum = sNumber as string;
const url = `/seedlots/a-class-registration/${seedlotNum}/?step=5`;
cy.visit(url);
cy.url().should('contains', url);
});
});
});

it('Orchard selection', () => {
// Press next button
cy.get('.seedlot-registration-button-row')
.find('button.form-action-btn')
.contains('Back')
.click();

cy.get('#primary-orchard-selection')
.siblings(`button.${prefix}--list-box__menu-icon[title="Open"]`)
.click();

// Select primary orchard
cy.get(`.${prefix}--list-box--expanded`)
.find('ul li')
.as('orchardDropdown')
.contains('324 - BAILEY - S - PRD')
.click();

// Select female gametic contribution methodology
cy.get('#orchard-female-gametic')
.siblings()
.click();

cy.get(`.${prefix}--list-box--expanded`)
.find('ul li')
.contains('F1 - Visual Estimate')
.click();

// Select male gametic contribution methodology
cy.get('#orchard-male-gametic')
.siblings()
.click();

cy.get(`.${prefix}--list-box--expanded`)
.find('ul li')
.contains('M2 - Pollen Volume Estimate by Partial Survey')
.click();

// Save changes
cy.saveSeedlotRegFormProgress();
});

it('Upload csv file', () => {
// Wait for the table to load
cy.get('#parentTreeNumber', { timeout: 10000 });

// Upload csv file
cy.get('button.upload-button')
.click({ force: true });

cy.get(`.${prefix}--modal-container[aria-label="Seedlot registration"]`)
.should('be.visible');

cy.get(`.${prefix}--file`)
.find(`input.${prefix}--file-input`)
.selectFile('cypress/fixtures/Seedlot_composition_template_FDI.csv', { force: true });

cy.get('button')
.contains('Import file and continue')
.click();

// Save changes
cy.saveSeedlotRegFormProgress();
});

it('Check Parent tree contribution summary', () => {
// Wait for the table to load
cy.get('#parentTreeNumber', { timeout: 10000 });

cy.get(`table.${prefix}--data-table > tbody`)
.find('tr')
.then((row) => {
totalParentTrees = row.length;
cy.get('#totalnumber\\ of\\ parent\\ trees')
.should('have.value', totalParentTrees);

// Get total cone counts
for (let i = 0; i < totalParentTrees; i += 1) {
cy.get('.parent-tree-step-table-container-col')
.find('table tbody tr')
.eq(i)
.find('td:nth-child(2) input')
.invoke('val')
.then(($value: any) => {
totalConeCount = totalConeCount + Number($value);

if (i === (totalParentTrees - 1)) {
// Check total cone counts
cy.get('#totalnumber\\ of\\ cone\\ count')
.should('have.value', totalConeCount);
}
});
}

// Get total pollen counts
for (let i = 0; i < totalParentTrees; i += 1) {
cy.get('.parent-tree-step-table-container-col')
.find('table tbody tr')
.eq(i)
.find('td:nth-child(3) input')
.invoke('val')
.then(($value) => {
totalPollenCount = totalPollenCount + Number($value);

if (i === (totalParentTrees - 1)) {
// Check total pollen counts
cy.get('#totalnumber\\ of\\ pollen\\ count')
.should('have.value', totalPollenCount);
}
});
}
});

// Click 'Calculate metrics' button
cy.get('.gen-worth-cal-row')
.find('button')
.contains('Calculate metrics')
.click();

cy.wait(3000);

// Store Ne value to a variable
cy.get('#effectivepopulation\\ size\\ \\(ne\\)')
.invoke('val')
.then(($input: any) => {
effectivePopulationSize = $input;
});

// Save changes
cy.saveSeedlotRegFormProgress();
});

it('Remove a single Parent tree contribution', () => {
// Wait for the table to load
cy.get('#parentTreeNumber', { timeout: 10000 });

cy.get('#8021-coneCount-value-input')
.invoke('val')
.then(($input: any) => {
// Store first cone count to a variable
firstConeValue = $input;

// Clear cone count of first row
cy.get('#8021-coneCount-value-input')
.clear()
.type('0')
.blur();

// Check new total cone count
cy.get('#totalnumber\\ of\\ cone\\ count')
.should('have.value', (totalConeCount - firstConeValue));
});

cy.get('#8021-pollenCount-value-input')
.invoke('val')
.then(($input: any) => {
// Store first pollen count to a variable
firstPollenValue = $input;

// Clear pollen count of first row
cy.get('#8021-pollenCount-value-input')
.clear()
.type('0')
.blur();

// Check new total parent trees
cy.get('#totalnumber\\ of\\ parent\\ trees')
.should('have.value', (totalParentTrees - 1));

// Check new total pollen count
cy.get('#totalnumber\\ of\\ pollen\\ count')
.should('have.value', (totalPollenCount - firstPollenValue));
});

// Click 'Calculate metrics' button again
cy.get('.gen-worth-cal-row')
.find('button')
.contains('Calculate metrics')
.click();

cy.wait(3000);

// Check Ne value after clearing first parent tree row
cy.get('#effectivepopulation\\ size\\ \\(ne\\)')
.invoke('val')
.then($value => {
expect(Number($value)).to.be.lessThan(Number(effectivePopulationSize));
});
});
});
66 changes: 66 additions & 0 deletions frontend/cypress/e2e/smoke-test/create-a-class-seedlot-fdi.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { TYPE_DELAY } from 'cypress/constants';
import prefix from '../../../src/styles/classPrefix';
import { SeedlotRegFixtureType } from '../../definitions';

describe('Create FDI Seedlot', () => {
let fixtureData: SeedlotRegFixtureType = {};
beforeEach(() => {
cy.fixture('aclass-seedlot').then((jsonData) => {
fixtureData = jsonData;
});

cy.login();
cy.visit('/seedlots/register-a-class');
});

it('Register fdi seedlot', () => {
const regData = fixtureData.fdi;
// Enter the applicant agency number
cy.get('#agency-number-input')
.clear()
.type(regData.agencyNumber, { delay: TYPE_DELAY });

// Enter the applicant email address
cy.get('#applicant-email-input')
.clear()
.type(regData.email, { delay: TYPE_DELAY });

// Enter the seedlot species, wait for species data to load
cy.get('#seedlot-species-combobox')
.click();
cy.contains(`.${prefix}--list-box__menu-item__option`, regData.species)
.scrollIntoView()
.click();

// Select the to be registered according to fixture
const regIdToClick = regData.toBeRegistered ? '#register-w-tsc-yes' : '#register-w-tsc-no';
cy.get(regIdToClick)
.siblings(`.${prefix}--radio-button__label`)
.find(`.${prefix}--radio-button__appearance`)
.click();
cy.get(regIdToClick)
.should('be.checked');

// Select the Collected within BC according to fixture
const collectedIdToClick = regData.withinBc ? '#collected-within-bc-yes' : '#collected-within-bc-no';
cy.get(collectedIdToClick)
.siblings(`.${prefix}--radio-button__label`)
.find(`.${prefix}--radio-button__appearance`)
.click();
cy.get(collectedIdToClick)
.should('be.checked');

// Click on button Create seedlot number
cy.get('.submit-button')
.click();

cy.url().should('contains', '/creation-success');

// remember seedlot number
cy.get('#created-seedlot-number').invoke('text')
.then((seedlotNumber) => {
cy.task('setData', [regData.species, seedlotNumber]);
});
cy.log('A-Class seedlot created with species', regData.species);
});
});
39 changes: 39 additions & 0 deletions frontend/cypress/fixtures/Seedlot_composition_template_FDI.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Parent Tree number,Cone count,Pollen count,SMP success,Pollen contamination
9465,45,27,,
9116,47,29,,
9524,90,49,,
9532,71,36,,
9536,80,37,,
9550,92,47,,
9551,78,44,,
9559,78,48,,
9562,78,38,,
9578,77,47,,
9583,96,56,,
9586,42,25,,
9590,15,8,,
9591,85,43,,
9592,68,34,,
9593,79,40,,
9594,57,27,,
9595,87,47,,
9598,87,53,,
9601,38,22,,
8021,37,20,,
8044,27,14,,
8168,47,168,,
8174,46,23,,
8185,17,12,,
8187,37,16,,
8206,82,44,,
8847,84,48,,
8875,44,28,,
8876,72,36,,
8946,50,28,,
8948,53,32,,
8955,88,48,,
8964,84,45,,
8965,78,42,,
8968,60,31,,
9094,51,29,,
9474,27,12,,
10 changes: 10 additions & 0 deletions frontend/cypress/fixtures/aclass-seedlot.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@
"source": "tpt",
"toBeRegistered": false,
"withinBc": false
},
"fdi": {
"agencyAcronym": "WFP",
"agencyName": "WFP - WESTERN FOREST PRODUCTS INC. - 00149081",
"agencyNumber": "22",
"email": "abc@gov.bc.ca",
"species": "FDI - Interior Douglas-fir",
"source": "tpt",
"toBeRegistered": true,
"withinBc": true
}
}

0 comments on commit 894450a

Please sign in to comment.