From 82d2828be66f41698c5e95ab6a8e30c0e7d2a181 Mon Sep 17 00:00:00 2001 From: Zarrar Date: Fri, 4 Aug 2017 15:33:27 +0530 Subject: [PATCH] [ui test] Student Group - manually and using creation tool (#10283) * fixing issues in original files * creating a student log * student group - manually and using creation tool --- .../student_group/test_student_group.js | 62 +++++++++++++ .../student_group_creation_tool.js | 2 +- .../student_group_creation_tool.py | 1 + .../test_student_group_creation_tool.js | 88 +++++++++++++++++++ .../doctype/student_log/test_student_log.js | 38 ++++++++ erpnext/tests/ui/tests.txt | 5 +- 6 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 erpnext/schools/doctype/student_group/test_student_group.js create mode 100644 erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js create mode 100644 erpnext/schools/doctype/student_log/test_student_log.js diff --git a/erpnext/schools/doctype/student_group/test_student_group.js b/erpnext/schools/doctype/student_group/test_student_group.js new file mode 100644 index 0000000000..842d0ba60d --- /dev/null +++ b/erpnext/schools/doctype/student_group/test_student_group.js @@ -0,0 +1,62 @@ +// Testing Student Module in Schools +QUnit.module('schools'); + +QUnit.test('Test: Student Group', function(assert){ + assert.expect(2); + let done = assert.async(); + let instructor_code; + let loop = ["test-batch-wise-group", "test-course-wise-group"]; + let tasks = []; + + frappe.run_serially([ + // Saving Instructor code beforehand + () => frappe.set_route('List', 'Instructor'), + () => frappe.timeout(0.5), + () => frappe.tests.click_link('Instructor 1'), + () => frappe.timeout(0.5), + () => {instructor_code = frappe.get_route()[2];}, + + // Creating a Batch and Course based group + () => { + loop.forEach(index => { + tasks.push(() => { + return frappe.tests.make('Student Group', [ + {academic_year: '2016-17'}, + {academic_term: '2016-17 (Semester 1)'}, + {program: "Standard Test"}, + {group_based_on: 'Batch'}, + {student_group_name: index}, + {max_strength: 10}, + {batch: 'A'}, + {instructors: [ + [ + {instructor: instructor_code} + ] + ]} + ]); + }); + }); + return frappe.run_serially(tasks); + }, + + // Populating the created group with Students + () => { + tasks = []; + loop.forEach(index => { + tasks.push( + () => frappe.timeout(0.3), + () => frappe.set_route("Form", ('Student Group/' + index)), + () => frappe.timeout(0.3), + () => frappe.tests.click_button('Get Students'), + () => frappe.timeout(0.2), + () => { + assert.equal(cur_frm.doc.students.length, 5, 'Successfully fetched list of students'); + }, + ); + }); + return frappe.run_serially(tasks); + }, + + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.js b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.js index 146f11c453..d0d7afd701 100644 --- a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.js +++ b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.js @@ -8,7 +8,7 @@ frappe.ui.form.on("Student Group Creation Tool", "refresh", function(frm) { }); frappe.realtime.on("student_group_creation_progress", function(data) { if(data.progress) { - frappe.hide_frappe.msgprint(true); + frappe.hide_msgprint(true); frappe.show_progress(__("Creating student groups"), data.progress[0],data.progress[1]); } }); diff --git a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py index a23650882e..4a4cec72a4 100644 --- a/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py +++ b/erpnext/schools/doctype/student_group_creation_tool/student_group_creation_tool.py @@ -64,6 +64,7 @@ class StudentGroupCreationTool(Document): student_group.program = self.program student_group.course = d.course student_group.batch = d.batch + student_group.max_strength = d.max_strength student_group.academic_term = self.academic_term student_group.academic_year = self.academic_year student_group.save() diff --git a/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js b/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js new file mode 100644 index 0000000000..c0b4dc85f8 --- /dev/null +++ b/erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js @@ -0,0 +1,88 @@ +QUnit.module('schools'); + +QUnit.test('Test: Student Group Creation Tool', function(assert){ + assert.expect(5); + let done = assert.async(); + let instructor_code; + + frappe.run_serially([ + // Saving Instructor code beforehand + () => frappe.set_route('List', 'Instructor'), + () => frappe.timeout(0.5), + () => frappe.tests.click_link('Instructor 1'), + () => frappe.timeout(0.5), + () => {instructor_code = frappe.get_route()[2];}, + + // Setting up the creation tool to generate and save Student Group + () => frappe.set_route('Form', 'Student Group Creation Tool'), + () => frappe.timeout(0.5), + () => { + cur_frm.set_value("academic_year", "2016-17"); + cur_frm.set_value("academic_term", "2016-17 (Semester 1)"); + cur_frm.set_value("program", "Standard Test"); + frappe.tests.click_button('Get Courses'); + }, + () => frappe.timeout(0.5), + () => { + assert.equal(cur_frm.doc.courses.length, 4, 'Successfully created groups using the tool'); + }, + + () => { + let d, grid, grid_row; + + for(d = 0; d < cur_frm.doc.courses.length; d++) + { + grid = cur_frm.get_field("courses").grid; + grid_row = grid.get_row(d).toggle_view(true); + if(grid_row.doc.student_group_name == 'Standard Test/A/2016-17 (Semester 1)'){ + grid_row.doc.max_strength = 10; + grid_row.doc.student_group_name = "test-batch-wise-group-2"; + $(`.octicon.octicon-triangle-up`).click(); + continue; + } + else if(grid_row.doc.student_group_name == 'Test_Sub/Standard Test/2016-17 (Semester 1)'){ + grid_row.doc.max_strength = 10; + grid_row.doc.student_group_name = "test-course-wise-group-2"; + $(`.octicon.octicon-triangle-up`).click(); + continue; + } + } + }, + + // Generating Student Group + () => frappe.timeout(0.5), + () => frappe.tests.click_button("Create Student Groups"), + () => frappe.timeout(0.5), + () => frappe.tests.click_button("Close"), + + // Goin to the generated group to set up student and instructor list + () => { + let loop = ['Student Group/test-batch-wise-group-2', 'Student Group/test-course-wise-group-2']; + let tasks = []; + loop.forEach(index => { + tasks.push( + () => frappe.timeout(1), + () => frappe.set_route("Form", index), + () => frappe.timeout(0.5), + () => frappe.tests.click_button("Get Students"), + () => frappe.timeout(0.5), + () => { + assert.equal(cur_frm.doc.students.length, 5, 'Successfully fetched list of students'); + }, + () => frappe.timeout(0.5), + () => { + d = cur_frm.add_child('instructors'); + d.instructor = instructor_code; + cur_frm.save(); + }, + () => { + assert.equal(cur_frm.doc.instructors.length, 1, 'Instructor detail stored successfully'); + }, + ); + }); + return frappe.run_serially(tasks); + }, + + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/schools/doctype/student_log/test_student_log.js b/erpnext/schools/doctype/student_log/test_student_log.js new file mode 100644 index 0000000000..6e03976836 --- /dev/null +++ b/erpnext/schools/doctype/student_log/test_student_log.js @@ -0,0 +1,38 @@ +// Testing Student Module in Schools +QUnit.module('schools'); + +QUnit.test('Test: Student Log', function(assert){ + assert.expect(9); + let done = assert.async(); + let student_code; + frappe.run_serially([ + () => frappe.set_route("List", "Student"), + () => frappe.timeout(0.5), + () => frappe.tests.click_link('Fname Mname Lname'), + () => frappe.timeout(0.5), + () => {student_code = frappe.get_route()[2];}, + () => { + return frappe.tests.make("Student Log", [ + {student: student_code}, + {academic_year: '2016-17'}, + {academic_term: '2016-17 (Semester 1)'}, + {program: "Standard Test"}, + {date: '2017-07-31'}, + {student_batch: 'A'}, + {log: 'This is Test log.'} + ]); + }, + () => { + assert.equal(cur_frm.doc.student, student_code, 'Student code was fetched properly'); + assert.equal(cur_frm.doc.student_name, 'Fname Mname Lname', 'Student name was correctly auto-fetched'); + assert.equal(cur_frm.doc.type, 'General', 'Default type selected'); + assert.equal(cur_frm.doc.academic_year, '2016-17'); + assert.equal(cur_frm.doc.academic_term, '2016-17 (Semester 1)'); + assert.equal(cur_frm.doc.program, 'Standard Test', 'Program correctly selected'); + assert.equal(cur_frm.doc.student_batch, 'A'); + assert.equal(cur_frm.doc.date, '2017-07-31'); + assert.equal(cur_frm.doc.log, 'This is Test log.'); + }, + () => done() + ]); +}); \ No newline at end of file diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt index b08c18ec87..4ce167516b 100644 --- a/erpnext/tests/ui/tests.txt +++ b/erpnext/tests/ui/tests.txt @@ -55,4 +55,7 @@ erpnext/schools/doctype/guardian/test_guardian.js erpnext/schools/doctype/student_admission/test_student_admission.js erpnext/schools/doctype/student_applicant/tests/test_student_applicant_dummy_data.js erpnext/schools/doctype/student_applicant/tests/test_student_applicant.js -erpnext/schools/doctype/student_applicant/tests/test_student_applicant_options.js \ No newline at end of file +erpnext/schools/doctype/student_applicant/tests/test_student_applicant_options.js +erpnext/schools/doctype/student_log/test_student_log.js +erpnext/schools/doctype/student_group/test_student_group.js +erpnext/schools/doctype/student_group_creation_tool/test_student_group_creation_tool.js \ No newline at end of file