summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js231
1 files changed, 225 insertions, 6 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js
index f05d7abf08e..1e623e54d9a 100644
--- a/addons/web/static/tests/fields/basic_fields_tests.js
+++ b/addons/web/static/tests/fields/basic_fields_tests.js
@@ -38,6 +38,8 @@ QUnit.module('basic_fields', {
selection: {string: "Selection", type: "selection", searchable:true,
selection: [['normal', 'Normal'],['blocked', 'Blocked'],['done', 'Done']]},
document: {string: "Binary", type: "binary"},
+ image_selection: {string: "Image Selection", type: "selection", searchable:true,
+ selection: [['background', 'Background'],['boxed', 'Boxed'],['clean', 'Clean'],['standard', 'Standard']]},
},
records: [{
id: 1,
@@ -353,6 +355,24 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.module('FieldBooleanToggle');
+
+ QUnit.test('use boolean toggle widget in form view', function (assert) {
+ assert.expect(2);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form><field name="bar" widget="boolean_toggle"/></form>',
+ res_id: 2,
+ });
+
+ assert.strictEqual(form.$(".o_checkbox.o_boolean_toggle").length, 1, "Boolean toggle widget applied to boolean field");
+ assert.strictEqual(form.$(".o_checkbox.o_boolean_toggle").find(".slider").length, 1, "Boolean toggle contains slider to toggle");
+ form.destroy();
+ });
+
QUnit.module('FieldToggleButton');
QUnit.test('use toggle_button in list view', function (assert) {
@@ -1020,6 +1040,24 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.test('url widget takes text from proper attribute', function (assert) {
+ assert.expect(1);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<field name="foo" widget="url" text="kebeclibre"/>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ assert.strictEqual(form.$('a[name="foo"]').text(), 'kebeclibre',
+ "url text should come from the text attribute");
+ form.destroy();
+ });
+
QUnit.test('char field in editable list view', function (assert) {
assert.expect(10);
@@ -1651,6 +1689,25 @@ QUnit.module('basic_fields', {
form.destroy();
});
+ QUnit.test('date field value should not set on first click', function (assert) {
+ assert.expect(2);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners"><field name="date"/></form>',
+ res_id: 4,
+ });
+ form.$buttons.find('.o_form_button_edit').click();
+ form.$('.o_datepicker_input').click();
+ assert.strictEqual(form.$('.o_datepicker_input').val(), '', "date field's input should be empty on first click");
+ $('.day:contains(22)').click();
+ form.$('.o_datepicker_input').click(); // Open Datepicker second time
+ assert.strictEqual($('.day.active').text(), '22', 'datepicker should be highlight with 22nd day of month');
+ form.destroy();
+ });
+
QUnit.test('date field in form view (with positive time zone offset)', function (assert) {
assert.expect(8);
@@ -2697,10 +2754,10 @@ QUnit.module('basic_fields', {
});
QUnit.test('phone field in form view on normal screens', function (assert) {
- // The behavior of this widget is completely altered by crm_voip so this
- // test is irrelevant and fails if crm_voip is installed. The enterprise
+ // The behavior of this widget is completely altered by voip so this
+ // test is irrelevant and fails if voip is installed. The enterprise
// module is responsible for testing its own behavior in its own tests.
- if ('crm.voip' in odoo.__DEBUG__.services) {
+ if ('voip.user_agent' in odoo.__DEBUG__.services) {
assert.expect(0);
return;
}
@@ -2752,10 +2809,10 @@ QUnit.module('basic_fields', {
});
QUnit.test('phone field in editable list view on normal screens', function (assert) {
- // The behavior of this widget is completely altered by crm_voip so this
- // test is irrelevant and fails if crm_voip is installed. The enterprise
+ // The behavior of this widget is completely altered by voip so this
+ // test is irrelevant and fails if voip is installed. The enterprise
// module is responsible for testing its own behavior in its own tests.
- if ('crm.voip' in odoo.__DEBUG__.services) {
+ if ('voip.user_agent' in odoo.__DEBUG__.services) {
assert.expect(0);
return;
}
@@ -3272,6 +3329,129 @@ QUnit.module('basic_fields', {
});
+ QUnit.module('FavoriteWidget');
+
+ QUnit.test('favorite widget in kanban view', function (assert) {
+ assert.expect(4);
+
+ var kanban = createView({
+ View: KanbanView,
+ model: 'partner',
+ data: this.data,
+ arch: '<kanban class="o_kanban_test">' +
+ '<templates>' +
+ '<t t-name="kanban-box">' +
+ '<div>' +
+ '<field name="bar" widget="boolean_favorite" />' +
+ '</div>' +
+ '</t>' +
+ '</templates>' +
+ '</kanban>',
+ domain: [['id', '=', 1]],
+ });
+
+ assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+ assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a').text(), ' Remove from Favorites',
+ 'the label should say "Remove from Favorites"');
+
+ // click on favorite
+ kanban.$('.o_field_widget.o_favorite').click();
+ assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a i.fa.fa-star').length, 0,
+ 'should not be favorite');
+ assert.strictEqual(kanban.$('.o_kanban_record .o_field_widget.o_favorite > a').text(), ' Add to Favorites',
+ 'the label should say "Add to Favorites"');
+
+ kanban.destroy();
+ });
+
+ QUnit.test('favorite widget in form view', function (assert) {
+ assert.expect(10);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<sheet>' +
+ '<group>' +
+ '<field name="bar" widget="boolean_favorite" />' +
+ '</group>' +
+ '</sheet>' +
+ '</form>',
+ res_id: 1,
+ });
+
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites',
+ 'the label should say "Remove from Favorites"');
+
+ // click on favorite
+ form.$('.o_field_widget.o_favorite').click();
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 0,
+ 'should not be favorite');
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Add to Favorites',
+ 'the label should say "Add to Favorites"');
+
+ // switch to edit mode
+ form.$buttons.find('.o_form_button_edit').click();
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star-o').length, 1,
+ 'should not be favorite');
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Add to Favorites',
+ 'the label should say "Add to Favorites"');
+
+ // click on favorite
+ form.$('.o_field_widget.o_favorite').click();
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites',
+ 'the label should say "Remove from Favorites"');
+
+ // save
+ form.$buttons.find('.o_form_button_save').click();
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+ assert.strictEqual(form.$('.o_field_widget.o_favorite > a').text(), ' Remove from Favorites',
+ 'the label should say "Remove from Favorites"');
+
+ form.destroy();
+ });
+
+ QUnit.test('favorite widget in editable list view without label', function (assert) {
+ assert.expect(4);
+
+ var list = createView({
+ View: ListView,
+ model: 'partner',
+ data: this.data,
+ arch: '<tree editable="bottom">' +
+ '<field name="bar" widget="boolean_favorite" nolabel="1" />' +
+ '</tree>',
+ });
+
+ assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+
+ // switch to edit mode
+ list.$('tbody td:not(.o_list_record_selector)').first().click();
+ assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 1,
+ 'should be favorite');
+
+ // click on favorite
+ list.$('.o_data_row:first .o_field_widget.o_favorite').click();
+ assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star').length, 0,
+ 'should not be favorite');
+
+ // save
+ list.$buttons.find('.o_list_button_save').click();
+ assert.strictEqual(list.$('.o_data_row:first .o_field_widget.o_favorite > a i.fa.fa-star-o').length, 1,
+ 'should not be favorite');
+
+ list.destroy();
+ });
+
+
QUnit.module('LabelSelectionWidget');
QUnit.test('label_selection widget in form view', function (assert) {
@@ -3933,6 +4113,45 @@ QUnit.module('basic_fields', {
form.destroy();
});
+
+ QUnit.module('FieldImageSelection');
+
+ QUnit.test('image selection widget in form view', function (assert) {
+ assert.expect(3);
+
+ var nodeOptions = {
+ background: {
+ image_link: '/base/static/img/preview_background.png',
+ preview_link: '/base/static/pdf/preview_background.pdf',
+ },
+ boxed: {
+ image_link: '/base/static/img/preview_boxed.png',
+ preview_link: '/base/static/pdf/preview_boxed.pdf',
+ },
+ };
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form>' +
+ '<field name="image_selection" widget="image_selection"' +
+ ' options=\'' + JSON.stringify(nodeOptions) + '\'/> '+
+ '</form>',
+ res_id: 2,
+ });
+
+ assert.strictEqual(form.$('.img.img-responsive').length, 2,
+ "Two images should be rendered");
+ assert.strictEqual(form.$('.img.btn-info').length, 0,
+ "No image should be selected");
+
+ // select first image
+ form.$(".img.img-responsive:first").click();
+ assert.ok(form.$(".img.img-responsive:first").hasClass('btn-info'),
+ "First image should be selected");
+
+ form.destroy();
+ });
});
});
});