diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js new file mode 100644 index 0000000000..4226880159 --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order.js @@ -0,0 +1,67 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order", function(assert) { + assert.expect(11); + 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'}, + {"schedule_date": frappe.datetime.add_days(frappe.datetime.now_date(), 1)}, + {"expected_delivery_date": frappe.datetime.add_days(frappe.datetime.now_date(), 5)}, + {"qty": 5}, + {"uom": 'Unit'}, + {"rate": 100}, + {"warehouse": 'Stores - WP'} + ] + ]}, + + {tc_name: 'Test Term 1'}, + {terms: 'This is a term.'} + ]); + }, + + () => { + // Get supplier details + assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct"); + assert.ok($('div.control-value.like-disabled-input.for-description').text().includes('Contact 3'), "Contact display correct"); + assert.ok(cur_frm.doc.contact_email == 'test@supplier.com', "Contact email correct"); + // Get item details + assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item name correct"); + assert.ok(cur_frm.doc.items[0].description == 'Test Product 4', "Description correct"); + assert.ok(cur_frm.doc.items[0].qty == 5, "Quantity correct"); + // Calculate total + assert.ok(cur_frm.doc.total == 500, "Total correct"); + // Get terms + assert.ok(cur_frm.doc.terms == 'This is a term.', "Terms correct"); + }, + + () => cur_frm.print_doc(), + () => frappe.timeout(1), + () => { + 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"); + }, + + () => cur_frm.print_doc(), + () => frappe.timeout(1), + + () => frappe.tests.click_button('Submit'), + () => frappe.tests.click_button('Yes'), + () => frappe.timeout(0.3), + + () => { + assert.ok(cur_frm.doc.status == 'To Receive and Bill', "Submitted successfully"); + }, + + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js new file mode 100644 index 0000000000..09fc33d4d8 --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_get_items.js @@ -0,0 +1,62 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order with get items", 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-USD'}, + {currency: 'USD'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"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'} + ] + ]} + ]); + }, + + () => { + assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct"); + }, + + () => frappe.timeout(0.3), + () => frappe.click_button('Get items from'), + () => frappe.timeout(0.3), + + () => frappe.click_link('Product Bundle'), + () => frappe.timeout(0.5), + + () => cur_dialog.set_value('product_bundle', 'Computer'), + () => frappe.click_button('Get Items'), + () => frappe.timeout(1), + + // Check if items are fetched from Product Bundle + () => { + assert.ok(cur_frm.doc.items[1].item_name == 'CPU', "Product bundle item 1 correct"); + assert.ok(cur_frm.doc.items[2].item_name == 'Screen', "Product bundle item 2 correct"); + assert.ok(cur_frm.doc.items[3].item_name == 'Keyboard', "Product bundle item 3 correct"); + }, + + () => cur_frm.doc.items[1].warehouse = 'Stores - WP', + () => cur_frm.doc.items[2].warehouse = 'Stores - WP', + () => cur_frm.doc.items[3].warehouse = 'Stores - WP', + + () => cur_frm.save(), + () => frappe.timeout(1), + + () => 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_multi_uom.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_multi_uom.js new file mode 100644 index 0000000000..0f543c5972 --- /dev/null +++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_multi_uom.js @@ -0,0 +1,40 @@ +QUnit.module('Buying'); + +QUnit.test("test: purchase order with multi UOM", 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'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"uom": 'Unit'}, + {"rate": 100}, + {"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'} + ] + ]} + ]); + }, + + () => { + assert.ok(cur_frm.doc.supplier_name == 'Test Supplier', "Supplier name correct"); + assert.ok(cur_frm.doc.items[0].item_name == 'Test Product 4', "Item name correct"); + assert.ok(cur_frm.doc.items[0].uom == 'Unit', "Multi UOM correct"); + }, + + () => frappe.timeout(1), + () => 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_for_item_wise_discount.js b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_item_wise_discount.js new file mode 100644 index 0000000000..bc07b753b3 --- /dev/null +++ b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_item_wise_discount.js @@ -0,0 +1,34 @@ +QUnit.module('Buying'); + +QUnit.test("test: supplier quotation with item wise discount", function(assert){ + assert.expect(2); + let done = assert.async(); + + frappe.run_serially([ + () => { + return frappe.tests.make('Supplier Quotation', [ + {supplier: 'Test Supplier'}, + {company: 'Test Company'}, + {items: [ + [ + {"item_code": 'Test Product 4'}, + {"qty": 5}, + {"uom": 'Unit'}, + {"warehouse": 'All Warehouses - TC'}, + {'discount_percentage': 10}, + ] + ]} + ]); + }, + + () => { + assert.ok(cur_frm.doc.total == 900, "Total correct"); + assert.ok(cur_frm.doc.grand_total == 900, "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/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt index 68cfad6542..c5d450af6f 100644 --- a/erpnext/tests/ui/tests.txt +++ b/erpnext/tests/ui/tests.txt @@ -83,4 +83,8 @@ erpnext/buying/doctype/supplier/test_supplier.js erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.js erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation.js erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_taxes_and_charges.js -erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js \ No newline at end of file +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