Skip to content

Commit

Permalink
Add specs for stages and gates edit dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dombesz committed Dec 17, 2024
1 parent 583a2f3 commit 5ad7378
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/project/life_cycle_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Project::LifeCycleStep < ApplicationRecord
class_name: "Project::LifeCycleStepDefinition"
has_many :work_packages, inverse_of: :project_life_cycle_step, dependent: :nullify

delegate :name, to: :definition
delegate :name, :position, to: :definition

attr_readonly :definition_id, :type

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#-- 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 "../shared_context"

RSpec.describe "Edit project stages and gates on project overview page", :js, :with_cuprite,
with_flag: { stages_and_gates: true } do
include_context "with seeded projects and stages and gates"
let(:user) { create(:admin) }
let(:overview_page) { Pages::Projects::Show.new(project) }

before do
# TODO: Could this work for all feature specs?
allow(User).to receive(:current).and_return user
overview_page.visit_page
end

describe "with the dialog open" do
context "when all LifeCycleSteps are blank" do
before do
Project::LifeCycleStep.update_all(start_date: nil, end_date: nil)
end

it "shows all the Project::LifeCycleSteps without a value" do
dialog = overview_page.open_edit_dialog_for_life_cycles

dialog.expect_input("Initiating", value: "", type: :stage, position: 1)
dialog.expect_input("Ready for Planning", value: "", type: :gate, position: 2)
dialog.expect_input("Planning", value: "", type: :stage, position: 3)
dialog.expect_input("Ready for Executing", value: "", type: :gate, position: 4)
dialog.expect_input("Executing", value: "", type: :stage, position: 5)
dialog.expect_input("Ready for Closing", value: "", type: :gate, position: 6)
dialog.expect_input("Closing", value: "", type: :stage, position: 7)
end
end

context "when all LifeCycleSteps have a value" do
it "shows all the Project::LifeCycleSteps including value" do
dialog = overview_page.open_edit_dialog_for_life_cycles

project.available_life_cycle_steps.each do |step|
dialog.expect_input_for(step)
end
end
end
end
end
106 changes: 106 additions & 0 deletions spec/support/components/projects/project_life_cycles/edit_dialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -- 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/components/common/modal"
require "support/components/autocompleter/ng_select_autocomplete_helpers"
module Components
module Projects
module ProjectLifeCycles
class EditDialog < Components::Common::Modal
def dialog_css_selector
"dialog#edit-project-life-cycles-dialog"
end

def async_content_container_css_selector
"#{dialog_css_selector} [data-test-selector='async-dialog-content']"
end

def within_dialog(&)
within(dialog_css_selector, &)
end

def within_async_content(close_after_yield: false, &)
within(async_content_container_css_selector, &)
close if close_after_yield
end

def close
within_dialog do
page.find(".close-button").click
end
end
alias_method :close_via_icon, :close

def close_via_button
within(dialog_css_selector) do
click_link_or_button "Cancel"
end
end

def submit
within(dialog_css_selector) do
page.find("[data-test-selector='save-project-life-cycles-button']").click
end
end

def expect_open
expect(page).to have_css(dialog_css_selector)
end

def expect_closed
expect(page).to have_no_css(dialog_css_selector)
end

def expect_async_content_loaded
expect(page).to have_css(async_content_container_css_selector)
end

def expect_input(label, value:, type:, position:)
field = type == :stage ? :date_range : :date
expect(page).to have_field(
label,
with: value,
name: "project[available_life_cycle_steps_attributes][#{position - 1}][#{field}]"
)
end

def expect_input_for(step)
options = if step.is_a?(Project::Stage)
value = "#{step.start_date.strftime('%Y-%m-%d')} - #{step.end_date.strftime('%Y-%m-%d')}"
{ type: :stage, value: }
else
value = step.date.strftime("%Y-%m-%d")
{ type: :gate, value: }
end

expect_input(step.name, position: step.position, **options)
end
end
end
end
end
10 changes: 8 additions & 2 deletions spec/support/pages/projects/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ module Projects
class Show < ::Pages::Page
attr_reader :project

# rubocop:disable Lint/MissingSuper
def initialize(project)
@project = project
end
# rubocop:enable Lint/MissingSuper

def path
project_path(project)
Expand Down Expand Up @@ -87,6 +85,14 @@ def open_edit_dialog_for_section(section)
expect(page).to have_css("[data-test-selector='async-dialog-content']", wait: 5)
end

def open_edit_dialog_for_life_cycles
within_life_cycles_sidebar do
page.find("[data-test-selector='project-life-cycles-edit-button']").click
end

Components::Projects::ProjectLifeCycles::EditDialog.new.tap(&:expect_open)
end

def within_life_cycles_sidebar(&)
within "#project-life-cycles-sidebar" do
expect(page).to have_css("[data-test-selector='project-life-cycles-sidebar-async-content']")
Expand Down

0 comments on commit 5ad7378

Please sign in to comment.