Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Maisa 07 e2 e #245

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions farmdata2/farmdata2_modules/fd2_school/api1/api1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<html>
<head>
<title>Vue Data Binding Spike</title>
</head>

<body>

<div id="sample-report" v-cloak>

<h1>Harvest Report</h1>
<p>This page is a <i>mockup</i> of a simplified harvest report.</p>

<label for=”title”>Title:</label>
<input type="text" id="title" name="title" value="My Sample Harvest Report" v-model="harvestTitle">

<br>

<label for=”start”>Start:</label>
<input type="date" id="start" name="start" v-model="startDate"
min="2014-01-01" :max="endDate">

<label for=”end”>End:</label>
<input type="date" id="end" name="end" v-model="endDate"
:min="startDate" max="2022-01-01">

<br>

<label for=”crop”>Crop:</label>
<select id="crop" name="crop" v-model="selectedCrop">
<option v-for="crop in cropMaptoArray">{{ crop }}</option>
</select>

<label for=”field”>Field:</label>
<select id="field" name="field" v-model="selectedField">
<option v-for="area in areaMaptoArray">{{ area }}</option>
</select>

<br>
<button class="btn btn-primary" @click="addReport() ; addLoginData()">Generate Report</button>

<hr>

<h1>{{ harvestTitle == '' ? 'Mock Harvest Report' : harvestTitle }}</h1>

<p>Details:</p>
<ul>
<li><b>Farm</b>: {{ farm }}</li>
<li><b>User</b>: {{ user }}</li>
<li><b>Language</b>: {{ language }}</li>
<br>
<li><b>Start</b>:{{ startDate }}</li>
<li><b>End</b>:{{ endDate }}</li>
<li><b>Crop</b>:{{ selectedCrop }}</li>
</ul>

<p v-if="harvestLogs.length === 0">There are no Harvest Logs to be displayed.</p>

<table border=1>
<tr v-if="harvestLogs.length > 0">
<th>Row</th>
<th>Date</th>
<th>Area</th>
<th>Crop</th>
<th>Yield</th>
<th>Units</th>
</tr>
<tr v-for="(harvestLog,index) in harvestLogs">
<td>{{ index }}</td>
<td>{{ harvestLog.date }}</td>
<td>{{ harvestLog.area }}</td>
<td>{{ harvestLog.crop }}</td>
<td>{{ harvestLog.yield }}</td>
<td>{{ harvestLog.units }}</td>
</tr>
</table>

</div>

<script src="https://unpkg.com/vue@2"></script>
<script>
var harvestReport = new Vue({
el: '#sample-report',
data: {
harvestTitle: 'My Sample Harvest Report',
startDate: '2020-05-05',
endDate: '2020-05-15',
selectedCrop: 'Kale',
cropOptions: [ 'Broccoli', 'Kale', 'Peas' ],
selectedField: 'All',
fieldOptions: [ 'All', 'Chuau-1', 'SQ7' ],
harvestLogs: [],
farm: '',
user: '',
language: '',
idToCropMap: [],
idToAreaMap: [],
},
methods: {
addReport: function() {
this.harvestLogs.push( {date: "2018-05-02", area: "Chuau-1", crop: "Kale", yield: 10, units: "Bunches"} )
},
addLoginData: function() {
axios
.get('/farm.json')
.then((response) => {
console.log("Got Response")
console.log(response)
this.farm = response.data.name;
this.user = response.data.user.name;
this.language = response.data.languages.en.name;
})
.catch((error) => {
console.log("Error Occurred")
console.log(error)

})
}
},
computed:{
cropMaptoArray() {
return Array.from(this.idToCropMap.values())
},
areaMaptoArray() {
return Array.from(this.idToAreaMap.values())
}
},
created() {
getIDToCropMap()
.then((response) => {
this.idToCropMap = new Map(response)
})
.catch((err) => {
console.log("Error Occurred")
console.log(err)
})
getIDToAreaMap()
.then((response) => {
this.idToAreaMap = new Map(response)
})
.catch((err) => {
console.log("Error Occurred")
console.log(err)
})
},
});

Vue.config.devtools = true;

</script>

</body>
</html>
169 changes: 169 additions & 0 deletions farmdata2/farmdata2_modules/fd2_school/api2/api2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<html>
<head>
<title>Vue Data Binding Spike</title>
</head>

<body>

<div id="sample-report" v-cloak>

<h1>Harvest Report</h1>
<p>This page is a <i>mockup</i> of a simplified harvest report.</p>

<label for=”title”>Title:</label>
<input type="text" id="title" name="title" value="My Sample Harvest Report" v-model="harvestTitle">

<br>

<label for=”start”>Start:</label>
<input type="date" id="start" name="start" v-model="startDate"
min="2014-01-01" :max="endDate">

<label for=”end”>End:</label>
<input type="date" id="end" name="end" v-model="endDate"
:min="startDate" max="2022-01-01">

<br>

<label for=”crop”>Crop:</label>
<select id="crop" name="crop" v-model="selectedCrop">
<option v-for="crop in cropMaptoArray">{{ crop }}</option>
</select>

<label for=”field”>Field:</label>
<select id="field" name="field" v-model="selectedField">
<option v-for="area in areaMaptoArray">{{ area }}</option>
</select>

<br>
<button class="btn btn-primary" @click="reqDates()">Generate Report</button>

<hr>

<h1>{{ harvestTitle == '' ? 'Mock Harvest Report' : harvestTitle }}</h1>

<p>Details:</p>
<ul>
<li><b>Farm</b>: {{ farm }}</li>
<li><b>User</b>: {{ user }}</li>
<li><b>Language</b>: {{ language }}</li>
<br>
<li><b>Start</b>:{{ startDate }}</li>
<li><b>End</b>:{{ endDate }}</li>
<li><b>Crop</b>:{{ selectedCrop }}</li>
</ul>

<p v-if="harvestLogs.length === 0">There are no Harvest Logs to be displayed.</p>

<table border=1>
<tr v-if="harvestReportRows.length > 0">
<th>Row</th>
<th>Date</th>
<th>Area</th>
<th>Crop</th>
<th>Yield</th>
<th>Units</th>
</tr>
<tr v-for="(harvestLog,index) in harvestReportRows">
<td>{{ index }}</td>
<td>{{ harvestLog.date }}</td>
<td>{{ harvestLog.area }}</td>
<td>{{ harvestLog.crop }}</td>
<td>{{ harvestLog.yield }}</td>
<td>{{ harvestLog.units }}</td>
</tr>
</table>

</div>

<script src="https://unpkg.com/vue@2"></script>
<script>
var harvestReport = new Vue({
el: '#sample-report',
data: {
harvestTitle: 'My Sample Harvest Report',
startDate: '2020-05-05',
endDate: '2020-05-15',
selectedCrop: 'Kale',
cropOptions: [ 'Broccoli', 'Kale', 'Peas' ],
selectedField: 'All',
fieldOptions: [ 'All', 'Chuau-1', 'SQ7' ],
harvestLogs: [],
farm: '',
user: '',
language: '',
idToCropMap: [],
idToAreaMap: [],
},
methods: {
addLoginData: function() {
axios
.get('/farm.json')
.then((response) => {
console.log("Got Response")
console.log(response)
this.farm = response.data.name;
this.user = response.data.user.name;
this.language = response.data.languages.en.name;
})
.catch((error) => {
console.log("Error Occurred")
console.log(error)

})
},
reqDates: function() {
let link = '/log.json?type=farm_harvest&timestamp[ge]=' + dayjs(this.startDate).unix() + '&timestamp[le]=' + dayjs(this.endDate).unix()
getAllPages(link,this.harvestLogs)
}
},
computed:{
cropMaptoArray() {
return Array.from(this.idToCropMap.values())
},
areaMaptoArray() {
return Array.from(this.idToAreaMap.values())
},
harvestReportRows() {
let tableRows = []
for(let log of this.harvestLogs) {
crop = this.idToCropMap.get(log.data.crop_tid)
let tableRow = {
date: log.timestamp,
area: log.area[0].name,
crop: crop,
yield: log.quantity[0].value,
units: log.quantity[0].unit.name,

}
tableRows.push(tableRow)
}
return tableRows
}
},
created() {
getIDToCropMap()
.then((response) => {
this.idToCropMap = new Map(response)
})
.catch((err) => {
console.log("Error Occurred")
console.log(err)
})
getIDToAreaMap()
.then((response) => {
this.idToAreaMap = new Map(response)
})
.catch((err) => {
console.log("Error Occurred")
console.log(err)
})
},
});

Vue.config.devtools = true;

</script>

</body>
</html>
29 changes: 29 additions & 0 deletions farmdata2/farmdata2_modules/fd2_school/e2e/e2e.defaults.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe("Test the harvest report default values", () => {
beforeEach(() => {
cy.login("manager1", "farmdata2")
cy.visit("/farm/fd2-school/e2e")
})

it("Check the page header", () => {
cy.get("[data-cy=page-header]")
.should("have.text","Harvest Report")
})

it("Check if start and end dates are correct", () => {
cy.get("[data-cy=Start-date]")
.should("have.value", "2020-05-05")
cy.get("[data-cy=End-date]")
.should("have.value", "2020-05-15")
})

it("check if crop select is correct", () => {
cy.get("[data-cy=select-crop]").children().eq(0)
.should("have.value", "ARUGULA")
cy.get("[data-cy=select-crop]").children().eq(4)
.should("have.value", "BEAN-FAVA")
cy.get("[data-cy=select-crop]").children().eq(110)
.should("have.value", "ZUCCHINI")
cy.get("[data-cy=select-crop]").children()
.should("have.length", 111)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
describe("Test the harvest report User Inputs", () => {

beforeEach(() => {
cy.login("manager1", "farmdata2")
cy.visit("/farm/fd2-school/e2e")
})

it("Check generate button - harvest report title",()=>{
cy.get("[data-cy=report-header]")
.should("not.exist")
cy.get("[data-cy=generate-report-button]").click()
cy.get("[data-cy=report-header]")
.should("be.visible")
})

it("Check generate button - farm info",()=>{

cy.get("[data-cy=generate-report-button]").click()
cy.get("[data-cy=farm-name]")
.should("have.text"," Sample Farm")
cy.get("[data-cy=user-name]")
.should("have.text"," manager1")
cy.get("[data-cy=language]")
.should("have.text"," English")
})
})
Loading