Skip to content

Commit

Permalink
#3024: Fix test failing - text formatting, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cemalettin-work committed Dec 28, 2020
1 parent 612af01 commit bf34355
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
7 changes: 1 addition & 6 deletions client/src/components/ReportTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import UltimatePaginationTopDown from "components/UltimatePaginationTopDown"
import _get from "lodash/get"
import _isEqual from "lodash/isEqual"
import { Report } from "models"
import moment from "moment"
import PropTypes from "prop-types"
import React, { useEffect, useRef, useState } from "react"
import { Table } from "react-bootstrap"
Expand Down Expand Up @@ -172,11 +171,7 @@ const ReportTable = ({
/>
</td>
{showStatus && <td>{report.state}</td>}
<td>
{moment(report.engagementDate).format(
Report.getEngagementDateFormat()
)}
</td>
<td>{Report.getFormattedEngagementDate(report)}</td>
</tr>
))}
</tbody>
Expand Down
4 changes: 1 addition & 3 deletions client/src/components/aggregations/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ export function reportsToEvents(reports) {
(r.location && r.location.name) ||
""
return {
title: `${who} @ ${where} - ${
Report.isEngagementAllDay(r) ? "(all day)" : ""
}`,
title: `${who} @ ${where} - ${Report.getAllDayIndicator(r)}`,
start: moment(r.engagementDate).format("YYYY-MM-DD HH:mm"),
end: moment(r.engagementDate)
.add(r.duration, "minutes")
Expand Down
18 changes: 9 additions & 9 deletions client/src/models/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,6 @@ export default class Report extends Model {
)
}

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

static getAllDayIndicator(report) {
return Report.isEngagementAllDay(report) ? "(all day)" : ""
}

static getEngagementDateFormat() {
return Settings.engagementsIncludeTimeAndDuration
? Settings.dateFormats.forms.displayLong.withTime
Expand Down Expand Up @@ -597,6 +589,14 @@ export default class Report extends Model {
)
}

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

static getAllDayIndicator(report) {
return Report.isEngagementAllDay(report) ? " (all day)" : ""
}

static getFormattedEngagementDate(report) {
if (!report?.engagementDate) {
return ""
Expand All @@ -606,7 +606,7 @@ export default class Report extends Model {
if (Report.isEngagementAllDay(report)) {
return Settings.engagementsIncludeTimeAndDuration
? start.format(Settings.dateFormats.forms.displayLong.date) +
" (all day)"
Report.getAllDayIndicator(report)
: start.format(Report.getEngagementDateFormat())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai"
import moment from "moment"
import Report from "../../../src/models/Report"
import CreateReport from "../pages/report/createReport.page"
import EditReport from "../pages/report/editReport.page"
import ShowReport from "../pages/report/showReport.page"
Expand Down Expand Up @@ -38,7 +39,7 @@ describe("When creating a Report with conflicts", () => {

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

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

expect(ShowReport.intent).to.equal(report01.intent)
expect(ShowReport.engagementDate).to.equal(
report01.engagementDate.format("dddd, D MMMM YYYY @ HH:mm")
Report.getFormattedEngagementDate(report01.engagementDate)
)
expect(ShowReport.reportConflictIcon.isExisting()).to.equal(true)

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

expect(ShowReport.intent).to.equal(report02.intent)
expect(ShowReport.engagementDate).to.equal(
report02.engagementDate.format("dddd, D MMMM YYYY @ HH:mm")
Report.getFormattedEngagementDate(report02.engagementDate)
)
expect(ShowReport.reportConflictIcon.isExisting()).to.equal(true)

Expand Down

0 comments on commit bf34355

Please sign in to comment.