2020-04-22 13:11:48 +02:00
|
|
|
describe("Converse.js Utilities", function() {
|
2016-10-26 12:50:00 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
it("applySiteSettings: recursively applies user settings", function () {
|
|
|
|
const context = {};
|
|
|
|
const settings = {
|
|
|
|
show_toolbar: true,
|
|
|
|
chatview_avatar_width: 32,
|
|
|
|
chatview_avatar_height: 32,
|
|
|
|
auto_join_rooms: [],
|
|
|
|
visible_toolbar_buttons: {
|
|
|
|
'emojis': true,
|
|
|
|
'call': false,
|
|
|
|
'clear': true,
|
|
|
|
'toggle_occupants': true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Object.assign(context, settings);
|
2016-10-26 12:50:00 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
let user_settings = {
|
|
|
|
something_else: 'xxx',
|
|
|
|
show_toolbar: false,
|
|
|
|
chatview_avatar_width: 32,
|
|
|
|
chatview_avatar_height: 48,
|
|
|
|
auto_join_rooms: [
|
|
|
|
'anonymous@conference.nomnom.im',
|
|
|
|
],
|
|
|
|
visible_toolbar_buttons: {
|
|
|
|
'emojis': false,
|
|
|
|
'call': false,
|
|
|
|
'toggle_occupants':false,
|
|
|
|
'invalid': false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const utils = converse.env.utils;
|
|
|
|
utils.applySiteSettings(context, settings, user_settings);
|
2016-10-26 12:50:00 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(context.something_else).toBeUndefined();
|
|
|
|
expect(context.show_toolbar).toBeFalsy();
|
|
|
|
expect(context.chatview_avatar_width).toBe(32);
|
|
|
|
expect(context.chatview_avatar_height).toBe(48);
|
|
|
|
expect(Object.keys(context.visible_toolbar_buttons)).toEqual(Object.keys(settings.visible_toolbar_buttons));
|
|
|
|
expect(context.visible_toolbar_buttons.emojis).toBeFalsy();
|
|
|
|
expect(context.visible_toolbar_buttons.call).toBeFalsy();
|
|
|
|
expect(context.visible_toolbar_buttons.toggle_occupants).toBeFalsy();
|
|
|
|
expect(context.visible_toolbar_buttons.invalid).toBeFalsy();
|
|
|
|
expect(context.auto_join_rooms.length).toBe(1);
|
|
|
|
expect(context.auto_join_rooms[0]).toBe('anonymous@conference.nomnom.im');
|
2016-10-26 12:50:00 +02:00
|
|
|
|
2020-04-22 13:11:48 +02:00
|
|
|
user_settings = {
|
|
|
|
visible_toolbar_buttons: {
|
|
|
|
'toggle_occupants': true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
utils.applySiteSettings(context, settings, user_settings);
|
|
|
|
expect(Object.keys(context.visible_toolbar_buttons)).toEqual(Object.keys(settings.visible_toolbar_buttons));
|
|
|
|
expect(context.visible_toolbar_buttons.toggle_occupants).toBeTruthy();
|
2016-10-26 12:50:00 +02:00
|
|
|
});
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|