From df1d0d1ccc1ebc0f91c0845c3a60f965a63469ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cemalettin=20Ta=C5=9F?= Date: Tue, 13 Oct 2020 10:22:13 +0300 Subject: [PATCH] NCI-Agency/anet#3024: Fix test failing - text formatting, refactoring --- client/src/components/ReportTable.js | 7 +------ client/src/components/aggregations/utils.js | 4 +--- client/src/models/Report.js | 18 +++++++++--------- .../createReportWithPlanningConflict.spec.js | 9 +++++---- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/client/src/components/ReportTable.js b/client/src/components/ReportTable.js index 4468a8e339d..070c94ff332 100644 --- a/client/src/components/ReportTable.js +++ b/client/src/components/ReportTable.js @@ -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" @@ -170,11 +169,7 @@ const ReportTable = ({ /> {showStatus && {report.state}} - - {moment(report.engagementDate).format( - Report.getEngagementDateFormat() - )} - + {Report.getFormattedEngagementDate(report)} ))} diff --git a/client/src/components/aggregations/utils.js b/client/src/components/aggregations/utils.js index 99463f57d83..277274a9c51 100644 --- a/client/src/components/aggregations/utils.js +++ b/client/src/components/aggregations/utils.js @@ -208,9 +208,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") diff --git a/client/src/models/Report.js b/client/src/models/Report.js index 8c6aeec4b4e..817891ed8f3 100644 --- a/client/src/models/Report.js +++ b/client/src/models/Report.js @@ -423,14 +423,6 @@ export default class Report extends Model { return attendees.find(el => el.role === role && el.primary) } - 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 @@ -537,6 +529,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 "" @@ -546,7 +546,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()) } diff --git a/client/tests/webdriver/specs/createReportWithPlanningConflict.spec.js b/client/tests/webdriver/specs/createReportWithPlanningConflict.spec.js index 37d87d968af..7337ef0cf3a 100644 --- a/client/tests/webdriver/specs/createReportWithPlanningConflict.spec.js +++ b/client/tests/webdriver/specs/createReportWithPlanningConflict.spec.js @@ -1,5 +1,6 @@ import { expect } from "chai" import moment from "moment" +import { Report } from "../../../src/models" import CreateReport from "../pages/report/createReport.page" import EditReport from "../pages/report/editReport.page" import ShowReport from "../pages/report/showReport.page" @@ -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.getAdvisor(1) @@ -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.getAdvisor(1) @@ -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) @@ -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)