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/support/edit_fields/edit_field.rb

233 lines
5.4 KiB

class EditField
include Capybara::DSL
include RSpec::Matchers
attr_reader :selector,
:property_name,
:context
attr_accessor :field_type
def initialize(context,
property_name,
selector: nil)
@property_name = property_name.to_s
@context = context
[31023] Preparation for project edit fields: Generalize edit and display fields currently work package specific (#7726) * Check edit fields for Work package dependencies * Make EditForm, NotificationService, EditContext indepenedent of Work Packages * Make EventsService independent of WorkPackages * Start renaming WpNotificationService (WiP) * Fix more references * Fix typescript errors * Add basic halEditingService * Rename to global halResourceEditingService (WiP) * Move typing from class to methods (WiP) * Fix typescript errors * Remove space in type * Add test project widget && generalize the editFieldGroup * Rename editing portal service [ci skip] * Rename WpEditFieldComponent * Rename WpDisplayFields * Rename display-XX-field to XX-display-field [ci skip] * Add WP specific ID field to distinguish between resources * Re-add state in work package resource * Generalize display field renderer * Rename spent-time to wp-spent-time and fix highlight specifics [ci skip] * Actually load the project schema and make field editable * Make edit-field-group.component an edit-form.component and subclass EditForm * Remove edit context in favor of specialized EditForm * Add special cases for work package editing * Fix edit actions bar * Fix codeclimate issues * Use WorkPackageNotificationService if necessary * Override NotificationService for WPs to allow WP specififc notifications (WiP) * Correctly provide wpNotification service Because the ui-router doesn't seem to correctly use the parent element's injector, we need to provide the wpNotification service not in the wp-base, but rather the wp-list component as well as in the isolated query space. * Allow to filter halEvents for specific resourceTypes (e.g. WorkPackage) * Remove superfluous cell class constant * Start renaming selectors for wp-edit-field into generics * Remove wp-table--cell-span in favor of display field selector * Consolidate other display and edit field styles * Provide specialized service for transitions in active edit forms * Remove superfluous overflowSelector * Accept that date field contains some work package specifics * Ignore unreadable files * Provide the changeset for work packages as a hook Since hal resource editing service is provided per query space, we cannot register them once (would only work globally) * Fix dangerfile * Remove another todo in halResourceNotification service * Fix npm TestBed for changed dependencies * Show inplace edit field in project details widget * Fix highlighting in single view * Provide HalResourceEditingService outside of project context * Used typedState for single-view * Also provide wpNotification service in split view * Correct check for resource type in eventsService * Fix getSchemaName in display field renderer * Fix passing ids into `halEditing.stopEditing` * Do not globally inject the halResourceEditingService There's a bug(?) in ui-router that gives you the global service before the parent injected service for a ui-view * Fix wpCreate service on copying and parallel creation * Remove test project widget * Revert changes for project details widget
5 years ago
@selector = selector || ".inline-edit--container.#{property_name}"
end
def field_container
context.find @selector
end
7 years ago
def display_selector
[31023] Preparation for project edit fields: Generalize edit and display fields currently work package specific (#7726) * Check edit fields for Work package dependencies * Make EditForm, NotificationService, EditContext indepenedent of Work Packages * Make EventsService independent of WorkPackages * Start renaming WpNotificationService (WiP) * Fix more references * Fix typescript errors * Add basic halEditingService * Rename to global halResourceEditingService (WiP) * Move typing from class to methods (WiP) * Fix typescript errors * Remove space in type * Add test project widget && generalize the editFieldGroup * Rename editing portal service [ci skip] * Rename WpEditFieldComponent * Rename WpDisplayFields * Rename display-XX-field to XX-display-field [ci skip] * Add WP specific ID field to distinguish between resources * Re-add state in work package resource * Generalize display field renderer * Rename spent-time to wp-spent-time and fix highlight specifics [ci skip] * Actually load the project schema and make field editable * Make edit-field-group.component an edit-form.component and subclass EditForm * Remove edit context in favor of specialized EditForm * Add special cases for work package editing * Fix edit actions bar * Fix codeclimate issues * Use WorkPackageNotificationService if necessary * Override NotificationService for WPs to allow WP specififc notifications (WiP) * Correctly provide wpNotification service Because the ui-router doesn't seem to correctly use the parent element's injector, we need to provide the wpNotification service not in the wp-base, but rather the wp-list component as well as in the isolated query space. * Allow to filter halEvents for specific resourceTypes (e.g. WorkPackage) * Remove superfluous cell class constant * Start renaming selectors for wp-edit-field into generics * Remove wp-table--cell-span in favor of display field selector * Consolidate other display and edit field styles * Provide specialized service for transitions in active edit forms * Remove superfluous overflowSelector * Accept that date field contains some work package specifics * Ignore unreadable files * Provide the changeset for work packages as a hook Since hal resource editing service is provided per query space, we cannot register them once (would only work globally) * Fix dangerfile * Remove another todo in halResourceNotification service * Fix npm TestBed for changed dependencies * Show inplace edit field in project details widget * Fix highlighting in single view * Provide HalResourceEditingService outside of project context * Used typedState for single-view * Also provide wpNotification service in split view * Correct check for resource type in eventsService * Fix getSchemaName in display field renderer * Fix passing ids into `halEditing.stopEditing` * Do not globally inject the halResourceEditingService There's a bug(?) in ui-router that gives you the global service before the parent injected service for a ui-view * Fix wpCreate service on copying and parallel creation * Remove test project widget * Revert changes for project details widget
5 years ago
'.inline-edit--display-field'
7 years ago
end
def display_element
context.find "#{@selector} #{display_selector}"
end
def input_element
context.find "#{@selector} #{input_selector}"
end
def clear
input_element.native.clear
end
def expect_read_only
expect(context).to have_selector "#{@selector} #{display_selector}.-read-only"
end
def expect_state_text(text)
expect(context).to have_selector(@selector, text: text)
end
alias :expect_text :expect_state_text
def expect_value(value)
expect(input_element.value).to eq(value)
end
##
# Activate the field and check it opened correctly
def activate!(expect_open: true)
retry_block do
unless active?
scroll_to_and_click(display_element)
end
if expect_open && !active?
raise "Expected field input type '#{field_type}' for attribute '#{property_name}'."
end
end
end
alias :activate_edition :activate!
def openSelectField
autocomplete_selector.click
end
def expect_state!(open:)
if open
expect_active!
else
expect_inactive!
end
end
def active?
7 years ago
@context.has_selector? "#{@selector} #{input_selector}", wait: 1
end
alias :editing? :active?
def expect_active!
7 years ago
expect(field_container)
.to have_selector(field_type, wait: 10),
"Expected field input type '#{field_type}' for attribute '#{property_name}'."
# Also ensure the element is not disabled
expect_enabled!
end
def expect_inactive!
expect(field_container).to have_selector(display_selector, wait: 10)
expect(field_container).to have_no_selector(field_type)
end
def expect_enabled!
expect(@context).to have_no_selector "#{@selector} #{input_selector}[disabled]"
end
def expect_invalid
expect(page).to have_selector("#{@selector} #{field_type}:invalid")
end
def expect_error
7 years ago
expect(page).to have_selector("#{@selector} .-error")
end
def save!
submit_by_enter
end
7 years ago
def submit_by_dashboard
field_container.find('.inplace-edit--control--save a', wait: 5).click
end
##
# Set or select the given value.
# For fields of type select, will check for an option with that value.
def set_value(content)
scroll_to_element(input_element)
if field_type.end_with?('-autocompleter')
page.find('.ng-dropdown-panel .ng-option', text: content).click
else
# A normal fill_in would cause the focus loss on the input for empty strings.
# Thus the form would be submitted.
# https://github.com/erikras/redux-form/issues/686
input_element.fill_in with: content, fill_options: { clear: :backspace }
end
end
##
# Set or select the given value.
# For fields of type select, will check for an option with that value.
def unset_value(content, multi=false)
scroll_to_element(input_element)
if field_type.end_with?('-autocompleter')
if multi
page.find('.ng-value-label', text: content).sibling('.ng-value-icon').click
else
page.find('.ng-dropdown-panel .ng-option', text: '-').click
end
else
input_element.set('')
end
end
##
# Use option of ng-select field to create new element from within the autocompleter
def set_new_value(content)
scroll_to_element(input_element)
input_element.find('input').set content
page.find('.ng-option', text: 'Create: ' + content).click
end
def type(text)
scroll_to_element(input_element)
input_element.send_keys text
end
##
# Update this attribute while retrying to open the field
# if unsuccessful at first.
def update(value, save: true, expect_failure: false)
# Retry to set attributes due to reloading the page after setting
# an attribute, which may cause an input not to open properly.
retry_block do
activate_edition
set_value value
# select fields are saved on change
save! if save && !field_type.end_with?('-autocompleter')
expect_state! open: expect_failure
end
end
def submit_by_enter
if field_type.end_with? '-autocompleter'
autocomplete_selector.send_keys :return
else
input_element.native.send_keys :return
end
end
def cancel_by_escape
if field_type.end_with? '-autocompleter'
autocomplete_selector.send_keys :escape
else
input_element.native.send_keys :escape
end
end
def editable?
7 years ago
field_container.has_selector? "#{display_selector}.-editable"
end
def input_selector
6 years ago
if property_name == 'description'
'.op-ckeditor--wrapper'
6 years ago
else
[31023] Preparation for project edit fields: Generalize edit and display fields currently work package specific (#7726) * Check edit fields for Work package dependencies * Make EditForm, NotificationService, EditContext indepenedent of Work Packages * Make EventsService independent of WorkPackages * Start renaming WpNotificationService (WiP) * Fix more references * Fix typescript errors * Add basic halEditingService * Rename to global halResourceEditingService (WiP) * Move typing from class to methods (WiP) * Fix typescript errors * Remove space in type * Add test project widget && generalize the editFieldGroup * Rename editing portal service [ci skip] * Rename WpEditFieldComponent * Rename WpDisplayFields * Rename display-XX-field to XX-display-field [ci skip] * Add WP specific ID field to distinguish between resources * Re-add state in work package resource * Generalize display field renderer * Rename spent-time to wp-spent-time and fix highlight specifics [ci skip] * Actually load the project schema and make field editable * Make edit-field-group.component an edit-form.component and subclass EditForm * Remove edit context in favor of specialized EditForm * Add special cases for work package editing * Fix edit actions bar * Fix codeclimate issues * Use WorkPackageNotificationService if necessary * Override NotificationService for WPs to allow WP specififc notifications (WiP) * Correctly provide wpNotification service Because the ui-router doesn't seem to correctly use the parent element's injector, we need to provide the wpNotification service not in the wp-base, but rather the wp-list component as well as in the isolated query space. * Allow to filter halEvents for specific resourceTypes (e.g. WorkPackage) * Remove superfluous cell class constant * Start renaming selectors for wp-edit-field into generics * Remove wp-table--cell-span in favor of display field selector * Consolidate other display and edit field styles * Provide specialized service for transitions in active edit forms * Remove superfluous overflowSelector * Accept that date field contains some work package specifics * Ignore unreadable files * Provide the changeset for work packages as a hook Since hal resource editing service is provided per query space, we cannot register them once (would only work globally) * Fix dangerfile * Remove another todo in halResourceNotification service * Fix npm TestBed for changed dependencies * Show inplace edit field in project details widget * Fix highlighting in single view * Provide HalResourceEditingService outside of project context * Used typedState for single-view * Also provide wpNotification service in split view * Correct check for resource type in eventsService * Fix getSchemaName in display field renderer * Fix passing ids into `halEditing.stopEditing` * Do not globally inject the halResourceEditingService There's a bug(?) in ui-router that gives you the global service before the parent injected service for a ui-view * Fix wpCreate service on copying and parallel creation * Remove test project widget * Revert changes for project details widget
5 years ago
'.inline-edit--field'
6 years ago
end
end
def autocomplete_selector
field_container.find('.ng-input input')
end
def field_type
@field_type ||= begin
case property_name.to_s
when 'version'
'version-autocompleter'
when 'assignee',
'responsible',
'priority',
'status',
'project',
'type',
'category'
'create-autocompleter'
else
:input
end.to_s
end
end
end