Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 1 | QUnit.module("sales"); |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 2 | |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 3 | QUnit.test("test: lead", function (assert) { |
| 4 | assert.expect(1); |
| 5 | let done = assert.async(); |
| 6 | let random = frappe.utils.get_random(10); |
| 7 | frappe.run_serially([ |
| 8 | () => frappe.tests.setup_doctype("Lead"), |
| 9 | () => frappe.set_route("List", "Lead"), |
| 10 | () => frappe.new_doc("Lead"), |
| 11 | () => cur_frm.set_value("lead_name", random), |
| 12 | () => cur_frm.save(), |
| 13 | () => { |
| 14 | assert.ok(cur_frm.doc.lead_name.includes(random)); |
| 15 | return done(); |
| 16 | } |
| 17 | ]); |
| 18 | }); |
| 19 | |
| 20 | QUnit.test("test: opportunity", function (assert) { |
| 21 | assert.expect(1); |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 22 | let done = assert.async(); |
| 23 | frappe.run_serially([ |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 24 | () => { |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 25 | return frappe.tests.make("Opportunity", [{ |
| 26 | enquiry_from: "Lead" |
| 27 | }, |
| 28 | { |
| 29 | lead: "LEAD-00002" |
| 30 | } |
| 31 | ]); |
| 32 | }, |
| 33 | () => { |
| 34 | assert.ok(cur_frm.doc.lead === "LEAD-00002"); |
| 35 | return done(); |
| 36 | } |
| 37 | ]); |
| 38 | }); |
| 39 | |
| 40 | QUnit.test("test: quotation", function (assert) { |
| 41 | assert.expect(18); |
| 42 | let done = assert.async(); |
| 43 | frappe.run_serially([ |
| 44 | () => frappe.tests.setup_doctype("Customer"), |
| 45 | () => frappe.tests.setup_doctype("Item"), |
| 46 | () => frappe.tests.setup_doctype("Address"), |
| 47 | () => frappe.tests.setup_doctype("Contact"), |
| 48 | () => frappe.tests.setup_doctype("Price List"), |
| 49 | () => frappe.tests.setup_doctype("Terms and Conditions"), |
| 50 | () => frappe.tests.setup_doctype("Sales Taxes and Charges Template"), |
| 51 | () => { |
| 52 | return frappe.tests.make("Quotation", [{ |
| 53 | customer: "Test Customer 1" |
| 54 | }, |
| 55 | { |
| 56 | items: [ |
| 57 | [{ |
| 58 | "item_code": "Test Product 1" |
| 59 | }, |
| 60 | { |
| 61 | "qty": 5 |
| 62 | } |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 63 | ] |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 64 | ] |
| 65 | } |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 66 | ]); |
| 67 | }, |
| 68 | () => { |
| 69 | // get_item_details |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 70 | assert.ok(cur_frm.doc.items[0].item_name == "Test Product 1", "Added Test Product 1"); |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 71 | |
| 72 | // calculate_taxes_and_totals |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 73 | assert.ok(cur_frm.doc.grand_total === 500, "Total Amount is correct"); |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 74 | }, |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 75 | () => cur_frm.set_value("customer_address", "Test1-Billing"), |
| 76 | () => cur_frm.set_value("shipping_address_name", "Test1-Warehouse"), |
| 77 | () => cur_frm.set_value("contact_person", "Contact 1-Test Customer 1"), |
| 78 | () => cur_frm.set_value("currency", "USD"), |
| 79 | () => frappe.timeout(0.3), |
| 80 | () => cur_frm.set_value("selling_price_list", "Test-Selling-USD"), |
| 81 | () => frappe.timeout(0.5), |
| 82 | () => cur_frm.doc.items[0].rate = 200, |
| 83 | () => frappe.timeout(0.3), |
| 84 | () => cur_frm.set_value("tc_name", "Test Term 1"), |
| 85 | () => cur_frm.set_value("taxes_and_charges", "TEST In State GST"), |
| 86 | () => frappe.timeout(0.3), |
| 87 | () => cur_frm.save(), |
| 88 | () => { |
| 89 | // Check Address and Contact Info |
| 90 | assert.ok(cur_frm.doc.address_display.includes("Billing Street 1"), "Address Changed"); |
| 91 | assert.ok(cur_frm.doc.shipping_address.includes("Warehouse Street 1"), "Address Changed"); |
| 92 | assert.ok(cur_frm.doc.contact_display == "Contact 1", "Contact info changed"); |
| 93 | |
| 94 | // Check Currency |
| 95 | assert.ok(cur_frm.doc_currency == "USD", "Currency Changed"); |
| 96 | assert.ok(cur_frm.doc.selling_price_list == "Test-Selling-USD", "Price List Changed"); |
| 97 | assert.ok(cur_frm.doc.items[0].rate == 200, "Price Changed Manually"); |
| 98 | assert.ok(cur_frm.doc.total == 1000, "New Total Calculated"); |
| 99 | |
| 100 | // Check Terms and Condtions |
| 101 | assert.ok(cur_frm.doc.tc_name == "Test Term 1", "Terms and Conditions Checked"); |
| 102 | |
| 103 | // Check Taxes |
| 104 | assert.ok(cur_frm.doc.taxes[0].account_head.includes("CGST")); |
| 105 | assert.ok(cur_frm.doc.taxes[1].account_head.includes("SGST")); |
| 106 | assert.ok(cur_frm.doc.grand_total == 1180, "Tax Amount Added to Total"); |
| 107 | assert.ok(cur_frm.doc.taxes_and_charges == "TEST In State GST", "Tax Template Selected"); |
| 108 | }, |
| 109 | () => frappe.timeout(0.3), |
| 110 | () => cur_frm.print_doc(), |
| 111 | () => frappe.timeout(1), |
| 112 | () => assert.ok($('.btn-print-print').is(':visible'), "Print Format Available"), |
| 113 | () => assert.ok(RegExp(/QTN-\d\d\d\d\d/g).test($("#header-html small").text())), |
| 114 | () => assert.ok($(".important .text-right.value").text().includes("$ 1,180.00")), |
| 115 | () => assert.ok($(".section-break+ .section-break .column-break:nth-child(1) .data-field:nth-child(1) .value").text().includes("Billing Street 1"), "Print Preview Works As Expected"), |
| 116 | () => frappe.timeout(0.3), |
| 117 | () => cur_frm.print_doc(), |
Rushabh Mehta | 43ef4e9 | 2017-07-03 11:53:07 +0530 | [diff] [blame] | 118 | () => done() |
| 119 | ]); |
Shivam Mishra | 3fe5ecc | 2017-07-11 10:33:07 +0530 | [diff] [blame] | 120 | }); |