fixed members/members feature (as spec)

- dropped cuke
- replaced with feature spec
- DRY'd the heck out of the cuke (shared_examples ftw?)
pull/3480/head
Markus Kahl 9 years ago
parent 5c3241ee50
commit 56e94fb01f
  1. 154
      features/members/membership.feature
  2. 127
      spec/features/members/membership_spec.rb
  3. 10
      spec/support/pages/pages.rb
  4. 14
      spec/support/pages/project/members.rb

@ -1,154 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
Feature: Membership
Background:
Given I am already admin
Given there is a role "Manager"
And there is a role "Developer"
And there is 1 project with the following:
| Identifier | project1 |
And there is 1 User with:
| Login | peter |
| Firstname | Peter |
| Lastname | Pan |
And there is 1 User with:
| Login | hannibal |
| Firstname | Hannibal |
| Lastname | Smith |
And there is 1 User with:
| Login | crash |
| Firstname | <script>alert('h4x');</script> |
| Lastname | <script>alert('h4x');</script> |
And there is a group named "A-Team" with the following members:
| peter |
| hannibal |
@javascript
Scenario: Adding and Removing a Group as Member, non impaired
When I go to the members tab of the settings page of the project "project1"
And I add the principal "A-Team" as "Manager"
Then I should be on the members tab of the settings page of the project "project1"
And I should see "Successful creation." within ".flash.notice"
And I should see "A-Team" within ".generic-table"
When I delete the "A-Team" membership
And I wait for the AJAX requests to finish
Then I should see "Nothing to display"
@javascript
Scenario: Adding and removing a User as Member, non impaired
When I go to the members tab of the settings page of the project "project1"
And I add the principal "Hannibal Smith" as "Manager"
Then I should see "Successful creation." within ".flash.notice"
And I should see "Hannibal Smith" within ".generic-table"
When I delete the "Hannibal Smith" membership
And I wait for the AJAX requests to finish
Then I should see "Nothing to display"
@javascript
Scenario: Entering a Username as Member in firstname, lastname order, non impaired
When I go to the members tab of the settings page of the project "project1"
And I enter the principal name "Hannibal S"
Then I should see "Hannibal Smith"
@javascript
Scenario: Entering a Username as Member in lastname, firstname order, non impaired
When I go to the members tab of the settings page of the project "project1"
And I enter the principal name "Smith, H"
Then I should see "Hannibal Smith"
@javascript
Scenario: Escaping should work properly when entering a name
When I go to the members tab of the settings page of the project "project1"
And I enter the principal name "script"
Then I should not see an alert dialog
And I should see "<script>alert('h4x');</script>"
@javascript
Scenario: Escaping should work properly when selecting a user
When I go to the members tab of the settings page of the project "project1"
When I select the principal "script"
Then I should not see an alert dialog
And I should see "<script>alert('h4x');</script>"
@javascript
Scenario: Adding and Removing a Group as Member, impaired
When I am impaired
And I go to the members tab of the settings page of the project "project1"
And I add the principal "A-Team" as "Manager"
And I go to the members tab of the settings page of the project "project1"
Then I should not see "A-Team" within "#principal_results"
And I should see "A-Team" within ".generic-table"
@javascript
Scenario: User should not appear in members form if he/she is already a member of the project, impaired
When I am impaired
And I go to the members tab of the settings page of the project "project1"
And I add the principal "A-Team" as "Manager"
Then I should be on the members tab of the settings page of the project "project1"
And I should see "Successful creation." within ".flash.notice"
And I should see "A-Team" within ".generic-table"
When I delete the "A-Team" membership
And I wait for the AJAX requests to finish
Then I should see "Nothing to display"
@javascript
Scenario: Entering a Username as Member in firstname, lastname order, impaired
When I am impaired
And I go to the members tab of the settings page of the project "project1"
And I enter the principal name "Hannibal S"
Then I should see "Hannibal Smith"
@javascript
Scenario: Entering a Username as Member in lastname, firstname order, impaired
When I am impaired
And I go to the members tab of the settings page of the project "project1"
And I enter the principal name "Smith, H"
Then I should see "Hannibal Smith"
@javascript
Scenario: Adding and removing a User as Member, impaired
When I am impaired
And I go to the members tab of the settings page of the project "project1"
And I add the principal "Hannibal Smith" as "Manager"
Then I should see "Successful creation." within ".flash.notice"
And I should see "Hannibal Smith" within ".generic-table"
When I delete the "Hannibal Smith" membership
And I wait for the AJAX requests to finish
Then I should see "Nothing to display"

@ -0,0 +1,127 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
feature 'group memberships through groups page', type: :feature, js: true do
let!(:project) { FactoryGirl.create :project, name: 'Project 1', identifier: 'project1' }
let(:admin) { FactoryGirl.create :admin }
let!(:peter) { FactoryGirl.create :user, firstname: 'Peter', lastname: 'Pan' }
let!(:hannibal) { FactoryGirl.create :user, firstname: 'Hannibal', lastname: 'Smith' }
let!(:crash) { FactoryGirl.create :user, firstname: "<script>alert('h4x');</script>",
lastname: "<script>alert('h4x');</script>" }
let(:group) { FactoryGirl.create :group, lastname: 'A-Team' }
let!(:manager) { FactoryGirl.create :role, name: 'Manager' }
let!(:developer) { FactoryGirl.create :role, name: 'Developer' }
let(:members_page) { Pages::Project::Members.new project.identifier }
before do
allow(User).to receive(:current).and_return admin
group.add_member! peter
group.add_member! hannibal
end
shared_examples 'adding and removing principals' do
scenario 'Adding and Removing a Group as Member' do
members_page.visit!
members_page.add_user! 'A-Team', as: 'Manager'
expect(members_page).to have_added_user 'A-Team'
members_page.remove_user! 'A-Team'
expect(page).to have_text 'Removed user from project'
expect(page).to have_text 'Nothing to display'
end
scenario 'Adding and removing a User as Member' do
members_page.visit!
members_page.add_user! 'Hannibal Smith', as: 'Manager'
expect(members_page).to have_added_user 'Hannibal Smith'
members_page.remove_user! 'Hannibal Smith'
expect(page).to have_text 'Removed user from project'
expect(page).to have_text 'Nothing to display'
end
scenario 'Entering a Username as Member in firstname, lastname order' do
members_page.visit!
members_page.open_new_member!
members_page.enter_principal_search! 'Hannibal S'
expect(page).to have_text 'Hannibal Smith'
end
scenario 'Entering a Username as Member in lastname, firstname order' do
members_page.visit!
members_page.open_new_member!
members_page.enter_principal_search! 'Smith, H'
expect(page).to have_text 'Hannibal Smith'
end
scenario 'Escaping should work properly when entering a name' do
members_page.visit!
members_page.open_new_member!
members_page.enter_principal_search! 'script'
expect(members_page).not_to have_alert_dialog
expect(page).to have_text "<script>alert('h4x');</script>"
end
end
context 'with an impaired user' do
before do
admin.impaired = true
admin.save!
end
it_behaves_like 'adding and removing principals'
end
context 'with an un-impaired user' do
it_behaves_like 'adding and removing principals'
# The following scenario is only tested with an unimpaired user
# as it does not make a difference whether or not the user is impaired.
scenario 'Escaping should work properly when selecting a user' do
members_page.visit!
members_page.open_new_member!
members_page.select_principal! 'script'
expect(members_page).not_to have_alert_dialog
expect(page).to have_text "<script>alert('h4x');</script>"
end
end
end

@ -55,6 +55,16 @@ module Pages
page.driver.browser.switch_to.alert
end
def has_alert_dialog?
if selenium_driver?
begin
page.driver.browser.switch_to.alert
rescue Selenium::WebDriver::Error::NoAlertPresentError
false
end
end
end
def selenium_driver?
Capybara.current_driver.to_s.include?('selenium')
end

@ -41,6 +41,10 @@ module Pages
"/projects/#{project_identifier}/members"
end
def open_new_member!
click_on 'Add Member'
end
##
# Adds the given user to this project.
#
@ -110,6 +114,16 @@ module Pages
find('form .roles').check role_name
end
end
def enter_principal_search!(principal_name)
if !User.current.impaired?
find('#s2id_member_user_ids')
.find('.select2-choices .select2-input')
.set(principal_name)
else
fill_in 'principal_search', with: principal_name
end
end
end
end
end

Loading…
Cancel
Save