Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce examples #1252

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/factories/tags.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FactoryBot.define do
factory :tag do
sequence(:name) { |n| "!#{"%06d" % n}_tag" }

transient do
project {}
end
end
end
16 changes: 1 addition & 15 deletions spec/features/card_pages/card_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

it 'should require authenticated users' do
project = create(:project)
@board = create(:board, project:, node: project.methodology_library)
@board = create(:board, project: project, node: project.methodology_library)
visit project_board_path(@board.project, @board)
expect(current_path).to eq(login_path)
expect(page).to have_content('Access denied.')
Expand All @@ -26,13 +26,6 @@
describe 'when in new page', js: true do
let(:submit_form) { click_button 'Create Card' }

describe 'textile form view' do
let(:action_path) { new_project_board_list_card_path(current_project, @board, @list) }
let(:required_form) { fill_in :card_name, with: 'New Card' }
it_behaves_like 'a textile form view', Card
it_behaves_like 'an editor that remembers what view you like'
end

describe 'submitting the form with valid information' do
before do
visit new_project_board_list_card_path(current_project, @board, @list)
Expand Down Expand Up @@ -117,13 +110,6 @@
@card = create(:card, list: @list)
end

describe 'textile form view' do
let(:action_path) { edit_project_board_list_card_path(current_project, @board, @list, @card) }
let(:item) { @card }
it_behaves_like 'a textile form view', Card
it_behaves_like 'an editor that remembers what view you like'
end

describe 'submitting the form with valid information' do
before do
visit edit_project_board_list_card_path(current_project, @board, @list, @card)
Expand Down
23 changes: 0 additions & 23 deletions spec/features/evidence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,6 @@
end
end

it 'uses the full-screen editor plugin' # TODO

it_behaves_like 'a form with a help button'

describe 'textile form view' do
let(:action_path) { edit_project_node_evidence_path(current_project, @node, @evidence) }
let(:item) { @evidence }
it_behaves_like 'a textile form view', Evidence
it_behaves_like 'an editor that remembers what view you like'
end

describe 'submitting the form with valid information', js: true do
let(:new_content) { 'new content' }
before do
Expand Down Expand Up @@ -187,14 +176,6 @@
click_link 'Source'
end

describe 'textile form view' do
let(:action_path) { new_project_node_evidence_path(current_project, @node) }
let(:params) { {} }
let(:required_form) { find('#evidence_issue_id option:nth-of-type(2)').select_option }
it_behaves_like 'a textile form view', Evidence
it_behaves_like 'an editor that remembers what view you like'
end

context 'when no template is specified' do
let(:params) { {} }

Expand All @@ -203,10 +184,6 @@
expect(textarea.value.strip).to eq ''
end

it 'uses the textile-editor plugin'

it_behaves_like 'a form with a help button'

describe 'submitting the form with valid information' do
before do
select @issue_1.title, from: :evidence_issue_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
# let(:default_columns) { ['Title', 'Created', ...] }
# let(:hidden_columns) { ['Description', 'Extra', ...] }
# let(:filter) { { keyword:'keyword', filter_count: 1 } }
shared_examples 'a DataTable' do
describe 'column visibility', js: true do
require 'rails_helper'

describe 'issue table', js: true do
subject { page }

let(:issue) { issues[0] }
let(:issues) do
[
create(
:issue,
text: "#[Title]#\nIssue1\n\n#[Risk]#\nHigh\n\n#[Description]#\nn/a",
node: current_project.issue_library
),
create(:issue, node: current_project.issue_library)
]
end

let(:tags) do
Tag::DEFAULT_TAGS.map do |tag|
create(:tag, name: tag, project: current_project)
end
end

before do
login_to_project_as_user
issues
tags
visit project_issues_path(current_project)
end

describe 'column visibility' do
let(:default_columns) { ['Title', 'Tags'] }
let(:hidden_columns) { ['Description', 'Risk'] }

it 'displays default columns on load' do
within '.dataTables_wrapper thead tr' do
default_columns.each do |column|
Expand All @@ -20,30 +49,21 @@
end

it 'can toggle column visibility by clicking on colvis button' do
if hidden_columns.present?
within '.dt-buttons.btn-group' do
page.find('.buttons-colvis').click

within '.dt-button-collection' do
click_link hidden_columns[0]
end
end
within '.dt-buttons.btn-group' do
page.find('.buttons-colvis').click

within '.dataTables_wrapper thead tr' do
expect(page).to have_text(hidden_columns[0])
within '.dt-button-collection' do
click_link hidden_columns[0]
end
end
end
end

describe 'delete button', js: true do
before do
unless page.has_css?('[data-table-destroy-url]')
# Skip this spec if table doesn't support bulk delete
skip
within '.dataTables_wrapper thead tr' do
expect(page).to have_text(hidden_columns[0])
end
end
end

describe 'delete button' do
it 'is hidden by default' do
within '.dt-buttons.btn-group' do
expect(page).to_not have_button('Delete')
Expand Down Expand Up @@ -84,14 +104,7 @@
end
end

describe 'tagging', js: true do
before do
unless page.has_css?('[data-tags]')
# Skip this spec if table doesn't support tagging
skip
end
end

describe 'tagging' do
it 'shows the tag button when an item is selected' do
within '.dataTables_wrapper' do
page.find('td.select-checkbox', match: :first).click
Expand All @@ -106,7 +119,7 @@
click_button('Tag')

within '.dt-button-collection' do
@tags.each do |tag|
tags.each do |tag|
expect(page).to have_link(tag.display_name)
end
end
Expand All @@ -120,87 +133,70 @@
click_button('Tag')

within '.dt-button-collection' do
click_link(@tags.first.display_name)
click_link(tags.first.display_name)
end
end

# Wait for the spinner to disappear
expect(page).to_not have_css('[data-behavior=spinner]')
expect(@issue.reload.tags).to include(@tags.first)
expect(issue.reload.tags).to include(tags.first)
end
end

it 'can filter rows', js: true do
within '.dataTables_filter' do
search_input = page.find('input[type=search]')
search_input.set(filter[:keyword])
end
describe 'dynamic columns' do
let(:default_columns) { ['Title', 'Tags'] }

within '.dataTable' do
expect(all('tbody tr').count).to eq(filter[:filter_count])
end
end
end

# let(:new_content) { "#[Title]#\nTitle\n\n#[New Field]#\nNew Field Value" }
# let(:old_content) { "#[Title]#\nTitle" }
# let(:resource) { Issue.take }
# let(:update_attribute) { :text }
shared_examples 'a DataTable with Dynamic Columns' do
let(:hide_default_columns) do
within '.dt-buttons.btn-group' do
page.find('.buttons-colvis').click
let(:hide_default_columns) do
within '.dt-buttons.btn-group' do
page.find('.buttons-colvis').click

within '.dt-button-collection' do
default_columns.each do |column|
click_link column
within '.dt-button-collection' do
default_columns.each do |column|
click_link column
end
end
end
end
end

let(:update_resource_with_new_content) do
resource.update_attribute(content_attribute, new_content)
end

let(:update_resource_with_old_content) do
resource.update_attribute(content_attribute, old_content)
end
context 'when new fields are added' do
it 'persists column state' do
hide_default_columns
issue.update_attribute(:text, "#[Title]#\nNew Title\n\n#[Risk]#\nHigh\n\n#[Description]#\nn/a\n\n#[New Field]#\nNew Field Value")

context 'when new columns are added', js: true do
it 'persists column state' do
hide_default_columns
update_resource_with_new_content
page.refresh

# Refresh
visit current_url

within '.dataTables_wrapper thead tr' do
expect(page).to_not have_text('Created')
expect(page).to_not have_text('Updated')
expect(page).to_not have_text('New Field')
within '.dataTables_wrapper thead tr' do
expect(page).to_not have_text('Created')
expect(page).to_not have_text('Updated')
expect(page).to_not have_text('New Field')
end
end
end
end

context 'when columns are removed', js: true do
it 'persists column state' do
hide_default_columns
update_resource_with_new_content
context 'when fields are removed' do
it 'persists column state' do
hide_default_columns
issue.update_attribute(:text, "#[Title]#\nIssue1")

# Refresh
visit current_url
page.refresh

update_resource_with_old_content
within '.dataTables_wrapper thead tr' do
expect(page).to_not have_text('Created')
expect(page).to_not have_text('Updated')
expect(page).to_not have_text('New Field')
end
end
end
end

# Refresh
visit current_url
it 'can filter rows' do
within '.dataTables_filter' do
search_input = page.find('input[type=search]')
search_input.set(issue.title)
end

within '.dataTables_wrapper thead tr' do
expect(page).to_not have_text('Created')
expect(page).to_not have_text('Updated')
expect(page).to_not have_text('New Field')
end
within '.dataTable' do
expect(all('tbody tr').count).to eq(1)
end
end
end
6 changes: 0 additions & 6 deletions spec/features/issue_pages/evidence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,5 @@
visit project_issue_path(current_project, issue)
click_link("Evidence #{issue.evidence.count}")
end

let(:default_columns) { ['Label', 'Title'] }
let(:hidden_columns) { ['Created by'] }
let(:filter) { { keyword: issue.evidence.first.title, filter_count: 1 } }

it_behaves_like 'a DataTable'
end
end
10 changes: 1 addition & 9 deletions spec/features/issue_pages/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@
expect(page).to have_content('1 issue merged into ')
end

context "merge issues into a new one", js: true do
describe 'textile form view' do
let(:action_path) { new_project_merge_path(current_project, ids: [@issue1.id, @issue2.id]) }
let(:required_form) do
choose('Merge into a new issue')
end
it_behaves_like 'a textile form view', Issue
end

context 'merge issues into a new one', js: true do
it 'creates a new issue' do
expect(page).to have_content /You're merging 2 Issues into a target Issue/i

Expand Down
42 changes: 0 additions & 42 deletions spec/features/issue_pages/table_spec.rb

This file was deleted.

Loading
Loading