diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/product/static/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/product/static/tests')
| -rw-r--r-- | addons/product/static/tests/product_pricelist_report_test.js | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/addons/product/static/tests/product_pricelist_report_test.js b/addons/product/static/tests/product_pricelist_report_test.js new file mode 100644 index 00000000..b9eac3cf --- /dev/null +++ b/addons/product/static/tests/product_pricelist_report_test.js @@ -0,0 +1,146 @@ +odoo.define('product.pricelist.report.tests', function (require) { +"use strict"; +const core = require('web.core'); +const GeneratePriceList = require('product.generate_pricelist').GeneratePriceList; +const NotificationService = require('web.NotificationService'); +const testUtils = require('web.test_utils'); +const createActionManager = testUtils.createActionManager; +const testUtilsMock = require('web.test_utils_mock'); + +QUnit.module('Product Pricelist', { + beforeEach: function () { + this.data = { + 'product.product': { + fields: { + id: {type: 'integer'} + }, + records: [{ + id: 42, + display_name: "Customizable Desk" + }] + }, + 'product.pricelist': { + fields: { + id: {type: 'integer'} + }, + records: [{ + id: 1, + display_name: "Public Pricelist" + }, { + id: 2, + display_name: "Test" + }] + } + }; + }, +}, function () { + QUnit.test('Pricelist Client Action', async function (assert) { + assert.expect(21); + + const self = this; + let Qty = [1, 5, 10]; // default quantities + testUtils.mock.patch(GeneratePriceList, { + _onFieldChanged: function (event) { + assert.step('field_changed'); + return this._super.apply(this, arguments); + }, + _onQtyChanged: function (event) { + assert.deepEqual(event.data.quantities, Qty.sort((a, b) => a - b), "changed quantity should be same."); + assert.step('qty_changed'); + return this._super.apply(this, arguments); + }, + }); + + const actionManager = await createActionManager({ + data: this.data, + mockRPC: function(route, args) { + if (route === '/web/dataset/call_kw/report.product.report_pricelist/get_html') { + return Promise.resolve(""); + } + return this._super(route, args); + }, + services: { + notification: NotificationService, + }, + }); + + await actionManager.doAction({ + id: 1, + name: 'Generate Pricelist', + tag: 'generate_pricelist', + type: 'ir.actions.client', + context: { + 'default_pricelist': 1, + 'active_ids': [42], + 'active_id': 42, + 'active_model': 'product.product' + } + }); + + // checking default pricelist + assert.strictEqual(actionManager.$('.o_field_many2one input').val(), "Public Pricelist", + "should have default pricelist"); + + // changing pricelist + await testUtils.fields.many2one.clickOpenDropdown("pricelist_id"); + await testUtils.fields.many2one.clickItem("pricelist_id", "Test"); + + // check wherther pricelist value has been updated or not. along with that check default quantities should be there. + assert.strictEqual(actionManager.$('.o_field_many2one input').val(), "Test", + "After pricelist change, the pricelist_id field should be updated"); + assert.strictEqual(actionManager.$('.o_badges > .badge').length, 3, + "There should be 3 default Quantities"); + + // existing quantity can not be added. + await testUtils.dom.click(actionManager.$('.o_add_qty')); + let notificationElement = document.body.querySelector('.o_notification_manager .o_notification.bg-info'); + assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent, + "Quantity already present (1).", "Existing Quantity can not be added"); + + // adding few more quantities to check. + actionManager.$('.o_product_qty').val(2); + Qty.push(2); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + actionManager.$('.o_product_qty').val(3); + Qty.push(3); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + + // should not be added more then 5 quantities. + actionManager.$('.o_product_qty').val(4); + await testUtils.dom.click(actionManager.$('.o_add_qty')); + + notificationElement = document.body.querySelector('.o_notification_manager .o_notification.bg-warning'); + assert.strictEqual(notificationElement.querySelector('.o_notification_content').textContent, + "At most 5 quantities can be displayed simultaneously. Remove a selected quantity to add others.", + "Can not add more then 5 quantities"); + + // removing all the quantities should work + Qty.pop(10); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("10") .o_remove_qty')); + Qty.pop(5); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("5") .o_remove_qty')); + Qty.pop(3); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("3") .o_remove_qty')); + Qty.pop(2); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("2") .o_remove_qty')); + Qty.pop(1); + await testUtils.dom.click(actionManager.$('.o_badges .badge:contains("1") .o_remove_qty')); + + assert.verifySteps([ + 'field_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed', + 'qty_changed' + ]); + + testUtils.mock.unpatch(GeneratePriceList); + actionManager.destroy(); + }); +} + +); +}); |
