Skip to content

Commit

Permalink
Issue #541 seeding input optional labor (#547)
Browse files Browse the repository at this point in the history
When labor data is optional, ensures that neither or both # of workers and hours/minutes are valid and specified.
  • Loading branch information
JingyuMarcelLee authored Jul 21, 2022
1 parent 005d04e commit b96a568
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
52 changes: 49 additions & 3 deletions farmdata2_modules/fd2_tabs/fd2_field_kit/seedingInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ <h1 style='text-align:center;'>Seeding Input Log</h1>
<legend class="panel-heading" style='background-color: #da4f3f; color: white;font-size: x-large;'>Labor</legend>
<div class="center-block" style='padding: 12px;text-align:center;font-size: medium; margin-top: 45px;'>
<label style='color: #da4f3f' v-show="configToIDMap.labor == 'Required'">*&nbsp;</label>
<regex-input data-cy='num-worker-input' :reg-exp="regPosInt" :default-val="numWorkers" set-type="number" set-min="0" :disabled="submitInProgress" @input-changed="setNewNumWorkers" @match-changed="(newBool) => updateValidMap('validNumWorkers', newBool)"></regex-input>
<regex-input data-cy='num-worker-input' :reg-exp="regNumWorker" :default-val="numWorkers" set-type="number" set-min="0" :disabled="submitInProgress" @input-changed="setNewNumWorkers" @match-changed="(newBool) => updateValidMap('validNumWorkers', newBool)"></regex-input>
<label>&nbsp; Worker(s) for </label>
<label><label style='color: #da4f3f' v-show="configToIDMap.labor == 'Required'">*</label>
<regex-input data-cy='minute-input' v-show='selectedTimeUnit == "minutes"' :reg-exp='regPosInt' :default-val="minute" set-type="number" set-min="0" :disabled="submitInProgress" @input-changed="setMinute" @match-changed="(newBool) => updateValidMap('validMinute', newBool)"></regex-input>
<regex-input data-cy='minute-input' v-show='selectedTimeUnit == "minutes"' :reg-exp='regMin' :default-val="minute" set-type="number" set-min="0" :disabled="submitInProgress" @input-changed="setMinute" @match-changed="(newBool) => updateValidMap('validMinute', newBool)"></regex-input>
<regex-input data-cy='hour-input' v-show='selectedTimeUnit == "hours"' :reg-exp='regHour' :default-val="hour" set-type="number" set-min="0" :disabled="submitInProgress" @input-changed="setHour" @match-changed="(newBool) => updateValidMap('validHour', newBool)"></regex-input>
<dropdown-with-all data-cy='time-unit' style='text-align:center;' :selected-val='selectedTimeUnit' :dropdown-list='timeUnits' @selection-changed='setNewTimeUnit' :disabled='submitInProgress'></dropdown-with-all></label>
</div>
Expand Down Expand Up @@ -130,7 +130,9 @@ <h1 style='text-align:center;'>Seeding Input Log</h1>
"validNumFeet": false,
},
regPosInt: "^[1-9]+[0-9]*$",
regMin: "^[1-9]+[0-9]*$",
regHour:"^[1-9]+[0-9]*([.][0-9]{1,2}){0,1}$|^[0]{0,1}[.][1-9][0-9]{0,1}$|^[0]{0,1}[1-9]$|^[1-9]+[0-9]*\.$",
regNumWorker: "^[1-9]+[0-9]*$",
errBanner: null,
configToIDMap: new Map(),
},
Expand Down Expand Up @@ -170,12 +172,39 @@ <h1 style='text-align:center;'>Seeding Input Log</h1>
this.numFeet = newNumFeet
},
setNewNumWorkers(newNumWorkers) {
if(this.configToIDMap.labor == "Optional") {
if (newNumWorkers == "" || newNumWorkers == null) {
this.regMin = "|^[1-9]+[0-9]*$"
this.regHour = "|^[1-9]+[0-9]*([.][0-9]{1,2}){0,1}$|^[0]{0,1}[.][1-9][0-9]{0,1}$|^[0]{0,1}[1-9]$|^[1-9]+[0-9]*\.$"
} else {
this.regMin = "^[1-9]+[0-9]*$"
this.regHour = "^[1-9]+[0-9]*([.][0-9]{1,2}){0,1}$|^[0]{0,1}[.][1-9][0-9]{0,1}$|^[0]{0,1}[1-9]$|^[1-9]+[0-9]*\.$"

}
}
this.numWorkers = newNumWorkers

},
setMinute(newMinute) {

if(this.configToIDMap.labor == "Optional") {
if (newMinute == "" || newMinute == null) {
this.regNumWorker = "|^[1-9]+[0-9]*$"
} else {
this.regNumWorker = "^[1-9]+[0-9]*$"
}

}
this.minute = newMinute
},
setHour(newHour) {
if(this.configToIDMap.labor == "Optional"){
if (newHour == "" || newHour == null) {
this.regNumWorker = "|^[1-9]+[0-9]*$"
} else {
this.regNumWorker = "^[1-9]+[0-9]*$"
}
}
this.hour = newHour
},
clearFields(){
Expand Down Expand Up @@ -306,7 +335,19 @@ <h1 style='text-align:center;'>Seeding Input Log</h1>
}
}
if(!this.validMap["validNumWorkers"]){
return true
return true
}
}
if(this.configToIDMap.labor == "Optional") {
if(this.selectedTimeUnit == 'minutes'){
if(!this.validMap['validMinute'] ^ !this.validMap['validNumWorkers']){
return true
}
}
if(this.selectedTimeUnit == 'hours'){
if(!this.validMap['validHours'] ^ !this.validMap['validNumWorkers']){
return true
}
}
}
if(this.selectedSeedingType == 'Direct Seedings'){
Expand Down Expand Up @@ -659,6 +700,11 @@ <h1 style='text-align:center;'>Seeding Input Log</h1>
getConfiguration()
.then((response) => {
this.configToIDMap = response.data
if(this.configToIDMap.labor == "Optional") {
this.regNumWorker = "|^[1-9]+[0-9]*$"
this.regMin = "|^[1-9]+[0-9]*$"
this.regHour = "|^[1-9]+[0-9]*([.][0-9]{1,2}){0,1}$|^[0]{0,1}[.][1-9][0-9]{0,1}$|^[0]{0,1}[1-9]$|^[1-9]+[0-9]*\.$"
}
})
.catch((err) => {
this.errBanner = true
Expand Down
30 changes: 21 additions & 9 deletions farmdata2_modules/fd2_tabs/fd2_field_kit/seedingInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('Test the seeding input page', () => {
it('invalid Cells/Tray input test', () => {
cy.get('[data-cy=num-cell-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('Test the seeding input page', () => {
it('invalid Tray input test', () => {
cy.get('[data-cy=num-tray-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -447,7 +447,7 @@ describe('Test the seeding input page', () => {
it('invalid Seed input test', () => {
cy.get('[data-cy=num-seed-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -491,7 +491,7 @@ describe('Test the seeding input page', () => {
it('invalid Row/Bed input test', () => {
cy.get('[data-cy=num-rowbed-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('Test the seeding input page', () => {
it('invalid Feet input test', () => {
cy.get('[data-cy=num-feet-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -568,7 +568,7 @@ describe('Test the seeding input page', () => {
it('invalid Worker input test', () => {
cy.get('[data-cy=num-worker-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -608,7 +608,7 @@ describe('Test the seeding input page', () => {
.then(() => {
cy.get('[data-cy=minute-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('1.11')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -669,7 +669,7 @@ describe('Test the seeding input page', () => {
.then(() => {
cy.get('[data-cy=hour-input] > [data-cy=text-input]')
.clear()
.type('asdf')
.type('-124.3')
.blur()
.should('have.css', 'background-color')
.and('eq', 'rgb(255, 192, 203)')
Expand Down Expand Up @@ -1721,7 +1721,7 @@ describe('Test the seeding input page', () => {
// })
})

context('Configuration tests', () => {
context.only('Configuration tests', () => {
before(() =>{
cy.login('manager1', 'farmdata2')
.then(() => {
Expand Down Expand Up @@ -1881,6 +1881,18 @@ describe('Test the seeding input page', () => {
.should('be.visible')
cy.get('[data-cy=submit-button]')
.should('not.be.disabled')

cy.get('[data-cy=num-worker-input] > [data-cy=text-input]')
.type('2')
.blur()
cy.get('[data-cy=submit-button]')
.should('be.disabled')

cy.get('[data-cy=num-worker-input] > [data-cy=text-input]')
.clear()
.blur()
cy.get('[data-cy=submit-button]')
.should('not.be.disabled')
})


Expand Down

0 comments on commit b96a568

Please sign in to comment.