mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
MDL-47368 Edit quiz: page should not reload so often
The approach is that we have a new JavaScript function M.mod_quiz.resource_toolbox.reorganise_edit_page which, after a ajax action, fixes up everything like page breaks, page and question numbers, that might now be wrong. We call that function instead of reloading the page. Also, there are a lot more Behat tests to verify this works correctly. AMOS BEGIN MOV [joinpages,mod_quiz],[removepagebreak,mod_quiz] MOV [splitpages,mod_quiz],[addpagebreak,mod_quiz] AMOS END
This commit is contained in:
parent
d63a81c507
commit
a69f81f0d3
25 changed files with 1842 additions and 360 deletions
|
@ -128,6 +128,22 @@ class behat_mod_quiz extends behat_question_base {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a particular question is not on a particular page of the quiz on the Edit quiz page.
|
||||
* @Given /^I should not see "(?P<question_name>(?:[^"]|\\")*)" on quiz page "(?P<page_number>\d+)"$/
|
||||
* @param string $questionname the name of the question we are looking for.
|
||||
* @param number $pagenumber the page it should be found on.
|
||||
* @return array of steps.
|
||||
*/
|
||||
public function i_should_not_see_on_quiz_page($questionname, $pagenumber) {
|
||||
$xpath = "//li[contains(., '" . $this->escape($questionname) .
|
||||
"')][./preceding-sibling::li[contains(@class, 'pagenumber')][1][contains(., 'Page " .
|
||||
$pagenumber . "')]]";
|
||||
return array(
|
||||
new Given('"' . $xpath . '" "xpath_element" should not exist'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether one question comes before another on the Edit quiz page.
|
||||
* The two questions must be on the same page.
|
||||
|
@ -153,13 +169,24 @@ class behat_mod_quiz extends behat_question_base {
|
|||
* @return array of steps.
|
||||
*/
|
||||
public function should_have_number_on_the_edit_quiz_page($questionname, $number) {
|
||||
$xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
|
||||
"')]//span[@class = 'slotnumber' and normalize-space(text()) = '" . $this->escape($number) . "']";
|
||||
$xpath = "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) .
|
||||
"')]//span[contains(@class, 'slotnumber') and normalize-space(text()) = '" . $this->escape($number) . "']";
|
||||
return array(
|
||||
new Given('"' . $xpath . '" "xpath_element" should exist'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the xpath for a partcular add/remove page-break icon.
|
||||
* @param string $addorremoves 'Add' or 'Remove'.
|
||||
* @param string $questionname the name of the question before the icon.
|
||||
* @return string the requried xpath.
|
||||
*/
|
||||
protected function get_xpath_page_break_icon_after_question($addorremoves, $questionname) {
|
||||
return "//li[contains(@class, 'slot') and contains(., '" . $this->escape($questionname) .
|
||||
"')]//a[contains(@class, 'page_split_join') and @title = '" . $addorremoves . " page break']";
|
||||
}
|
||||
|
||||
/**
|
||||
* Click the add or remove page-break icon after a particular question.
|
||||
* @When /^I click on the "(Add|Remove)" page break icon after question "(?P<question_name>(?:[^"]|\\")*)"$/
|
||||
|
@ -168,8 +195,50 @@ class behat_mod_quiz extends behat_question_base {
|
|||
* @return array of steps.
|
||||
*/
|
||||
public function i_click_on_the_page_break_icon_after_question($addorremoves, $questionname) {
|
||||
$xpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
|
||||
"')]//a[@class = 'page_split_join' and @title = '" . $addorremoves . " page break']";
|
||||
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
|
||||
return array(
|
||||
new Given('I click on "' . $xpath . '" "xpath_element"'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the add or remove page-break icon after a particular question exists.
|
||||
* @When /^the "(Add|Remove)" page break icon after question "(?P<question_name>(?:[^"]|\\")*)" should exist$/
|
||||
* @param string $addorremoves 'Add' or 'Remove'.
|
||||
* @param string $questionname the name of the question before the icon to click.
|
||||
* @return array of steps.
|
||||
*/
|
||||
public function the_page_break_icon_after_question_should_exist($addorremoves, $questionname) {
|
||||
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
|
||||
return array(
|
||||
new Given('"' . $xpath . '" "xpath_element" should exist'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the add or remove page-break icon after a particular question does not exist.
|
||||
* @When /^the "(Add|Remove)" page break icon after question "(?P<question_name>(?:[^"]|\\")*)" should not exist$/
|
||||
* @param string $addorremoves 'Add' or 'Remove'.
|
||||
* @param string $questionname the name of the question before the icon to click.
|
||||
* @return array of steps.
|
||||
*/
|
||||
public function the_page_break_icon_after_question_should_not_exist($addorremoves, $questionname) {
|
||||
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
|
||||
return array(
|
||||
new Given('"' . $xpath . '" "xpath_element" should not exist'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the add or remove page-break link after a particular question contains the given parameters in its url.
|
||||
* @When /^the "(Add|Remove)" page break link after question "(?P<question_name>(?:[^"]|\\")*) should contain:"$/
|
||||
* @param string $addorremoves 'Add' or 'Remove'.
|
||||
* @param string $questionname the name of the question before the icon to click.
|
||||
* @param TableNode $paramdata with data for checking the page break url
|
||||
* @return array of steps.
|
||||
*/
|
||||
public function the_page_break_link_after_question_should_contain($addorremoves, $questionname, $paramdata) {
|
||||
$xpath = $this->get_xpath_page_break_icon_after_question($addorremoves, $questionname);
|
||||
return array(
|
||||
new Given('I click on "' . $xpath . '" "xpath_element"'),
|
||||
);
|
||||
|
@ -210,4 +279,21 @@ class behat_mod_quiz extends behat_question_base {
|
|||
'and I drop it in "' . $destinationxpath . '" "xpath_element"'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a question on the Edit quiz page by first clicking on the Delete icon,
|
||||
* then clicking one of the "After ..." links.
|
||||
* @When /^I delete "(?P<question_name>(?:[^"]|\\")*)" in the quiz by clicking the delete icon$/
|
||||
* @param string $questionname the name of the question we are looking for.
|
||||
* @return array of steps.
|
||||
*/
|
||||
public function i_delete_question_by_clicking_the_delete_icon($questionname) {
|
||||
$slotxpath = "//li[contains(@class, ' slot ') and contains(., '" . $this->escape($questionname) .
|
||||
"')]";
|
||||
$deletexpath = "//a[contains(@class, 'editing_delete')]";
|
||||
return array(
|
||||
new Given('I click on "' . $slotxpath . $deletexpath . '" "xpath_element"'),
|
||||
new Given('I click on "Yes" "button" in the "Confirm" "dialogue"'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
118
mod/quiz/tests/behat/editing_click_delete_icon.feature
Normal file
118
mod/quiz/tests/behat/editing_click_delete_icon.feature
Normal file
|
@ -0,0 +1,118 @@
|
|||
@mod @mod_quiz
|
||||
Feature: Edit quiz page - delete
|
||||
In order to change the layout of a quiz I built
|
||||
As a teacher
|
||||
I need to be able to delete questions.
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@moodle.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | idnumber |
|
||||
| quiz | Quiz 1 | C1 | quiz1 |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Delete questions by clicking on the delete icon.
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question A |
|
||||
| Question text | Answer me |
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question B |
|
||||
| Question text | Answer again |
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question C |
|
||||
| Question text | And again |
|
||||
And I click on the "Add" page break icon after question "Question B"
|
||||
|
||||
# Confirm the starting point.
|
||||
Then I should see "Question A" on quiz page "1"
|
||||
And I should see "Question B" on quiz page "1"
|
||||
And I should see "Question C" on quiz page "2"
|
||||
And I should see "Total of marks: 3.00"
|
||||
|
||||
# Delete last question in last page. Page contains multiple questions
|
||||
When I delete "Question C" in the quiz by clicking the delete icon
|
||||
Then I should see "Question A" on quiz page "1"
|
||||
And I should see "Question B" on quiz page "1"
|
||||
And I should not see "Question C" on quiz page "2"
|
||||
And I should see "Total of marks: 2.00"
|
||||
|
||||
# Delete last question in last page. The page contains multiple questions and there are multiple pages.
|
||||
When I click on the "Add" page break icon after question "Question A"
|
||||
Then I should see "Question B" on quiz page "2"
|
||||
And the "Remove" page break icon after question "Question A" should exist
|
||||
And I delete "Question B" in the quiz by clicking the delete icon
|
||||
Then I should see "Question A" on quiz page "1"
|
||||
And I should not see "Page 2"
|
||||
And I should not see "Question B" on quiz page "2"
|
||||
And the "Remove" page break icon after question "Question A" should not exist
|
||||
And I should see "Total of marks: 1.00"
|
||||
|
||||
# Delete last remaining question in the last remaining page.
|
||||
And I delete "Question A" in the quiz by clicking the delete icon
|
||||
Then I should not see "Question A" on quiz page "1"
|
||||
And I should not see "Page 1"
|
||||
And I should see "Total of marks: 0.00"
|
||||
|
||||
@javascript @edit_quiz_delete_start
|
||||
Scenario: Delete questions from the start of the list.
|
||||
# Add more questions.
|
||||
When I add a "Description" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question A |
|
||||
| Question text | Answer A |
|
||||
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question B |
|
||||
| Question text | Answer B |
|
||||
|
||||
And I add a "Description" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question C |
|
||||
| Question text | Answer C |
|
||||
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question D |
|
||||
| Question text | Answer D |
|
||||
|
||||
And I add a "True/False" question to the "Quiz 1" quiz with:
|
||||
| Question name | Question E |
|
||||
| Question text | Answer E |
|
||||
|
||||
Then "Question A" should have number "i" on the edit quiz page
|
||||
And "Question B" should have number "1" on the edit quiz page
|
||||
And "Question C" should have number "i" on the edit quiz page
|
||||
And "Question D" should have number "2" on the edit quiz page
|
||||
And "Question E" should have number "3" on the edit quiz page
|
||||
|
||||
# Delete from first question in the last remaining page. Are the page breaks updated?
|
||||
When I delete "Question A" in the quiz by clicking the delete icon
|
||||
Then "Question B" should have number "1" on the edit quiz page
|
||||
And "Question C" should have number "i" on the edit quiz page
|
||||
And "Question D" should have number "2" on the edit quiz page
|
||||
And "Question E" should have number "3" on the edit quiz page
|
||||
|
||||
When I click on the "Add" page break icon after question "Question C"
|
||||
Then I should see "Page 1"
|
||||
And I should see "Question B" on quiz page "1"
|
||||
And I should see "Question C" on quiz page "1"
|
||||
Then I should see "Page 2"
|
||||
And I should see "Question D" on quiz page "2"
|
||||
And I should see "Question E" on quiz page "2"
|
||||
|
||||
# Test reorder of pages
|
||||
When I click on the "Add" page break icon after question "Question B"
|
||||
Then I should see "Page 1"
|
||||
And I should see "Question B" on quiz page "1"
|
||||
Then I should see "Page 2"
|
||||
And I should see "Question C" on quiz page "2"
|
||||
Then I should see "Page 3"
|
||||
And I should see "Question D" on quiz page "3"
|
||||
And I should see "Question E" on quiz page "3"
|
Loading…
Add table
Add a link
Reference in a new issue