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

replace cuke with spec

ulfertsf2f72220c165
diff --git a/modules/backlogs/features/product_owner.feature b/modules/backlogs/features/product_owner.feature
index 35166a03497..43adaacd465 100644
--- a/modules/backlogs/features/product_owner.feature
+++ b/modules/backlogs/features/product_owner.feature
@@ -90,17 +90,6 @@ Feature: Product Owner
| Story B | Sprint 001 |
And I am already logged in as "mathias"
- # TODO: add to stories_in_backlog spec
- @javascript
- Scenario: Create a new story
- When I go to the master backlog
- And I want to create a story
- And I set the backlog of the story to Product Backlog
- And I set the subject of the story to A Whole New Story
- And I create the story
- Then the 1st story in the "Product Backlog" should be "A Whole New Story"
- And all positions should be unique for each version
-
@javascript
Scenario: Move a story to the top
Given I am on the master backlog
diff --git a/modules/backlogs/spec/features/stories_in_backlog_spec.rb b/modules/backlogs/spec/features/stories_in_backlog_spec.rb
index 011db5864b6..90b8b1104ae 100644
--- a/modules/backlogs/spec/features/stories_in_backlog_spec.rb
+++ b/modules/backlogs/spec/features/stories_in_backlog_spec.rb
@@ -70,6 +70,7 @@ describe 'Stories in backlog',
type: story,
status: default_status,
version: sprint,
+ position: 1,
story_points: 10)
end
let!(:sprint_story1_task) do
@@ -92,6 +93,7 @@ describe 'Stories in backlog',
type: story,
status: default_status,
version: sprint,
+ position: 2,
story_points: 20)
end
let!(:backlog_story1) do
@@ -145,6 +147,32 @@ describe 'Stories in backlog',
backlogs_page
.expect_story_not_in_sprint(sprint_story1_task, sprint)
+ backlogs_page
+ .expect_stories_in_order(sprint, sprint_story1, sprint_story2)
+
+ # Creating a story
+
+ backlogs_page.click_in_backlog_menu(sprint, 'New Story')
+ backlogs_page.edit_new_story(subject: 'New story',
+ story_points: 10)
+
+ new_story = WorkPackage.find_by(subject: 'New story')
+
+ backlogs_page
+ .expect_story_in_sprint(new_story, sprint)
+
+ # All positions will be unique in the sprint
+ expect(Story.where(version: sprint, type: story).pluck(:position))
+ .to match_array([1,2,3])
+
+ backlogs_page
+ .expect_stories_in_order(sprint, new_story, sprint_story1, sprint_story2)
+
+ # Creating the story will update the velocity
+ backlogs_page
+ .expect_velocity(sprint_story1, 40)
+
+
# Editing in a sprint
backlogs_page
@@ -162,7 +190,7 @@ describe 'Stories in backlog',
# Updating the story_points of a story will update the velocity of the sprint
backlogs_page
- .expect_velocity(sprint_story1, 35)
+ .expect_velocity(sprint_story1, 45)
# Editing in the backlog
diff --git a/modules/backlogs/spec/support/pages/backlogs.rb b/modules/backlogs/spec/support/pages/backlogs.rb
index a8c2497f6f9..d74a54eda1b 100644
--- a/modules/backlogs/spec/support/pages/backlogs.rb
+++ b/modules/backlogs/spec/support/pages/backlogs.rb
@@ -44,7 +44,7 @@ module Pages
end
def alter_attributes_in_edit_mode(story, attributes)
- within_story(story) do
+ edit_proc = ->() do
attributes.each do |key, value|
case key
when :subject
@@ -58,18 +58,27 @@ module Pages
end
end
end
+
+ if story
+ within_story(story, &edit_proc)
+ else
+ edit_proc.call
+ end
end
def save_story_from_edit_mode(story)
- within_story(story) do
+ save_proc = -> () do
find('input[name=subject]').native.send_key :return
expect(page)
.not_to have_selector('input[name=subject]')
end
- expect(page)
- .not_to have_selector("#{story_selector(story)}.ajax_indicator")
+ if story
+ within_story(story, &save_proc)
+ else
+ save_proc.call
+ end
end
def edit_story(story, attributes)
@@ -80,14 +89,33 @@ module Pages
save_story_from_edit_mode(story)
end
+ def edit_new_story(attributes)
+ within('.story.editing') do
+ alter_attributes_in_edit_mode(nil, attributes)
+
+ save_story_from_edit_mode(nil)
+ end
+ end
+
+ def click_in_backlog_menu(backlog, item_name)
+ within_backlog(backlog) do
+ find('.header .menu-trigger').click
+ find('.header .menu .item', text: item_name).click
+ end
+ end
+
def expect_story_in_sprint(story, sprint)
- expect(page)
- .to have_selector("#backlog_#{sprint.id} #{story_selector(story)}")
+ within_backlog(sprint) do
+ expect(page)
+ .to have_selector("#{story_selector(story)}")
+ end
end
def expect_story_not_in_sprint(story, sprint)
- expect(page)
- .not_to have_selector("#backlog_#{sprint.id} #{story_selector(story)}")
+ within_backlog(sprint) do
+ expect(page)
+ .not_to have_selector("#{story_selector(story)}")
+ end
end
def expect_for_story(story, attributes)
@@ -126,6 +154,16 @@ module Pages
.to have_selector("#backlog_#{backlog.id} .velocity", text: velocity.to_s)
end
+ def expect_stories_in_order(backlog, *stories)
+ within_backlog(backlog) do
+ ids = stories.map { |s| "story_#{s.id}" }
+ existing_ids_in_order = all(ids.map { |id| "##{id}" }.join(', ')).map { |element| element[:id] }
+
+ expect(existing_ids_in_order)
+ .to eql(ids)
+ end
+ end
+
def path
backlogs_project_backlogs_path(project)
end
@@ -136,6 +174,10 @@ module Pages
within(story_selector(story), &block)
end
+ def within_backlog(backlog, &block)
+ within("#backlog_#{backlog.id}", &block)
+ end
+
def story_selector(story)
"#story_#{story.id}"
end