MDL-57455 mod_data: extended Behat test to cover searching names
[moodle.git] / mod / data / tests / behat / view_entries.feature
CommitLineData
a0f59af8
DM
1@mod @mod_data
2Feature: Users can view and search database entries
3 In order to find the database entries that I am looking for
4 As a user
5 I need to list and search the database entries
6
0f09368c 7 Background:
a0f59af8 8 Given the following "users" exist:
0f09368c
MN
9 | username | firstname | lastname | email |
10 | student1 | Bob | 1 | student1@example.com |
11 | student2 | Alice | 2 | student2@example.com |
12 | teacher1 | Teacher | 1 | teacher1@example.com |
13 And the following "tags" exist:
14 | name | isstandard |
15 | Tag1 | 1 |
a0f59af8
DM
16 And the following "courses" exist:
17 | fullname | shortname | category |
0f09368c 18 | Course 1 | C1 | 0 |
a0f59af8 19 And the following "course enrolments" exist:
0f09368c
MN
20 | user | course | role |
21 | teacher1 | C1 | editingteacher |
22 | student1 | C1 | student |
23 | student2 | C1 | student |
a0f59af8 24 And the following "activities" exist:
0f09368c
MN
25 | activity | name | intro | course | idnumber |
26 | data | Test database name | Database intro | C1 | data1 |
a0f59af8 27 And I log in as "teacher1"
fdeeaff9 28 And I am on "Course 1" course homepage
a0f59af8 29 And I add a "Text input" field to "Test database name" database and I fill the form with:
0f09368c 30 | Field name | Test field name |
a0f59af8 31 | Field description | Test field description |
0f09368c
MN
32 And I add a "Text input" field to "Test database name" database and I fill the form with:
33 | Field name | Test field 2 name |
34 | Field description | Test field 2 description |
a0f59af8
DM
35 # To generate the default templates.
36 And I follow "Templates"
0f09368c
MN
37 And I log out
38
39 Scenario: Students can add view, list and search entries
40 Given I log in as "student1"
41 And I am on "Course 1" course homepage
42 And I follow "Test database name"
a0f59af8 43 And I add an entry to "Test database name" database with:
0f09368c 44 | Test field name | Student entry 1 |
a0f59af8
DM
45 And I press "Save and add another"
46 And I add an entry to "Test database name" database with:
0f09368c 47 | Test field name | Student entry 2 |
a0f59af8
DM
48 And I press "Save and add another"
49 And I add an entry to "Test database name" database with:
0f09368c 50 | Test field name | Student entry 3 |
a0f59af8 51 And I press "Save and view"
a0f59af8 52 And I follow "Test database name"
0f09368c
MN
53 Then I should see "Student entry 1"
54 And I should see "Student entry 2"
55 And I should see "Student entry 3"
a0f59af8 56 And I follow "View single"
0f09368c
MN
57 And I should see "Student entry 1"
58 And I should not see "Student entry 2"
a0f59af8
DM
59 And "2" "link" should exist
60 And "3" "link" should exist
61 And I follow "Next"
0f09368c
MN
62 And I should see "Student entry 2"
63 And I should not see "Student entry 1"
ba5c5083 64 And I click on "3" "link" in the "region-main" "region"
0f09368c
MN
65 And I should see "Student entry 3"
66 And I should not see "Student entry 2"
a0f59af8 67 And I follow "Previous"
0f09368c
MN
68 And I should see "Student entry 2"
69 And I should not see "Student entry 1"
70 And I should not see "Student entry 3"
a0f59af8 71 And I follow "Search"
0f09368c 72 And I set the field "Test field name" to "Student entry 1"
a0f59af8 73 And I press "Save settings"
0f09368c
MN
74 And I should see "Student entry 1"
75 And I should not see "Student entry 2"
76 And I should not see "Student entry 3"
a0f59af8 77 And I follow "Search"
0f09368c 78 And I set the field "Test field name" to "Student entry"
a0f59af8
DM
79 And I set the field "Order" to "Descending"
80 And I press "Save settings"
0f09368c
MN
81 And "Student entry 3" "text" should appear before "Student entry 2" "text"
82 And "Student entry 2" "text" should appear before "Student entry 1" "text"
83
84 @javascript
85 Scenario: Check that searching by tags works as expected
86 Given I log in as "student1"
87 And I am on "Course 1" course homepage
88 And I add an entry to "Test database name" database with:
89 | Test field name | Student original entry untagged |
90 | Test field 2 name | Student original entry untagged 2 |
91 And I add an entry to "Test database name" database with:
92 | Test field name | Student original entry tagged |
93 | Test field 2 name | Student original entry tagged 2 |
94 And I set the field with xpath "//div[@class='datatagcontrol']//input[@type='text']" to "Tag1"
95 And I click on "[data-value='Tag1']" "css_element"
96 And I press "Save and view"
97 And I should see "Student original entry"
98 And I should see "Tag1" in the "div.tag_list" "css_element"
99 And I follow "Edit"
100 And I should see "Tag1" in the ".form-autocomplete-selection" "css_element"
101 And I follow "View list"
102 And I should see "Tag1" in the "div.tag_list" "css_element"
103 And I follow "Search"
104 And I set the field with xpath "//div[@class='datatagcontrol']//input[@type='text']" to "Tag1"
105 And I click on "[data-value='Tag1']" "css_element"
106 When I press "Save settings"
107 Then I should see "Student original entry tagged"
108 And I should see "Student original entry tagged 2"
109 And I should not see "Student original entry untagged"
110 And I should not see "Student original entry untagged 2"
111
112 Scenario: Check that searching by first and last name works as expected
113 Given I log in as "student1"
114 And I am on "Course 1" course homepage
115 And I add an entry to "Test database name" database with:
116 | Test field name | Student entry 1 |
117 And I press "Save and view"
118 And I log out
119 And I log in as "student2"
120 And I am on "Course 1" course homepage
121 And I add an entry to "Test database name" database with:
122 | Test field name | Student entry 2 |
123 And I press "Save and view"
124 And I log out
125 When I log in as "teacher1"
126 And I am on "Course 1" course homepage
127 And I follow "Test database name"
128 And I follow "Search"
129 And I set the field "Author first name" to "Bob"
130 And I press "Save settings"
131 Then I should see "Student entry 1"
132 And I should not see "Student entry 2"
133 And I set the field "Author first name" to ""
134 And I set the field "Author surname" to "2"
135 And I press "Save settings"
136 And I should not see "Student entry 1"
137 And I should see "Student entry 2"