[FIX] web: make calendar toggle full width work

toggle full width of calendar not working, this is because getItem of
localstorage service now returns parsed value, AbstractStorageService now
return JSON.parse(value)

this commit fixes that.

task-1975004

closes odoo/odoo#33570

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>


Co-authored-by: Priyanka Kaakdiya <pka@odoo.com>
This commit is contained in:
Hetal Dhanak
2019-05-24 11:19:34 +00:00
committed by Mohammed Shekha
co-authored by Priyanka Kaakdiya
parent 946641da55
commit 84130174df
2 changed files with 42 additions and 2 deletions
@@ -307,7 +307,7 @@ return AbstractModel.extend({
* Toggle the sidebar (containing the mini calendar)
*/
toggleFullWidth: function () {
var fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') !== 'true';
var fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') !== true;
this.call('local_storage', 'setItem', 'calendar_fullWidth', fullWidth);
},
/**
@@ -439,7 +439,7 @@ return AbstractModel.extend({
*/
_loadCalendar: function () {
var self = this;
this.data.fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') === 'true';
this.data.fullWidth = this.call('local_storage', 'getItem', 'calendar_fullWidth') === true;
this.data.fc_options = this._getFullCalendarOptions();
var defs = _.map(this.data.filters, this._loadFilter.bind(this));
@@ -1,11 +1,13 @@
odoo.define('web.calendar_tests', function (require) {
"use strict";
var AbstractStorageService = require('web.AbstractStorageService');
var CalendarView = require('web.CalendarView');
var CalendarRenderer = require('web.CalendarRenderer');
var Dialog = require('web.Dialog');
var fieldUtils = require('web.field_utils');
var mixins = require('web.mixins');
var RamStorage = require('web.RamStorage');
var testUtils = require('web.test_utils');
var time = require('web.time');
var session = require('web.session');
@@ -2604,6 +2606,44 @@ QUnit.module('Views', {
calendar.destroy();
});
QUnit.test('calendar sidebar toggle', function (assert) {
assert.expect(5);
var calendar = createView({
View: CalendarView,
model: 'event',
data: this.data,
arch:
'<calendar date_start="start_date">'+
'<field name="name"/>'+
'</calendar>',
services: {
local_storage: AbstractStorageService.extend({storage: new RamStorage()}),
},
});
var fullWidth = calendar.call('local_storage', 'getItem', 'calendar_fullWidth');
assert.strictEqual(fullWidth, undefined,
"calendar_fullWidth should be undefined in local storage");
assert.containsNone(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden',
"sidebar should be opened");
// click on close
testUtils.dom.click(calendar.$('.o_calendar_sidebar_toggler'));
fullWidth = calendar.call('local_storage', 'getItem', 'calendar_fullWidth');
assert.strictEqual(fullWidth, true,
"calendar_fullWidth should be true in local storage");
assert.containsOnce(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden',
"sidebar should be hidden");
// reload calendar view and check calendar view has still full width
calendar.reload();
assert.containsOnce(calendar, '.o_calendar_sidebar_container.o_sidebar_hidden',
"sidebar should be hidden");
calendar.destroy();
});
});
});