Fix inline create specs

pull/6145/head
Oliver Günther 7 years ago
parent 957483698c
commit edf04f83f1
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 84
      frontend/app/components/wp-edit-form/table-row-edit-context.ts
  2. 2
      spec/features/work_packages/table/inline_create/inline_create_refresh_spec.rb
  3. 6
      spec/support/pages/work_packages_table.rb

@ -68,42 +68,48 @@ export class TableRowEditContext implements WorkPackageEditContext {
}
public activateField(form:WorkPackageEditForm, field:EditField, fieldName:string, errors:string[]):ng.IPromise<WorkPackageEditFieldHandler> {
const cell = this.findContainer(fieldName);
const deferred = this.$q.defer<WorkPackageEditFieldHandler>();
this.waitForContainer(fieldName)
.then((cell) => {
// Forcibly set the width since the edit field may otherwise
// be given more width
const td = this.findCell(fieldName);
const width = td.css('width');
td.css('max-width', width);
td.css('width', width);
// Create a field handler for the newly active field
const fieldHandler = new WorkPackageEditFieldHandler(
form,
fieldName,
field,
cell,
errors
);
fieldHandler.$scope = this.templateRenderer.createRenderScope();
const promise = this.templateRenderer.renderIsolated(
// Replace the current cell
cell,
fieldHandler.$scope,
'/components/wp-edit-form/wp-edit-form.template.html',
{
vm: fieldHandler,
}
);
promise.then(() => {
// Assure the element is visible
this.$timeout(() => {
fieldHandler.focus();
deferred.resolve(fieldHandler);
});
}).catch(deferred.reject);
}).catch(deferred.reject);
// Forcibly set the width since the edit field may otherwise
// be given more width
const td = this.findCell(fieldName);
const width = td.css('width');
td.css('max-width', width);
td.css('width', width);
// Create a field handler for the newly active field
const fieldHandler = new WorkPackageEditFieldHandler(
form,
fieldName,
field,
cell,
errors
);
fieldHandler.$scope = this.templateRenderer.createRenderScope();
const promise = this.templateRenderer.renderIsolated(
// Replace the current cell
cell,
fieldHandler.$scope,
'/components/wp-edit-form/wp-edit-form.template.html',
{
vm: fieldHandler,
}
);
return promise.then(() => {
// Assure the element is visible
return this.$timeout(() => {
fieldHandler.focus();
return fieldHandler;
});
});
return deferred.promise;
}
public refreshField(field:EditField, handler:WorkPackageEditFieldHandler) {
@ -124,7 +130,7 @@ export class TableRowEditContext implements WorkPackageEditContext {
}
}
public requireVisible(fieldName:string):Promise<undefined> {
public requireVisible(fieldName:string):Promise<any> {
this.wpTableColumns.addColumn(fieldName);
return this.waitForContainer(fieldName);
}
@ -139,15 +145,15 @@ export class TableRowEditContext implements WorkPackageEditContext {
// Ensure the given field is visible.
// We may want to look into MutationObserver if we need this in several places.
private waitForContainer(fieldName:string):Promise<undefined> {
const deferred = this.$q.defer<undefined>();
private waitForContainer(fieldName:string):Promise<JQuery> {
const deferred = this.$q.defer<JQuery>();
const interval = setInterval(() => {
const container = this.findContainer(fieldName);
if (container.length > 0) {
clearInterval(interval);
deferred.resolve();
deferred.resolve(container);
}
}, 100);

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'Refreshing in inline-create row', js: true do
describe 'Refreshing in inline-create row', flaky: true, js: true do
let(:user) { FactoryGirl.create :admin }
let(:project) { FactoryGirl.create :project }

@ -93,6 +93,12 @@ module Pages
end
def click_inline_create
##
# When using the inline create on initial page load,
# there is a delay on travis where inline create can be clicked.
sleep 3
find('.wp-inline-create--add-link').click
expect(page).to have_selector('.wp-inline-create-row', wait: 10)
end

Loading…
Cancel
Save