From 289400d94492c5ff46584996584beee288cd4709 Mon Sep 17 00:00:00 2001 From: Shreya Shah Date: Wed, 16 Aug 2017 11:31:34 +0530 Subject: [PATCH] [UI Test] Buying module - Multiple tests for Purchase orders (#10414) * Extended timeout to avoid rare failures * Get purchase orders with discount on grand total * Get purchase orders with discount on individual items * Get purchase orders and calculate taxes * Added paths --- .../tests/test_purchase_order.js | 2 +- ...hase_order_with_discount_on_grand_total.js | 48 +++++++++++++++++++ ..._purchase_order_with_item_wise_discount.js | 45 +++++++++++++++++ ...t_purchase_order_with_taxes_and_charges.js | 44 +++++++++++++++++ .../tests/test_supplier_quotation.js | 2 +- erpnext/tests/ui/tests.txt | 5 +- 6 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js create mode 100644 erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js create mode 100644 erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js index 4226880159..940f36f1fd 100644 --- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -45,7 +45,7 @@ QUnit.test("test: purchase order", function(assert) { }, () => cur_frm.print_doc(), - () => frappe.timeout(1), + () => frappe.timeout(2), () => { assert.ok($('.btn-print-print').is(':visible'), "Print Format Available"); assert.ok($('div > div:nth-child(5) > div > div > table > tbody > tr > td:nth-child(4) > div').text().includes('Test Product 4'), "Print Preview Works"); diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js new file mode 100644 index 0000000000..54fa777668 --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js @@ -0,0 +1,48 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order with discount on grand total", function(assert) { + assert.expect(4); + let done = assert.async(); + + frappe.run_serially([ + () => { + return frappe.tests.make('Purchase Order', [ + {supplier: 'Test Supplier'}, + {company: 'Wind Power LLC'}, + {is_subcontracted: 'No'}, + {buying_price_list: 'Test-Buying-EUR'}, + {currency: 'EUR'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"uom": 'Unit'}, + {"rate": 500 }, + {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)}, + {"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)}, + {"warehouse": 'Stores - WP'} + ] + ]}, + {apply_discount_on: 'Grand Total'}, + {additional_discount_percentage: 10} + ]); + }, + + () => frappe.timeout(1), + + () => { + assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct"); + assert.ok(cur_frm.doc.items[0].rate == 500, "Rate correct"); + // Calculate total + assert.ok(cur_frm.doc.total == 2500, "Total correct"); + // Calculate grand total after discount + assert.ok(cur_frm.doc.grand_total == 2250, "Grand total correct"); + }, + + () => frappe.tests.click_button('Submit'), + () => frappe.tests.click_button('Yes'), + () => frappe.timeout(0.3), + + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js new file mode 100644 index 0000000000..4ea8b976fb --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js @@ -0,0 +1,45 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order with item wise discount", function(assert) { + assert.expect(4); + let done = assert.async(); + + frappe.run_serially([ + () => { + return frappe.tests.make('Purchase Order', [ + {supplier: 'Test Supplier'}, + {company: 'Wind Power LLC'}, + {is_subcontracted: 'No'}, + {buying_price_list: 'Test-Buying-EUR'}, + {currency: 'EUR'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"uom": 'Unit'}, + {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)}, + {"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)}, + {"warehouse": 'Stores - WP'}, + {"discount_percentage": 20} + ] + ]} + ]); + }, + + () => frappe.timeout(1), + + () => { + assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct"); + assert.ok(cur_frm.doc.items[0].discount_percentage == 20, "Discount correct"); + // Calculate totals after discount + assert.ok(cur_frm.doc.total == 2000, "Total correct"); + assert.ok(cur_frm.doc.grand_total == 2000, "Grand total correct"); + }, + + () => frappe.tests.click_button('Submit'), + () => frappe.tests.click_button('Yes'), + () => frappe.timeout(0.3), + + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js new file mode 100644 index 0000000000..b5f59ad339 --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js @@ -0,0 +1,44 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order with taxes and charges", function(assert) { + assert.expect(3); + let done = assert.async(); + + frappe.run_serially([ + () => { + return frappe.tests.make('Purchase Order', [ + {supplier: 'Test Supplier'}, + {company: 'Wind Power LLC'}, + {is_subcontracted: 'No'}, + {buying_price_list: 'Test-Buying-USD'}, + {currency: 'USD'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"uom": 'Unit'}, + {"rate": 500 }, + {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)}, + {"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)}, + {"warehouse": 'Stores - WP'} + ] + ]}, + + {taxes_and_charges: 'TEST In State GST'} + ]); + }, + + () => { + // Check taxes and calculate grand total + assert.ok(cur_frm.doc.taxes[1].account_head=='SGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), "Account Head abbr correct"); + assert.ok(cur_frm.doc.total_taxes_and_charges == 225, "Taxes and charges correct"); + assert.ok(cur_frm.doc.grand_total == 2725, "Grand total correct"); + }, + + () => frappe.timeout(0.3), + () => frappe.tests.click_button('Submit'), + () => frappe.tests.click_button('Yes'), + () => frappe.timeout(0.3), + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js index 81e512ba2c..8404cb5b25 100644 --- a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js @@ -46,7 +46,7 @@ QUnit.test("test: supplier quotation", function(assert) { }, () => cur_frm.print_doc(), - () => frappe.timeout(1), + () => frappe.timeout(2), () => { assert.ok($('.btn-print-print').is(':visible'), "Print Format Available"); assert.ok($("table > tbody > tr > td:nth-child(3) > div").text().includes("Test Product 4"), "Print Preview Works As Expected"); diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt index c5d450af6f..86b6a3a512 100644 --- a/erpnext/tests/ui/tests.txt +++ b/erpnext/tests/ui/tests.txt @@ -87,4 +87,7 @@ erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_item_wise_discount.js erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_multi_uom.js -erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js \ No newline at end of file +erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js +erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_discount_on_grand_total.js +erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_item_wise_discount.js +erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js \ No newline at end of file