From d92a6a307869faffa1bbdf2ad44f78aa7298d341 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 11 Feb 2021 12:10:08 +0530 Subject: [PATCH] feat: Show date along with time in messages (#1748) --- .../components/widgets/conversation/Message.vue | 2 +- app/javascript/dashboard/mixins/specs/time.spec.js | 10 ++++++++++ app/javascript/dashboard/mixins/time.js | 5 ++--- jest.config.js | 1 + jest.setup.js | 3 +++ 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 app/javascript/dashboard/mixins/specs/time.spec.js create mode 100644 jest.setup.js diff --git a/app/javascript/dashboard/components/widgets/conversation/Message.vue b/app/javascript/dashboard/components/widgets/conversation/Message.vue index 50867f717..511302a2b 100644 --- a/app/javascript/dashboard/components/widgets/conversation/Message.vue +++ b/app/javascript/dashboard/components/widgets/conversation/Message.vue @@ -131,7 +131,7 @@ export default { return !this.data.message_type ? 'left' : 'right'; }, readableTime() { - return this.messageStamp(this.data.created_at); + return this.messageStamp(this.data.created_at, 'LLL d, h:mm a'); }, isBubble() { return [0, 1, 3].includes(this.data.message_type); diff --git a/app/javascript/dashboard/mixins/specs/time.spec.js b/app/javascript/dashboard/mixins/specs/time.spec.js new file mode 100644 index 000000000..c470dfe27 --- /dev/null +++ b/app/javascript/dashboard/mixins/specs/time.spec.js @@ -0,0 +1,10 @@ +import TimeMixin from '../time'; + +describe('#messageStamp', () => { + it('returns correct value', () => { + expect(TimeMixin.methods.messageStamp(1612971343)).toEqual('3:35 PM'); + expect(TimeMixin.methods.messageStamp(1612971343, 'LLL d, h:mm a')).toEqual( + 'Feb 10, 3:35 PM' + ); + }); +}); diff --git a/app/javascript/dashboard/mixins/time.js b/app/javascript/dashboard/mixins/time.js index 4516c5c67..0048d5764 100644 --- a/app/javascript/dashboard/mixins/time.js +++ b/app/javascript/dashboard/mixins/time.js @@ -1,13 +1,12 @@ -/* eslint no-console: 0 */ import fromUnixTime from 'date-fns/fromUnixTime'; import format from 'date-fns/format'; import formatDistanceToNow from 'date-fns/formatDistanceToNow'; export default { methods: { - messageStamp(time) { + messageStamp(time, dateFormat = 'h:mm a') { const unixTime = fromUnixTime(time); - return format(unixTime, 'h:mm a'); + return format(unixTime, dateFormat); }, dynamicTime(time) { const unixTime = fromUnixTime(time); diff --git a/jest.config.js b/jest.config.js index 620fcb82a..fe17abaf9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -30,4 +30,5 @@ module.exports = { '**/app/javascript/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)', ], testURL: 'http://localhost/', + globalSetup: './jest.setup.js', }; diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 000000000..6e1fbf41d --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,3 @@ +module.exports = async () => { + process.env.TZ = 'UTC'; +};