Skip to content

Commit

Permalink
#3024: Fix Report import by moving report logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Dec 28, 2020
1 parent bf34355 commit b0f2788
Showing 1 changed file with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
import { expect } from "chai"
import moment from "moment"
import Report from "../../../src/models/Report"
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 isEngagementAllDay(report) {
return !report.duration
}

function getEngagementDateFormat() {
return Settings.engagementsIncludeTimeAndDuration
? Settings.dateFormats.forms.displayLong.withTime
: Settings.dateFormats.forms.displayLong.date
}

function getAllDayIndicator(report) {
return isEngagementAllDay(report) ? " (all day)" : ""
}

function getFormattedEngagementDate(report) {
if (!report?.engagementDate) {
return ""
}

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

const end = moment(report.engagementDate).add(report.duration, "minutes")

return (
start.format(getEngagementDateFormat()) +
end.format(
start.isSame(end, "day")
? " - HH:mm"
: " >>> " + getEngagementDateFormat()
)
)
}

describe("When creating a Report with conflicts", () => {
let firstReportUUID
let secondReportUUID
Expand Down Expand Up @@ -39,7 +80,7 @@ describe("When creating a Report with conflicts", () => {

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

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

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

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

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

Expand Down

0 comments on commit b0f2788

Please sign in to comment.