diff options
| author | Akash Bhavsar <abh@odoo.com> | 2017-06-26 17:24:01 +0530 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-08-25 15:54:56 +0200 |
| commit | b131e9b0ef458e8cc00b0a2eb6c1b4d8dfe889a0 (patch) | |
| tree | 51589b025dffc424e6e67dfac5c11a35fe88ea42 /addons/barcodes/static/tests | |
| parent | 7095c32f1cd17a86606e4137ece8baa3034fe74a (diff) | |
[FIX] barcodes: fix several issues when scanning barcodes
Since the new views, most of the barcodes feature was
broken. This commit re-enables the support of commands like
'edit', 'save', 'cancel', 'previous' and 'next'.
Also changed javascript event handler to jquery event handler to
make barcodes testable in phantomjs.
Diffstat (limited to 'addons/barcodes/static/tests')
| -rw-r--r-- | addons/barcodes/static/tests/barcode_tests.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js new file mode 100644 index 00000000000..09daebcd976 --- /dev/null +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -0,0 +1,121 @@ +odoo.define('barcodes.tests', function (require) { +"use strict"; + +var testUtils = require('web.test_utils'); +var FormView = require('web.FormView'); + +var createView = testUtils.createView; +var triggerKeypressEvent = testUtils.triggerKeypressEvent; + +QUnit.module('Barcodes', { + beforeEach: function () { + this.data = { + product: { + fields: { + name: {string : "Product name", type: "char"}, + }, + records: [ + {id: 1, name: "iPad Mini"}, + {id: 2, name: "Mouse, Optical"}, + ], + }, + }; + } +}); + +QUnit.test('Button with barcode_trigger', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form>' + + '<header>' + + '<button name="do_something" string="Validate" type="object" barcode_trigger="doit"/>' + + '</header>' + + '</form>', + res_id: 2, + intercepts: { + execute_action: function (event) { + assert.strictEqual(event.data.action_data.name, 'do_something', + "do_something method call verified"); + }, + }, + }); + + // O-BTN.doit + _.each(['O','-','B','T','N','.','d','o','i','t','Enter'], triggerKeypressEvent); + + form.destroy(); +}); + +QUnit.test('edit, save and cancel buttons', function (assert) { + assert.expect(6); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form><field name="display_name"/></form>', + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.step('save'); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + }); + + // O-CMD.EDIT + _.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_editable").length, 1, + "should have switched to 'edit' mode"); + // dummy change to check that it actually saves + form.$('.o_field_widget').val('test').trigger('input'); + // O-CMD.SAVE + _.each(["O","-","C","M","D",".","S","A","V","E","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_readonly").length, 1, + "should have switched to 'readonly' mode"); + assert.verifySteps(['save'], 'should have saved'); + + // O-CMD.EDIT + _.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent); + // dummy change to check that it correctly discards + form.$('.o_field_widget').val('test').trigger('input'); + // O-CMD.CANCEL + _.each(["O","-","C","M","D",".","C","A","N","C","E","L","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_readonly").length, 1, + "should have switched to 'readonly' mode"); + assert.verifySteps(['save'], 'should not have saved'); + + form.destroy(); +}); + +QUnit.test('pager buttons', function (assert) { + assert.expect(3); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form><field name="display_name"/></form>', + res_id: 1, + viewOptions: { + ids: [1, 2], + index: 0, + }, + }); + + assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini'); + // O-CMD.PAGER-NEXT + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","N","E","X","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'Mouse, Optical'); + // O-CMD.PAGER-PREV + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","P","R","E","V","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini'); + + form.destroy(); +}); + +}); |
