Replace the project/issues/labels.feature spinach test with an rspec analog

This commit is contained in:
blackst0ne 2018-04-03 13:20:50 +00:00 committed by Rémy Coutable
parent 0dcd92ba05
commit a4e3b32685
8 changed files with 193 additions and 154 deletions

View file

@ -0,0 +1,5 @@
---
title: Replace the `project/issues/labels.feature` spinach test with an rspec analog
merge_request: 18126
author: blackst0ne
type: other

View file

@ -1,48 +0,0 @@
@project_issues
Feature: Project Issues Labels
Background:
Given I sign in as a user
And I own project "Shop"
And project "Shop" has labels: "bug", "feature", "enhancement"
Given I visit project "Shop" labels page
Scenario: I should see labels list
Then I should see label 'bug'
And I should see label 'feature'
Scenario: I create new label
Given I visit project "Shop" new label page
When I submit new label 'support'
Then I should see label 'support'
Scenario: I edit label
Given I visit 'bug' label edit page
When I change label 'bug' to 'fix'
Then I should not see label 'bug'
Then I should see label 'fix'
Scenario: I remove label
When I remove label 'bug'
Then I should not see label 'bug'
@javascript
Scenario: I remove all labels
When I delete all labels
Then I should see labels help message
Scenario: I create a label with invalid color
Given I visit project "Shop" new label page
When I submit new label with invalid color
Then I should see label color error message
Scenario: I create a label that already exists
Given I visit project "Shop" new label page
When I submit new label 'bug'
Then I should see label label exist error message
Scenario: I create the same label on another project
Given I own project "Forum"
And I visit project "Forum" labels page
And I visit project "Forum" new label page
When I submit new label 'bug'
Then I should see label 'bug'

View file

@ -1,101 +0,0 @@
class Spinach::Features::ProjectIssuesLabels < Spinach::FeatureSteps
include SharedAuthentication
include SharedProject
include SharedPaths
step 'I visit \'bug\' label edit page' do
visit edit_project_label_path(project, bug_label)
end
step 'I remove label \'bug\'' do
page.within "#project_label_#{bug_label.id}" do
first(:link, 'Delete').click
end
end
step 'I delete all labels' do
page.within '.labels' do
page.all('.label-list-item').each do
first('.remove-row').click
first(:link, 'Delete label').click
end
end
end
step 'I should see labels help message' do
page.within '.labels' do
expect(page).to have_content 'Generate a default set of labels'
expect(page).to have_content 'New label'
end
end
step 'I submit new label \'support\'' do
fill_in 'Title', with: 'support'
fill_in 'Background color', with: '#F95610'
click_button 'Create label'
end
step 'I submit new label \'bug\'' do
fill_in 'Title', with: 'bug'
fill_in 'Background color', with: '#F95610'
click_button 'Create label'
end
step 'I submit new label with invalid color' do
fill_in 'Title', with: 'support'
fill_in 'Background color', with: '#12'
click_button 'Create label'
end
step 'I should see label label exist error message' do
page.within '.label-form' do
expect(page).to have_content 'Title has already been taken'
end
end
step 'I should see label color error message' do
page.within '.label-form' do
expect(page).to have_content 'Color must be a valid color code'
end
end
step 'I should see label \'feature\'' do
page.within '.other-labels .manage-labels-list' do
expect(page).to have_content 'feature'
end
end
step 'I should see label \'bug\'' do
page.within '.other-labels .manage-labels-list' do
expect(page).to have_content 'bug'
end
end
step 'I should not see label \'bug\'' do
page.within '.other-labels .manage-labels-list' do
expect(page).not_to have_content 'bug'
end
end
step 'I should see label \'support\'' do
page.within '.other-labels .manage-labels-list' do
expect(page).to have_content 'support'
end
end
step 'I change label \'bug\' to \'fix\'' do
fill_in 'Title', with: 'fix'
fill_in 'Background color', with: '#F15610'
click_button 'Save changes'
end
step 'I should see label \'fix\'' do
page.within '.other-labels .manage-labels-list' do
expect(page).to have_content 'fix'
end
end
def bug_label
project.labels.find_or_create_by(title: 'bug')
end
end

View file

@ -336,11 +336,6 @@ module SharedPaths
visit project_issue_path(issue.project, issue)
end
step 'I visit project "Shop" labels page' do
project = Project.find_by(name: 'Shop')
visit project_labels_path(project)
end
step 'I visit project "Forum" labels page' do
project = Project.find_by(name: 'Forum')
visit project_labels_path(project)

View file

@ -0,0 +1,88 @@
require "spec_helper"
describe "User creates labels" do
set(:project) { create(:project_empty_repo, :public) }
set(:user) { create(:user) }
shared_examples_for "label creation" do
it "creates new label" do
title = "bug"
create_label(title)
page.within(".other-labels .manage-labels-list") do
expect(page).to have_content(title)
end
end
end
context "in project" do
before do
project.add_master(user)
sign_in(user)
visit(new_project_label_path(project))
end
context "when data is valid" do
include_examples "label creation"
end
context "when data is invalid" do
context "when title is invalid" do
it "shows error message" do
create_label("")
page.within(".label-form") do
expect(page).to have_content("Title can't be blank")
end
end
end
context "when color is invalid" do
it "shows error message" do
create_label("feature", "#12")
page.within(".label-form") do
expect(page).to have_content("Color must be a valid color code")
end
end
end
end
context "when label already exists" do
let!(:label) { create(:label, project: project) }
it "shows error message" do
create_label(label.title)
page.within(".label-form") do
expect(page).to have_content("Title has already been taken")
end
end
end
end
context "in another project" do
set(:another_project) { create(:project_empty_repo, :public) }
before do
create(:label, project: project, title: "bug") # Create label for `project` (not `another_project`) project.
another_project.add_master(user)
sign_in(user)
visit(new_project_label_path(another_project))
end
include_examples "label creation"
end
private
def create_label(title, color = "#F95610")
fill_in("Title", with: title)
fill_in("Background color", with: color)
click_button("Create label")
end
end

View file

@ -0,0 +1,25 @@
require "spec_helper"
describe "User edits labels" do
set(:project) { create(:project_empty_repo, :public) }
set(:label) { create(:label, project: project) }
set(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
visit(edit_project_label_path(project, label))
end
it "updates label's title" do
new_title = "fix"
fill_in("Title", with: new_title)
click_button("Save changes")
page.within(".other-labels .manage-labels-list") do
expect(page).to have_content(new_title).and have_no_content(label.title)
end
end
end

View file

@ -0,0 +1,52 @@
require "spec_helper"
describe "User removes labels" do
let(:project) { create(:project_empty_repo, :public) }
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
end
context "when one label" do
let!(:label) { create(:label, project: project) }
before do
visit(project_labels_path(project))
end
it "removes label" do
page.within(".labels") do
page.first(".label-list-item") do
first(".remove-row").click
first(:link, "Delete label").click
end
end
expect(page).to have_content("Label was removed").and have_no_content(label.title)
end
end
context "when many labels", :js do
before do
create_list(:label, 3, project: project)
visit(project_labels_path(project))
end
it "removes all labels" do
page.within(".labels") do
loop do
li = page.first(".label-list-item")
break unless li
li.click_link("Delete")
click_link("Delete label")
end
expect(page).to have_content("Generate a default set of labels").and have_content("New label")
end
end
end
end

View file

@ -0,0 +1,23 @@
require "spec_helper"
describe "User views labels" do
set(:project) { create(:project_empty_repo, :public) }
set(:user) { create(:user) }
LABEL_TITLES = %w[bug enhancement feature].freeze
before do
LABEL_TITLES.each { |title| create(:label, project: project, title: title) }
project.add_guest(user)
sign_in(user)
visit(project_labels_path(project))
end
it "shows all labels" do
page.within('.other-labels .manage-labels-list') do
LABEL_TITLES.each { |title| expect(page).to have_content(title) }
end
end
end