Commit 034397d3 authored by Phil Hughes's avatar Phil Hughes

This should make the ordering feature specs more reliable

parent 3ab101cc
......@@ -43,7 +43,14 @@
return event;
}
function getTraget(target) {
function isLast(target) {
var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
var children = el.children;
return children.length - 1 === target.index;
}
function getTarget(target) {
var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
var children = el.children;
......@@ -55,13 +62,6 @@
);
}
function isLast(target) {
var el = typeof target.el === 'string' ? document.getElementById(target.el.substr(1)) : target.el;
var children = el.children;
return children.length - 1 === target.index;
}
function getRect(el) {
var rect = el.getBoundingClientRect();
var width = rect.right - rect.left;
......@@ -82,12 +82,22 @@
function simulateDrag(options, callback) {
options.to.el = options.to.el || options.from.el;
var fromEl = getTraget(options.from);
var toEl = getTraget(options.to);
var fromEl = getTarget(options.from);
var toEl = getTarget(options.to);
var firstEl = getTarget({
el: options.to.el,
index: 'first'
});
var lastEl = getTarget({
el: options.to.el,
index: 'last'
});
var scrollable = options.scrollable;
var fromRect = getRect(fromEl);
var toRect = getRect(toEl);
var firstRect = getRect(firstEl);
var lastRect = getRect(lastEl);
var startTime = new Date().getTime();
var duration = options.duration || 1000;
......@@ -95,8 +105,10 @@
options.ontap && options.ontap();
window.SIMULATE_DRAG_ACTIVE = 1;
if (isLast(options.to)) {
toRect.cy += 100;
if (options.to.index === 0) {
toRect.cy = firstRect.y;
} else if (isLast(options.to)) {
toRect.cy = lastRect.y + lastRect.h + 50;
}
var dragInterval = setInterval(function loop() {
......
......@@ -9,9 +9,9 @@ describe 'Issue Boards', :feature, :js do
let(:user) { create(:user) }
let(:label) { create(:label, project: project) }
let!(:list1) { create(:list, board: board, label: label, position: 0) }
let!(:issue1) { create(:labeled_issue, project: project, labels: [label]) }
let!(:issue2) { create(:labeled_issue, project: project, labels: [label]) }
let!(:issue3) { create(:labeled_issue, project: project, labels: [label]) }
let!(:issue1) { create(:labeled_issue, project: project, title: 'testing 1', labels: [label], relative_position: 3.0) }
let!(:issue2) { create(:labeled_issue, project: project, title: 'testing 2', labels: [label], relative_position: 2.0) }
let!(:issue3) { create(:labeled_issue, project: project, title: 'testing 3', labels: [label], relative_position: 1.0) }
before do
project.team << [user, :master]
......@@ -32,7 +32,7 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(first('.card')).to have_content(issue2.iid)
expect(first('.card')).to have_content(issue2.title)
end
it 'moves from middle to bottom' do
......@@ -40,7 +40,7 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(all('.card').last).to have_content(issue2.iid)
expect(all('.card').last).to have_content(issue2.title)
end
it 'moves from top to bottom' do
......@@ -48,7 +48,7 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(all('.card').last).to have_content(issue3.iid)
expect(all('.card').last).to have_content(issue3.title)
end
it 'moves from bottom to top' do
......@@ -56,7 +56,7 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(first('.card')).to have_content(issue1.iid)
expect(first('.card')).to have_content(issue1.title)
end
it 'moves from top to middle' do
......@@ -64,7 +64,7 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(first('.card')).to have_content(issue2.iid)
expect(first('.card')).to have_content(issue2.title)
end
it 'moves from bottom to middle' do
......@@ -72,16 +72,16 @@ describe 'Issue Boards', :feature, :js do
wait_for_vue_resource
expect(all('.card').last).to have_content(issue2.iid)
expect(all('.card').last).to have_content(issue2.title)
end
end
context 'ordering when changing list' do
let(:label2) { create(:label, project: project) }
let!(:list2) { create(:list, board: board, label: label2, position: 1) }
let!(:issue4) { create(:labeled_issue, project: project, labels: [label2]) }
let!(:issue5) { create(:labeled_issue, project: project, labels: [label2]) }
let!(:issue6) { create(:labeled_issue, project: project, labels: [label2]) }
let!(:issue4) { create(:labeled_issue, project: project, title: 'testing 1', labels: [label2], relative_position: 3.0) }
let!(:issue5) { create(:labeled_issue, project: project, title: 'testing 2', labels: [label2], relative_position: 2.0) }
let!(:issue6) { create(:labeled_issue, project: project, title: 'testing 3', labels: [label2], relative_position: 1.0) }
before do
visit namespace_project_board_path(project.namespace, project, board)
......@@ -99,7 +99,7 @@ describe 'Issue Boards', :feature, :js do
expect(all('.board')[1]).to have_selector('.card', count: 4)
page.within(all('.board')[1]) do
expect(first('.card')).to have_content(issue3.iid)
expect(first('.card')).to have_content(issue3.title)
end
end
......@@ -112,7 +112,7 @@ describe 'Issue Boards', :feature, :js do
expect(all('.board')[1]).to have_selector('.card', count: 4)
page.within(all('.board')[1]) do
expect(all('.card').last).to have_content(issue3.iid)
expect(all('.card').last).to have_content(issue3.title)
end
end
......@@ -125,7 +125,7 @@ describe 'Issue Boards', :feature, :js do
expect(all('.board')[1]).to have_selector('.card', count: 4)
page.within(all('.board')[1]) do
expect(all('.card')[1]).to have_content(issue3.iid)
expect(all('.card')[1]).to have_content(issue3.title)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment