Browse Source

[MIG] web_responsive test to 11.0

pull/1066/head
Minh H.G 7 years ago
committed by Jairo Llopis
parent
commit
132cf2ede5
No known key found for this signature in database GPG Key ID: 59564BF1E22F314F
  1. 364
      web_responsive/static/tests/js/web_responsive.js
  2. 1
      web_responsive/tests/__init__.py

364
web_responsive/static/tests/js/web_responsive.js

@ -1,278 +1,318 @@
/* Copyright 2016 LasLabs Inc.
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define_section('web_responsive', ['web_responsive'], function(test) {
odoo.define('web_responsive.test', function(require) {
"use strict";
// It provides a base drawer compatible interface for testing
self.initInterface = function(AppDrawer) {
var core = require('web.core');
var responsive = require('web_responsive');
var $el = $('<div class="drawer drawer--left">');
$el.append(
$('<header role="banner">')
.append(
$('<button class="drawer-toggle"><span class="drawer-hamburger-icon">')
)
.append(
$('<nav class="drawer-nav"><ul class="drawer-menu"><li class="drawer-menu-item">')
)
.append(
$('<div class="panel-title" id="appDrawerAppPanelHead">')
)
).append($('<main role="main">'));
self.$clickZone = $('<a class="oe_menu_leaf">');
self.$secondaryMenu = $('<div><div class="o_sub_menu_content">');
self.$dropdown = $('<div class="dropdown-scrollable">');
QUnit.module('web_responsive', {
beforeEach: function() {
var $el = $(
'<div class="drawer drawer--left">' +
'<header role="banner">' +
'<button class="drawer-toggle">' +
'<span class="drawer-hamburger-icon"/>' +
'</button>' +
'<nav class="drawer-nav">' +
'<ul class="drawer-menu">' +
'<li class="drawer-menu-item"/>' +
'</ul>' +
'</nav>' +
'<div class="panel-title" id="appDrawerAppPanelHead"></div>' +
'</header>' +
'<main role="main"></main>' +
'<a class="oe_menu_leaf"/>' +
'<div>' +
'<div class="o_sub_menu_content"></div>' +
'</div>' +
'<div class="dropdown-scrollable"></div>' +
'</div>'
);
$el.append(self.$clickZone)
.append(self.$secondaryMenu)
.append(self.$dropdown);
this.$clickZone = $el.find('a.oe_menu_leaf');
this.$secondaryMenu = $el.find('div.o_sub_menu_content').parent();
this.$dropdown = $el.find('div.dropdown-scrollable');
var $document = $("#qunit-fixture");
$document.append($el);
this.document = $("#qunit-fixture");
this.document.append($el);
self.drawer = new AppDrawer.AppDrawer();
this.drawer = new responsive.AppDrawer();
},
return $document;
linkGrid: function() {
for(var i = 0; i < 3; i++){
this.drawer.$el.append(
$('<div class="row">').append(
$('<a class="col-md-6" id="a_' + i + '"><span class="app-drawer-icon-app /></a>' +
'<a class="col-md-6" id="b_' + i + '"><span class="app-drawer-icon-app /></a>'
)
)
);
this.drawer.$appLinks = this.drawer.$el.find('a.col-md-6');
}
}
});
};
QUnit.test('It should set initialized after success init',
function(assert) {
assert.expect(1);
self.linkGrid = function() {
for(var i=0; i < 3; i++){
self.drawer.$el.append(
$('<div class="row">').append(
$('<a class="col-md-6" id="a_' + i + '"><span class="app-drawer-icon-app /></a>' +
'<a class="col-md-6" id="b_' + i + '"><span class="app-drawer-icon-app /></a>'
)
)
);
self.drawer.$appLinks = $('a.col-md-6');
assert.ok(this.drawer.initialized);
}
};
test('It should set initialized after success init',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
assert.ok(self.drawer.initialized);
}
);
test('It should close drawer after click on clickZone',
{asserts: 1},
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.$clickZone.click();
QUnit.test('It should close drawer after click on clickZone',
function(assert) {
assert.expect(1);
this.$clickZone.click();
var self = this;
var d = $.Deferred();
setTimeout(function() {
assert.ok(self.drawer.$el.hasClass('drawer-close'));
d.resolve();
}, 100);
return d;
}
}
);
test('It should collapse open secondary menus during handleClickZones',
{asserts: 1},
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.$clickZone.click();
QUnit.test('It should collapse open secondary menus during handleClickZones',
function(assert) {
assert.expect(1);
this.$clickZone.click();
var self = this;
var d = $.Deferred();
setTimeout(function() {
assert.equal(self.$secondaryMenu.attr('aria-expanded'), 'false');
d.resolve();
}, 100);
}, 200);
return d;
}
}
);
test('It should update max-height on scrollable dropdowns',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.drawer.handleWindowResize();
var height = $(window).height() * self.drawer.dropdownHeightFactor;
assert.equal(
self.$dropdown.css('max-height'),
height + 'px'
);
}
QUnit.test('It should update max-height on scrollable dropdowns',
function(assert) {
assert.expect(1);
this.drawer.handleWindowResize();
var height = $(window).height() * this.drawer.dropdownHeightFactor;
var actual = parseFloat(this.$dropdown.css('max-height'));
var pass = Math.abs(actual - height) < 0.001;
assert.pushResult({
result: pass,
actual: actual,
expect: height,
message: ''
});
}
);
test('It should return keybuffer + new key',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.drawer.keyBuffer = 'TES';
var res = self.drawer.handleKeyBuffer(84);
QUnit.test('It should return keybuffer + new key',
function(assert) {
assert.expect(1);
this.drawer.keyBuffer = 'TES';
var res = this.drawer.handleKeyBuffer(84);
assert.equal(res, 'TEST');
}
}
);
test('It should clear keybuffer after timeout',
{asserts: 1},
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.drawer.keyBuffer = 'TES';
self.drawer.keyBufferTime = 10;
self.drawer.handleKeyBuffer(84);
QUnit.test('It should clear keybuffer after timeout',
function(assert) {
assert.expect(1);
this.drawer.keyBuffer = 'TES';
this.drawer.keyBufferTime = 10;
this.drawer.handleKeyBuffer(84);
var self = this;
var d = $.Deferred();
setTimeout(function() {
assert.equal(self.drawer.keyBuffer, "");
d.resolve();
}, 100);
return d;
}
}
);
test('It should trigger core bus event for drawer close',
['web.core'], {asserts: 1},
function(assert, AppDrawer, core) {
self.initInterface(AppDrawer);
self.drawer.onDrawerOpen();
QUnit.test('It should trigger core bus event for drawer close',
function(assert) {
assert.expect(1);
this.drawer.onDrawerOpen();
var d = $.Deferred();
core.bus.on('drawer.closed', this, function() {
assert.ok(true);
d.resolve();
});
self.drawer.$el.trigger({type: 'drawer.closed'});
this.drawer.$el.trigger({type: 'drawer.closed'});
return d;
}
}
);
test('It should set isOpen to false when closing',
{asserts: 1},
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.drawer.onDrawerOpen();
QUnit.test('It should set isOpen to false when closing',
function(assert) {
assert.expect(1);
this.drawer.onDrawerOpen();
var self = this;
var d = $.Deferred();
setTimeout(function() {
assert.equal(self.drawer.isOpen, false);
d.resolve();
});
self.drawer.$el.trigger({type: 'drawer.closed'});
}, 100);
this.drawer.$el.trigger({type: 'drawer.closed'});
return d;
}
}
);
test('It should set isOpen to true when opening',
{asserts: 1},
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
QUnit.test('It should set isOpen to true when opening',
function(assert) {
assert.expect(1);
this.drawer.$el.trigger({type: 'drawer.opened'});
var self = this;
var d = $.Deferred();
self.drawer.$el.trigger({type: 'drawer.opened'});
setTimeout(function() {
assert.ok(self.drawer.isOpen);
d.resolve();
});
}, 100);
return d;
}
}
);
test('It should trigger core bus event for drawer open',
['web.core'], {asserts: 1},
function(assert, AppDrawer, core) {
self.initInterface(AppDrawer);
self.drawer.onDrawerOpen();
QUnit.test('It should trigger core bus event for drawer open',
function(assert) {
assert.expect(1);
this.drawer.onDrawerOpen();
var d = $.Deferred();
core.bus.on('drawer.opened', this, function() {
assert.ok(true);
d.resolve();
});
self.drawer.$el.trigger({type: 'drawer.opened'});
this.drawer.$el.trigger({type: 'drawer.opened'});
return d;
}
}
);
test('It should choose link to right',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose link to right',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_1'),
$expect = $('#a_2'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.RIGHT
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.RIGHT
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose link to left',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose link to left',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_2'),
$expect = $('#a_1'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.LEFT
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.LEFT
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose link above',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose link above',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_1'),
$expect = $('#a_0'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.UP
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.UP
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose link below',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose link below',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_1'),
$expect = $('#a_2'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.DOWN
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.DOWN
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose first link if next on last',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose first link if next on last',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#b_2'),
$expect = $('#a_0'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.RIGHT
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.RIGHT
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose bottom link if up on top',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose bottom link if up on top',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_0'),
$expect = $('#a_2'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.UP
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.UP
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
test('It should choose top link if down on bottom',
function(assert, AppDrawer) {
self.initInterface(AppDrawer);
self.linkGrid();
QUnit.test('It should choose top link if down on bottom',
function(assert) {
assert.expect(1);
this.linkGrid();
var $appLink = $('#a_2'),
$expect = $('#a_0'),
$res = self.drawer.findAdjacentAppLink(
$appLink, self.drawer.DOWN
$res = this.drawer.findAdjacentAppLink(
$appLink, this.drawer.DOWN
);
assert.equal($res[0].id, $expect[0].id);
}
}
);
});

1
web_responsive/tests/__init__.py

@ -0,0 +1 @@
from . import test_ui
Loading…
Cancel
Save