diff options
-rw-r--r-- | features/admin/labels.feature | 39 | ||||
-rw-r--r-- | features/steps/admin/labels.rb | 117 | ||||
-rw-r--r-- | spec/features/admin/admin_labels_spec.rb | 116 |
3 files changed, 116 insertions, 156 deletions
diff --git a/features/admin/labels.feature b/features/admin/labels.feature deleted file mode 100644 index 9632c679ee1..00000000000 --- a/features/admin/labels.feature +++ /dev/null @@ -1,39 +0,0 @@ -Feature: Admin Issues Labels - Background: - Given I sign in as an admin - And I have labels: "bug", "feature", "enhancement" - Given I visit admin 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 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 delete all labels - When I delete all labels - And I visit admin labels page - Then I should see labels help message - - Scenario: I create a label with invalid color - Given I visit admin 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 admin new label page - When I submit new label 'bug' - Then I should see label exist error message diff --git a/features/steps/admin/labels.rb b/features/steps/admin/labels.rb deleted file mode 100644 index c362c98d66d..00000000000 --- a/features/steps/admin/labels.rb +++ /dev/null @@ -1,117 +0,0 @@ -class Spinach::Features::AdminIssuesLabels < Spinach::FeatureSteps - include SharedAuthentication - include SharedProject - include SharedPaths - - step 'I visit \'bug\' label edit page' do - visit edit_admin_label_path(bug_label) - end - - step 'I visit admin new label page' do - visit new_admin_label_path - end - - step 'I visit admin labels page' do - visit admin_labels_path - end - - step 'I remove label \'bug\'' do - page.within "#label_#{bug_label.id}" do - click_link 'Delete' - end - end - - step 'I have labels: "bug", "feature", "enhancement"' do - ["bug", "feature", "enhancement"].each do |title| - Label.create(title: title, label_type: Label.label_types[:global_label]) - end - end - - step 'I delete all labels' do - page.within '.global-labels' do - page.all('.fa-trash-o').each do |remove| - remove.click - sleep 0.05 - end - end - end - - step 'I should see labels help message' do - page.within '.labels' do - expect(page).to have_content 'There are no labels yet' - end - end - - step 'I submit new label \'support\'' do - visit new_admin_label_path - fill_in 'Title', with: 'support' - fill_in 'Background color', with: '#F95610' - click_button 'Save' - end - - step 'I submit new label \'bug\'' do - visit new_admin_label_path - fill_in 'Title', with: 'bug' - fill_in 'Background color', with: '#F95610' - click_button 'Save' - end - - step 'I submit new label with invalid color' do - visit new_admin_label_path - fill_in 'Title', with: 'support' - fill_in 'Background color', with: '#12' - click_button 'Save' - end - - step 'I should see 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 '.manage-labels-list' do - expect(page).to have_content 'feature' - end - end - - step 'I should see label \'bug\'' do - page.within '.manage-labels-list' do - expect(page).to have_content 'bug' - end - end - - step 'I should not see label \'bug\'' do - page.within '.manage-labels-list' do - expect(page).not_to have_content 'bug' - end - end - - step 'I should see label \'support\'' do - page.within '.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' - end - - step 'I should see label \'fix\'' do - page.within '.manage-labels-list' do - expect(page).to have_content 'fix' - end - end - - def bug_label - Label.global_labels.find_or_create_by(title: 'bug') - end -end diff --git a/spec/features/admin/admin_labels_spec.rb b/spec/features/admin/admin_labels_spec.rb new file mode 100644 index 00000000000..51bf8f9e65d --- /dev/null +++ b/spec/features/admin/admin_labels_spec.rb @@ -0,0 +1,116 @@ +require 'spec_helper' + +describe 'Admin Global Labels' do + before do + login_as :admin + end + + describe 'Listing labels' do + context 'when have labels' do + it 'shows all labels' do + create(:global_label, title: 'bug') + create(:global_label, title: 'feature') + create(:global_label, title: 'enhancement') + + visit admin_labels_path + + page.within('.global-labels') do + expect(page.all('.label-row').size).to eq(3) + expect(page).to have_content 'bug' + expect(page).to have_content 'feature' + expect(page).to have_content 'enhancement' + end + end + end + + context 'when have no labels' do + it 'shows a message' do + visit admin_labels_path + + expect(page).to have_content 'There are no labels yet' + end + end + end + + describe 'Creating labels' do + context 'with valid attributes' do + it 'creates a new label' do + visit new_admin_label_path + + fill_in 'Title', with: 'support' + fill_in 'Background color', with: '#F95610' + + click_button 'Save' + + page.within('.global-labels') do + expect(page).to have_content 'support' + end + end + end + + context 'with invalid color' do + it 'shows an error message' do + visit new_admin_label_path + + fill_in 'Title', with: 'support' + fill_in 'Background color', with: '#12' + + click_button 'Save' + + expect(page).to have_content 'Color must be a valid color code' + end + end + + context 'with title that already exists' do + it 'shows an error message' do + create(:global_label, title: 'bug') + + visit new_admin_label_path + + fill_in 'Title', with: 'bug' + fill_in 'Background color', with: '#F95610' + + click_button 'Save' + + expect(page).to have_content 'Title has already been taken' + end + end + end + + describe 'Editing labels' do + context 'with valid attributes' do + it 'updates the label' do + label = create(:global_label, title: 'bug') + + visit edit_admin_label_path(label) + + fill_in 'Title', with: 'fix' + + click_button 'Save' + + page.within('.global-labels') do + expect(page).not_to have_content 'bug' + expect(page).to have_content 'fix' + end + end + end + end + + describe 'Removing labels' do + it 'removes the label from the list' do + bug = create(:global_label, title: 'bug') + create(:global_label, title: 'enhancement') + + visit admin_labels_path + + page.within("#label_#{bug.id} .pull-right") do + click_link 'Delete' + end + + page.within('.global-labels') do + expect(page).not_to have_content 'bug' + expect(page).to have_content 'enhancement' + end + end + end +end |