Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix drag & drop spec by using firefox

Oliver Günther94d696acb2d1
diff --git a/app/assets/stylesheets/vendor/_select2.scss b/app/assets/stylesheets/vendor/_select2.scss
index d5da01bf998..66253cdc91b 100644
--- a/app/assets/stylesheets/vendor/_select2.scss
+++ b/app/assets/stylesheets/vendor/_select2.scss
@@ -238,12 +238,6 @@ $se2-width: 100%;
}
}
-.select2-modal-content {
- .select2-container {
- max-width: calc(100% - 45px);
- }
-}
-
// MOVE SEARCHFIELD INSIDE SELECTFIELD (overwrites)
$se2-element-height: 34px;
$se2-button-width: 32px;
diff --git a/frontend/src/app/components/wp-table/configuration-modal/tabs/columns-tab.component.html b/frontend/src/app/components/wp-table/configuration-modal/tabs/columns-tab.component.html
index d5ab31b62b4..2cd84803670 100644
--- a/frontend/src/app/components/wp-table/configuration-modal/tabs/columns-tab.component.html
+++ b/frontend/src/app/components/wp-table/configuration-modal/tabs/columns-tab.component.html
@@ -1,4 +1,4 @@
-<div class="columns-modal--content select2-modal-content">
+<div class="columns-modal--content">
<label
[textContent]="text.selectedColumns"
class="hidden-for-sighted">
@@ -9,13 +9,7 @@
(onChange)="updateSelected($event)">
</draggable-autocompleter>
- <ng-container>
- <input #select2Columns
- type="hidden" />
- <div>
- <p class="form--inline-instructions" [textContent]="text.columnsHelp"></p>
- </div>
- </ng-container>
+ <p class="form--inline-instructions" [textContent]="text.columnsHelp"></p>
</div>
<enterprise-banner class="ee-relation-columns-upsale"
diff --git a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.html b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.html
index 2942842af23..d589e6fc13e 100644
--- a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.html
+++ b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.html
@@ -1,13 +1,8 @@
<div class="draggable-autocomplete--container">
- <div cdkDropList
- class="draggable-autocomplete--selected"
- cdkDropListOrientation="horizontal"
- (cdkDropListDropped)="onItemMoved($event)">
- <div class="draggable-autocomplete--item"
- cdkDrag
- (cdkDragStarted)="startDragging($event)"
- (cdkDragEnded)="stopDragging($event)"
- *ngFor="let item of selected">
+ <div class="draggable-autocomplete--selected"
+ dragula="columns"
+ [(dragulaModel)]="selected">
+ <div class="draggable-autocomplete--item" *ngFor="let item of selected">
<span class="draggable-autocomplete--item-text"
[textContent]="item.name"></span>
<a (click)="remove(item)"
diff --git a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.sass b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.sass
index c945f07ead0..1cb8c466d5e 100644
--- a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.sass
+++ b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.sass
@@ -1,13 +1,15 @@
.draggable-autocomplete--selected
display: flex
+ flex-wrap: wrap
padding-bottom: 1rem
.draggable-autocomplete--item
padding: 5px
margin-right: 5px
+ margin-bottom: 5px
min-width: 50px
border: 1px solid #ddd
- background: #eee
+ background: #F8F8F8
cursor: move
font-size: 14px
display: flex
diff --git a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.ts b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.ts
index 36d4e71b4bc..69cd2b0bb8f 100644
--- a/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.ts
+++ b/frontend/src/app/modules/common/draggable-autocomplete/draggable-autocomplete.component.ts
@@ -1,7 +1,19 @@
-import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewChild} from "@angular/core";
+import {
+ AfterViewInit,
+ ChangeDetectionStrategy,
+ Component,
+ EventEmitter,
+ Input,
+ OnInit,
+ Output,
+ ViewChild
+} from "@angular/core";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {NgSelectComponent} from "@ng-select/ng-select";
-import {CdkDragDrop, CdkDragEnd, CdkDragStart, moveItemInArray} from "@angular/cdk/drag-drop";
+import {DragulaService, Group} from "ng2-dragula";
+import {DomAutoscrollService} from "core-app/modules/common/drag-and-drop/dom-autoscroll.service";
+import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";
+import {merge} from "rxjs";
import {DomHelpers} from "core-app/helpers/dom/set-window-cursor.helper";
export interface DraggableOption {
@@ -15,10 +27,13 @@ export interface DraggableOption {
styleUrls: ['./draggable-autocomplete.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush
})
-export class DraggableAutocompleteComponent implements OnInit {
+export class DraggableAutocompleteComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
/** Options to show in the autocompleter */
@Input() options:DraggableOption[];
+ /** Should we focus the autocompleter ? */
+ @Input() autofocus:boolean = true;
+
/** Order list of selected items */
@Input('selected') _selected:DraggableOption[] = [];
@@ -28,17 +43,65 @@ export class DraggableAutocompleteComponent implements OnInit {
/** List of items still available for selection */
availableOptions:DraggableOption[] = [];
+ private autoscroll:any;
+ private columnsGroup:Group;
+
@ViewChild('ngSelectComponent') public ngSelectComponent:NgSelectComponent;
text = {
placeholder: this.I18n.t('js.label_add_columns')
};
- constructor(readonly I18n:I18nService) {
+ constructor(readonly I18n:I18nService,
+ readonly dragula:DragulaService) {
+ super();
}
ngOnInit():void {
this.updateAvailableOptions();
+
+ // Setup groups
+ this.columnsGroup = this.dragula.createGroup('columns', {});
+
+ // Set cursor when dragging
+ this.dragula.drag('columns')
+ .pipe(this.untilDestroyed())
+ .subscribe(() => DomHelpers.setBodyCursor('move', 'important'));
+
+ // Reset cursor when cancel or dropped
+ merge(
+ this.dragula.drop("columns"),
+ this.dragula.cancel("columns")
+ )
+ .pipe(this.untilDestroyed())
+ .subscribe(() => DomHelpers.setBodyCursor('auto'));
+
+ // Setup autoscroll
+ const that = this;
+ this.autoscroll = new DomAutoscrollService(
+ [
+ document.getElementById('content-wrapper')!
+ ],
+ {
+ margin: 25,
+ maxSpeed: 10,
+ scrollWhenOutside: true,
+ autoScroll: function (this:any) {
+ return this.down && that.columnsGroup.drake.dragging;
+ }
+ });
+ }
+
+ ngAfterViewInit():void {
+ if (this.autofocus) {
+ this.ngSelectComponent.focus();
+ }
+ }
+
+ ngOnDestroy():void {
+ super.ngOnDestroy();
+
+ this.dragula.destroy('columns');
}
select(item:DraggableOption|undefined) {
@@ -78,19 +141,6 @@ export class DraggableAutocompleteComponent implements OnInit {
}, 25);
}
- onItemMoved(event:CdkDragDrop<DraggableOption[]>) {
- moveItemInArray(this.selected, event.previousIndex, event.currentIndex);
- }
-
-
- startDragging($event:CdkDragStart) {
- DomHelpers.setBodyCursor('move', 'important');
- }
-
- stopDragging($event:CdkDragEnd) {
- DomHelpers.setBodyCursor('auto');
- }
-
private updateAvailableOptions() {
this.availableOptions = this.options
.filter(item => !this.selected.find(selected => selected.id === item.id));
diff --git a/frontend/src/app/modules/common/openproject-common.module.ts b/frontend/src/app/modules/common/openproject-common.module.ts
index 1b744edc8d0..6626c1a60a1 100644
--- a/frontend/src/app/modules/common/openproject-common.module.ts
+++ b/frontend/src/app/modules/common/openproject-common.module.ts
@@ -84,6 +84,7 @@ import {CurrentUserService} from "core-components/user/current-user.service";
import {WorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/wp-autocompleter.component";
import {TimeEntryWorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/te-work-package-autocompleter.component";
import {DraggableAutocompleteComponent} from "core-app/modules/common/draggable-autocomplete/draggable-autocomplete.component";
+import {DragulaModule} from "ng2-dragula";
export function bootstrapModule(injector:Injector) {
// Ensure error reporter is run
@@ -122,6 +123,7 @@ export function bootstrapModule(injector:Injector) {
// Angular CDK
PortalModule,
DragDropModule,
+ DragulaModule,
// Our own A11y module
OpenprojectAccessibilityModule,
NgSelectModule,
diff --git a/spec/features/support/ui_select.rb b/spec/features/support/ui_select.rb
deleted file mode 100644
index 407dabc89e5..00000000000
--- a/spec/features/support/ui_select.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2017 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See docs/COPYRIGHT.rdoc for more details.
-#++
-
-shared_context 'ui-select helpers' do
- def ui_select_choose(select2_element, option_name)
- # Open the element
- select2_element.find('.select2-choice').click
- # Insert the text to find
- select2_element.find('.select2-search input').set(option_name)
- # click the element to select it
- select2_element.find('ul.select2-result-single li', text: option_name).click
- end
-
- def ui_select(select2_element, option_name)
- # Open the element
- select2_element.find('.select2-choice, .select2-choices').click
- # click the element to select it
- page.find('.select2-result-label', text: option_name).click
- end
-
- def ui_select_clear(select2_element)
- select2_element.all('.select2-search-choice-close').each(&:click)
- end
-end
diff --git a/spec/features/work_packages/sorting/table_sorting_spec.rb b/spec/features/work_packages/sorting/table_sorting_spec.rb
index 196c903e20f..a6c220dc2de 100644
--- a/spec/features/work_packages/sorting/table_sorting_spec.rb
+++ b/spec/features/work_packages/sorting/table_sorting_spec.rb
@@ -63,7 +63,6 @@ describe 'Select work package row', type: :feature, js: true do
work_packages_page.visit_index
end
- include_context 'ui-select helpers'
include_context 'work package table helpers'
context 'sorting by version' do
diff --git a/spec/features/work_packages/table/configuration_modal/column_spec.rb b/spec/features/work_packages/table/configuration_modal/column_spec.rb
index 14abb03a342..d1cc59b604d 100644
--- a/spec/features/work_packages/table/configuration_modal/column_spec.rb
+++ b/spec/features/work_packages/table/configuration_modal/column_spec.rb
@@ -47,7 +47,7 @@ describe 'Work Package table configuration modal columns spec', js: true do
it_behaves_like 'add and remove columns'
- context 'with three columns' do
+ context 'with three columns', driver: :firefox_headless_de do
let!(:query) do
query = FactoryBot.build(:query, user: user, project: project)
query.column_names = %w[id project subject]
@@ -63,22 +63,28 @@ describe 'Work Package table configuration modal columns spec', js: true do
columns.expect_checked 'Subject'
# Drag subject left of project
- subject = find('.select2-search-choice', text: 'Subject')
+ subject_column = columns.column_item('Subject').find('span')
+ project_column = columns.column_item('Project').find('span')
+
page
.driver
.browser
.action
- .move_to(subject.native)
- .drag_and_drop_by(subject.native, -100, 0)
+ .drag_and_drop(subject_column.native, project_column.native)
+ .release
.perform
+ sleep 1
+
columns.apply
expect(page).to have_selector('.wp-table--table-header', text: 'ID')
expect(page).to have_selector('.wp-table--table-header', text: 'PROJECT')
expect(page).to have_selector('.wp-table--table-header', text: 'SUBJECT')
names = all('.wp-table--table-header').map(&:text)
- expect(names).to eq(%w[ID SUBJECT PROJECT])
+ # Depending on what browser is used, subject column may be first or second
+ # it doesn't matter for the outcome of this test
+ expect(names).to eq(%w[SUBJECT ID PROJECT]).or(%w[ID SUBJECT PROJECT])
end
end
end
diff --git a/spec/features/work_packages/table/configuration_modal/table_configuration_modal_spec.rb b/spec/features/work_packages/table/configuration_modal/table_configuration_modal_spec.rb
index fdb08173be0..c2dcba7f017 100644
--- a/spec/features/work_packages/table/configuration_modal/table_configuration_modal_spec.rb
+++ b/spec/features/work_packages/table/configuration_modal/table_configuration_modal_spec.rb
@@ -24,11 +24,6 @@ describe 'Work Package table configuration modal', js: true do
wp_table.expect_work_package_listed wp_1
end
- it 'focuses on the modal when opening it' do
- modal.open!
- expect(page).to have_focus_on('.columns-modal--content input.select2-input')
- end
-
it 'focuses on the columns tab when opened through header' do
# Open header dropdown
find('.work-package-table--container th #subject').click
@@ -36,9 +31,6 @@ describe 'Work Package table configuration modal', js: true do
# Open insert columns entry
find('#column-context-menu .menu-item', text: 'Insert columns ...').click
- # Expect focus on table configuration modal
- expect(page).to have_focus_on('.columns-modal--content input.select2-input')
-
# Expect active tab is columns
expect(page).to have_selector('.tab-show.selected', text: 'COLUMNS')
end
diff --git a/spec/support/components/work_packages/columns.rb b/spec/support/components/work_packages/columns.rb
index f515976994d..693392a5144 100644
--- a/spec/support/components/work_packages/columns.rb
+++ b/spec/support/components/work_packages/columns.rb
@@ -39,26 +39,39 @@ module Components
self.trigger_parent = trigger_parent
end
+ def column_autocompleter
+ find('.columns-modal--content .draggable-autocomplete--input')
+ end
+
+ def close_autocompleter
+ find('.columns-modal--content .draggable-autocomplete--input input').send_keys :escape
+ end
+
+ def column_item(name)
+ find('.draggable-autocomplete--item', text: name)
+ end
+
def expect_column_not_available(name)
modal_open? or open_modal
- find('.columns-modal--content .draggable-autocomplete--input').click
+ column_autocompleter.click
expect(page).to have_no_selector('.ng-option', text: name, visible: :all)
- find('.columns-modal--content .draggable-autocomplete--input').send_keys :escape
+ close_autocompleter
end
def expect_column_available(name)
modal_open? or open_modal
- find('.columns-modal--content .draggable-autocomplete--input').click
+ column_autocompleter.click
expect(page).to have_selector('.ng-option', text: name, visible: :all)
- find('.columns-modal--content .draggable-autocomplete--input').send_keys :escape
+ close_autocompleter
end
def add(name, save_changes: true)
modal_open? or open_modal
- select_autocomplete '.columns-modal--content .draggable-autocomplete--input',
+ select_autocomplete column_autocompleter,
+ results_selector: '.ng-dropdown-panel-items',
query: name
apply if save_changes
@@ -68,7 +81,7 @@ module Components
modal_open? or open_modal
within_modal do
- container = find('.draggable-autocomplete--item', text: name)
+ container = column_item(name)
container.find('.draggable-autocomplete--remove-item').click
end