Skip to content

Commit

Permalink
Fix selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed Jan 14, 2019
1 parent 186cf7e commit 69ee3ab
Show file tree
Hide file tree
Showing 12 changed files with 993 additions and 840 deletions.
34 changes: 29 additions & 5 deletions src/js_tests/wirecloud/WidgetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,22 +881,46 @@

describe("reload()", () => {

it("should reload widget view", () => {
it("should reload widget view", (done) => {
var widget = new Wirecloud.Widget(WORKSPACE_TAB, EMPTY_WIDGET_META, {
id: "1",
title: "old title"
});
let listener = jasmine.createSpy("listener");
let element = widget.wrapperElement;
widget.wrapperElement = {
contentDocument: {
defaultView: {
addEventListener: jasmine.createSpy("addEventListener")
}
},
contentWindow: {
location: {
reload: jasmine.createSpy("reload")
href: widget.codeurl,
reload: jasmine.createSpy("reload").and.callFake(() => {
// call unload event
widget.wrapperElement.contentDocument.defaultView.addEventListener.calls.argsFor(0)[1]();
}),
replace: jasmine.createSpy("replace")
}
},
setAttribute: jasmine.createSpy("setAttribute")
};
expect(widget.reload()).toBe(widget);

expect(widget.wrapperElement.contentWindow.location.reload).toHaveBeenCalledWith();
widget.addEventListener("unload", listener);
widget.addEventListener("load", () => {
setTimeout(() => {
expect(listener).not.toHaveBeenCalled();
expect(widget.reload()).toBe(widget);
expect(widget.wrapperElement.contentWindow.location.reload).toHaveBeenCalledWith();

setTimeout(() => {
expect(listener).toHaveBeenCalledTimes(1);
done();
}, 0);
}, 0);
});
widget.load();
element.dispatchEvent(new Event("load"));
});

});
Expand Down
69 changes: 55 additions & 14 deletions src/wirecloud/commons/utils/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def has_icon(self, extra_class):

class FieldTester(WebElementTester):

@property
def is_disabled(self):
return self.get_attribute('disabled').strip().lower() == "true"

@property
def is_selected(self):
return self.element.is_selected()
Expand Down Expand Up @@ -474,9 +478,10 @@ def tab_created(driver):
return WebDriverWait(self.driver, timeout=5).until(tab_created)

def create_widget(self, query, new_title=None, version=None):
with self.resource_sidebar as sidebar:
resource = sidebar.search_component('widget', query)
tab_widget = resource.create_component(version=version)
with self.edit_mode as edit_session:
with edit_session.resource_sidebar as sidebar:
resource = sidebar.search_component('widget', query)
tab_widget = resource.create_component(version=version)

if new_title is not None:
tab_widget.rename(new_title)
Expand All @@ -496,6 +501,34 @@ def find_widget(self, id=None, title=None):
return None


class EditModeSession(object):

def __init__(self, testcase):
self.resource_sidebar = WorkspaceComponentSidebarTester(testcase)
self.wiring_view = WiringViewTester(testcase)


class EditMode(object):

def __init__(self, testcase):
self.testcase = testcase
self.nestinglevel = 0

def __enter__(self):
if self.nestinglevel == 0:
edit_mode_button = self.testcase.find_navbar_button("wc-edit-mode-button")
edit_mode_button.click()
self.nestinglevel += 1

return EditModeSession(self.testcase)

def __exit__(self, type, value, traceback):
self.nestinglevel -= 1
if self.nestinglevel == 0:
edit_mode_button = self.testcase.find_navbar_button("wc-edit-mode-button")
edit_mode_button.click()


class WorkspaceComponentSidebarTester(object):

def __init__(self, testcase):
Expand Down Expand Up @@ -824,6 +857,7 @@ def minimize(self, timeout=10):

def reload(self):
self.open_menu().click_entry('Reload')
return self

def remove(self, timeout=10):
old_length = len(self.testcase.driver.find_elements_by_css_selector(".wc-workspace .wc-widget"))
Expand Down Expand Up @@ -1287,10 +1321,9 @@ def tearDownClass(cls):

def setUp(self):

self.resource_sidebar = WorkspaceComponentSidebarTester(self)
self.edit_mode = EditMode(self)
self.marketplace_view = MarketplaceViewTester(self)
self.myresources_view = MyResourcesViewTester(self)
self.wiring_view = WiringViewTester(self)

def tearDown(self):

Expand Down Expand Up @@ -1333,21 +1366,29 @@ def wait_wirecloud_unload(self, timeout=15):
loading_window = self.wait_element_visible('#loading-window')
WebDriverWait(self.driver, timeout).until(EC.staleness_of(loading_window))

def wait_wirecloud_ready(self, start_timeout=20, timeout=20, embedded=False):
def wait_wirecloud_ready(self, start_timeout=20, timeout=20, login=False, embedded=False):

loading_window = None

def wait_loading_window_fadding(driver):
return 'in' not in loading_window.get_attribute('class').strip()

loading_window = self.wait_element_visible('#loading-window')
WebDriverWait(self.driver, timeout).until(wait_loading_window_fadding)

loading_message = loading_window.find_element_by_id('loading-message')
try:
self.driver.execute_script("arguments[0].click();", loading_message)
except:
pass
loading_window = self.wait_element_visible('#loading-window')
except TimeoutException:
# On page load, selenium sometimes waits until the loading process
# ends completely. In that case, the loading window element won't be
# visible, but because WireCloud is already ready.
if not login:
raise
else:
WebDriverWait(self.driver, timeout).until(wait_loading_window_fadding)

loading_message = loading_window.find_element_by_id('loading-message')
try:
self.driver.execute_script("arguments[0].click();", loading_message)
except:
pass

if embedded:
self.wait_element_visible('.wc-body:not(.se-on-transition)')
Expand All @@ -1372,7 +1413,7 @@ def login(self, username='admin', password='admin', next=None):
form.get_field('password').set_value(password)
form.submit()

self.wait_wirecloud_ready()
self.wait_wirecloud_ready(login=True)

def get_current_view(self):

Expand Down
11 changes: 6 additions & 5 deletions src/wirecloud/platform/localcatalogue/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,12 @@ def test_resource_uninstall(self):
self.assertEqual(widgetT1.wait_loaded().error_count, 1)
self.assertEqual(widgetT2.wait_loaded().error_count, 1)

# As the two Test v1.0 widgets
# one in the first tab and another in the second one
self.assertEqual(self.find_widget(title="Test 1").error_count, 1)
self.find_tab(title="Tab 2").click()
self.assertEqual(self.find_widget(title="Test 2").wait_loaded().error_count, 1)
with self.edit_mode as edit_session:
# As well as the two Test v1.0 widgets
# one in the first tab and another in the second one
self.assertEqual(self.find_widget(title="Test 1").error_count, 1)
self.find_tab(title="Tab 2").click()
self.assertEqual(self.find_widget(title="Test 2").wait_loaded().error_count, 1)

@uses_extra_resources((
'Wirecloud_Test_2.0.wgt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
options.effect = StyledElements.Alternatives.CROSS_DISSOLVE;
}
this.rootKeydownHandler = null;
this.alternatives.showAlternative(newView, options);
return this.alternatives.showAlternative(newView, options);
};

UserInterfaceManager.handleEscapeEvent = function handleEscapeEvent() {
Expand Down Expand Up @@ -317,11 +317,10 @@
};

UserInterfaceManager.onHistoryChange = function onHistoryChange(state) {
this.changeCurrentView(state.view, {
onComplete: function (alternatives, oldView, nextView) {
if ('onHistoryChange' in nextView) {
nextView.onHistoryChange(state);
}
this.changeCurrentView(state.view, true).then((info) => {
let nextView = info.in;
if ('onHistoryChange' in nextView) {
nextView.onHistoryChange(state);
}
});
};
Expand Down
13 changes: 10 additions & 3 deletions src/wirecloud/platform/static/js/wirecloud/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@
* @returns {Wirecloud.Widget}
*/
reload: function reload() {
let priv = privates.get(this);
priv.status = STATUS.UNLOADING;
this.wrapperElement.setAttribute('type', this.meta.codecontenttype);
this.wrapperElement.contentWindow.location.reload();

Expand Down Expand Up @@ -593,7 +595,8 @@
var STATUS = {
CREATED: 0,
LOADING: 1,
RUNNING: 2
RUNNING: 2,
UNLOADING: 3
};

var build_endpoints = function build_endpoints() {
Expand Down Expand Up @@ -791,11 +794,15 @@

var on_unload = function on_unload() {

if (!this.loaded) {
let priv = privates.get(this);

if (priv.status !== STATUS.RUNNING && priv.status !== STATUS.UNLOADING) {
return;
}

privates.get(this).status = STATUS.CREATED;
// Currently, the only scenario where current status can be "unloading"
// is when reloading the widget
priv.status = priv.status === STATUS.RUNNING ? STATUS.CREATED : STATUS.LOADING;
this.prefCallback = null;

remove_context_callbacks.call(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
buttonArea: this.windowBottom
});
this.form.insertInto(this.windowContent);
this.form.setdefaultsButton.addClassName('btn-set-defaults');
this.form.cancelButton.addClassName('btn-cancel');
this.form.acceptButton.addClassName('btn-accept');
this.form.addEventListener('submit', this._savePrefs.bind(this));
this.form.addEventListener('cancel', this.hide.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@
};

MarketplaceView.prototype.onHistoryChange = function onHistoryChange(state) {
this.changeCurrentMarket(state.market, {history: "ignore"});
if ('onHistoryChange' in this.viewsByName[state.market]) {
this.viewsByName[state.market].onHistoryChange(state);
if (this.loading === false && state.market in this.viewsByName) {
this.changeCurrentMarket(state.market, {history: "ignore"});
if ('onHistoryChange' in this.viewsByName[state.market]) {
this.viewsByName[state.market].onHistoryChange(state);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

// Reset button
this.resetButton = new se.Button({
class: 'btn-set-defaults',
text: utils.gettext('Set Defaults'),
});
this.resetButton.addEventListener("click", function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
});
this.editButton.addEventListener("click", (button) => {
showHideTabBar.call(this, button.active);
if (!button.active) {
this.walletButton.active = false;
this.layout.slideOut();
}
this.activeTab.dragboard._updateIWidgetSizes(true, true);
});

this.walletButton = this.buildAddWidgetButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
(new Wirecloud.ui.RenameWindowMenu(this, utils.gettext('Rename Workspace'))).show();
}.bind(this.workspace.model));
item.addIconClass("fa fa-pencil");
item.setDisabled(!this.workspace.model.isAllowed('rename'));
item.setDisabled(!this.workspace.editing || !this.workspace.model.isAllowed('rename'));
items.push(item);

item = new se.MenuItem(utils.gettext("Share"), function () {
Expand Down Expand Up @@ -95,7 +95,7 @@
this.showSettings();
}.bind(this.workspace));
item.addIconClass("fa fa-cog");
item.setDisabled(!this.workspace.model.isAllowed('update_preferences'));
item.setDisabled(!this.workspace.editing || !this.workspace.model.isAllowed('update_preferences'));
items.push(item);

item = new se.MenuItem(utils.gettext("Remove"), () => {
Expand Down
Loading

0 comments on commit 69ee3ab

Please sign in to comment.