Added first UI tests (#9532)

* [wip]

* [tests] wip

* [ui-tests] first-cut

* [minor] remove old tests
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index 36db684..8015fb7 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -3238,7 +3238,7 @@
    "in_filter": 0, 
    "in_global_search": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 0, 
@@ -3767,10 +3767,11 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-06-13 14:28:57.930167", 
+ "modified": "2017-06-29 10:48:09.707735", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
+ "name_case": "Title Case", 
  "owner": "Administrator", 
  "permissions": [
   {
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 4a1685b..49665bb 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -71,17 +71,19 @@
 					});
 
 				if(!from_delivery_note && !is_delivered_by_supplier) {
-					cur_frm.add_custom_button(__('Delivery'), cur_frm.cscript['Make Delivery Note'],
-						__("Make"));
+					cur_frm.add_custom_button(__('Delivery'),
+						cur_frm.cscript['Make Delivery Note'], __("Make"));
 				}
 			}
 
 			if(doc.outstanding_amount!=0 && !cint(doc.is_return)) {
-				cur_frm.add_custom_button(__('Payment'), this.make_payment_entry, __("Make"));
+				cur_frm.add_custom_button(__('Payment'),
+					this.make_payment_entry, __("Make"));
 			}
 
 			if(doc.outstanding_amount>0 && !cint(doc.is_return)) {
-				cur_frm.add_custom_button(__('Payment Request'), this.make_payment_request, __("Make"));
+				cur_frm.add_custom_button(__('Payment Request'),
+					this.make_payment_request, __("Make"));
 			}
 
 
@@ -481,7 +483,7 @@
 			'Delivery Note': 'Delivery',
 			'Sales Invoice': 'Sales Return',
 			'Payment Request': 'Payment Request',
-			'Payment': 'Payment Entry'
+			'Payment Entry': 'Payment'
 		},
 		frm.fields_dict["timesheets"].grid.get_field("time_sheet").get_query = function(doc, cdt, cdn){
 			return{
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 36a66c6..a2e9ddf 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -2511,7 +2511,7 @@
    "in_filter": 0, 
    "in_global_search": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "Outstanding Amount", 
    "length": 0, 
    "no_copy": 1, 
@@ -3597,7 +3597,7 @@
    "in_filter": 0, 
    "in_global_search": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -4627,10 +4627,11 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-06-22 14:45:35.257640", 
+ "modified": "2017-06-29 10:47:49.522969", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
+ "name_case": "Title Case", 
  "owner": "Administrator", 
  "permissions": [
   {
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index 644f0f5..aefc212 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -215,7 +215,7 @@
 			erpnext.taxes.set_conditional_mandatory_rate_or_amount(open_form);
 		} else {
 			// apply in current row
-			erpnext.taxes.set_conditional_mandatory_rate_or_amount(frm.get_field('taxes').grid.get_grid_row(cdn));
+			erpnext.taxes.set_conditional_mandatory_rate_or_amount(frm.get_field('taxes').grid.get_row(cdn));
 		}
 	});
 
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index 989dfbc..1b77418 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -107,6 +107,7 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
@@ -168,10 +169,12 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "default": "Company", 
    "fieldname": "customer_type", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -186,7 +189,7 @@
    "no_copy": 0, 
    "oldfieldname": "customer_type", 
    "oldfieldtype": "Select", 
-   "options": "\nCompany\nIndividual", 
+   "options": "Company\nIndividual", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -1197,7 +1200,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-06-13 14:29:11.114613", 
+ "modified": "2017-06-28 14:55:39.910819", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Customer", 
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 46e4d5c..71734f2 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -41,8 +41,7 @@
 			"email"				:"test@erpnext.com",
 			"password"			:"test",
 			"chart_of_accounts" : "Standard",
-			"domain"			: "Manufacturing",
-
+			"domain"			: "Manufacturing"
 		})
 
 	frappe.db.sql("delete from `tabLeave Allocation`")
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index 80a7834..ceeceaa 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -4,10 +4,10 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe.utils.nestedset import get_root_of
 
 def boot_session(bootinfo):
 	"""boot session - send website info if guest"""
-	import frappe
 
 	bootinfo.custom_css = frappe.db.get_value('Style Settings', None, 'custom_css') or ''
 	bootinfo.website_settings = frappe.get_doc('Website Settings')
@@ -16,6 +16,8 @@
 		update_page_info(bootinfo)
 
 		load_country_and_currency(bootinfo)
+		bootinfo.sysdefaults.territory = get_root_of('Territory')
+		bootinfo.sysdefaults.customer_group = get_root_of('Customer Group')
 
 		bootinfo.notification_settings = frappe.get_doc("Notification Control",
 			"Notification Control")
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index f5f3493..9328194 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -524,7 +524,7 @@
 
 	def before_rename(self, old_name, new_name, merge=False):
 		if self.item_name==old_name:
-			self.item_name=new_name
+			frappe.db.set_value("Item", old_name, "item_name", new_name)
 
 		if merge:
 			# Validate properties before merging
diff --git a/erpnext/tests/sel_tests.py b/erpnext/tests/sel_tests.py
deleted file mode 100644
index 174e9c2..0000000
--- a/erpnext/tests/sel_tests.py
+++ /dev/null
@@ -1,106 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-"""
-Run Selenium Tests
-
-Requires a clean install. After reinstalling fresh db, call
-
-	frappe --execute erpnext.tests.sel_tests.start
-
-"""
-
-from __future__ import unicode_literals
-import frappe
-
-from frappe.utils import sel
-import time
-
-def start():
-	try:
-		run()
-	finally:
-		sel.close()
-
-def run():
-	def next_slide(idx, selector="next-btn"):
-		sel.find('[data-slide-id="{0}"] .{1}'.format(idx, selector))[0].click()
-		sel.wait_for_ajax()
-
-
-	sel.start(verbose=True, driver="Firefox")
-	sel.input_wait = 0.2
-	sel.login("#page-setup-wizard")
-
-	# slide 1
-	next_slide("0")
-
-	sel.set_field("first_name", "Test")
-	sel.set_field("last_name", "User")
-	sel.set_field("email", "test@erpnext.com")
-	sel.set_field("password", "test")
-
-	next_slide("1")
-
-	sel.set_select("country", "India")
-
-	next_slide("2")
-
-	sel.set_field("company_name", "Wind Power LLC")
-	sel.set_field("fy_start_date", "01-04-2014")
-	sel.set_field("company_tagline", "Wind Power For Everyone")
-
-	next_slide("3")
-	next_slide("4")
-
-	sel.set_field("tax_1", "VAT")
-	sel.set_field("tax_rate_1", "12.5")
-
-	sel.set_field("tax_2", "Service Tax")
-	sel.set_field("tax_rate_2", "10.36")
-
-	next_slide("5")
-
-	sel.set_field("customer_1", "Asian Junction")
-	sel.set_field("customer_contact_1", "January Vaclavik")
-	sel.set_field("customer_2", "Life Plan Counselling")
-	sel.set_field("customer_contact_2", "Jana Tobeolisa")
-	sel.set_field("customer_3", "Two Pesos")
-	sel.set_field("customer_contact_3", "Satomi Shigeki")
-	sel.set_field("customer_4", "Intelacard")
-	sel.set_field("customer_contact_4", "Hans Rasmussen")
-
-	next_slide("6")
-
-	sel.set_field("item_1", "Wind Turbine A")
-	sel.set_field("item_2", "Wind Turbine B")
-	sel.set_field("item_3", "Wind Turbine C")
-
-	next_slide("7")
-
-	sel.set_field("supplier_1", "Helios Air")
-	sel.set_field("supplier_contact_1", "Quimey Osorio")
-	sel.set_field("supplier_2", "Ks Merchandise")
-	sel.set_field("supplier_contact_2", "Edgarda Salcedo")
-	sel.set_field("supplier_3", "Eagle Hardware")
-	sel.set_field("supplier_contact_3", "Hafsteinn Bjarnarsonar")
-
-	next_slide("8")
-
-	sel.set_field("item_buy_1", "Bearing Pipe")
-	sel.set_field("item_buy_2", "Bearing Assembly")
-	sel.set_field("item_buy_3", "Base Plate")
-	sel.set_field("item_buy_4", "Coil")
-
-	next_slide("9", "complete-btn")
-
-	sel.wait('[data-state="setup-complete"]')
-
-	w = raw_input("quit?")
-
-# complete setup
-# new customer
-# new supplier
-# new item
-# sales cycle
-# purchase cycle
diff --git a/erpnext/tests/test_client.py b/erpnext/tests/test_client.py
deleted file mode 100644
index bf88341..0000000
--- a/erpnext/tests/test_client.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-from __future__ import unicode_literals
-
-import unittest, frappe
-from frappe.utils import sel
-from frappe.utils import formatdate
-
-#selenium_tests = True
-
-# class TestLogin(unittest.TestCase):
-# 	def setUp(self):
-# 		sel.login()
-#
-# 	def test_material_request(self):
-# 		sel.new_doc("Stock", "Material Request")
-# 		sel.set_field("company", "_Test Company")
-# 		sel.add_child("items")
-# 		sel.set_field("item_code", "_Test Item")
-# 		sel.set_field("qty", "1")
-# 		sel.set_field("warehouse", "_Test Warehouse - _TC")
-# 		sel.set_field("schedule_date", formatdate())
-# 		sel.done_add_child("items")
-# 		sel.primary_action()
-# 		sel.wait_for_state("clean")
diff --git a/erpnext/tests/test_init.py b/erpnext/tests/test_init.py
index 2baea97..43340ce 100644
--- a/erpnext/tests/test_init.py
+++ b/erpnext/tests/test_init.py
@@ -6,7 +6,6 @@
 
 test_records = frappe.get_test_records('Company')
 
-
 class TestInit(unittest.TestCase):
 	def test_encode_company_abbr(self):
 		company = frappe.new_doc("Company")
diff --git a/erpnext/tests/ui/test_fixtures.js b/erpnext/tests/ui/test_fixtures.js
new file mode 100644
index 0000000..e4ee664
--- /dev/null
+++ b/erpnext/tests/ui/test_fixtures.js
@@ -0,0 +1,48 @@
+$.extend(frappe.test_data, {
+	'Customer': {
+		'Test Customer 1': [
+			{customer_name: 'Test Customer 1'}
+		],
+		'Test Customer 2': [
+			{customer_name: 'Test Customer 2'}
+		],
+		'Test Customer 3': [
+			{customer_name: 'Test Customer 3'}
+		],
+	},
+	'Item': {
+		'Test Product 1': [
+			{item_code: 'Test Product 1'},
+			{item_group: 'Products'},
+			{is_stock_item: 1},
+			{standard_rate: 100},
+			{opening_stock: 100},
+		],
+		'Test Product 2': [
+			{item_code: 'Test Product 2'},
+			{item_group: 'Products'},
+			{is_stock_item: 1},
+			{standard_rate: 150},
+			{opening_stock: 200},
+		],
+		'Test Product 3': [
+			{item_code: 'Test Product 3'},
+			{item_group: 'Products'},
+			{is_stock_item: 1},
+			{standard_rate: 250},
+			{opening_stock: 100},
+		],
+		'Test Service 1': [
+			{item_code: 'Test Service 1'},
+			{item_group: 'Services'},
+			{is_stock_item: 0},
+			{standard_rate: 200}
+		],
+		'Test Service 2': [
+			{item_code: 'Test Service 2'},
+			{item_group: 'Services'},
+			{is_stock_item: 0},
+			{standard_rate: 300}
+		]
+	}
+});
\ No newline at end of file
diff --git a/erpnext/tests/ui/test_sellling.js b/erpnext/tests/ui/test_sellling.js
new file mode 100644
index 0000000..5543a67
--- /dev/null
+++ b/erpnext/tests/ui/test_sellling.js
@@ -0,0 +1,29 @@
+QUnit.module('sales');
+
+QUnit.test("test quotation", function(assert) {
+	assert.expect(2);
+	let done = assert.async();
+	frappe.run_serially([
+		() => frappe.tests.setup_doctype('Customer'),
+		() => frappe.tests.setup_doctype('Item'),
+		() => {
+			return frappe.tests.make('Quotation', [
+				{customer: 'Test Customer 1'},
+				{items: [
+					[
+						{'item_code': 'Test Product 1'},
+						{'qty': 5}
+					]
+				]}
+			]);
+		},
+		() => {
+			// get_item_details
+			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1');
+
+			// calculate_taxes_and_totals
+			assert.ok(cur_frm.doc.grand_total==500);
+		},
+		() => done()
+	]);
+});