Try to get existing tests working
authorCharles Connell <charles@connells.org>
Thu, 13 Mar 2014 23:12:48 +0000 (19:12 -0400)
committerCharles Connell <charles@connells.org>
Thu, 13 Mar 2014 23:13:00 +0000 (19:13 -0400)
karmaworld/apps/courses/forms.py
karmaworld/apps/courses/test/__init__.py [new file with mode: 0644]
karmaworld/apps/courses/test/test_selenium.py
karmaworld/assets/js/add-course.js [deleted file]
karmaworld/templates/partial/add_course.html

index d898f7ffd3ac92bb803c4ccc47e4b45802ba62c4..02915a66661ffcfe254f26500fbbe37fccd5d136 100644 (file)
@@ -89,7 +89,8 @@ class DepartmentForm(NiceErrorModelForm, ACFieldModelForm):
         # autocomplete department based on school
         dependsOn=school,
         # allows creating a new department on the fly
-        required=False
+        required=False,
+        widget_id='input_department_name'
     )
 
     class Meta:
diff --git a/karmaworld/apps/courses/test/__init__.py b/karmaworld/apps/courses/test/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 3130704f8eb2d59a4bcde87303eb273f92754fbb..bb7015dd9152408a33fd656e273a00239342e776 100644 (file)
@@ -15,16 +15,16 @@ class AddCourseTest(LiveServerTestCase):
         self.driver = webdriver.Firefox()
         self.driver.implicitly_wait(3)
         self.wait = WebDriverWait(self.driver, 10)
-        self.harvard = School.objects.create(name="Harvard University")
-        self.northeastern = School.objects.create(name="Northeastern University")
+        self.harvard = School.objects.create(name="Harvard University", usde_id=12345)
+        self.northeastern = School.objects.create(name="Northeastern University", usde_id=33333)
 
     def tearDown(self):
         self.driver.close()
 
-    def selectAutocomplete(self, inputId, keys, fieldIndex):
-        input = self.driver.find_element_by_id(inputId)
+    def selectAutocomplete(self, name, keys, fieldIndex):
+        input = self.driver.find_element_by_name(name)
         input.send_keys(keys)
-        self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'ui-autocomplete')][" + str(fieldIndex) + "]/li")))
+        self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'ui-autocomplete')]/li[" + str(fieldIndex) + "]")))
         input.send_keys(Keys.DOWN)
         autocompleteMenuItem = self.driver.find_element_by_id("ui-active-menuitem")
         autocompleteMenuItem.click()
@@ -41,20 +41,22 @@ class AddCourseTest(LiveServerTestCase):
         self.driver.execute_script("javascript:window.scrollBy(0,200)")
 
         # Type in part of a school name
-        schoolInput = self.driver.find_element_by_id("str_school")
+        schoolInput = self.driver.find_element_by_name("DepartmentForm-school_text")
         schoolInput.send_keys("harvard u")
 
         # Wait for autocomplete menu to appear
-        self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'ui-autocomplete')][1]/li")))
+        # li.ui-menu-item:nth-child(1)
+        self.wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[contains(@class,'ui-autocomplete')]/li[1]")))
 
         # Choose the first suggestion
         schoolInput.send_keys(Keys.DOWN)
         activeItem = self.driver.find_element_by_id("ui-active-menuitem")
         activeItem.click()
 
-        self.assertEqual(schoolInput.get_attribute("value"), "Harvard University")
+        school_name_on_deck = self.driver.find_element_by_xpath("//div[contains(@class,'results-on-deck')][1]")
+        self.assertIn("Harvard University", school_name_on_deck.text)
 
-        schoolId = self.driver.find_element_by_id("id_school")
+        schoolId = self.driver.find_element_by_name("DepartmentForm-school")
         self.assertEqual(schoolId.get_attribute("value"), str(self.harvard.id))
 
     def testCreateCourse(self):
@@ -65,24 +67,17 @@ class AddCourseTest(LiveServerTestCase):
         addCourseButton.click()
         self.driver.execute_script("javascript:window.scrollBy(0,200)")
 
-        # We shouldn't be able to save it yet
-        saveButton = self.driver.find_element_by_id("save-btn")
-        self.assertIn("disabled", saveButton.get_attribute("class"))
-
         # Choose a school
-        self.selectAutocomplete("str_school", "northeastern u", 1)
-
-        # Check that save button is now enabled
-        self.assertNotIn("disabled", saveButton.get_attribute("class"))
+        self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1)
 
         # Course name
         newCourseName = "SELENIUM TEST COURSE " + uuid.uuid4().hex
-        courseNameInput = self.driver.find_element_by_id("id_name")
+        courseNameInput = self.driver.find_element_by_id("id_CourseForm-name")
         courseNameInput.send_keys(newCourseName)
 
         # Instructor name
         newInstructorName = "SELENIUM TEST INSTRUCTOR " + uuid.uuid4().hex
-        instructorNameInput = self.driver.find_element_by_id("id_instructor_name")
+        instructorNameInput = self.driver.find_element_by_id("id_ProfessorForm-name_text")
         instructorNameInput.send_keys(newInstructorName)
 
         # Click "Save"
@@ -101,24 +96,17 @@ class AddCourseTest(LiveServerTestCase):
         addCourseButton.click()
         self.driver.execute_script("javascript:window.scrollBy(0,200)")
 
-        # We shouldn't be able to save it yet
-        saveButton = self.driver.find_element_by_id("save-btn")
-        self.assertIn("disabled", saveButton.get_attribute("class"))
-
         # Choose a school
-        self.selectAutocomplete("str_school", "northeastern u", 1)
-
-        # Check that save button is now enabled
-        self.assertNotIn("disabled", saveButton.get_attribute("class"))
+        self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1)
 
         # Course name
         newCourseName = "SELENIUM TEST COURSE " + uuid.uuid4().hex
-        courseNameInput = self.driver.find_element_by_id("id_name")
+        courseNameInput = self.driver.find_element_by_id("id_CourseForm-name")
         courseNameInput.send_keys(newCourseName)
 
         # Instructor name
         newInstructorName = "SELENIUM TEST INSTRUCTOR " + uuid.uuid4().hex
-        instructorNameInput = self.driver.find_element_by_id("id_instructor_name")
+        instructorNameInput = self.driver.find_element_by_id("id_ProfessorForm-name_text")
         instructorNameInput.send_keys(newInstructorName)
 
         # Click "Save"
@@ -137,25 +125,15 @@ class AddCourseTest(LiveServerTestCase):
         self.driver.execute_script("javascript:window.scrollBy(0,200)")
 
         # Choose the SAME school
-        self.selectAutocomplete("str_school", "northeastern u", 1)
+        self.selectAutocomplete("DepartmentForm-school_text", "northeastern u", 1)
 
         # The SAME course name
-        self.selectAutocomplete("id_name", newCourseName, 2)
+        self.selectAutocomplete("id_CourseForm-name", newCourseName, 2)
 
         # The SAME instructor name
-        self.selectAutocomplete("id_instructor_name", newInstructorName, 3)
+        self.selectAutocomplete("id_ProfessorForm-name_text", newInstructorName, 3)
 
-        # Make sure Save button is disabled and hidden
-        saveButton = self.driver.find_element_by_id("save-btn")
-        self.assertIn("disabled", saveButton.get_attribute("class"))
-        self.wait.until_not(EC.visibility_of(saveButton))
-
-        # Make sure Existing Course link is shown
-        existingCourse = self.driver.find_element_by_id("existing-course-btn")
-        self.wait.until(EC.visibility_of(existingCourse))
-        existingCourse.click()
+        saveButton.click()
 
-        # See if we are taken to the new course page
-        self.wait.until(EC.title_contains(newCourseName))
 
 
diff --git a/karmaworld/assets/js/add-course.js b/karmaworld/assets/js/add-course.js
deleted file mode 100644 (file)
index d037412..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// Setup all the javascript stuff we need for the various
-// incarnations of the Add Course form
-
-$(function() {
-
-  var schoolSelected = false;
-  var courseNameSelected = false;
-  var instructorSelected = false;
-
-  function fieldEdited() {
-    if (schoolSelected && courseNameSelected && instructorSelected) {
-      $('#save-btn').hide();
-      $('#save-btn').addClass('disabled');
-      $('#existing-course-msg').show();
-    } else {
-      $('#save-btn').show();
-      $('#save-btn').removeClass('disabled');
-      $('#existing-course-msg').hide();
-    }
-  };
-
-  addCourse = function() {
-    // Show the add a course form
-    $('#add-course-form').show();
-    // Hide the add a course button
-    $('#add-course-btn').hide();
-    // Scroll the user's page to here
-    $('#add-course-divider').ScrollTo();
-    // Put focus in first input field
-    $('#str_school').focus();
-  };
-
-  // Set up the "Add Course" button at bottom
-  // of page
-  $('#add-course-btn').click(addCourse);
-
-  // Set up the "Add Course" button in the
-  // page header
-  $('#add_course_header_button').click(addCourse);
-
-  KARMAWORLD.Course.initCourseNameAutocomplete({
-    select: function(event, ui) {
-      courseNameSelected = true;
-      fieldEdited();
-    },
-    change: function(event, ui) {
-      if (ui.item == null) {
-        courseNameSelected = false;
-        fieldEdited();
-      }
-    }
-  });
-
-  KARMAWORLD.Course.initInstructorNameAutocomplete({
-    select: function(event, ui) {
-      instructorSelected = true;
-      $('#existing-course-btn').attr('href', ui.item.url);
-      fieldEdited();
-    },
-    change: function(event, ui) {
-      if (ui.item == null) {
-        instructorSelected = false;
-        $('#existing-course-btn').attr('href', '');
-        fieldEdited();
-      }
-    }
-  });
-
-});
index 6b21186eca695008d24948f8416925855096bdef..0e2582617b99c84f274c9aa38f838672962a481d 100644 (file)
@@ -27,7 +27,7 @@
 
     <div class="row">
       <div class="small-4 large-8 columns small-centered text-center">
-        <button id="save-btn" class="disabled">
+        <button id="save-btn" type="submit">
           <i class="fa fa-save"></i> Save
         </button>
         <span id="existing-course-msg" class="hide">