Compare commits

...
7 Commits
4 changed files with 51 additions and 24 deletions
+5 -1
View File
@@ -20,7 +20,11 @@
"IN_A_FEW_MINUTES": "Typically replies in a few minutes", "IN_A_FEW_MINUTES": "Typically replies in a few minutes",
"IN_A_FEW_HOURS": "Typically replies in a few hours", "IN_A_FEW_HOURS": "Typically replies in a few hours",
"IN_A_DAY": "Typically replies in a day", "IN_A_DAY": "Typically replies in a day",
"BACK_IN": "We will be back online" "WILL_BE_BACK": "We will be back online {time}",
"BACK_IN": "We will be back online in {time}",
"BACK_AT": "We will be back online at {time}",
"BACK_ON": "We will be back online on {day}",
"BACK_IN_SOME_TIME": "We will be back online in some time"
}, },
"DAY_NAMES": [ "DAY_NAMES": [
"Sunday", "Sunday",
+1 -1
View File
@@ -26,7 +26,7 @@ export default {
if (workingHoursEnabled) { if (workingHoursEnabled) {
return this.isOnline return this.isOnline
? this.replyTimeStatus ? this.replyTimeStatus
: `${this.$t('REPLY_TIME.BACK_IN')} ${this.timeLeftToBackInOnline}`; : this.timeLeftToBackInOnline;
} }
return this.isOnline return this.isOnline
? this.replyTimeStatus ? this.replyTimeStatus
@@ -111,7 +111,11 @@ export default {
}, },
exactTimeInAmPm() { exactTimeInAmPm() {
return `${ return `${
this.timeSlot.day === this.currentDay ? `at ${this.timeSlot.from}` : '' this.timeSlot.day === this.currentDay
? this.$t('REPLY_TIME.BACK_AT', {
time: this.timeSlot.from,
})
: ''
}`; }`;
}, },
hoursAndMinutesLeft() { hoursAndMinutesLeft() {
@@ -121,24 +125,14 @@ export default {
if (hoursLeft > 0) { if (hoursLeft > 0) {
const roundedUpHoursLeft = minutesLeft > 0 ? hoursLeft + 1 : hoursLeft; const roundedUpHoursLeft = minutesLeft > 0 ? hoursLeft + 1 : hoursLeft;
const hourRelative = generateRelativeTime( timeLeftChars.push(`${roundedUpHoursLeft} hours`);
roundedUpHoursLeft,
'hour',
this.languageCode
);
timeLeftChars.push(`${hourRelative}`);
} }
if (minutesLeft > 0 && hoursLeft === 0) { if (minutesLeft > 0 && hoursLeft === 0) {
const roundedUpMinLeft = const roundedUpMinLeft =
Math.ceil(minutesLeft / MINUTE_ROUNDING_FACTOR) * Math.ceil(minutesLeft / MINUTE_ROUNDING_FACTOR) *
MINUTE_ROUNDING_FACTOR; MINUTE_ROUNDING_FACTOR;
const minRelative = generateRelativeTime( timeLeftChars.push(`${roundedUpMinLeft} minutes`);
roundedUpMinLeft,
'minutes',
this.languageCode
);
timeLeftChars.push(`${minRelative}`);
} }
return timeLeftChars.join(' '); return timeLeftChars.join(' ');
@@ -149,9 +143,11 @@ export default {
return this.exactTimeInAmPm; return this.exactTimeInAmPm;
} }
if (hoursLeft > 0 || minutesLeft > 0) { if (hoursLeft > 0 || minutesLeft > 0) {
return this.hoursAndMinutesLeft; return this.$t('REPLY_TIME.BACK_IN', {
time: this.hoursAndMinutesLeft,
});
} }
return 'in some time'; return this.$t('REPLY_TIME.BACK_IN_SOME_TIME');
}, },
timeLeftToBackInOnline() { timeLeftToBackInOnline() {
if ( if (
@@ -163,14 +159,19 @@ export default {
'days', 'days',
this.languageCode this.languageCode
); );
return `${hourRelative}`; return this.$t('REPLY_TIME.WILL_BE_BACK', {
time: hourRelative,
});
} }
if ( if (
this.dayDiff >= 1 && this.dayDiff >= 1 &&
this.presentHour >= this.currentDayTimings.closeHour this.presentHour >= this.currentDayTimings.closeHour
) { ) {
return `on ${this.dayNameOfNextWorkingDay}`; return this.$t('REPLY_TIME.BACK_ON', {
day: this.dayNameOfNextWorkingDay,
});
} }
return this.hoursAndMinutesToBack; return this.hoursAndMinutesToBack;
}, },
}, },
@@ -1,6 +1,13 @@
import { createWrapper } from '@vue/test-utils'; import { createWrapper } from '@vue/test-utils';
import nextAvailabilityTimeMixin from '../nextAvailabilityTime'; import nextAvailabilityTimeMixin from '../nextAvailabilityTime';
import Vue from 'vue'; import Vue from 'vue';
import i18n from 'widget/i18n';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
const i18nConfig = new VueI18n({
locale: 'en',
messages: i18n,
});
describe('nextAvailabilityTimeMixin', () => { describe('nextAvailabilityTimeMixin', () => {
const chatwootWebChannel = { const chatwootWebChannel = {
@@ -383,6 +390,7 @@ describe('nextAvailabilityTimeMixin', () => {
const Component = { const Component = {
render() {}, render() {},
mixins: [nextAvailabilityTimeMixin], mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
}; };
jest jest
.useFakeTimers('modern') .useFakeTimers('modern')
@@ -410,13 +418,16 @@ describe('nextAvailabilityTimeMixin', () => {
chatwootWebChannel.workingHours[4].open_hour = 18; chatwootWebChannel.workingHours[4].open_hour = 18;
chatwootWebChannel.workingHours[4].open_minutes = 0; chatwootWebChannel.workingHours[4].open_minutes = 0;
chatwootWebChannel.workingHours[4].close_hour = 23; chatwootWebChannel.workingHours[4].close_hour = 23;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('in 30 minutes'); expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online in 30 minutes'
);
}); });
it('should return in 3 hours', () => { it('should return in 3 hours', () => {
const Component = { const Component = {
render() {}, render() {},
mixins: [nextAvailabilityTimeMixin], mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
}; };
jest jest
.useFakeTimers('modern') .useFakeTimers('modern')
@@ -441,13 +452,16 @@ describe('nextAvailabilityTimeMixin', () => {
'Saturday', 'Saturday',
]; ];
chatwootWebChannel.workingHours[4].open_hour = 19; chatwootWebChannel.workingHours[4].open_hour = 19;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('in 2 hours'); expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online in 2 hours'
);
}); });
it('should return at 10:00 AM', () => { it('should return at 10:00 AM', () => {
const Component = { const Component = {
render() {}, render() {},
mixins: [nextAvailabilityTimeMixin], mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
}; };
jest jest
.useFakeTimers('modern') .useFakeTimers('modern')
@@ -472,13 +486,16 @@ describe('nextAvailabilityTimeMixin', () => {
'Saturday', 'Saturday',
]; ];
chatwootWebChannel.workingHours[4].open_hour = 10; chatwootWebChannel.workingHours[4].open_hour = 10;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('at 10:00 AM'); expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online at 10:00 AM'
);
}); });
it('should return tomorrow', () => { it('should return tomorrow', () => {
const Component = { const Component = {
render() {}, render() {},
mixins: [nextAvailabilityTimeMixin], mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
}; };
jest jest
.useFakeTimers('modern') .useFakeTimers('modern')
@@ -504,13 +521,16 @@ describe('nextAvailabilityTimeMixin', () => {
]; ];
chatwootWebChannel.workingHours[4].open_hour = 9; chatwootWebChannel.workingHours[4].open_hour = 9;
chatwootWebChannel.workingHours[4].close_hour = 16; chatwootWebChannel.workingHours[4].close_hour = 16;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('tomorrow'); expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online tomorrow'
);
}); });
it('should return on Saturday', () => { it('should return on Saturday', () => {
const Component = { const Component = {
render() {}, render() {},
mixins: [nextAvailabilityTimeMixin], mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
}; };
jest jest
.useFakeTimers('modern') .useFakeTimers('modern')
@@ -538,6 +558,8 @@ describe('nextAvailabilityTimeMixin', () => {
chatwootWebChannel.workingHours[4].open_hour = 9; chatwootWebChannel.workingHours[4].open_hour = 9;
chatwootWebChannel.workingHours[4].close_hour = 16; chatwootWebChannel.workingHours[4].close_hour = 16;
chatwootWebChannel.workingHours[5].closed_all_day = true; chatwootWebChannel.workingHours[5].closed_all_day = true;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('on Saturday'); expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online on Saturday'
);
}); });
}); });