Skip to content

Commit

Permalink
#3024: Fix tests and import Report issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Dec 28, 2020
1 parent a87dab2 commit fb53fa7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
7 changes: 6 additions & 1 deletion client/src/pages/reports/EngagementDateFormPartial.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ const EngagementDatePartialFormWithDuration = ({
disabled={isAllDay}
/>
</Col>
<Col sm={2} style={{ marginTop: "2.2em", maxWidth: "max-content" }}>
<Col
sm={2}
style={{ marginTop: "2.2em", maxWidth: "max-content" }}
id="all-day-col"
>
<Checkbox
checked={isAllDay}
label="All Day"
id="all-day"
onChange={e => {
setIsAllDay(e.target.checked)
if (e.target.checked) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { expect } from "chai"
import moment from "moment"
import Settings from "../../../platform/node/settings"
import CreateReport from "../pages/report/createReport.page"
import EditReport from "../pages/report/editReport.page"
import ShowReport from "../pages/report/showReport.page"

// NOTE: Copied Report model logic here because importing issues

function getFormattedDateInput(report) {
return report.engagementDate.format("DD-MM-YYYY HH:mm")
}

function isEngagementAllDay(report) {
return !report.duration
}

function getEngagementDateFormat() {
return Settings.engagementsIncludeTimeAndDuration
? Settings.dateFormats.forms.displayLong.withTime
: Settings.dateFormats.forms.displayLong.date
return "dddd, D MMMM YYYY @ HH:mm"
}

function getAllDayIndicator(report) {
Expand All @@ -28,10 +29,7 @@ function getFormattedEngagementDate(report) {

const start = moment(report.engagementDate)
if (isEngagementAllDay(report)) {
return Settings.engagementsIncludeTimeAndDuration
? start.format(Settings.dateFormats.forms.displayLong.date) +
getAllDayIndicator(report)
: start.format(getEngagementDateFormat())
return start.format("dddd, D MMMM YYYY") + getAllDayIndicator(report)
}

const end = moment(report.engagementDate).add(report.duration, "minutes")
Expand All @@ -52,7 +50,7 @@ describe("When creating a Report with conflicts", () => {
const report01 = {
intent: "111111111111",
engagementDate: moment()
.add(1, "day")
.add(2, "day")
.hours(1)
.minutes(0)
.seconds(0)
Expand All @@ -64,7 +62,7 @@ describe("When creating a Report with conflicts", () => {
const report02 = {
intent: "2222222222",
engagementDate: moment()
.add(1, "day")
.add(2, "day")
.hours(1)
.minutes(10)
.seconds(0)
Expand All @@ -80,7 +78,7 @@ describe("When creating a Report with conflicts", () => {

expect(CreateReport.intent.getValue()).to.equal(report01.intent)
expect(CreateReport.engagementDate.getValue()).to.equal(
getFormattedEngagementDate(report01.engagementDate)
getFormattedDateInput(report01)
)
expect(CreateReport.duration.getValue()).to.equal(report01.duration)
const advisor01 = CreateReport.getPersonByName("CIV ERINSON, Erin")
Expand Down Expand Up @@ -112,7 +110,7 @@ describe("When creating a Report with conflicts", () => {

expect(CreateReport.intent.getValue()).to.equal(report02.intent)
expect(CreateReport.engagementDate.getValue()).to.equal(
getFormattedEngagementDate(report02.engagementDate)
getFormattedDateInput(report02)
)
expect(CreateReport.duration.getValue()).to.equal(report02.duration)
const advisor01 = CreateReport.getPersonByName("CIV ERINSON, Erin")
Expand Down Expand Up @@ -158,7 +156,7 @@ describe("When creating a Report with conflicts", () => {

expect(ShowReport.intent).to.equal(report01.intent)
expect(ShowReport.engagementDate).to.equal(
getFormattedEngagementDate(report01.engagementDate)
getFormattedEngagementDate(report01)
)
expect(ShowReport.reportConflictIcon.isExisting()).to.equal(true)

Expand Down Expand Up @@ -199,7 +197,7 @@ describe("When creating a Report with conflicts", () => {

expect(ShowReport.intent).to.equal(report02.intent)
expect(ShowReport.engagementDate).to.equal(
getFormattedEngagementDate(report02.engagementDate)
getFormattedEngagementDate(report02)
)
expect(ShowReport.reportConflictIcon.isExisting()).to.equal(true)

Expand Down
12 changes: 11 additions & 1 deletion client/tests/webdriver/customFieldsSpecs/createReport.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe("Create report form page", () => {
})

it("Should be able to prevent invalid duration values", () => {
// make it not an all day first to enable duration input
CreateReport.allDayCheckbox.click()
CreateReport.duration.waitForClickable()

CreateReport.duration.setValue(INVALID_ENGAGEMENT_DURATION_1)
browser.waitUntil(
() => {
Expand All @@ -48,7 +52,13 @@ describe("Create report form page", () => {
timeoutMsg: "Large positive duration value was not sliced "
}
)
CreateReport.duration.setValue(INVALID_ENGAGEMENT_DURATION_2)

// remove first value, otherwise appends the value
CreateReport.duration.setValue(
"\uE003".repeat(VALID_ENGAGEMENT_DURATION_1) +
INVALID_ENGAGEMENT_DURATION_2
)

browser.waitUntil(
() => {
return (
Expand Down
4 changes: 4 additions & 0 deletions client/tests/webdriver/pages/createReport.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class CreateReport extends Page {
return browser.$(`div[id="fg-${id}"]`)
}

get allDayCheckbox() {
return browser.$("#all-day-col label")
}

get engagementInformationTitle() {
return browser.$('//span[text()="Engagement information"]')
}
Expand Down
19 changes: 14 additions & 5 deletions client/tests/webdriver/pages/report/createReport.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ class CreateReport extends Page {
return browser.$("#engagementDate")
}

get tomorrow() {
const tomorrow = moment().add(1, "day").format("ddd MMM DD YYYY")
return browser.$(`div[aria-label="${tomorrow}"]`)
get datePickPopover() {
// check the today button
const today = moment().format("ddd MMM DD YYYY")
return browser.$(`div[aria-label="${today}"]`)
}

get duration() {
return browser.$("#duration")
}

get allDayCheckbox() {
return browser.$("#all-day-col label")
}

get reportPeople() {
return browser.$("#reportPeople")
}
Expand Down Expand Up @@ -91,13 +96,17 @@ class CreateReport extends Page {
this.intentHelpBlock.waitForExist({ reverse: true })

if (moment.isMoment(fields.engagementDate)) {
// remove all day as it would block duration adding
if (!this.duration.isClickable()) {
this.allDayCheckbox.click()
}
this.engagementDate.waitForClickable()
this.engagementDate.click()
this.tomorrow.waitForDisplayed()
this.datePickPopover.waitForDisplayed()
browser.keys(fields.engagementDate.format("DD-MM-YYYY HH:mm"))

this.title.click()
this.tomorrow.waitForExist({ reverse: true, timeout: 3000 })
this.datePickPopover.waitForExist({ reverse: true, timeout: 3000 })
}

if (fields.duration !== undefined) {
Expand Down

0 comments on commit fb53fa7

Please sign in to comment.