From a034615025798564699c3f14768866067573eeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 9 May 2016 12:35:38 +0200 Subject: [PATCH 1/2] Add work package fields to WP pages for context Since we may have several `.wp-edit-field` locations now (e.g., subject in table and split view), we need context in the work package field. This adds a helper method to table, split, and full page to create work package fields. --- spec/support/pages/abstract_work_package.rb | 4 ++ spec/support/pages/full_work_package.rb | 4 ++ spec/support/pages/split_work_package.rb | 4 ++ spec/support/pages/work_packages_table.rb | 11 +++++- .../work_packages}/work_package_field.rb | 38 +++++++++---------- 5 files changed, 41 insertions(+), 20 deletions(-) rename spec/{features/work_packages/details/inplace_editor => support/work_packages}/work_package_field.rb (59%) diff --git a/spec/support/pages/abstract_work_package.rb b/spec/support/pages/abstract_work_package.rb index d482f68018..a4d5d829a1 100644 --- a/spec/support/pages/abstract_work_package.rb +++ b/spec/support/pages/abstract_work_package.rb @@ -41,6 +41,10 @@ module Pages visit path(tab) end + def edit_field(attribute, context) + WorkPackageField.new(context, attribute) + end + def expect_subject within(container) do expect(page).to have_content(work_package.subject) diff --git a/spec/support/pages/full_work_package.rb b/spec/support/pages/full_work_package.rb index bcf278a206..8db185fe86 100644 --- a/spec/support/pages/full_work_package.rb +++ b/spec/support/pages/full_work_package.rb @@ -31,6 +31,10 @@ require 'support/pages/abstract_work_package' module Pages class FullWorkPackage < Pages::AbstractWorkPackage + def edit_field(attribute) + super(attribute, container) + end + private def container diff --git a/spec/support/pages/split_work_package.rb b/spec/support/pages/split_work_package.rb index 8fc7550d19..73366a846d 100644 --- a/spec/support/pages/split_work_package.rb +++ b/spec/support/pages/split_work_package.rb @@ -37,6 +37,10 @@ module Pages @project = project end + def edit_field(attribute) + super(attribute, container) + end + private def container diff --git a/spec/support/pages/work_packages_table.rb b/spec/support/pages/work_packages_table.rb index 06f9882f29..c73a36adbb 100644 --- a/spec/support/pages/work_packages_table.rb +++ b/spec/support/pages/work_packages_table.rb @@ -88,11 +88,20 @@ module Pages end def edit_field(work_package, attribute) - InlineEditField.new(work_package, attribute) + context = + if work_package.nil? + table_container.find('.wp--row.-new') + else + row(work_package) + end + super(attribute, context) end private + def row_selector(work_package) + end + def path project ? project_work_packages_path(project) : work_packages_path end diff --git a/spec/features/work_packages/details/inplace_editor/work_package_field.rb b/spec/support/work_packages/work_package_field.rb similarity index 59% rename from spec/features/work_packages/details/inplace_editor/work_package_field.rb rename to spec/support/work_packages/work_package_field.rb index cfb5248ac8..1442d7852e 100644 --- a/spec/features/work_packages/details/inplace_editor/work_package_field.rb +++ b/spec/support/work_packages/work_package_field.rb @@ -4,14 +4,15 @@ class WorkPackageField attr_reader :element - def initialize(page, property_name, selector = nil) + def initialize(context, property_name, selector: nil) @property_name = property_name + @context = context if selector.nil? if property_name == :'start-date' || property_name == :'end-date' - @selector = '.work-package-field.work-packages--details--date' + @selector = '.wp-edit-field.date' else - @selector = ".work-package-field.work-packages--details--#{@property_name}" + @selector = ".wp-edit-field.#{@property_name}" end else @selector = selector @@ -19,11 +20,11 @@ class WorkPackageField ensure_page_loaded - @element = page.find(field_selector) + @element = @context.find(@selector) end def expect_state_text(text) - expect(@element).to have_selector('.inplace-edit--read-value', text: text) + expect(@element).to have_selector(trigger_link_selector, text: text) end def trigger_link @@ -31,7 +32,7 @@ class WorkPackageField end def trigger_link_selector - 'a.inplace-editing--trigger-link' + '.wp-table--cell-span' end def field_selector @@ -41,7 +42,7 @@ class WorkPackageField def activate_edition tag = element.find("#{trigger_link_selector}, #{input_selector}") - if tag.tag_name == 'a' + if tag.tag_name == 'span' tag.click end # else do nothing as the element is already in edit mode @@ -52,7 +53,8 @@ class WorkPackageField end def submit_by_click - @element.find('.inplace-edit--control--save > a', wait: 5).click + ActiveSupport::Deprecation.warn('submit_by_click is no longer available') + submit_by_enter end def submit_by_enter @@ -60,10 +62,8 @@ class WorkPackageField end def cancel_by_click - cancel_link_selector = '.inplace-edit--control--cancel a' - if @element.has_selector?(cancel_link_selector) - @element.find(cancel_link_selector).click - end + ActiveSupport::Deprecation.warn('cancel_by_click is no longer available') + cancel_by_escape end def cancel_by_escape @@ -71,11 +71,14 @@ class WorkPackageField end def editable? - trigger_link.visible? rescue false + @element['class'].include? '-editable' end def editing? - @element.find('.inplace-edit--write').visible? rescue false + @element.find(input_selector) + true + rescue + false end def errors_text @@ -91,16 +94,13 @@ class WorkPackageField extend ::Angular::DSL unless singleton_class.included_modules.include?(::Angular::DSL) ng_wait - expect(page).to have_selector('.work-packages--details--subject') + expect(page).to have_selector('.work-packages--details--title') end end private def input_selector - selector = { :'start-date' => 'date-start', - :'end-date' => 'date-end' }[@property_name] || @property_name - - "#inplace-edit--write-value--#{selector}" + '.wp-inline-edit--field' end end From cdbcf7c4396058a27dd56e4d4e71fbe71fe1b9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 9 May 2016 12:35:44 +0200 Subject: [PATCH 2/2] Fix subject-editor spec This does not yet fix the focussing tests, which rely on functionality not yet existant here. --- .../wp-edit/wp-edit-field/wp-edit-field.directive.html | 7 ++++++- .../details/inplace_editor/shared_examples.rb | 6 +----- .../details/inplace_editor/subject_editor_spec.rb | 9 +++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.html b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.html index 5594fb16ba..175fb0245d 100644 --- a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.html +++ b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.html @@ -1,5 +1,10 @@
+ ng-class="[ + vm.errorenous && '-error' || '', + vm.isEditable && '-editable' || '', + vm.active && '-active' || '', + vm.fieldName + ]">
diff --git a/spec/features/work_packages/details/inplace_editor/shared_examples.rb b/spec/features/work_packages/details/inplace_editor/shared_examples.rb index e0c521f206..21e73ee0b8 100644 --- a/spec/features/work_packages/details/inplace_editor/shared_examples.rb +++ b/spec/features/work_packages/details/inplace_editor/shared_examples.rb @@ -42,7 +42,7 @@ shared_examples 'an auth aware field' do } it 'is not editable' do - expect { field.trigger_link }.to raise_error Capybara::ElementNotFound + expect(field).not_to be_editable end end end @@ -107,10 +107,6 @@ shared_examples 'a cancellable field' do field.cancel_by_escape end - after do - field.cancel_by_click - end - it_behaves_like 'cancelling properly' end end diff --git a/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb b/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb index 87696b2e4f..daaf15698b 100644 --- a/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb +++ b/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb @@ -9,16 +9,17 @@ describe 'subject inplace editor', js: true, selenium: true do let(:project) { FactoryGirl.create :project_with_types, is_public: true } let(:property_name) { :subject } let(:property_title) { 'Subject' } - let!(:work_package) { FactoryGirl.create :work_package, project: project } + let(:work_package) { FactoryGirl.create :work_package, project: project } let(:user) { FactoryGirl.create :admin } - let(:work_packages_page) { WorkPackagesPage.new(project) } - let(:field) { WorkPackageField.new page, property_name } + let(:work_packages_page) { Pages::SplitWorkPackage.new(work_package,project) } + let(:field) { work_packages_page.edit_field(property_name) } let(:notification) { ::PageObjects::Notifications.new(page) } before do login_as(user) - work_packages_page.visit_index(work_package) + work_packages_page.visit! + work_packages_page.ensure_page_loaded end context 'in read state' do