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

4.3 KB
Raw Blame
#-- 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 "spec_helper"

require_relative "../../support/pages/my/page"

RSpec.describe "Accountable widget on my page",
               :js,
               :selenium do
  let!(:type) { create(:type) }
  let!(:priority) { create(:default_priority) }
  let!(:project) { create(:project, types: [type]) }
  let!(:other_project) { create(:project, types: [type]) }
  let!(:open_status) { create(:default_status) }
  let!(:accountable_work_package) do
    create(:work_package,
           project:,
           type:,
           author: user,
           responsible: user)
  end
  let!(:accountable_by_other_work_package) do
    create(:work_package,
           project:,
           type:,
           author: user,
           responsible: other_user)
  end
  let!(:accountable_but_invisible_work_package) do
    create(:work_package,
           project: other_project,
           type:,
           author: user,
           responsible: user)
  end
  let(:other_user) do
    create(:user)
  end

  let(:role) { create(:project_role, permissions: %i[view_work_packages add_work_packages save_queries]) }

  let(:user) do
    create(:user,
           member_with_roles: { project => role })
  end
  let(:my_page) do
    Pages::My::Page.new
  end

  before do
    login_as user

    my_page.visit!
  end

  it "can add the widget and see the work packages the user is accountable for" do
    # Added to ensure the page has finished loading.
    # The page starts with a "wp created widget".
    created_area = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(2)")
    expect(created_area.area)
      .to have_css(".subject", text: accountable_work_package.subject)

    # Add widget below existing widgets
    my_page.add_widget(2, 2, :row, "Work packages I am accountable for")

    # Actually there are two success messages displayed currently. One for the grid getting updated and one
    # for the query assigned to the new widget being created. A user will not notice it but the automated
    # browser can get confused. Therefore we wait.
    sleep(1)

    my_page.expect_and_dismiss_toaster message: I18n.t("js.notice_successful_update")

    accountable_area = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(3)")

    accountable_area.expect_to_span(2, 2, 3, 3)

    assigned_area = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(1)")
    assigned_area.remove

    my_page.expect_and_dismiss_toaster message: I18n.t("js.notice_successful_update")

    created_area = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(1)")
    created_area.expect_to_span(1, 1, 2, 2)
    # as the assigned widget was removed, the numbers have changed
    accountable_area = Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(2)")
    accountable_area.expect_to_span(2, 1, 3, 2)

    expect(accountable_area.area)
      .to have_css(".subject", text: accountable_work_package.subject)

    expect(accountable_area.area)
      .to have_no_css(".subject", text: accountable_by_other_work_package.subject)

    expect(accountable_area.area)
      .to have_no_css(".subject", text: accountable_but_invisible_work_package.subject)
  end
end