From 9d27cf3c624a2c069ab3817b9db5c78dded95ca3 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 20 Jul 2017 15:35:03 +0530 Subject: [PATCH] [tests] refactored (#9984) * [tests] refactored * [fix] test_quotation.js * [fix] tests.text * [fix] fiscal year not needed * [test] add long test * [fix] add timeout in lead --- .../doctype/account}/test_account.js | 8 +-- erpnext/crm/doctype/lead/test_lead.js | 43 ++++++++++++++ .../doctype/opportunity/test_opportunity.js | 56 +++++++++++++++++++ .../projects/doctype/timesheet/timesheet.js | 13 +++-- .../doctype/quotation/test_quotation.js} | 48 ++++------------ .../test_fixtures.js => make_fixtures.js} | 38 ++++++++----- erpnext/tests/ui/selling/_test_lead.js | 18 ------ erpnext/tests/ui/selling/_test_opportunity.js | 19 ------- erpnext/tests/ui/tests.txt | 5 ++ 9 files changed, 150 insertions(+), 98 deletions(-) rename erpnext/{tests/ui/accounts => accounts/doctype/account}/test_account.js (77%) create mode 100644 erpnext/crm/doctype/lead/test_lead.js create mode 100644 erpnext/crm/doctype/opportunity/test_opportunity.js rename erpnext/{tests/ui/selling/_test_quotation.js => selling/doctype/quotation/test_quotation.js} (50%) rename erpnext/tests/ui/{data/test_fixtures.js => make_fixtures.js} (87%) delete mode 100644 erpnext/tests/ui/selling/_test_lead.js delete mode 100644 erpnext/tests/ui/selling/_test_opportunity.js create mode 100644 erpnext/tests/ui/tests.txt diff --git a/erpnext/tests/ui/accounts/test_account.js b/erpnext/accounts/doctype/account/test_account.js similarity index 77% rename from erpnext/tests/ui/accounts/test_account.js rename to erpnext/accounts/doctype/account/test_account.js index 6d7709b415..7b23ef01dd 100644 --- a/erpnext/tests/ui/accounts/test_account.js +++ b/erpnext/accounts/doctype/account/test_account.js @@ -5,16 +5,16 @@ QUnit.test("test account", function(assert) { let done = assert.async(); frappe.run_serially([ () => frappe.set_route('Tree', 'Account'), - () => frappe.tests.click_button('Expand All'), - () => frappe.tests.click_link('Debtors'), - () => frappe.tests.click_button('Edit'), + () => frappe.click_button('Expand All'), + () => frappe.click_link('Debtors'), + () => frappe.click_button('Edit'), () => frappe.timeout(1), () => { assert.ok(cur_frm.doc.root_type=='Asset'); assert.ok(cur_frm.doc.report_type=='Balance Sheet'); assert.ok(cur_frm.doc.account_type=='Receivable'); }, - () => frappe.tests.click_button('Ledger'), + () => frappe.click_button('Ledger'), () => frappe.timeout(1), () => { // check if general ledger report shown diff --git a/erpnext/crm/doctype/lead/test_lead.js b/erpnext/crm/doctype/lead/test_lead.js new file mode 100644 index 0000000000..66d33379ad --- /dev/null +++ b/erpnext/crm/doctype/lead/test_lead.js @@ -0,0 +1,43 @@ +QUnit.module("sales"); + +QUnit.test("test: lead", function (assert) { + assert.expect(4); + let done = assert.async(); + let lead_name = frappe.utils.get_random(10); + frappe.run_serially([ + // test lead creation + () => frappe.set_route("List", "Lead"), + () => frappe.new_doc("Lead"), + () => frappe.timeout(1), + () => cur_frm.set_value("lead_name", lead_name), + () => cur_frm.save(), + () => frappe.timeout(1), + () => { + assert.ok(cur_frm.doc.lead_name.includes(lead_name), + 'name correctly set'); + frappe.lead_name = cur_frm.doc.name; + }, + // create address and contact + () => frappe.click_link('Address & Contact'), + () => frappe.click_button('New Address'), + () => frappe.timeout(1), + () => frappe.set_control('address_line1', 'Gateway'), + () => frappe.set_control('city', 'Mumbai'), + () => cur_frm.save(), + () => frappe.timeout(3), + () => assert.equal(frappe.get_route()[1], 'Lead', + 'back to lead form'), + () => frappe.click_link('Address & Contact'), + () => assert.ok($('.address-box').text().includes('Mumbai'), + 'city is seen in address box'), + + // make opportunity + () => frappe.click_button('Make'), + () => frappe.click_link('Opportunity'), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.lead, frappe.lead_name, + 'lead name correctly mapped'), + + () => done() + ]); +}); diff --git a/erpnext/crm/doctype/opportunity/test_opportunity.js b/erpnext/crm/doctype/opportunity/test_opportunity.js new file mode 100644 index 0000000000..f2b04f8647 --- /dev/null +++ b/erpnext/crm/doctype/opportunity/test_opportunity.js @@ -0,0 +1,56 @@ +QUnit.test("test: opportunity", function (assert) { + assert.expect(8); + let done = assert.async(); + frappe.run_serially([ + () => frappe.set_route('List', 'Opportunity'), + () => frappe.timeout(1), + () => frappe.click_button('New'), + () => frappe.timeout(1), + () => cur_frm.set_value('enquiry_from', 'Customer'), + () => cur_frm.set_value('customer', 'Test Customer 1'), + + // check items + () => cur_frm.set_value('with_items', 1), + () => frappe.tests.set_grid_values(cur_frm, 'items', [ + [ + {item_code:'Test Product 1'}, + {qty: 4} + ] + ]), + () => cur_frm.save(), + () => frappe.timeout(1), + () => { + assert.notOk(cur_frm.is_new(), 'saved'); + frappe.opportunity_name = cur_frm.doc.name; + }, + + // close and re-open + () => frappe.click_button('Close'), + () => frappe.timeout(1), + () => assert.equal(cur_frm.doc.status, 'Closed', + 'closed'), + + () => frappe.click_button('Reopen'), + () => assert.equal(cur_frm.doc.status, 'Open', + 'reopened'), + () => frappe.timeout(1), + + // make quotation + () => frappe.click_button('Make'), + () => frappe.click_link('Quotation', 1), + () => frappe.timeout(2), + () => { + assert.equal(frappe.get_route()[1], 'Quotation', + 'made quotation'); + assert.equal(cur_frm.doc.customer, 'Test Customer 1', + 'customer set in quotation'); + assert.equal(cur_frm.doc.items[0].item_code, 'Test Product 1', + 'item set in quotation'); + assert.equal(cur_frm.doc.items[0].qty, 4, + 'qty set in quotation'); + assert.equal(cur_frm.doc.items[0].prevdoc_docname, frappe.opportunity_name, + 'opportunity set in quotation'); + }, + () => done() + ]); +}); diff --git a/erpnext/projects/doctype/timesheet/timesheet.js b/erpnext/projects/doctype/timesheet/timesheet.js index 2edfa9e810..441ab1afb0 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.js +++ b/erpnext/projects/doctype/timesheet/timesheet.js @@ -133,10 +133,15 @@ var calculate_end_time = function(frm, cdt, cdn) { var child = locals[cdt][cdn]; var d = moment(child.from_time); - d.add(child.hours, "hours"); - frm._setting_hours = true; - frappe.model.set_value(cdt, cdn, "to_time", d.format(moment.defaultDatetimeFormat)); - frm._setting_hours = false; + if(child.hours) { + d.add(child.hours, "hours"); + frm._setting_hours = true; + frappe.model.set_value(cdt, cdn, "to_time", + d.format(moment.defaultDatetimeFormat)).then(() => { + frm._setting_hours = false; + }); + } + if((frm.doc.__islocal || frm.doc.__onload.maintain_bill_work_hours_same) && child.hours){ frappe.model.set_value(cdt, cdn, "billing_hours", child.hours); diff --git a/erpnext/tests/ui/selling/_test_quotation.js b/erpnext/selling/doctype/quotation/test_quotation.js similarity index 50% rename from erpnext/tests/ui/selling/_test_quotation.js rename to erpnext/selling/doctype/quotation/test_quotation.js index 62dd05dc84..44173cc0e1 100644 --- a/erpnext/tests/ui/selling/_test_quotation.js +++ b/erpnext/selling/doctype/quotation/test_quotation.js @@ -1,29 +1,16 @@ QUnit.test("test: quotation", function (assert) { - assert.expect(18); + assert.expect(10); let done = assert.async(); frappe.run_serially([ - () => frappe.tests.setup_doctype("Customer"), - () => frappe.tests.setup_doctype("Item"), - () => frappe.tests.setup_doctype("Address"), - () => frappe.tests.setup_doctype("Contact"), - () => frappe.tests.setup_doctype("Price List"), - () => frappe.tests.setup_doctype("Terms and Conditions"), - () => frappe.tests.setup_doctype("Sales Taxes and Charges Template"), () => { - return frappe.tests.make("Quotation", [{ - customer: "Test Customer 1" - }, - { - items: [ - [{ - "item_code": "Test Product 1" - }, - { - "qty": 5 - } - ] - ] - } + return frappe.tests.make("Quotation", [ + {customer: "Test Customer 1"}, + {items: [ + [ + {"item_code": "Test Product 1"}, + {"qty": 5} + ]] + } ]); }, () => { @@ -43,7 +30,6 @@ QUnit.test("test: quotation", function (assert) { () => cur_frm.doc.items[0].rate = 200, () => frappe.timeout(0.3), () => cur_frm.set_value("tc_name", "Test Term 1"), - () => cur_frm.set_value("taxes_and_charges", "TEST In State GST"), () => frappe.timeout(0.3), () => cur_frm.save(), () => { @@ -56,26 +42,12 @@ QUnit.test("test: quotation", function (assert) { assert.ok(cur_frm.doc_currency == "USD", "Currency Changed"); assert.ok(cur_frm.doc.selling_price_list == "Test-Selling-USD", "Price List Changed"); assert.ok(cur_frm.doc.items[0].rate == 200, "Price Changed Manually"); - assert.ok(cur_frm.doc.total == 1000, "New Total Calculated"); + assert.equal(cur_frm.doc.total, 1000, "New Total Calculated"); // Check Terms and Condtions assert.ok(cur_frm.doc.tc_name == "Test Term 1", "Terms and Conditions Checked"); - // Check Taxes - assert.ok(cur_frm.doc.taxes[0].account_head.includes("CGST")); - assert.ok(cur_frm.doc.taxes[1].account_head.includes("SGST")); - assert.ok(cur_frm.doc.grand_total == 1180, "Tax Amount Added to Total"); - assert.ok(cur_frm.doc.taxes_and_charges == "TEST In State GST", "Tax Template Selected"); }, - () => frappe.timeout(0.3), - () => cur_frm.print_doc(), - () => frappe.timeout(1), - () => assert.ok($('.btn-print-print').is(':visible'), "Print Format Available"), - () => assert.ok(RegExp(/QTN-\d\d\d\d\d/g).test($("#header-html small").text())), - () => assert.ok($(".important .text-right.value").text().includes("$ 1,180.00")), - () => 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"), - () => frappe.timeout(0.3), - () => cur_frm.print_doc(), () => done() ]); }); \ No newline at end of file diff --git a/erpnext/tests/ui/data/test_fixtures.js b/erpnext/tests/ui/make_fixtures.js similarity index 87% rename from erpnext/tests/ui/data/test_fixtures.js rename to erpnext/tests/ui/make_fixtures.js index 2ba5db5606..0c5b4beebe 100644 --- a/erpnext/tests/ui/data/test_fixtures.js +++ b/erpnext/tests/ui/make_fixtures.js @@ -1,4 +1,11 @@ $.extend(frappe.test_data, { + // "Fiscal Year": { + // "2017-18": [ + // {"year": "2017-18"}, + // {"year_start_date": "2017-04-01"}, + // {"year_end_date": "2018-03-31"}, + // ] + // }, "Customer": { "Test Customer 1": [ {customer_name: "Test Customer 1"} @@ -198,19 +205,20 @@ $.extend(frappe.test_data, { {title: "Test Term 2"} ] }, - "Sales Taxes and Charges Template": { - "TEST In State GST": [ - {title: "TEST In State GST"}, - {taxes:[ - [ - {charge_type:"On Net Total"}, - {account_head:"CGST - "+frappe.get_abbr(frappe.defaults.get_default("Company")) } - ], - [ - {charge_type:"On Net Total"}, - {account_head:"SGST - "+frappe.get_abbr(frappe.defaults.get_default("Company")) } - ] - ]} - ] - } +}); + + +// this is a script that creates all fixtures +// called as a test +QUnit.module('fixture'); + +QUnit.test('Make fixtures', assert => { + // create all fixtures first + assert.expect(0); + let done = assert.async(); + let tasks = []; + Object.keys(frappe.test_data).forEach(function(doctype) { + tasks.push(function() { return frappe.tests.setup_doctype(doctype); }); + }); + frappe.run_serially(tasks).then(() => done()); }); diff --git a/erpnext/tests/ui/selling/_test_lead.js b/erpnext/tests/ui/selling/_test_lead.js deleted file mode 100644 index 2b895d953a..0000000000 --- a/erpnext/tests/ui/selling/_test_lead.js +++ /dev/null @@ -1,18 +0,0 @@ -QUnit.module("sales"); - -QUnit.test("test: lead", function (assert) { - assert.expect(1); - let done = assert.async(); - let random = frappe.utils.get_random(10); - frappe.run_serially([ - () => frappe.tests.setup_doctype("Lead"), - () => frappe.set_route("List", "Lead"), - () => frappe.new_doc("Lead"), - () => cur_frm.set_value("lead_name", random), - () => cur_frm.save(), - () => { - assert.ok(cur_frm.doc.lead_name.includes(random)); - return done(); - } - ]); -}); diff --git a/erpnext/tests/ui/selling/_test_opportunity.js b/erpnext/tests/ui/selling/_test_opportunity.js deleted file mode 100644 index 716a36e7e3..0000000000 --- a/erpnext/tests/ui/selling/_test_opportunity.js +++ /dev/null @@ -1,19 +0,0 @@ -QUnit.test("test: opportunity", function (assert) { - assert.expect(1); - let done = assert.async(); - frappe.run_serially([ - () => { - return frappe.tests.make("Opportunity", [{ - enquiry_from: "Lead" - }, - { - lead: "LEAD-00002" - } - ]); - }, - () => { - assert.ok(cur_frm.doc.lead === "LEAD-00002"); - return done(); - } - ]); -}); diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt new file mode 100644 index 0000000000..42233dc800 --- /dev/null +++ b/erpnext/tests/ui/tests.txt @@ -0,0 +1,5 @@ +erpnext/tests/ui/make_fixtures.js #long +erpnext/accounts/doctype/account/test_account.js +erpnext/crm/doctype/lead/test_lead.js +erpnext/crm/doctype/opportunity/test_opportunity.js +erpnext/selling/doctype/quotation/test_quotation.js \ No newline at end of file