diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-04-03 13:20:50 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-04-03 13:20:50 +0000 |
commit | a4e3b32685cff9f601773de053849a95a352dd63 (patch) | |
tree | fc16bd865332a8b86286f3c8a7a3247bff02bc6a /spec/features | |
parent | 0dcd92ba05060a488a6d0c48069c27746dde65fb (diff) | |
download | gitlab-ce-a4e3b32685cff9f601773de053849a95a352dd63.tar.gz |
Replace the `project/issues/labels.feature` spinach test with an rspec analog
Diffstat (limited to 'spec/features')
4 files changed, 188 insertions, 0 deletions
diff --git a/spec/features/projects/labels/user_creates_labels_spec.rb b/spec/features/projects/labels/user_creates_labels_spec.rb new file mode 100644 index 00000000000..9fd7f3ee775 --- /dev/null +++ b/spec/features/projects/labels/user_creates_labels_spec.rb @@ -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 diff --git a/spec/features/projects/labels/user_edits_labels_spec.rb b/spec/features/projects/labels/user_edits_labels_spec.rb new file mode 100644 index 00000000000..d1041ff5c1e --- /dev/null +++ b/spec/features/projects/labels/user_edits_labels_spec.rb @@ -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 diff --git a/spec/features/projects/labels/user_removes_labels_spec.rb b/spec/features/projects/labels/user_removes_labels_spec.rb new file mode 100644 index 00000000000..f4fda6de465 --- /dev/null +++ b/spec/features/projects/labels/user_removes_labels_spec.rb @@ -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 diff --git a/spec/features/projects/labels/user_views_labels_spec.rb b/spec/features/projects/labels/user_views_labels_spec.rb new file mode 100644 index 00000000000..0cbeca4e392 --- /dev/null +++ b/spec/features/projects/labels/user_views_labels_spec.rb @@ -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 |