[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
This commit is contained in:
Rushabh Mehta 2017-07-20 15:35:03 +05:30 committed by GitHub
parent 0e6933a1e8
commit 9d27cf3c62
9 changed files with 150 additions and 98 deletions

View File

@ -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

View File

@ -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()
]);
});

View File

@ -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()
]);
});

View File

@ -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);

View File

@ -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()
]);
});

View File

@ -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());
});

View File

@ -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();
}
]);
});

View File

@ -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();
}
]);
});

View File

@ -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