OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/features/work_packages/details/activity_comments_spec.rb

171 lines
5.7 KiB

require 'spec_helper'
require 'features/work_packages/shared_contexts'
require 'features/work_packages/details/inplace_editor/shared_examples'
describe 'activity comments', js: true, selenium: true do
let(:project) { FactoryGirl.create :project, is_public: true }
let!(:work_package) {
FactoryGirl.create(:work_package,
project: project,
journal_notes: initial_comment)
}
let(:wp_page) { Pages::SplitWorkPackage.new(work_package, project) }
let(:selector) { '.work-packages--activity--add-comment' }
let(:comment_field) {
WorkPackageTextAreaField.new wp_page,
'comment',
selector: selector,
trigger: '.inplace-editing--trigger-container'
}
let(:initial_comment) { 'the first comment in this WP' }
before do
login_as(user)
allow(user.pref).to receive(:warn_on_leaving_unsaved?).and_return(false)
end
context 'with permission' do
let(:user) { FactoryGirl.create :admin }
before do
wp_page.visit!
wp_page.ensure_page_loaded
end
context 'in edit state' do
before do
comment_field.activate!
end
describe 'editing' do
it 'buttons are disabled when empty' do
expect(page).to have_selector("#{selector} .inplace-edit--control--save[disabled]")
comment_field.cancel_by_click
end
end
describe 'submitting comment' do
it 'does not submit with enter' do
comment_field.input_element.set 'this is a comment'
comment_field.submit_by_enter
expect(page).to_not have_selector('.user-comment .message', text: 'this is a comment')
end
it 'submits with click' do
comment_field.input_element.set 'this is a comment!1'
comment_field.submit_by_click
expect(page).to have_selector('.user-comment .message', text: 'this is a comment!1')
end
it 'submits comments repeatedly' do
comment_field.input_element.set 'this is my first comment!1'
comment_field.submit_by_click
expect(page).to have_selector('.user-comment > .message', count: 2)
expect(page).to have_selector('.user-comment > .message',
text: 'this is my first comment!1')
expect(comment_field.editing?).to be false
comment_field.activate!
expect(comment_field.editing?).to be true
comment_field.input_element.set 'this is my second comment!1'
comment_field.submit_by_click
expect(page).to have_selector('.user-comment > .message', count: 3)
expect(page).to have_selector('.user-comment > .message',
text: 'this is my second comment!1')
end
end
describe 'cancel comment' do
it do
expect(comment_field.editing?).to be true
comment_field.input_element.set 'this is a comment'
comment_field.cancel_by_escape
expect(comment_field.editing?).to be false
expect(page).to_not have_selector('.user-comment .message', text: 'this is a comment')
comment_field.activate!
expect(comment_field.editing?).to be true
comment_field.input_element.set 'this is a comment'
comment_field.cancel_by_click
expect(comment_field.editing?).to be false
expect(page).to_not have_selector('.user-comment .message', text: 'this is a comment')
end
end
describe 'preview' do
it 'previews the comment' do
comment_field.input_element.set '*Highlight*'
preview = comment_field.element.find('.jstb_preview')
# Enable preview
preview.click
expect(comment_field.element).to have_selector('strong', text: 'Highlight')
# Disable preview
preview.click
expect(comment_field.element).to have_no_selector('strong')
9 years ago
comment_field.submit_by_click
expect(page).to have_selector('.user-comment .message', text: 'Highlight')
end
end
describe 'autocomplete' do
let!(:wp2) { FactoryGirl.create(:work_package, project: project, subject: 'AutoFoo') }
it 'autocompletes the other work package' do
comment_field.input_element.send_keys("##{wp2.id}")
expect(page).to have_selector('.atwho-view-ul li', text: wp2.to_s.strip)
end
end
describe 'quoting' do
it 'can quote a previous comment' do
expect(page).to have_selector('.user-comment .message',
text: initial_comment)
# Hover comment
page.find('.user-comment > .message').hover
# Quote this comment
page.find('.comments-icons .icon-quote').click
expect(comment_field.editing?).to be true
# Add our comment
quote = comment_field.input_element[:value]
expect(quote).to include("> #{initial_comment}")
quote << "\nthis is some remark under a quote"
comment_field.input_element.set(quote)
comment_field.submit_by_click
expect(page).to have_selector('.user-comment > .message', count: 2)
expect(page).to have_selector('.user-comment > .message blockquote')
end
end
end
end
context 'with no permission' do
let(:user) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) }
let(:role) { FactoryGirl.create :role, permissions: %i(view_work_packages) }
before do
wp_page.visit!
wp_page.ensure_page_loaded
end
it 'does not show the field' do
expect(page).to have_no_selector(selector, visible: true)
end
end
end