fix: Issue with closed all hours (#4521)

fixing the accidentally merged conditions for open all day and closed all day.
This commit is contained in:
Pranav Raj S
2022-04-21 14:14:56 +05:30
committed by GitHub
parent f2815a2c00
commit f769471439
2 changed files with 47 additions and 3 deletions

View File

@@ -34,10 +34,14 @@ export default {
openAllDay, openAllDay,
} = this.currentDayAvailability; } = this.currentDayAvailability;
if (openAllDay || closedAllDay) { if (openAllDay) {
return true; return true;
} }
if (closedAllDay) {
return false;
}
const { utcOffset } = this.channelConfig; const { utcOffset } = this.channelConfig;
const today = this.getDateWithOffset(utcOffset); const today = this.getDateWithOffset(utcOffset);
const currentHours = today.getHours(); const currentHours = today.getHours();

View File

@@ -28,6 +28,10 @@ global.chatwootWebChannel = {
}; };
describe('availabilityMixin', () => { describe('availabilityMixin', () => {
beforeEach(() => {
jest.useRealTimers();
});
it('returns valid isInBetweenWorkingHours if in different timezone', () => { it('returns valid isInBetweenWorkingHours if in different timezone', () => {
const Component = { const Component = {
render() {}, render() {},
@@ -40,7 +44,6 @@ describe('availabilityMixin', () => {
const vm = new Constructor().$mount(); const vm = new Constructor().$mount();
const wrapper = createWrapper(vm); const wrapper = createWrapper(vm);
expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(true); expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(true);
jest.useRealTimers();
}); });
it('returns valid isInBetweenWorkingHours if in same timezone', () => { it('returns valid isInBetweenWorkingHours if in same timezone', () => {
@@ -55,6 +58,43 @@ describe('availabilityMixin', () => {
const Constructor = Vue.extend(Component); const Constructor = Vue.extend(Component);
const wrapper = createWrapper(new Constructor().$mount()); const wrapper = createWrapper(new Constructor().$mount());
expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(true); expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(true);
jest.useRealTimers(); });
it('returns false if closed all day', () => {
const Component = {
render() {},
mixins: [availabilityMixin],
};
global.chatwootWebChannel.utcOffset = '-07:00';
global.chatwootWebChannel.workingHours = [
{ day_of_week: 3, closed_all_day: true },
];
jest
.useFakeTimers('modern')
.setSystemTime(new Date('Thu Apr 14 2022 09:01:46 GMT+0530'));
const Constructor = Vue.extend(Component);
const vm = new Constructor().$mount();
const wrapper = createWrapper(vm);
expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(false);
});
it('returns true if open all day', () => {
const Component = {
render() {},
mixins: [availabilityMixin],
};
global.chatwootWebChannel.utcOffset = '-07:00';
global.chatwootWebChannel.workingHours = [
{ day_of_week: 3, open_all_day: true },
];
jest
.useFakeTimers('modern')
.setSystemTime(new Date('Thu Apr 14 2022 09:01:46 GMT+0530'));
const Constructor = Vue.extend(Component);
const vm = new Constructor().$mount();
const wrapper = createWrapper(vm);
expect(wrapper.vm.isInBetweenTheWorkingHours).toBe(true);
}); });
}); });