From bd6464b2b58f5c44987a674ac6a9d0ab756edb36 Mon Sep 17 00:00:00 2001 From: Boris Rogachov Date: Mon, 1 Jul 2024 21:36:40 +0300 Subject: [PATCH] #126: Feat: Add noteable title to record --- documentation.md | 1 + spec/models/time.title.spec.js | 36 ++++++++++++++++++++++++++++++++++ src/models/time.js | 11 ++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 spec/models/time.title.spec.js diff --git a/documentation.md b/documentation.md index 41fe224..aac9616 100644 --- a/documentation.md +++ b/documentation.md @@ -558,6 +558,7 @@ mergeRequestColumns: recordColumns: - user - iid +- title - time # Add columns for each project member to issue and diff --git a/spec/models/time.title.spec.js b/spec/models/time.title.spec.js new file mode 100644 index 0000000..1e8b726 --- /dev/null +++ b/spec/models/time.title.spec.js @@ -0,0 +1,36 @@ +const moment = require('moment'); +const Config = require('../../src/include/config'); +const Time = require('./../../src/models/time'); +const issue = require('../../src/models/issue'); +const mergeRequest = require('../../src/models/mergeRequest'); +const expect = require('chai').expect; + +describe('time class', () => { + it('Returns title of parent Issue', () => { + const config = new Config(); + const parent = new issue(config, {title: "Test title"}) + const time = new Time('1h', moment(), {}, parent, config); + + expect(time.title).to.be.equal("Test title"); + }); + + it('Returns title of parent MergeRequest', () => { + const config = new Config(); + const parent = new mergeRequest(config, {title: "Test title"}) + const time = new Time('1h', moment(), {}, parent, config); + + expect(time.title).to.be.equal("Test title"); + }); + + it('Returns Null for missed title or parent', () => { + const config = new Config(); + const parent = new mergeRequest(config, {}); + let time; + time = new Time('1h', moment(), {}, parent, config); + expect(time.title).to.be.equal(null); + + time = new Time('1h', moment(), {}, null, config); + expect(time.title).to.be.equal(null); + }); +}); + diff --git a/src/models/time.js b/src/models/time.js index abb0ae2..2050f94 100755 --- a/src/models/time.js +++ b/src/models/time.js @@ -21,7 +21,7 @@ class time { * construct * @param timeString * @param note - * @param parent + * @param {hasTimes} parent * @param config */ constructor(timeString, date = null, note, parent, config) { @@ -68,6 +68,15 @@ class time { return time.toHumanReadable(this.seconds, this._hoursPerDay, this._timeFormat); } + /** + * Title of the linked Noteable object (Issue/MergeRequest) + * + * @returns {String|null} + */ + get title() { + return this.parent && this.parent.title || null; + } + get _timeFormat() { return this.config && this.config.get('timeFormat', 'records') ? this.config.get('timeFormat', 'records') : ''; }