Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

3.4 KB
Raw Blame
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# 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 COPYRIGHT and LICENSE files for more details.
#++

require "support/pages/page"

module Pages
  module Admin
    module Users
      class Edit < ::Pages::Page
        attr_reader :id

        def initialize(id)
          @id = id
        end

        def path
          "/users/#{id}/edit"
        end

        def open_projects_tab!
          within(".content--tabs") do
            click_on "Projects"
          end
        end

        def add_to_project!(project_name, as:)
          open_projects_tab!
          select_project! project_name
          Array(as).each { |role| check role }
          click_on "Add"

          expect_project(project_name)
        end

        def remove_from_project!(name)
          open_projects_tab!
          find_project(name).find("a[data-method=delete]").click
        end

        def edit_roles!(membership, roles)
          find("#member-#{membership.id} .user-memberships--edit-button").click

          page.within("#member-#{membership.id}-roles-form") do
            page.all(".form--check-box").each do |f|
              f.set false
            rescue Selenium::WebDriver::Error::InvalidElementStateError
              # Happens if an element is disabled
            end
            Array(roles).each { |role| page.check role }
            page.find(".user-memberships--edit-submit-button").click
          end
        end

        def expect_project(project_name)
          expect(page).to have_css("tr", text: project_name, wait: 10)
        end

        def expect_no_membership(project_name)
          expect(page).to have_no_css("tr", text: project_name)
        end

        def expect_roles(project_name, roles)
          row = page.find("tr", text: project_name, wait: 10)

          roles.each do |role|
            expect(row).to have_css("span", text: role)
          end
        end

        def find_project(name)
          find("tr", text: name)
        end

        def has_project?(name)
          has_selector? "tr", text: name
        end

        def select_project!(project_name)
          select(project_name, from: "membership_project_id")
        end

        def activate!
          within ".PageHeader-actions" do
            click_on "Activate"
          end
        end
      end
    end
  end
end