diff --git a/src/js_tests/wirecloud/WidgetSpec.js b/src/js_tests/wirecloud/WidgetSpec.js index d81423ab7a..a567333597 100644 --- a/src/js_tests/wirecloud/WidgetSpec.js +++ b/src/js_tests/wirecloud/WidgetSpec.js @@ -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")); }); }); diff --git a/src/wirecloud/commons/utils/remote.py b/src/wirecloud/commons/utils/remote.py index f5458e1fc9..0d28221731 100644 --- a/src/wirecloud/commons/utils/remote.py +++ b/src/wirecloud/commons/utils/remote.py @@ -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() @@ -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) @@ -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): @@ -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")) @@ -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): @@ -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)') @@ -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): diff --git a/src/wirecloud/platform/localcatalogue/tests.py b/src/wirecloud/platform/localcatalogue/tests.py index 0765d1533a..9d9558c4d6 100644 --- a/src/wirecloud/platform/localcatalogue/tests.py +++ b/src/wirecloud/platform/localcatalogue/tests.py @@ -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', diff --git a/src/wirecloud/platform/static/js/wirecloud/UserInterfaceManager.js b/src/wirecloud/platform/static/js/wirecloud/UserInterfaceManager.js index d84d05a497..9cc9c2740c 100644 --- a/src/wirecloud/platform/static/js/wirecloud/UserInterfaceManager.js +++ b/src/wirecloud/platform/static/js/wirecloud/UserInterfaceManager.js @@ -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() { @@ -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); } }); }; diff --git a/src/wirecloud/platform/static/js/wirecloud/Widget.js b/src/wirecloud/platform/static/js/wirecloud/Widget.js index 64acb59103..c49a24f0f9 100644 --- a/src/wirecloud/platform/static/js/wirecloud/Widget.js +++ b/src/wirecloud/platform/static/js/wirecloud/Widget.js @@ -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(); @@ -593,7 +595,8 @@ var STATUS = { CREATED: 0, LOADING: 1, - RUNNING: 2 + RUNNING: 2, + UNLOADING: 3 }; var build_endpoints = function build_endpoints() { @@ -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); diff --git a/src/wirecloud/platform/static/js/wirecloud/Widget/PreferencesWindowMenu.js b/src/wirecloud/platform/static/js/wirecloud/Widget/PreferencesWindowMenu.js index c2c588e2a6..48c70b3bd2 100644 --- a/src/wirecloud/platform/static/js/wirecloud/Widget/PreferencesWindowMenu.js +++ b/src/wirecloud/platform/static/js/wirecloud/Widget/PreferencesWindowMenu.js @@ -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)); diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js b/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js index 6726002fff..3a33c431d3 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/MarketplaceView.js @@ -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); + } } }; diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/PreferencesWindowMenu.js b/src/wirecloud/platform/static/js/wirecloud/ui/PreferencesWindowMenu.js index 17db3e6a38..3126785c6f 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/PreferencesWindowMenu.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/PreferencesWindowMenu.js @@ -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 () { diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js index 298a4dbeb2..1f66be55be 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceView.js @@ -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(); diff --git a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceViewMenuItems.js b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceViewMenuItems.js index 8a81a51eaf..fc9beb1d77 100644 --- a/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceViewMenuItems.js +++ b/src/wirecloud/platform/static/js/wirecloud/ui/WorkspaceViewMenuItems.js @@ -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 () { @@ -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"), () => { diff --git a/src/wirecloud/platform/tests/selenium.py b/src/wirecloud/platform/tests/selenium.py index ba35b3c5e2..46fea74cf7 100644 --- a/src/wirecloud/platform/tests/selenium.py +++ b/src/wirecloud/platform/tests/selenium.py @@ -58,27 +58,28 @@ def test_basic_workspace_operations(self): self.login(username="admin", next="/admin/Workspace") # admin only have one workspace, but WireCloud should allow any workspace operation - self.open_menu().check(('Rename', 'Settings', 'New workspace', 'Upload to my resources', 'Remove', 'Share', 'Embed')).close() + self.open_menu().check(('New workspace', 'Upload to my resources', 'Remove', 'Share', 'Embed')).close() self.create_workspace('Test') - # Now we have two workspaces, nothing should change - self.open_menu().check(('Rename', 'Settings', 'New workspace', 'Upload to my resources', 'Remove', 'Share', 'Embed'), ()).close() - self.rename_workspace('test2') - tab = self.find_tab(title="Tab") + # Now we have two workspaces, nothing should change except that now we are on edit mode + with self.edit_mode as edit_session: + self.open_menu().check(('Rename', 'Settings', 'New workspace', 'Upload to my resources', 'Remove', 'Share', 'Embed'), ()).close() + self.rename_workspace('test2') + tab = self.find_tab(title="Tab") - # Only one tab => we cannot remove it - tab.show_preferences().check(('Rename',), must_be_disabled=('Remove',)) + # Only one tab => we cannot remove it + tab.show_preferences().check(('Rename',), must_be_disabled=('Remove',)) - new_tab = self.create_tab() + new_tab = self.create_tab() - # Now we have two tabs so we can remove any of them - tab.show_preferences().check(must_be=('Rename', 'Remove')) - new_tab.click() - new_tab.show_preferences().check(must_be=('Rename', 'Remove')).close() + # Now we have two tabs so we can remove any of them + tab.show_preferences().check(must_be=('Rename', 'Remove')) + new_tab.click() + new_tab.show_preferences().check(must_be=('Rename', 'Remove')).close() - # Remove the recently created one (no confirmation needed as the tab is empty) - new_tab.remove() + # Remove the recently created one (no confirmation needed as the tab is empty) + new_tab.remove() self.remove_workspace() @@ -101,10 +102,11 @@ def test_move_iwidget_between_tabs(self): iwidget = self.find_tab(id="102").widgets[0] tab = self.find_tab(title='Tab 2') - ActionChains(self.driver).click_and_hold(iwidget.title_element).move_to_element(tab.element).release().perform() + with self.edit_mode as edit_session: + ActionChains(self.driver).click_and_hold(iwidget.title_element).move_to_element(tab.element).release().perform() - self.assertEqual(len(self.find_tab(id="102").widgets), src_iwidget_count - 1) - self.assertEqual(len(self.find_tab(id="103").widgets), dst_iwidget_count + 1) + self.assertEqual(len(self.find_tab(id="102").widgets), src_iwidget_count - 1) + self.assertEqual(len(self.find_tab(id="103").widgets), dst_iwidget_count + 1) test_move_iwidget_between_tabs.tags = tags + ('wirecloud-dragboard',) def test_create_widget_from_component_sidebar(self): @@ -113,34 +115,39 @@ def test_create_widget_from_component_sidebar(self): def test_remove_widget_from_workspace(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/Workspace") - self.find_widget(title="Test 1").remove() + with self.edit_mode as edit_session: + self.find_widget(title="Test 1").remove() def test_remove_tab_from_workspace(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/pending-events') self.find_tab(title="Tab 1").remove() - with self.wiring_view as wiring: - self.assertIsNone(wiring.find_draggable_component('widget', title="Test 1")) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self.assertIsNone(wiring.find_draggable_component('widget', title="Test 1")) def test_tabs_with_read_only_widgets_cannot_be_removed(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/pending-events') - tab = self.find_tab(title="Tab 2") - tab.show_preferences().check(must_be_disabled=('Remove',)) + with self.edit_mode as edit_session: + tab = self.find_tab(title="Tab 2") + tab.show_preferences().check(must_be_disabled=('Remove',)) - tab.click() - tab_widget = tab.find_widget(title="Test 2") - self.assertTrue(tab_widget.remove_button.is_disabled) + tab.click() + tab_widget = tab.find_widget(title="Test 2") + self.assertTrue(tab_widget.remove_button.is_disabled) def test_refresh_widget(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/Workspace") - tab_widget = self.find_widget(title="Test 1") - with tab_widget: - last_received_event_field = self.driver.find_element_by_id('wiringOut') - self.driver.execute_script('arguments[0].textContent = "hello world!!";', last_received_event_field) + with self.edit_mode as edit_session: + tab_widget = self.find_widget(title="Test 1") + with tab_widget: + last_received_event_field = self.driver.find_element_by_id('wiringOut') + self.driver.execute_script('arguments[0].textContent = "hello world!!";', last_received_event_field) + + tab_widget.reload().wait_loaded() - tab_widget.reload() with tab_widget: last_received_event_field = self.wait_element_visible('#wiringOut') self.assertEqual(last_received_event_field.text, '') @@ -149,86 +156,89 @@ def test_refresh_widget(self): def test_basic_widget_functionalities(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/Workspace") - iwidget = self.find_widget(title="Test 1") + with self.edit_mode as edit_session: + iwidget = self.find_widget(title="Test 1") - with iwidget: - check_default_settings_values(self) + with iwidget: + check_default_settings_values(self) - # Open widget settings - modal = iwidget.show_settings() + # Open widget settings + modal = iwidget.show_settings() - # Check dialog shows correct values - self.assertEqual(modal.get_field('list').value, "default") - self.assertEqual(modal.get_field('text').value, "initial text") - self.assertFalse(modal.get_field('boolean').is_selected) - self.assertEqual(modal.get_field('number').value, "2") - self.assertEqual(modal.get_field('password').value, "default") + # Check dialog shows correct values + self.assertEqual(modal.get_field('list').value, "default") + self.assertEqual(modal.get_field('text').value, "initial text") + self.assertFalse(modal.get_field('boolean').is_selected) + self.assertEqual(modal.get_field('number').value, "2") + self.assertEqual(modal.get_field('password').value, "default") - # Change widget settings - modal.get_field('list').set_value("1") # value1 - modal.get_field('text').set_value("test") - modal.get_field('boolean').click() - modal.get_field('number').set_value("0") - modal.get_field('password').set_value("password") + # Change widget settings + modal.get_field('list').set_value("1") # value1 + modal.get_field('text').set_value("test") + modal.get_field('boolean').click() + modal.get_field('number').set_value("0") + modal.get_field('password').set_value("password") - modal.accept() + modal.accept() - with iwidget: - self.assertEqual(self.driver.find_element_by_id('listPref').text, '1') - self.assertEqual(self.driver.find_element_by_id('textPref').text, 'test') - self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'true') - self.assertEqual(self.driver.find_element_by_id('numberPref').text, '0') - self.assertEqual(self.driver.find_element_by_id('passwordPref').text, 'password') + with iwidget: + self.assertEqual(self.driver.find_element_by_id('listPref').text, '1') + self.assertEqual(self.driver.find_element_by_id('textPref').text, 'test') + self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'true') + self.assertEqual(self.driver.find_element_by_id('numberPref').text, '0') + self.assertEqual(self.driver.find_element_by_id('passwordPref').text, 'password') - # Open widget settings again - modal = iwidget.show_settings() + # Open widget settings again + modal = iwidget.show_settings() - # Check dialog shows correct values - self._check_modified_widget_preferences(modal) + # Check dialog shows correct values + self._check_modified_widget_preferences(modal) - modal.accept() + modal.accept() self.reload() + self.wait_wirecloud_ready(login=True) WebDriverWait(self.driver, timeout=15).until(lambda driver: self.active_tab is not None) - iwidget = self.find_widget(title="Test 1") + with self.edit_mode as edit_session: + iwidget = self.find_widget(title="Test 1") - # Open widget settings again - modal = iwidget.show_settings() + # Open widget settings again + modal = iwidget.show_settings() - # Check dialog shows correct values - self._check_modified_widget_preferences(modal) + # Check dialog shows correct values + self._check_modified_widget_preferences(modal) - # Change widget settings - modal.get_field('text').set_value("") - modal.get_field('password').set_value("") + # Change widget settings + modal.get_field('text').set_value("") + modal.get_field('password').set_value("") - modal.accept() + modal.accept() - with iwidget: - self.assertEqual(self.driver.find_element_by_id('listPref').text, '1') - self.assertEqual(self.driver.find_element_by_id('textPref').text, '') - self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'true') - self.assertEqual(self.driver.find_element_by_id('numberPref').text, '0') - self.assertEqual(self.driver.find_element_by_id('passwordPref').text, '') + with iwidget: + self.assertEqual(self.driver.find_element_by_id('listPref').text, '1') + self.assertEqual(self.driver.find_element_by_id('textPref').text, '') + self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'true') + self.assertEqual(self.driver.find_element_by_id('numberPref').text, '0') + self.assertEqual(self.driver.find_element_by_id('passwordPref').text, '') - # Restore default widget settings - modal = iwidget.show_settings() - modal.find_button("Set Defaults").click() - modal.accept() + # Restore default widget settings + modal = iwidget.show_settings() + modal.find_button("Set Defaults").click() + modal.accept() - with iwidget: - check_default_settings_values(self) + with iwidget: + check_default_settings_values(self) - # Use api test widget to test other API features - self.network._servers['http']['example.com'].add_response('GET', '/success.html', {'content': 'remote makerequest was successful'}) - api_test_iwidget = self.create_widget("Wirecloud API test") - api_test_iwidget_id = api_test_iwidget.id + # Use api test widget to test other API features + self.network._servers['http']['example.com'].add_response('GET', '/success.html', {'content': 'remote makerequest was successful'}) + api_test_iwidget = self.create_widget("Wirecloud API test") + api_test_iwidget_id = api_test_iwidget.id - # Open widget settings again - modal = api_test_iwidget.show_settings() - modal.get_field('text').set_value("Success!!") - modal.accept() + # Open widget settings again + modal = api_test_iwidget.show_settings() + modal.get_field('text').set_value("Success!!") + modal.accept() expected_value = 'new value' @@ -295,22 +305,23 @@ def test_basic_widget_functionalities(self): def test_resize_widgets(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/Workspace") - widget1 = self.widgets[1] - old_size = widget1.size - old_position = widget1.position + with self.edit_mode as edit_session: + widget1 = self.widgets[1] + old_size = widget1.size + old_position = widget1.position - widget1.resize('bottom_left', -30, 30) - new_size = widget1.size - new_position = widget1.position - self.assertNotEqual(new_size, old_size) - self.assertNotEqual(new_position, old_position) + widget1.resize('bottom_left', -30, 30) + new_size = widget1.size + new_position = widget1.position + self.assertNotEqual(new_size, old_size) + self.assertNotEqual(new_position, old_position) # Django uses http 1.0 by default # If-Modified-Since has a 1 second resolution time.sleep(1) self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) widget1 = self.widgets[1] self.assertEqual(new_size, widget1.size) @@ -387,21 +398,23 @@ def test_http_cache(self): self.assertEqual(self.get_current_workspace_title(), 'Test') # Add a new tab - self.create_tab() + with self.edit_mode as edit_session: + self.create_tab() self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) tabs = len(self.tabs) self.assertEqual(tabs, 2) - tab = self.find_tab(title='Tab') + with self.edit_mode as edit_session: + tab = self.find_tab(title='Tab') - # Rename the created tab - tab.rename('Other Name') + # Rename the created tab + tab.rename('Other Name') self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(len(self.tabs), 2) tab = self.find_tab(title='Other Name') @@ -410,52 +423,56 @@ def test_http_cache(self): self.assertIsNone(tab) # Add two widgets to the mashup - with self.resource_sidebar as sidebar: - resource = sidebar.search_component('widget', 'Test') - resource.create_component() - resource.create_component() + with self.edit_mode as edit_session: + with edit_session.resource_sidebar as sidebar: + resource = sidebar.search_component('widget', 'Test') + resource.create_component() + resource.create_component() self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(len(self.widgets), 2) # Rename a widget - - iwidget = self.widgets[1] - iwidget.rename('Other Test') + with self.edit_mode as edit_session: + iwidget = self.widgets[1] + iwidget.rename('Other Test') self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) - iwidget = self.widgets[0] - self.assertEqual(iwidget.title, 'Test') + with self.edit_mode as edit_session: + iwidget = self.widgets[0] + self.assertEqual(iwidget.title, 'Test') - iwidget = self.widgets[1] - self.assertEqual(iwidget.title, 'Other Test') + iwidget = self.widgets[1] + self.assertEqual(iwidget.title, 'Other Test') - # Remove a widget - iwidget.remove() + # Remove a widget + iwidget.remove() self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(len(self.widgets), 1) # Rename the workspace - self.rename_workspace('test2') + with self.edit_mode as edit_session: + self.rename_workspace('test2') self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(self.get_current_workspace_title(), 'test2') # Remove the tab with widgets - tab = self.find_tab(title='Other Name') - tab.remove() + with self.edit_mode as edit_session: + tab = self.find_tab(title='Other Name') + tab.remove() self.reload() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(len(self.tabs), 1) self.assertEqual(len(self.widgets), 0) @@ -502,33 +519,32 @@ def test_create_workspace_from_catalogue_using_parameters(self): iwidget = self.widgets[0] - iwidget.open_menu().click_entry('Settings') - - self.assertEqual(self.driver.find_element_by_css_selector('.window_menu [name="list"]').get_attribute('value'), 'default') - text_pref = self.driver.find_element_by_css_selector('.window_menu [name="text"]') - self.assertEqual(text_pref.get_attribute('disabled'), 'true') - self.assertEqual(text_pref.get_attribute('value'), 'parameterized value') - - self.assertFalse(self.driver.find_element_by_css_selector('.window_menu [name="boolean"]').is_selected()) - password_prefs = self.driver.find_elements_by_css_selector('.window_menu [name="password"]') - self.assertEqual(len(password_prefs), 0) - - self.driver.find_element_by_xpath("//*[contains(@class, 'window_menu')]//*[text()='Cancel']").click() - - with iwidget: - self.assertEqual(self.driver.find_element_by_id('listPref').text, 'default') - self.assertEqual(self.driver.find_element_by_id('textPref').text, 'parameterized value') - self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'false') - self.assertEqual(self.driver.find_element_by_id('passwordPref').text, 'parameterized password') - - with self.wiring_view as wiring: - operator = wiring.find_draggable_component('operator', title="TestOperator") - - modal = operator.show_settings() - prefix_field = modal.get_field('prefix') - self.assertEqual(prefix_field.get_attribute('disabled'), 'true') - self.assertEqual(prefix_field.get_attribute('value'), 'parameterized value: ') - modal.accept() + with self.edit_mode as edit_session: + iwidget.open_menu().click_entry('Settings') + + form = FormModalTester(self, self.wait_element_visible(".wc-component-preferences-modal")) + self.assertEqual(form.get_field('list').value, 'default') + text_pref = form.get_field('text') + self.assertTrue(text_pref.is_disabled) + self.assertEqual(text_pref.value, 'parameterized value') + self.assertFalse(form.get_field('boolean').is_selected) + self.assertRaises(NoSuchElementException, form.get_field, 'password') + form.cancel() + + with iwidget: + self.assertEqual(self.driver.find_element_by_id('listPref').text, 'default') + self.assertEqual(self.driver.find_element_by_id('textPref').text, 'parameterized value') + self.assertEqual(self.driver.find_element_by_id('booleanPref').text, 'false') + self.assertEqual(self.driver.find_element_by_id('passwordPref').text, 'parameterized password') + + with edit_session.wiring_view as wiring: + operator = wiring.find_draggable_component('operator', title="TestOperator") + + modal = operator.show_settings() + prefix_field = modal.get_field('prefix') + self.assertEqual(prefix_field.get_attribute('disabled'), 'true') + self.assertEqual(prefix_field.get_attribute('value'), 'parameterized value: ') + modal.accept() def test_create_workspace_from_catalogue_duplicated_workspaces(self): @@ -566,9 +582,10 @@ def test_merge_mashup(self): self.login(username="admin", next="/admin/Workspace") - with self.resource_sidebar as sidebar: - resource = sidebar.search_component('mashup', 'Test Mashup') - resource.merge() + with self.edit_mode as edit_session: + with edit_session.resource_sidebar as sidebar: + resource = sidebar.search_component('mashup', 'Test Mashup') + resource.merge() self.assertEqual(len(self.tabs), 3) tab1 = self.find_tab(name='tab') @@ -614,14 +631,15 @@ def test_workspace_publish_readonly_widgets_and_connections(self): 'readOnlyConnectables': True, }) self.create_workspace(mashup='Published Workspace') - iwidget = self.widgets[0] - close_button = ButtonTester(self, iwidget.element.find_element_by_css_selector('.fa-remove')) - self.assertTrue(close_button.is_disabled) - # bypass the internal call to element_be_clickable as the button is usually hidden - close_button.element.click() + with self.edit_mode as edit_session: + iwidget = self.widgets[0] + close_button = ButtonTester(self, iwidget.element.find_element_by_css_selector('.fa-remove')) + self.assertTrue(close_button.is_disabled) + # bypass the internal call to element_be_clickable as the button is usually hidden + close_button.element.click() - with self.wiring_view as wiring: - self.assertEqual(len(wiring.find_connections(extra_class="readonly")), 3) + with edit_session.wiring_view as wiring: + self.assertEqual(len(wiring.find_connections(extra_class="readonly")), 3) self.assertEqual(len(self.widgets), 2) @@ -661,7 +679,7 @@ def test_public_workspaces_anonymous_user(self): url = self.live_server_url + '/user_with_workspaces/public-workspace' self.driver.get(url) - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertIsNone(self.find_navbar_button("wc-show-component-sidebar-button")) self.assertIsNone(self.find_navbar_button("wc-show-wiring-button")) @@ -678,7 +696,7 @@ def test_public_workspaces_anonymous_user(self): form.get_field('password').set_value('admin') form.submit() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(self.get_current_workspace_title(), 'Public Workspace') def test_embedded_view(self): @@ -705,12 +723,11 @@ def check_public_workspace(self, frame_id=None): target_iwidget = iwidgets[0] source_iwidget.wait_loaded() target_iwidget.wait_loaded() - source_iwidget.open_menu().check(must_be_disabled=('Rename', 'Settings', 'Upgrade/Downgrade', 'Full Dragboard', 'Extract from grid')).close() - target_iwidget.open_menu().check(must_be_disabled=('Rename', 'Settings', 'Upgrade/Downgrade', 'Full Dragboard', 'Extract from grid')) + self.assertFalse(source_iwidget.btn_preferences.is_displayed) + self.assertFalse(target_iwidget.btn_preferences.is_displayed) - tab = self.find_tab(title='Tab') + tab = self.tabs[0] self.assertRaises(NoSuchElementException, tab.element.find_element_by_css_selector, '.icon-tab-menu') - self.assertRaises(NoSuchElementException, self.driver.find_element_by_css_selector, '.icon-add-tab') # Check wiring works @@ -727,8 +744,9 @@ def test_browser_navigation_history_management(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view: - pass + with self.edit_mode as edit_session: + with edit_session.wiring_view: + pass with self.marketplace_view: pass @@ -744,7 +762,7 @@ def test_browser_navigation_history_management(self): WebDriverWait(self.driver, timeout=10).until(lambda driver: self.driver.current_url == self.live_server_url + '/login?next=/user_with_workspaces/Workspace') self.driver.forward() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) self.assertEqual(self.get_current_workspace_title(), 'Workspace') self.driver.forward() @@ -798,7 +816,7 @@ def test_browser_workspace_navigation(self): # Replay navigation history self.driver.forward() - self.wait_wirecloud_ready() + self.wait_wirecloud_ready(login=True) WebDriverWait(self.driver, timeout=10).until( WEC.workspace(self, owner='user_with_workspaces', name='Pending Events', tab='Tab 1') ) @@ -835,7 +853,8 @@ def test_browser_navigation_from_renamed_tab(self): initial_workspace_tab = self.active_tab initial_workspace_tab_name = initial_workspace_tab.title - self.find_tab(title='Tab 2').click().rename('NewName') + with self.edit_mode as edit_session: + self.find_tab(title='Tab 2').click().rename('NewName') initial_workspace_tab.click() WebDriverWait(self.driver, 5).until(WEC.workspace(self, tab=initial_workspace_tab_name)) @@ -858,7 +877,8 @@ def test_browser_navigation_from_renamed_workspace(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/Workspace") self.change_current_workspace('Pending Events') - self.rename_workspace('New Name') + with self.edit_mode as edit_session: + self.rename_workspace('New Name') self.change_current_workspace('ExistingWorkspace') @@ -894,8 +914,9 @@ def test_browser_navigation_to_deleted_workspace(self): WebDriverWait(self.driver, 10).until(WEC.workspace(self, owner='user_with_workspaces', name='Workspace')) # "Workspace" workspace should be editable - self.assertFalse(self.find_navbar_button("wc-show-component-sidebar-button").is_disabled) - self.assertFalse(self.find_navbar_button("wc-show-wiring-button").is_disabled) + self.assertFalse(self.find_navbar_button("wc-edit-mode-button").is_disabled) + self.assertTrue(self.find_navbar_button("wc-show-component-sidebar-button").is_disabled) + self.assertTrue(self.find_navbar_button("wc-show-wiring-button").is_disabled) def assertElementHasFocus(self, element): # Workaround webkit problem with xhtml and retreiving element with focus @@ -926,18 +947,19 @@ def test_gui_tutorials(self): next_button.click() WebDriverWait(self.driver, 10).until(WEC.element_be_clickable((By.CSS_SELECTOR, ".wc-toolbar .wc-show-component-sidebar-button"))) - with self.resource_sidebar as sidebar: + with self.edit_mode as edit_session: + with edit_session.resource_sidebar as sidebar: - # Add the youtube browser widget - WebDriverWait(self.driver, timeout=15).until(WEC.component_instantiable(sidebar, 'YouTube Browser')) + # Add the youtube browser widget + WebDriverWait(self.driver, timeout=15).until(WEC.component_instantiable(sidebar, 'YouTube Browser')) - # Next tutorial step - next_button = self.wait_element_visible_by_xpath("//*[contains(@class, 'window_menu')]//*[text()='Next']") - self.assertElementHasFocus(next_button) - next_button.click() + # Next tutorial step + next_button = self.wait_element_visible_by_xpath("//*[contains(@class, 'window_menu')]//*[text()='Next']") + self.assertElementHasFocus(next_button) + next_button.click() - # Add the input box widget - WebDriverWait(self.driver, timeout=15).until(WEC.component_instantiable(sidebar, 'Input Box')) + # Add the input box widget + WebDriverWait(self.driver, timeout=15).until(WEC.component_instantiable(sidebar, 'Input Box')) # cancel current tutorial self.wait_element_visible_by_xpath("//*[contains(@class, 'window_menu')]//*[text()='Cancel']").click() @@ -951,15 +973,16 @@ def test_move_widget_and_restore(self): iwidgets = self.widgets - self.assertEqual(iwidgets[0].layout_position, (0, 0)) - self.assertEqual(iwidgets[1].layout_position, (6, 0)) + with self.edit_mode as edit_session: + self.assertEqual(iwidgets[0].layout_position, (0, 0)) + self.assertEqual(iwidgets[1].layout_position, (6, 0)) - offset = iwidgets[1].element.location['x'] - iwidgets[0].element.location['x'] - ActionChains(self.driver).click_and_hold(iwidgets[0].title_element).move_by_offset(offset, 0).release().perform() - WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (6, 0) and iwidgets[1].layout_position == (6, 24)) + offset = iwidgets[1].element.location['x'] - iwidgets[0].element.location['x'] + ActionChains(self.driver).click_and_hold(iwidgets[0].title_element).move_by_offset(offset, 0).release().perform() + WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (6, 0) and iwidgets[1].layout_position == (6, 24)) - ActionChains(self.driver).click_and_hold(iwidgets[0].title_element).move_by_offset(-offset, 300).release().perform() - WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (0, 0) and iwidgets[1].layout_position == (6, 0)) + ActionChains(self.driver).click_and_hold(iwidgets[0].title_element).move_by_offset(-offset, 300).release().perform() + WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (0, 0) and iwidgets[1].layout_position == (6, 0)) test_move_widget_and_restore.tags = tags + ('wirecloud-dragboard',) @@ -972,18 +995,19 @@ def test_move_widget_and_restore_touch(self): iwidgets = self.widgets - self.assertEqual(iwidgets[0].layout_position, (0, 0)) - self.assertEqual(iwidgets[1].layout_position, (6, 0)) + with self.edit_mode as edit_session: + self.assertEqual(iwidgets[0].layout_position, (0, 0)) + self.assertEqual(iwidgets[1].layout_position, (6, 0)) - iwidgets[0].wait_loaded() + iwidgets[0].wait_loaded() - title_location = iwidgets[0].title_element.location - TouchActions(self.driver).tap_and_hold(title_location['x'] + 10, title_location['y'] + 10).move(330, title_location['y'] + 10).release(990, 300).perform() - WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (6, 0) and iwidgets[1].layout_position == (6, 24)) + title_location = iwidgets[0].title_element.location + TouchActions(self.driver).tap_and_hold(title_location['x'] + 10, title_location['y'] + 10).move(330, title_location['y'] + 10).release(990, 300).perform() + WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (6, 0) and iwidgets[1].layout_position == (6, 24)) - title_location = iwidgets[0].title_element.location - TouchActions(self.driver).tap_and_hold(title_location['x'] + 10, title_location['y'] + 10).move(0, 300).release(0, 300).perform() - WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (0, 0) and iwidgets[1].layout_position == (6, 0)) + title_location = iwidgets[0].title_element.location + TouchActions(self.driver).tap_and_hold(title_location['x'] + 10, title_location['y'] + 10).move(0, 300).release(0, 300).perform() + WebDriverWait(self.driver, timeout=5).until(lambda driver: iwidgets[0].layout_position == (0, 0) and iwidgets[1].layout_position == (6, 0)) test_move_widget_and_restore_touch.tags = tags + ('wirecloud-dragboard',) @@ -992,105 +1016,106 @@ def test_basic_add_and_move_widget(self): self.login(username="admin", next="/admin/Workspace") - with self.resource_sidebar as sidebar: - resource = sidebar.search_component('widget', 'Context Inspector') - widget1 = resource.create_component() - widget2 = resource.create_component() - - initial_widget1_position = widget1.layout_position - with widget1: - position_from_context = ( - int(self.driver.find_element_by_css_selector('[data-name="xPosition"] .content').text), - int(self.driver.find_element_by_css_selector('[data-name="yPosition"] .content').text), - ) - self.assertEqual(position_from_context, initial_widget1_position) - initial_widget1_xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - initial_widget1_yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - - with widget2: - initial_widget2_xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - self.assertEqual(initial_widget2_xPosition_changes, '0') - - initial_widget2_yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - self.assertEqual(initial_widget2_yPosition_changes, '0') - - # Move widget2 moving widget1 as side effect - self.driver.execute_script(''' - var view = Wirecloud.UserInterfaceManager.views.workspace; - var layout = view.activeTab.dragboard.baseLayout; - var widget = view.activeTab.findWidget(%s); - layout.initializeMove(widget); - layout.moveTemporally(3, 0); - layout.acceptMove(); - ''' % widget2.id) - - self.assertEqual(widget1.layout_position, (initial_widget1_position[0], 24)) - self.assertEqual(widget2.layout_position, (3, 0)) - - with widget1: - xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - self.assertEqual(xPosition_changes, initial_widget1_xPosition_changes) - - yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - self.assertEqual(yPosition_changes, str(int(initial_widget1_yPosition_changes) + 1)) - - height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text - self.assertEqual(height_changes, "0") - - width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text - self.assertEqual(width_changes, "0") - - with widget2: - xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - self.assertEqual(xPosition_changes, str(int(initial_widget2_xPosition_changes) + 1)) - - yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - self.assertEqual(yPosition_changes, initial_widget2_yPosition_changes) - - height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text - self.assertEqual(height_changes, "0") - - width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text - self.assertEqual(width_changes, "0") - - # Move widget2 again without affecting widget1 - self.driver.execute_script(''' - var view = Wirecloud.UserInterfaceManager.views.workspace; - var layout = view.activeTab.dragboard.baseLayout; - var widget = view.activeTab.findWidget(%s); - layout.initializeMove(widget); - layout.moveTemporally(0, 3); - layout.acceptMove(); - ''' % widget2.id) - - self.assertEqual(widget1.layout_position, (initial_widget1_position[0], 24)) - self.assertEqual(widget2.layout_position, (0, 0)) - - with widget1: - xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - self.assertEqual(xPosition_changes, initial_widget1_xPosition_changes) - - yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - self.assertEqual(yPosition_changes, str(int(initial_widget1_yPosition_changes) + 1)) - - height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text - self.assertEqual(height_changes, "0") - - width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text - self.assertEqual(width_changes, "0") - - with widget2: - xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text - self.assertEqual(xPosition_changes, str(int(initial_widget2_xPosition_changes) + 2)) - - yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text - self.assertEqual(yPosition_changes, initial_widget2_yPosition_changes) - - height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text - self.assertEqual(height_changes, "0") - - width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text - self.assertEqual(width_changes, "0") + with self.edit_mode as edit_session: + with edit_session.resource_sidebar as sidebar: + resource = sidebar.search_component('widget', 'Context Inspector') + widget1 = resource.create_component() + widget2 = resource.create_component() + + initial_widget1_position = widget1.layout_position + with widget1: + position_from_context = ( + int(self.driver.find_element_by_css_selector('[data-name="xPosition"] .content').text), + int(self.driver.find_element_by_css_selector('[data-name="yPosition"] .content').text), + ) + self.assertEqual(position_from_context, initial_widget1_position) + initial_widget1_xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + initial_widget1_yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + + with widget2: + initial_widget2_xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + self.assertEqual(initial_widget2_xPosition_changes, '0') + + initial_widget2_yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + self.assertEqual(initial_widget2_yPosition_changes, '0') + + # Move widget2 moving widget1 as side effect + self.driver.execute_script(''' + var view = Wirecloud.UserInterfaceManager.views.workspace; + var layout = view.activeTab.dragboard.baseLayout; + var widget = view.activeTab.findWidget(%s); + layout.initializeMove(widget); + layout.moveTemporally(3, 0); + layout.acceptMove(); + ''' % widget2.id) + + self.assertEqual(widget1.layout_position, (initial_widget1_position[0], 24)) + self.assertEqual(widget2.layout_position, (3, 0)) + + with widget1: + xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + self.assertEqual(xPosition_changes, initial_widget1_xPosition_changes) + + yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + self.assertEqual(yPosition_changes, str(int(initial_widget1_yPosition_changes) + 1)) + + height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text + self.assertEqual(height_changes, "0") + + width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text + self.assertEqual(width_changes, "0") + + with widget2: + xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + self.assertEqual(xPosition_changes, str(int(initial_widget2_xPosition_changes) + 1)) + + yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + self.assertEqual(yPosition_changes, initial_widget2_yPosition_changes) + + height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text + self.assertEqual(height_changes, "0") + + width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text + self.assertEqual(width_changes, "0") + + # Move widget2 again without affecting widget1 + self.driver.execute_script(''' + var view = Wirecloud.UserInterfaceManager.views.workspace; + var layout = view.activeTab.dragboard.baseLayout; + var widget = view.activeTab.findWidget(%s); + layout.initializeMove(widget); + layout.moveTemporally(0, 3); + layout.acceptMove(); + ''' % widget2.id) + + self.assertEqual(widget1.layout_position, (initial_widget1_position[0], 24)) + self.assertEqual(widget2.layout_position, (0, 0)) + + with widget1: + xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + self.assertEqual(xPosition_changes, initial_widget1_xPosition_changes) + + yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + self.assertEqual(yPosition_changes, str(int(initial_widget1_yPosition_changes) + 1)) + + height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text + self.assertEqual(height_changes, "0") + + width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text + self.assertEqual(width_changes, "0") + + with widget2: + xPosition_changes = self.driver.find_element_by_css_selector('[data-name="xPosition"] .badge').text + self.assertEqual(xPosition_changes, str(int(initial_widget2_xPosition_changes) + 2)) + + yPosition_changes = self.driver.find_element_by_css_selector('[data-name="yPosition"] .badge').text + self.assertEqual(yPosition_changes, initial_widget2_yPosition_changes) + + height_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text + self.assertEqual(height_changes, "0") + + width_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text + self.assertEqual(width_changes, "0") test_basic_add_and_move_widget.tags = tags + ('wirecloud-dragboard',) def test_move_widget_interchange(self): @@ -1099,32 +1124,33 @@ def test_move_widget_interchange(self): iwidgets = self.widgets - self.assertEqual(iwidgets[0].layout_position, (0, 0)) - self.assertEqual(iwidgets[1].layout_position, (6, 0)) - - self.driver.execute_script(''' - var view = Wirecloud.UserInterfaceManager.views.workspace; - var layout = view.activeTab.dragboard.baseLayout; - var widget = view.activeTab.findWidget(%s); - layout.initializeMove(widget); - layout.moveTemporally(6, 25); - layout.acceptMove(); - ''' % iwidgets[0].id) - - self.assertEqual(iwidgets[0].layout_position, (6, 24)) - self.assertEqual(iwidgets[1].layout_position, (6, 0)) - - self.driver.execute_script(''' - var view = Wirecloud.UserInterfaceManager.views.workspace; - var layout = view.activeTab.dragboard.baseLayout; - var widget = view.activeTab.findWidget(%s); - layout.initializeMove(widget); - layout.moveTemporally(0, 0); - layout.acceptMove(); - ''' % iwidgets[1].id) - - self.assertEqual(iwidgets[0].layout_position, (6, 0)) - self.assertEqual(iwidgets[1].layout_position, (0, 0)) + with self.edit_mode as edit_session: + self.assertEqual(iwidgets[0].layout_position, (0, 0)) + self.assertEqual(iwidgets[1].layout_position, (6, 0)) + + self.driver.execute_script(''' + var view = Wirecloud.UserInterfaceManager.views.workspace; + var layout = view.activeTab.dragboard.baseLayout; + var widget = view.activeTab.findWidget(%s); + layout.initializeMove(widget); + layout.moveTemporally(6, 25); + layout.acceptMove(); + ''' % iwidgets[0].id) + + self.assertEqual(iwidgets[0].layout_position, (6, 24)) + self.assertEqual(iwidgets[1].layout_position, (6, 0)) + + self.driver.execute_script(''' + var view = Wirecloud.UserInterfaceManager.views.workspace; + var layout = view.activeTab.dragboard.baseLayout; + var widget = view.activeTab.findWidget(%s); + layout.initializeMove(widget); + layout.moveTemporally(0, 0); + layout.acceptMove(); + ''' % iwidgets[1].id) + + self.assertEqual(iwidgets[0].layout_position, (6, 0)) + self.assertEqual(iwidgets[1].layout_position, (0, 0)) test_move_widget_interchange.tags = tags + ('wirecloud-dragboard',) @@ -1134,12 +1160,14 @@ def test_extract_widget_from_grid(self): self.login(username="admin", next="/admin/GridLayoutTests") iwidget = self.widgets[0] - _, old_size = self.get_widget_sizes_from_context(iwidget) - iwidget.open_menu().click_entry('Extract from grid') - _, new_size = self.get_widget_sizes_from_context(iwidget.wait_still()) + with self.edit_mode as edit_session: + _, old_size = self.get_widget_sizes_from_context(iwidget) - self.assertEqual(old_size, new_size) + iwidget.open_menu().click_entry('Extract from grid') + _, new_size = self.get_widget_sizes_from_context(iwidget.wait_still()) + + self.assertEqual(old_size, new_size) test_extract_widget_from_grid.tags = tags + ('wirecloud-dragboard',) @uses_extra_resources(('Wirecloud_context-inspector_0.5.wgt',), shared=True) @@ -1148,24 +1176,25 @@ def test_minimize_widget(self): self.login(username="user_with_workspaces", next="/user_with_workspaces/ColumnLayoutTests") - iwidget = self.widgets[0] - affected_iwidget = self.widgets[2] - old_size, old_size_in_pixels = self.get_widget_sizes_from_context(iwidget) - old_affected_iwidget_position = affected_iwidget.layout_position + with self.edit_mode as edit_session: + iwidget = self.widgets[0] + affected_iwidget = self.widgets[2] + old_size, old_size_in_pixels = self.get_widget_sizes_from_context(iwidget) + old_affected_iwidget_position = affected_iwidget.layout_position - iwidget.minimize() - minimized_size, minimized_size_in_pixels = self.get_widget_sizes_from_context(iwidget) - self.assertEqual(minimized_size[0], old_size[0]) - self.assertLess(minimized_size[1], old_size[1]) - self.assertEqual(minimized_size_in_pixels, (old_size_in_pixels[0], 0)) - self.assertEqual(affected_iwidget.layout_position, (0, minimized_size[1])) + iwidget.minimize() + minimized_size, minimized_size_in_pixels = self.get_widget_sizes_from_context(iwidget) + self.assertEqual(minimized_size[0], old_size[0]) + self.assertLess(minimized_size[1], old_size[1]) + self.assertEqual(minimized_size_in_pixels, (old_size_in_pixels[0], 0)) + self.assertEqual(affected_iwidget.layout_position, (0, minimized_size[1])) - iwidget.maximize() - new_size, new_size_in_pixels = self.get_widget_sizes_from_context(iwidget) + iwidget.maximize() + new_size, new_size_in_pixels = self.get_widget_sizes_from_context(iwidget) - self.assertEqual(old_size, new_size) - self.assertEqual(old_size_in_pixels, new_size_in_pixels) - self.assertEqual(old_affected_iwidget_position, affected_iwidget.layout_position) + self.assertEqual(old_size, new_size) + self.assertEqual(old_size_in_pixels, new_size_in_pixels) + self.assertEqual(old_affected_iwidget_position, affected_iwidget.layout_position) test_minimize_widget.tags = tags + ('wirecloud-dragboard',) @@ -1179,18 +1208,20 @@ def test_basic_layout_parameter_change(self): # Check initial sizes with widget: old_width_from_context = int(self.driver.find_element_by_css_selector('[data-name="width"] .content').text) + old_height_in_pixels_changes = int(self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text) self.assertEqual(old_width_from_context, 6) # Change columns to 10 - self.open_menu().click_entry('Settings') - workspace_preferences_dialog = FormModalTester(self, self.wait_element_visible('.wc-workspace-preferences-modal')) + with self.edit_mode as edit_session: + self.open_menu().click_entry('Settings') + workspace_preferences_dialog = FormModalTester(self, self.wait_element_visible('.wc-workspace-preferences-modal')) - workspace_preferences_dialog.find_element('.fa-cogs').click() - layout_form = FormModalTester(self, self.wait_element_visible(".wc-layout-settings-modal")) - layout_form.get_field("columns").set_value('10') - layout_form.accept() + workspace_preferences_dialog.find_element('.fa-cogs').click() + layout_form = FormModalTester(self, self.wait_element_visible(".wc-layout-settings-modal")) + layout_form.get_field("columns").set_value('10') + layout_form.accept() - workspace_preferences_dialog.accept() + workspace_preferences_dialog.accept() # Check new sizes with widget: @@ -1205,7 +1236,7 @@ def test_basic_layout_parameter_change(self): width_in_pixels_changes = self.driver.find_element_by_css_selector('[data-name="widthInPixels"] .badge').text self.assertEqual(width_in_pixels_changes, '0') height_in_pixels_changes = self.driver.find_element_by_css_selector('[data-name="heightInPixels"] .badge').text - self.assertEqual(height_in_pixels_changes, '0') + self.assertEqual(height_in_pixels_changes, "%s" % (old_height_in_pixels_changes + 1)) test_basic_layout_parameter_change.tags = tags + ('wirecloud-dragboard',) @@ -1234,15 +1265,16 @@ def test_basic_layout_parameter_change_several_widgets(self): old_size_from_context2, old_size_in_pixels_from_context2 = self.get_widget_sizes_from_context(iwidgets[1]) # Change columns to 10 - self.open_menu().click_entry('Settings') - workspace_preferences_dialog = FormModalTester(self, self.wait_element_visible('.wc-workspace-preferences-modal')) + with self.edit_mode as edit_session: + self.open_menu().click_entry('Settings') + workspace_preferences_dialog = FormModalTester(self, self.wait_element_visible('.wc-workspace-preferences-modal')) - workspace_preferences_dialog.find_element('.fa-cogs').click() - layout_form = FormModalTester(self, self.wait_element_visible(".wc-layout-settings-modal")) - layout_form.get_field("columns").set_value('10') - layout_form.accept() + workspace_preferences_dialog.find_element('.fa-cogs').click() + layout_form = FormModalTester(self, self.wait_element_visible(".wc-layout-settings-modal")) + layout_form.get_field("columns").set_value('10') + layout_form.accept() - workspace_preferences_dialog.accept() + workspace_preferences_dialog.accept() # Check new widget 1 sizes new_size_from_context1, new_size_in_pixels_from_context1 = self.get_widget_sizes_from_context(iwidgets[0].wait_still()) @@ -1271,10 +1303,11 @@ def test_layout_type_change(self): self.assertEqual(old_size_from_context[0], 6) # Change current layout to grid - self.open_menu().click_entry('Settings') - form = FormModalTester(self, self.wait_element_visible(".wc-workspace-preferences-modal")) - form.get_field("baselayout-type").set_value('gridlayout') - form.accept() + with self.edit_mode as edit_session: + self.open_menu().click_entry('Settings') + form = FormModalTester(self, self.wait_element_visible(".wc-workspace-preferences-modal")) + form.get_field("baselayout-type").set_value('gridlayout') + form.accept() # Check new sizes new_size_from_context, new_size_in_pixels_from_context = self.get_widget_sizes_from_context(widget) @@ -1380,51 +1413,52 @@ def test_upgrade_widget(self): widget, other_widget = self.widgets - # Upgrade to version 3.0 - widget.open_menu().click_entry('Upgrade/Downgrade') - form = FormModalTester(self, self.wait_element_visible(".wc-upgrade-component-modal")) - form.accept() - - # Check settings - widget.open_menu().click_entry('Settings') - - form = FormModalTester(self, self.wait_element_visible(".wc-component-preferences-modal")) - self.assertRaises(NoSuchElementException, form.get_field, 'list') - self.assertEqual(form.get_field('text').value, 'initial text') - self.assertRaises(NoSuchElementException, form.get_field, 'boolean') - self.assertRaises(NoSuchElementException, form.get_field, 'number') - self.assertRaises(NoSuchElementException, form.get_field, 'password') - self.assertEqual(form.get_field('new').value, 'initial value') - form.accept() - - # Check wiring - self.send_basic_event(widget) - - # This should work as the outputendpoint is still available on version 3.0 - with other_widget: - WebDriverWait(self.driver, timeout=3).until(lambda driver: driver.find_element_by_id('wiringOut').text == 'hello world!!') - - self.send_basic_event(other_widget) - time.sleep(3) - - # Instead inputendpoint has been replaced by inputendpoint2 - with widget: - text_div = self.driver.find_element_by_id('wiringOut') - self.assertEqual(text_div.text, '') - - # Downgrade to version 1.0 - widget.open_menu().click_entry('Upgrade/Downgrade') - form = FormModalTester(self, self.wait_element_visible(".wc-upgrade-component-modal")) - form.accept() - - # Check settings - widget.open_menu().click_entry('Settings') - - form = FormModalTester(self, self.wait_element_visible(".wc-component-preferences-modal")) - self.assertEqual(form.get_field('list').value, 'default') - self.assertEqual(form.get_field('text').value, 'initial text') - self.assertRaises(NoSuchElementException, form.get_field, 'new') - form.accept() + with self.edit_mode as edit_session: + # Upgrade to version 3.0 + widget.open_menu().click_entry('Upgrade/Downgrade') + form = FormModalTester(self, self.wait_element_visible(".wc-upgrade-component-modal")) + form.accept() + + # Check settings + widget.open_menu().click_entry('Settings') + + form = FormModalTester(self, self.wait_element_visible(".wc-component-preferences-modal")) + self.assertRaises(NoSuchElementException, form.get_field, 'list') + self.assertEqual(form.get_field('text').value, 'initial text') + self.assertRaises(NoSuchElementException, form.get_field, 'boolean') + self.assertRaises(NoSuchElementException, form.get_field, 'number') + self.assertRaises(NoSuchElementException, form.get_field, 'password') + self.assertEqual(form.get_field('new').value, 'initial value') + form.accept() + + # Check wiring + self.send_basic_event(widget) + + # This should work as the outputendpoint is still available on version 3.0 + with other_widget: + WebDriverWait(self.driver, timeout=3).until(lambda driver: driver.find_element_by_id('wiringOut').text == 'hello world!!') + + self.send_basic_event(other_widget) + time.sleep(3) + + # Instead inputendpoint has been replaced by inputendpoint2 + with widget: + text_div = self.driver.find_element_by_id('wiringOut') + self.assertEqual(text_div.text, '') + + # Downgrade to version 1.0 + widget.open_menu().click_entry('Upgrade/Downgrade') + form = FormModalTester(self, self.wait_element_visible(".wc-upgrade-component-modal")) + form.accept() + + # Check settings + widget.open_menu().click_entry('Settings') + + form = FormModalTester(self, self.wait_element_visible(".wc-component-preferences-modal")) + self.assertEqual(form.get_field('list').value, 'default') + self.assertEqual(form.get_field('text').value, 'initial text') + self.assertRaises(NoSuchElementException, form.get_field, 'new') + form.accept() # Check wiring self.send_basic_event(widget, 'hello world 2!!') diff --git a/src/wirecloud/platform/wiring/tests.py b/src/wirecloud/platform/wiring/tests.py index 2fb9425361..f2ebf0dfd0 100644 --- a/src/wirecloud/platform/wiring/tests.py +++ b/src/wirecloud/platform/wiring/tests.py @@ -2143,105 +2143,110 @@ def _read_json_fixtures(self, *args): def test_component_dropped_out_of_bounds_should_be_added(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/WiringTests') - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - self.assertIsNotNone(sidebar.add_component('operator', "Wirecloud/TestOperator", y=-20)) - self.assertIsNotNone(sidebar.add_component('widget', "Wirecloud/Test", title="Test (1)", x=-4)) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + self.assertIsNotNone(sidebar.add_component('operator', "Wirecloud/TestOperator", y=-20)) + self.assertIsNotNone(sidebar.add_component('widget', "Wirecloud/Test", title="Test (1)", x=-4)) test_component_dropped_out_of_bounds_should_be_added.tags = tags + ('wirecloud-wiring-draggable-component',) @uses_extra_resources(('Wirecloud_TestOperator_2.0.zip',), shared=True) def test_upgrade_operator(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - operator = sidebar.find_component('operator', "Wirecloud/TestOperator", id=0) - operator.change_version("2.0") - modal = operator.show_logs() - WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The operator was upgraded to v2.0 successfully.")) == 1) - modal.accept() - draggable_operator = wiring.find_draggable_component('operator', id=operator.id) - - self.assertEqual(len(draggable_operator.find_endpoints('target')), 2) - target = draggable_operator.find_endpoint('target', "input") - self.assertFalse(target.has_class('missing')) - self.assertTrue(len(target.find_connections()), 1) - - self.assertEqual(len(draggable_operator.find_endpoints('source')), 2) - source = draggable_operator.find_endpoint('source', "output") - self.assertTrue(source.has_class('missing')) - self.assertTrue(len(source.find_connections()), 1) - - self.assertEqual(len(wiring.find_connections(extra_class="missing")), 1) - connection = wiring.find_connections(extra_class="missing")[0] - self.assertEqual(connection.source_id, source.id) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + operator = sidebar.find_component('operator', "Wirecloud/TestOperator", id=0) + operator.change_version("2.0") + modal = operator.show_logs() + WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The operator was upgraded to v2.0 successfully.")) == 1) + modal.accept() + draggable_operator = wiring.find_draggable_component('operator', id=operator.id) + + self.assertEqual(len(draggable_operator.find_endpoints('target')), 2) + target = draggable_operator.find_endpoint('target', "input") + self.assertFalse(target.has_class('missing')) + self.assertTrue(len(target.find_connections()), 1) + + self.assertEqual(len(draggable_operator.find_endpoints('source')), 2) + source = draggable_operator.find_endpoint('source', "output") + self.assertTrue(source.has_class('missing')) + self.assertTrue(len(source.find_connections()), 1) + + self.assertEqual(len(wiring.find_connections(extra_class="missing")), 1) + connection = wiring.find_connections(extra_class="missing")[0] + self.assertEqual(connection.source_id, source.id) @uses_extra_resources(('Wirecloud_Test_3.0.wgt',), shared=True) def test_upgrade_and_downgrade_widget(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - # Upgrade to v3 on the sidebar - with wiring.component_sidebar as sidebar: - widget = sidebar.find_component('widget', "Wirecloud/Test", title="Test 1") - widget.change_version("3.0") - WebDriverWait(self.driver, timeout=3).until(lambda driver: widget.version == "v3.0") - modal = widget.show_logs() - WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The widget was upgraded to v3.0 successfully.")) == 1) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + # Upgrade to v3 on the sidebar + with wiring.component_sidebar as sidebar: + widget = sidebar.find_component('widget', "Wirecloud/Test", title="Test 1") + widget.change_version("3.0") + WebDriverWait(self.driver, timeout=3).until(lambda driver: widget.version == "v3.0") + modal = widget.show_logs() + WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The widget was upgraded to v3.0 successfully.")) == 1) + modal.accept() + + draggable_widget = wiring.find_draggable_component('widget', id=widget.id) + + self.assertEqual(len(draggable_widget.find_endpoints('target')), 2) + target = draggable_widget.find_endpoint('target', "inputendpoint") + self.assertTrue(target.has_class('missing')) + self.assertTrue(len(target.find_connections()), 1) + + self.assertEqual(len(wiring.find_connections(extra_class="missing")), 1) + connection = wiring.find_connections(extra_class="missing")[0] + self.assertEqual(connection.target_id, target.id) + + self.assertEqual(len(draggable_widget.find_endpoints('source')), 1) + source = draggable_widget.find_endpoint('source', "outputendpoint") + self.assertFalse(source.has_class('missing')) + self.assertTrue(len(source.find_connections()), 1) + + # Downgrade to v1 using the widget preferences + draggable_widget.change_version("1.0") + modal = draggable_widget.show_logs() + WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The widget was downgraded to v1.0 successfully.")) == 1) modal.accept() - draggable_widget = wiring.find_draggable_component('widget', id=widget.id) - - self.assertEqual(len(draggable_widget.find_endpoints('target')), 2) - target = draggable_widget.find_endpoint('target', "inputendpoint") - self.assertTrue(target.has_class('missing')) - self.assertTrue(len(target.find_connections()), 1) - - self.assertEqual(len(wiring.find_connections(extra_class="missing")), 1) - connection = wiring.find_connections(extra_class="missing")[0] - self.assertEqual(connection.target_id, target.id) - - self.assertEqual(len(draggable_widget.find_endpoints('source')), 1) - source = draggable_widget.find_endpoint('source', "outputendpoint") - self.assertFalse(source.has_class('missing')) - self.assertTrue(len(source.find_connections()), 1) - - # Downgrade to v1 using the widget preferences - draggable_widget.change_version("1.0") - modal = draggable_widget.show_logs() - WebDriverWait(self.driver, timeout=5).until(lambda driver: len(modal.find_alerts(title="The widget was downgraded to v1.0 successfully.")) == 1) - modal.accept() - - self.assertEqual(len(draggable_widget.find_endpoints('target')), 2) - target = draggable_widget.find_endpoint('target', "inputendpoint") - self.assertFalse(target.has_class('missing')) - self.assertTrue(len(target.find_connections()), 1) + self.assertEqual(len(draggable_widget.find_endpoints('target')), 2) + target = draggable_widget.find_endpoint('target', "inputendpoint") + self.assertFalse(target.has_class('missing')) + self.assertTrue(len(target.find_connections()), 1) - self.assertEqual(len(wiring.find_connections(extra_class="missing")), 0) + self.assertEqual(len(wiring.find_connections(extra_class="missing")), 0) @uses_extra_resources(('Wirecloud_Test_3.0.wgt',), shared=True) def test_remove_missing_endpoint_with_no_connections(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - draggable_widget = wiring.find_draggable_component('widget', title="Test 1") - draggable_widget.change_version("3.0") + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + draggable_widget = wiring.find_draggable_component('widget', title="Test 1") + draggable_widget.change_version("3.0") - WebDriverWait(self.driver, timeout=5).until(lambda driver: len(wiring.find_connections(extra_class="missing")) == 1) + WebDriverWait(self.driver, timeout=5).until(lambda driver: len(wiring.find_connections(extra_class="missing")) == 1) - connection = wiring.find_connections(extra_class="missing")[0] - connection.remove() + connection = wiring.find_connections(extra_class="missing")[0] + connection.remove() - self.assertIsNone(draggable_widget.find_endpoint('target', "inputendpoint")) + self.assertIsNone(draggable_widget.find_endpoint('target', "inputendpoint")) @uses_extra_resources(('Wirecloud_Test_3.0.wgt',), shared=True) def test_missing_endpoints_cannot_be_ordered(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - draggable_widget = wiring.find_draggable_component('widget', title="Test 1") - draggable_widget.change_version("3.0") - draggable_widget.show_preferences().check(must_be_disabled=("Order endpoints",)) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + draggable_widget = wiring.find_draggable_component('widget', title="Test 1") + draggable_widget.change_version("3.0") + draggable_widget.show_preferences().check(must_be_disabled=("Order endpoints",)) def test_widget_uninstalled_with_tradeinfo(self): @@ -2249,8 +2254,9 @@ def test_widget_uninstalled_with_tradeinfo(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - self.assertEqual(len(wiring.find_draggable_components('widget', extra_class='missing')), 2) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self.assertEqual(len(wiring.find_draggable_components('widget', extra_class='missing')), 2) def test_widget_with_visualinfo_and_connections_is_not_in_workspace(self): @@ -2267,9 +2273,10 @@ def test_widget_with_visualinfo_and_connections_is_not_in_workspace(self): # status self.assertIsNone(self.find_navbar_button("wc-show-wiring-button").badge) - with self.wiring_view as wiring: - # Check the Wiring Editor only display the valid widgets - self.assertEqual(len(wiring.find_draggable_components('widget')), 2) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + # Check the Wiring Editor only display the valid widgets + self.assertEqual(len(wiring.find_draggable_components('widget')), 2) def _check_operator_missing(self, wiring, component_id, source_length, target_length): operator = wiring.find_draggable_component('operator', id=component_id) @@ -2288,11 +2295,12 @@ def test_operator_uninstalled_with_tradeinfo(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/Workspace') self.check_wiring_badge("1") - with self.wiring_view as wiring: - self._check_operator_missing(wiring, 1, 0, 0) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self._check_operator_missing(wiring, 1, 0, 0) - with self.wiring_view as wiring: - self._check_operator_missing(wiring, 1, 0, 0) + with edit_session.wiring_view as wiring: + self._check_operator_missing(wiring, 1, 0, 0) def test_operator_uninstalled_with_tradeinfo_and_connections(self): workspace = Workspace.objects.get(id=2) @@ -2302,9 +2310,10 @@ def test_operator_uninstalled_with_tradeinfo_and_connections(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") self.check_wiring_badge("4") - with self.wiring_view as wiring: - self._check_operator_missing(wiring, 1, 1, 1) - self.assertEqual(len(wiring.find_connections(extra_class="missing")), 3) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self._check_operator_missing(wiring, 1, 1, 1) + self.assertEqual(len(wiring.find_connections(extra_class="missing")), 3) @uses_extra_resources(('Wirecloud_TestOperator_2.0.zip',), shared=True) def test_upgrade_missing_operator(self): @@ -2314,15 +2323,16 @@ def test_upgrade_missing_operator(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: - # Check operator is marked as missing - operator = wiring.find_draggable_component('operator', id=0) - self.assertTrue(operator.has_class('missing')) + # Check operator is marked as missing + operator = wiring.find_draggable_component('operator', id=0) + self.assertTrue(operator.has_class('missing')) - # Upgrade it to version 2.0 and check it leaves the missing status - operator.change_version("2.0") - WebDriverWait(self.driver, timeout=5).until(lambda driver: not operator.has_class('missing')) + # Upgrade it to version 2.0 and check it leaves the missing status + operator.change_version("2.0") + WebDriverWait(self.driver, timeout=5).until(lambda driver: not operator.has_class('missing')) def test_operator_install_uninstall(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/pending-events') @@ -2330,18 +2340,20 @@ def test_operator_install_uninstall(self): with self.myresources_view as myresources: myresources.upload_resource('Wirecloud_TestOperatorSelenium_1.0.zip', 'TestOperatorSelenium', shared=True) - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - self.assertIsNotNone(sidebar.find_component_group('operator', "Wirecloud/TestOperatorSelenium")) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + self.assertIsNotNone(sidebar.find_component_group('operator', "Wirecloud/TestOperatorSelenium")) with self.myresources_view as myresources: myresources.uninstall_resource("TestOperator") - with self.wiring_view as wiring: - self.assertTrue(wiring.find_draggable_component('operator', id=0).has_class('missing')) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self.assertTrue(wiring.find_draggable_component('operator', id=0).has_class('missing')) - with wiring.component_sidebar as sidebar: - self.assertIsNone(sidebar.find_component_group('operator', "Wirecloud/TestOperator")) + with wiring.component_sidebar as sidebar: + self.assertIsNone(sidebar.find_component_group('operator', "Wirecloud/TestOperator")) test_operator_install_uninstall.tags = tags + ('wirecloud-wiring-components',) def test_operator_not_usable_after_being_deleted(self): @@ -2350,9 +2362,10 @@ def test_operator_not_usable_after_being_deleted(self): with self.myresources_view as myresources: myresources.delete_resource('TestOperator') - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - self.assertIsNone(sidebar.find_component_group('operator', "Wirecloud/TestOperator")) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + self.assertIsNone(sidebar.find_component_group('operator', "Wirecloud/TestOperator")) test_operator_not_usable_after_being_deleted.tags = tags + ('wirecloud-wiring-components',) @uses_extra_resources(('Wirecloud_Test_NoImage_3.0.wgt',), shared=True) @@ -2360,10 +2373,11 @@ def test_widget_with_no_image(self): # Add a widget with no image included. self.login(username="admin", next="admin/Workspace") - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - # The current version displayed should show the default no-image. - self.assertFalse(sidebar.find_component_group('widget', "Wirecloud/Test_NoImage").has_image()) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + # The current version displayed should show the default no-image. + self.assertFalse(sidebar.find_component_group('widget', "Wirecloud/Test_NoImage").has_image()) test_widget_with_no_image.tags = tags + ('wirecloud-wiring-components',) def test_operator_can_be_used_after_being_reinstalled(self): @@ -2420,12 +2434,13 @@ def _check_reinstalled_operator(self, prefix): WebDriverWait(self.driver, timeout=5).until(lambda driver: driver.find_element_by_id('wiringOut').text == prefix + event) # Check preference values has been restored to the values used before uninstalling the widget and not to the default ones - with self.wiring_view as wiring: - modal = wiring.find_draggable_component('operator', id=0).show_settings() - self.assertEqual(modal.get_field('prefix').value, "test_") - self.assertFalse(modal.get_field('exception_on_event').is_selected) - self.assertTrue(modal.get_field('test_logging').is_selected) - modal.accept() + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + modal = wiring.find_draggable_component('operator', id=0).show_settings() + self.assertEqual(modal.get_field('prefix').value, "test_") + self.assertFalse(modal.get_field('exception_on_event').is_selected) + self.assertTrue(modal.get_field('test_logging').is_selected) + modal.accept() @uses_extra_resources(('Wirecloud_api-test_0.9.wgt',), shared=True) @uses_extra_workspace('admin', 'Wirecloud_api-test-mashup_1.0.wgt', shared=True) @@ -2455,19 +2470,20 @@ def test_dashboard_management_api_support(self): # the connection between the volatile operator and the volatile widget WebDriverWait(self.driver, timeout=5).until(lambda driver: len(self.widgets) == (iwidgets_count + 2)) - with self.wiring_view as wiring: - self.assertEqual(len(wiring.find_draggable_components('operator')), 1) - self.assertEqual(len(wiring.find_draggable_components('widget')), 3) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self.assertEqual(len(wiring.find_draggable_components('operator')), 1) + self.assertEqual(len(wiring.find_draggable_components('widget')), 3) - with wiring.component_sidebar as sidebar: - # The dasboard management test creates a volatile operator, - self.assertEqual(len(sidebar.find_components('operator', "Wirecloud/TestOperator", state='volatile')), 1) - # two volatile widgets - self.assertEqual(len(sidebar.find_components('widget', "Wirecloud/api-test", state='volatile')), 2) + with wiring.component_sidebar as sidebar: + # The dasboard management test creates a volatile operator, + self.assertEqual(len(sidebar.find_components('operator', "Wirecloud/TestOperator", state='volatile')), 1) + # two volatile widgets + self.assertEqual(len(sidebar.find_components('widget', "Wirecloud/api-test", state='volatile')), 2) - # and a volatile connection between the operator and one the volatile widgets - # Wiring Editor should only display the initial connections - self.assertEqual(len(wiring.find_connections()), 2) + # and a volatile connection between the operator and one the volatile widgets + # Wiring Editor should only display the initial connections + self.assertEqual(len(wiring.find_connections()), 2) # Check dynamic connections created by the dashboard_management_button works as expected with iwidgets[1]: @@ -2508,13 +2524,14 @@ def test_connections_works_engine_disabled(self): tab_widget1, tab_widget2, _ = self.widgets # Create a new connection and check it works - with self.wiring_view as wiring: - widget1 = wiring.find_draggable_component('widget', id=tab_widget1.id) - widget2 = wiring.find_draggable_component('widget', id=tab_widget2.id) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + widget1 = wiring.find_draggable_component('widget', id=tab_widget1.id) + widget2 = wiring.find_draggable_component('widget', id=tab_widget2.id) - source = widget1.find_endpoint('source', "outputendpoint") - target = widget2.find_endpoint('target', "inputendpoint") - source.create_connection(target) + source = widget1.find_endpoint('source', "outputendpoint") + target = widget2.find_endpoint('target', "inputendpoint") + source.create_connection(target) self.send_basic_event(tab_widget1, event) @@ -2525,9 +2542,10 @@ def test_connections_works_engine_disabled(self): ) # Now remove the connection - with self.wiring_view as wiring: - for connection in wiring.find_connections(): - connection.remove() + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + for connection in wiring.find_connections(): + connection.remove() self.send_basic_event(tab_widget1, "other") # Wait 5 seconds before checking no event is received @@ -2539,23 +2557,25 @@ def test_connections_works_engine_disabled(self): def test_component_preferences_in_wiring_editor(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - tab_widget = self.find_widget(title="Test 1") pref_prefix = "prefix: " - with self.wiring_view as wiring: - widget = wiring.find_draggable_component('widget', id=tab_widget.id) - operator = wiring.find_draggable_component('operator', id=0) - operator.wait_to_be_loaded() + with self.edit_mode as edit_session: + tab_widget = self.find_widget(title="Test 1") + + with edit_session.wiring_view as wiring: + widget = wiring.find_draggable_component('widget', id=tab_widget.id) + operator = wiring.find_draggable_component('operator', id=0) + operator.wait_to_be_loaded() - # Update widget preferences using the wiring editor interface - modal = widget.show_settings() - modal.get_field('text').set_value("test") - modal.accept() + # Update widget preferences using the wiring editor interface + modal = widget.show_settings() + modal.get_field('text').set_value("test") + modal.accept() - # Update operator preferences using the wiring editor interface - modal = operator.show_settings() - modal.get_field('prefix').set_value(pref_prefix) - modal.accept() + # Update operator preferences using the wiring editor interface + modal = operator.show_settings() + modal.get_field('prefix').set_value(pref_prefix) + modal.accept() # Check the widget has received an event with the new values with tab_widget: @@ -2596,15 +2616,16 @@ def test_wiring_editor_create_and_modify_connection_endpoints(self): # Modify connection between widget1 and widget2 # so widget1 is connected to widget3 instead - with self.wiring_view as wiring: - widget2 = wiring.find_draggable_component('widget', title="Test (2)") - widget3 = wiring.find_draggable_component('widget', title="Test (3)") + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + widget2 = wiring.find_draggable_component('widget', title="Test (2)") + widget3 = wiring.find_draggable_component('widget', title="Test (3)") - old_target = widget2.find_endpoint('target', "inputendpoint") - new_target = widget3.find_endpoint('target', "inputendpoint") + old_target = widget2.find_endpoint('target', "inputendpoint") + new_target = widget3.find_endpoint('target', "inputendpoint") - connection = wiring.find_connection("widget/7/outputendpoint", "widget/8/inputendpoint") - connection.change_endpoint(old_target, new_target) + connection = wiring.find_connection("widget/7/outputendpoint", "widget/8/inputendpoint") + connection.change_endpoint(old_target, new_target) # Check new wiring configuration self.send_basic_event(widgets[0], event2) @@ -2619,81 +2640,85 @@ def test_operator_logging_support(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - operator = wiring.find_draggable_component('operator', id=0) - operator.wait_to_be_loaded() + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + operator = wiring.find_draggable_component('operator', id=0) + operator.wait_to_be_loaded() - modal = operator.show_logs() - self.assertEqual(len(modal.find_alerts(state='error')), 0) - modal.accept() + modal = operator.show_logs() + self.assertEqual(len(modal.find_alerts(state='error')), 0) + modal.accept() - # Make test operator log some errors - modal = operator.show_settings() - modal.get_field('test_logging').click() - modal.accept() + # Make test operator log some errors + modal = operator.show_settings() + modal.get_field('test_logging').click() + modal.accept() - # Check operator registered correctly the errors raised by the operator - modal = operator.show_logs() - self.assertEqual(len(modal.find_alerts(state='error')), 2) - modal.accept() + # Check operator registered correctly the errors raised by the operator + modal = operator.show_logs() + self.assertEqual(len(modal.find_alerts(state='error')), 2) + modal.accept() - with self.find_widget(title="Test 1"): - self.assertEqual(self.driver.find_element_by_id('wiringOut').text, 'preferences changed: test_logging') + with self.find_widget(title="Test 1"): + self.assertEqual(self.driver.find_element_by_id('wiringOut').text, 'preferences changed: test_logging') @uses_extra_resources(('Wirecloud_api-test_0.9.wgt',), shared=True) @uses_extra_workspace('admin', 'Wirecloud_api-test-mashup_1.0.wgt', shared=True) def test_wiring_status_change_events_from_components(self): self.login(username="admin", next="admin/api-test-mashup") - tab_widget = self.find_widget(title="Wirecloud API test") - with tab_widget: - self.assertEqual(self.driver.find_element_by_id('wiring_hasinputconnections_test').text, "true") - self.assertEqual(self.driver.find_element_by_id('wiring_hasoutputconnections_test').text, "false") + with self.edit_mode as edit_session: + tab_widget = self.find_widget(title="Wirecloud API test") - with self.wiring_view as wiring: + with tab_widget: + self.assertEqual(self.driver.find_element_by_id('wiring_hasinputconnections_test').text, "true") + self.assertEqual(self.driver.find_element_by_id('wiring_hasoutputconnections_test').text, "false") - # Make modifications into the wiring - for connection in wiring.find_connections(): - connection.remove() + with edit_session.wiring_view as wiring: - widget = wiring.find_draggable_component('widget', id=tab_widget.id) - operator = wiring.find_draggable_component('operator', id=1) + # Make modifications into the wiring + for connection in wiring.find_connections(): + connection.remove() - target = operator.find_endpoint('target', "input") - source = widget.find_endpoint('source', "outputendpoint") - source.create_connection(target) + widget = wiring.find_draggable_component('widget', id=tab_widget.id) + operator = wiring.find_draggable_component('operator', id=1) - # Create another connection between the operator and the output widget - widget2 = wiring.find_draggable_component('widget', title="Test (connected to the test operator)") + target = operator.find_endpoint('target', "input") + source = widget.find_endpoint('source', "outputendpoint") + source.create_connection(target) - source = operator.find_endpoint('source', "output") - target = widget2.find_endpoint('target', "inputendpoint") - source.create_connection(target) + # Create another connection between the operator and the output widget + widget2 = wiring.find_draggable_component('widget', title="Test (connected to the test operator)") - with tab_widget: - self.assertEqual(self.driver.find_element_by_id('wiring_hasinputconnections_test').text, "false") - self.assertEqual(self.driver.find_element_by_id('wiring_hasoutputconnections_test').text, "true") + source = operator.find_endpoint('source', "output") + target = widget2.find_endpoint('target', "inputendpoint") + source.create_connection(target) - # The operator automatically sends a "wiring modified" event when it detects a wiring change - with self.find_widget(title="Test (connected to the test operator)"): - element = self.driver.find_element_by_id('wiringOut') - WebDriverWait(self.driver, timeout=2).until( - lambda driver: element.text == "wiring modified" - ) + with tab_widget: + self.assertEqual(self.driver.find_element_by_id('wiring_hasinputconnections_test').text, "false") + self.assertEqual(self.driver.find_element_by_id('wiring_hasoutputconnections_test').text, "true") + + # The operator automatically sends a "wiring modified" event when it detects a wiring change + with self.find_widget(title="Test (connected to the test operator)"): + element = self.driver.find_element_by_id('wiringOut') + WebDriverWait(self.driver, timeout=2).until( + lambda driver: element.text == "wiring modified" + ) def test_remove_components_with_endpoint_attached_to_more_than_one_connection(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - # Ready an endpoint with more than one connection - operator = wiring.find_draggable_component('operator', id=0) - target = operator.find_endpoint('source', "output") - source = wiring.find_draggable_component('widget', title="Test 1").find_endpoint('target', "nothandled") - source.create_connection(target) - self.assertEqual(len(target.find_connections()), 2) - - operator.remove() - self.assertEqual(len(wiring.find_connections()), 1) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + # Ready an endpoint with more than one connection + operator = wiring.find_draggable_component('operator', id=0) + target = operator.find_endpoint('source', "output") + source = wiring.find_draggable_component('widget', title="Test 1").find_endpoint('target', "nothandled") + source.create_connection(target) + self.assertEqual(len(target.find_connections()), 2) + + operator.remove() + self.assertEqual(len(wiring.find_connections()), 1) test_remove_components_with_endpoint_attached_to_more_than_one_connection.tags = tags + ('wirecloud-wiring-draggable-component',) @uses_extra_workspace('user_with_workspaces', 'Wirecloud_mashup-with-behaviours_1.0.wgt', shared=True) @@ -2711,57 +2736,59 @@ def test_remove_components_using_key_delete_when_behaviour_engine_is_enabled(sel self.login(username='user_with_workspaces', next='/user_with_workspaces/mashup-with-behaviours') - with self.wiring_view as wiring: + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: - # Select the components using the command key - widget1 = wiring.find_draggable_component('widget', title="Test 1") - widget2 = wiring.find_draggable_component('widget', title="Test 2") - operator = wiring.find_draggable_component('operator', id=1) + # Select the components using the command key + widget1 = wiring.find_draggable_component('widget', title="Test 1") + widget2 = wiring.find_draggable_component('widget', title="Test 2") + operator = wiring.find_draggable_component('operator', id=1) - wiring.select(components=(widget1, widget2, operator), key=Keys.COMMAND) + wiring.select(components=(widget1, widget2, operator), key=Keys.COMMAND) - # Remove the selection using the backspace key - send_basic_key_event(self.driver, 8) + # Remove the selection using the backspace key + send_basic_key_event(self.driver, 8) - modal = FormModalTester(self, self.wait_element_visible(".wc-alert-modal")) - self.assertIn('Test 2', modal.body.text) - self.assertNotIn('Test 1', modal.body.text) - self.assertNotIn('TestOperator', modal.body.text) - modal.accept() + modal = FormModalTester(self, self.wait_element_visible(".wc-alert-modal")) + self.assertIn('Test 2', modal.body.text) + self.assertNotIn('Test 1', modal.body.text) + self.assertNotIn('TestOperator', modal.body.text) + modal.accept() - self.assertIsNone(wiring.find_draggable_component('widget', title="Test 2")) - self.assertTrue(wiring.find_draggable_component('operator', id=1).has_class('background')) - self.assertTrue(wiring.find_draggable_component('widget', title="Test 1").has_class('background')) + self.assertIsNone(wiring.find_draggable_component('widget', title="Test 2")) + self.assertTrue(wiring.find_draggable_component('operator', id=1).has_class('background')) + self.assertTrue(wiring.find_draggable_component('widget', title="Test 1").has_class('background')) test_remove_components_using_key_delete_when_behaviour_engine_is_enabled.tags = tags + ('wirecloud-wiring-draggable-component',) def test_rename_widget_from_component_preferences(self): new_title = "New title" self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - # Rename the widget available in sidebar. - component = sidebar.find_component('widget', "Wirecloud/Test", title="Test 1") - component.scroll().rename(new_title) - # Check if the widget draggable's title is changed too. - self.assertIsNotNone(wiring.find_draggable_component('widget', title=new_title)) - # Check if the widget interface's title is changed too. - self.assertIsNotNone(self.find_widget(title=new_title)) - - # - # Now rename the widget from the draggable component instead - # - with self.wiring_view as wiring: - # Rename the widget draggable available in wiring diagram. - component = wiring.find_draggable_component('widget', title=new_title) - new_title = "Other Name" - component.rename(new_title) - - with wiring.component_sidebar as sidebar: - # Check if the widget 's title of in sidebar is changed too. - self.assertIsNotNone(sidebar.find_component('widget', "Wirecloud/Test", title=new_title)) - # Check if the widget interface's title has changed too - self.assertIsNotNone(self.find_widget(title=new_title)) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + # Rename the widget available in sidebar. + component = sidebar.find_component('widget', "Wirecloud/Test", title="Test 1") + component.scroll().rename(new_title) + # Check if the widget draggable's title is changed too. + self.assertIsNotNone(wiring.find_draggable_component('widget', title=new_title)) + # Check if the widget interface's title is changed too. + self.assertIsNotNone(self.find_widget(title=new_title)) + + # + # Now rename the widget from the draggable component instead + # + with edit_session.wiring_view as wiring: + # Rename the widget draggable available in wiring diagram. + component = wiring.find_draggable_component('widget', title=new_title) + new_title = "Other Name" + component.rename(new_title) + + with wiring.component_sidebar as sidebar: + # Check if the widget 's title of in sidebar is changed too. + self.assertIsNotNone(sidebar.find_component('widget', "Wirecloud/Test", title=new_title)) + # Check if the widget interface's title has changed too + self.assertIsNotNone(self.find_widget(title=new_title)) test_rename_widget_from_component_preferences.tags = tags + ('wirecloud-wiring-draggable-component',) def test_components_with_readonly_connections_cannot_be_deleted(self): @@ -2772,114 +2799,118 @@ def test_components_with_readonly_connections_cannot_be_deleted(self): self.login(username='user_with_workspaces', next="/user_with_workspaces/Workspace") - with self.wiring_view as wiring: - # Such connection should be readonly and its button 'delete' - # should be disabled - connection = wiring.find_connection("widget/2/outputendpoint", "operator/0/input") - self.assertTrue(connection.has_class('readonly')) - self.assertTrue(connection.btn_remove.is_disabled) - - # Both components of the readonly connection should also be readonly and - # their buttons 'delete' should be disabled - widget = wiring.find_draggable_component('widget', id=2) - self.assertTrue(widget.has_class('readonly')) - self.assertTrue(widget.btn_remove.is_disabled) - operator = wiring.find_draggable_component('operator', id=0) - self.assertTrue(operator.has_class('readonly')) - self.assertTrue(operator.btn_remove.is_disabled) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + # Such connection should be readonly and its button 'delete' + # should be disabled + connection = wiring.find_connection("widget/2/outputendpoint", "operator/0/input") + self.assertTrue(connection.has_class('readonly')) + self.assertTrue(connection.btn_remove.is_disabled) + + # Both components of the readonly connection should also be readonly and + # their buttons 'delete' should be disabled + widget = wiring.find_draggable_component('widget', id=2) + self.assertTrue(widget.has_class('readonly')) + self.assertTrue(widget.btn_remove.is_disabled) + operator = wiring.find_draggable_component('operator', id=0) + self.assertTrue(operator.has_class('readonly')) + self.assertTrue(operator.btn_remove.is_disabled) test_components_with_readonly_connections_cannot_be_deleted.tags = tags + ('wirecloud-wiring-connection-management',) def test_modify_connection_on_active_behaviours(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/WorkspaceBehaviours') - with self.wiring_view as wiring: - operator = wiring.find_draggable_component('operator', id=0) - target1 = operator.find_endpoint('target', 'input') - target2 = operator.find_endpoint('target', 'nothandled') - - # The button 'cancel' corresponds to modify such connection only in the active behaviour - connection = wiring.find_connection('widget/11/outputendpoint', 'operator/0/input') - connection.change_endpoint(target1, target2) - modal = FormModalTester(self, self.wait_element_visible(".wc-alert-modal")) - modal.cancel() - - self.assertTrue(wiring.find_connection('widget/11/outputendpoint', 'operator/0/input').has_class('background')) - connection = wiring.find_connection('widget/11/outputendpoint', 'operator/0/nothandled') - self.assertIsNotNone(connection) - self.assertTrue(connection.has_class('active')) - - # Connections on the background cannot be modified - # In this case, a new connection is created - source = operator.find_endpoint('source', 'output') - - widget = wiring.find_draggable_component('widget', title="Test 1") - target = widget.find_endpoint('target', 'nothandled') - - connection1 = wiring.find_connection('operator/0/output', 'widget/10/inputendpoint') - # Remove connection1 from the current behaviour (convert into a - # background connection) - connection1.remove().click() - connection2 = source.create_connection(target) - - self.assertTrue(connection1.has_class('background')) - self.assertFalse(connection1.has_class('active')) - self.assertIsNotNone(connection2) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + operator = wiring.find_draggable_component('operator', id=0) + target1 = operator.find_endpoint('target', 'input') + target2 = operator.find_endpoint('target', 'nothandled') + + # The button 'cancel' corresponds to modify such connection only in the active behaviour + connection = wiring.find_connection('widget/11/outputendpoint', 'operator/0/input') + connection.change_endpoint(target1, target2) + modal = FormModalTester(self, self.wait_element_visible(".wc-alert-modal")) + modal.cancel() + + self.assertTrue(wiring.find_connection('widget/11/outputendpoint', 'operator/0/input').has_class('background')) + connection = wiring.find_connection('widget/11/outputendpoint', 'operator/0/nothandled') + self.assertIsNotNone(connection) + self.assertTrue(connection.has_class('active')) + + # Connections on the background cannot be modified + # In this case, a new connection is created + source = operator.find_endpoint('source', 'output') + + widget = wiring.find_draggable_component('widget', title="Test 1") + target = widget.find_endpoint('target', 'nothandled') + + connection1 = wiring.find_connection('operator/0/output', 'widget/10/inputendpoint') + # Remove connection1 from the current behaviour (convert into a + # background connection) + connection1.remove().click() + connection2 = source.create_connection(target) + + self.assertTrue(connection1.has_class('background')) + self.assertFalse(connection1.has_class('active')) + self.assertIsNotNone(connection2) test_modify_connection_on_active_behaviours.tags = tags + ('wirecloud-wiring-connection-management',) @uses_extra_workspace('user_with_workspaces', 'Wirecloud_test-mashup-recommendations_1.0.wgt', shared=True) def test_endpoints_are_recommended(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/test-mashup-recommendations') - with self.wiring_view as wiring: - # Check endpoints are recommended on mouse over - widget1 = wiring.find_draggable_component('widget', id=self.widgets[0].id) - widget2 = wiring.find_draggable_component('widget', id=self.widgets[1].id) - widget3 = wiring.find_draggable_component('widget', id=self.widgets[2].id) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + # Check endpoints are recommended on mouse over + widget1 = wiring.find_draggable_component('widget', id=self.widgets[0].id) + widget2 = wiring.find_draggable_component('widget', id=self.widgets[1].id) + widget3 = wiring.find_draggable_component('widget', id=self.widgets[2].id) - target1 = widget1.find_endpoint('target', 'inputendpoint') - source2 = widget2.find_endpoint('source', 'outputendpoint') - target3 = widget3.find_endpoint('target', 'inputendpoint') - source3 = widget3.find_endpoint('source', 'outputendpoint') + target1 = widget1.find_endpoint('target', 'inputendpoint') + source2 = widget2.find_endpoint('source', 'outputendpoint') + target3 = widget3.find_endpoint('target', 'inputendpoint') + source3 = widget3.find_endpoint('source', 'outputendpoint') - source2.mouse_over(must_recommend=(target1, target3)) - target1.mouse_over(must_recommend=(source2, source3)) + source2.mouse_over(must_recommend=(target1, target3)) + target1.mouse_over(must_recommend=(source2, source3)) - # Check endpoints are recommended on connection creation - source2.create_connection(target3, must_recommend=(target1, target3)) - target1.create_connection(source3, must_recommend=(source2, source3)) + # Check endpoints are recommended on connection creation + source2.create_connection(target3, must_recommend=(target1, target3)) + target1.create_connection(source3, must_recommend=(source2, source3)) test_endpoints_are_recommended.tags = tags + ('wirecloud-wiring-endpoint-management',) def test_components_can_be_collapsed_and_expanded(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/Workspace') # Collapse a widget and an operator - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') - widgets = sidebar.find_components('widget', 'Wirecloud/Test', state='in use') + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') + widgets = sidebar.find_components('widget', 'Wirecloud/Test', state='in use') - operator = wiring.find_draggable_component('operator', id=operators[0].id) - operator.collapse_endpoints() + operator = wiring.find_draggable_component('operator', id=operators[0].id) + operator.collapse_endpoints() - widget1 = wiring.find_draggable_component('widget', id=widgets[0].id) - widget1.collapse_endpoints() + widget1 = wiring.find_draggable_component('widget', id=widgets[0].id) + widget1.collapse_endpoints() - # Check the components are expanded while creating a connection - widget2 = wiring.find_draggable_component('widget', id=widgets[1].id) + # Check the components are expanded while creating a connection + widget2 = wiring.find_draggable_component('widget', id=widgets[1].id) - source = widget2.find_endpoint('source', "outputendpoint") - target = widget1.find_endpoint('target', "inputendpoint") - source.create_connection(target, must_expand=(operator, widget1)) + source = widget2.find_endpoint('source', "outputendpoint") + target = widget1.find_endpoint('target', "inputendpoint") + source.create_connection(target, must_expand=(operator, widget1)) - # Expand the components - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') - widgets = sidebar.find_components('widget', 'Wirecloud/Test', state='in use') + # Expand the components + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') + widgets = sidebar.find_components('widget', 'Wirecloud/Test', state='in use') - wiring.find_draggable_component('operator', id=operators[0].id).expand_endpoints() - wiring.find_draggable_component('widget', id=widgets[0].id).expand_endpoints() + wiring.find_draggable_component('operator', id=operators[0].id).expand_endpoints() + wiring.find_draggable_component('widget', id=widgets[0].id).expand_endpoints() test_components_can_be_collapsed_and_expanded.tags = tags + ('wirecloud-wiring-endpoint-management',) def check_input_endpoint_exceptions(self): @@ -2909,13 +2940,14 @@ def check_input_endpoint_exceptions(self): self.send_basic_event(source_iwidget) self.check_wiring_badge("1") - with self.wiring_view as wiring: - with wiring.component_sidebar as sidebar: - operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') - operator = wiring.find_draggable_component('operator', id=operators[0].id) - modal = operator.show_logs() - self.assertEqual(len(modal.find_alerts(state='error')), 1) - modal.accept() + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.component_sidebar as sidebar: + operators = sidebar.find_components('operator', 'Wirecloud/TestOperator', state='in use') + operator = wiring.find_draggable_component('operator', id=operators[0].id) + modal = operator.show_logs() + self.assertEqual(len(modal.find_alerts(state='error')), 1) + modal.accept() def test_input_endpoint_exceptions(self): user = User.objects.get(pk=4) @@ -2956,11 +2988,12 @@ def test_type_error_and_value_exceptions(self): self.check_wiring_badge("4") - with self.wiring_view as wiring: - connections = wiring.find_connections(extra_class='has-error') - self.assertEqual(len(connections), 2) - self._check_connection_errors(connections[0], 2) - self._check_connection_errors(connections[1], 2) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + connections = wiring.find_connections(extra_class='has-error') + self.assertEqual(len(connections), 2) + self._check_connection_errors(connections[0], 2) + self._check_connection_errors(connections[1], 2) def test_input_endpoint_no_handler_exceptions(self): @@ -2985,55 +3018,57 @@ def test_missing_input_and_output_endpoints(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/Workspace') - with self.wiring_view as wiring: - self.assertEqual(len(wiring.find_connections(extra_class='missing')), 2) + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + self.assertEqual(len(wiring.find_connections(extra_class='missing')), 2) test_missing_input_and_output_endpoints.tags = tags + ('wirecloud-wiring-endpoint-management',) @uses_extra_workspace('user_with_workspaces', 'Wirecloud_test-mashup-multiendpoint_1.0.wgt', shared=True) def test_ordering_component_endpoints(self): self.login(username='user_with_workspaces', next='/user_with_workspaces/test-mashup-multiendpoint') - with self.wiring_view as wiring: - operator = wiring.find_draggable_component('operator', title="TestOp. Multiendpoint") - widget = wiring.find_draggable_component('widget', title="Test_Multiendpoint") + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + operator = wiring.find_draggable_component('operator', title="TestOp. Multiendpoint") + widget = wiring.find_draggable_component('widget', title="Test_Multiendpoint") - source = widget.find_endpoint('source', 'output1') - target = operator.find_endpoint('target', 'input2') - connection = source.create_connection(target) + source = widget.find_endpoint('source', 'output1') + target = operator.find_endpoint('target', 'input2') + connection = source.create_connection(target) - operator_targets_count = len(operator.find_endpoints('target')) - operator_sources_count = len(operator.find_endpoints('target')) - widget_targets_count = len(widget.find_endpoints('target')) - widget_sources_count = len(widget.find_endpoints('target')) + operator_targets_count = len(operator.find_endpoints('target')) + operator_sources_count = len(operator.find_endpoints('target')) + widget_targets_count = len(widget.find_endpoints('target')) + widget_sources_count = len(widget.find_endpoints('target')) - with operator.order_endpoints as component_editable: - component_editable.move_endpoint('source', 'output1', 'output2') - component_editable.move_endpoint('target', 'input2', 'input3', must_change=(connection,)) + with operator.order_endpoints as component_editable: + component_editable.move_endpoint('source', 'output1', 'output2') + component_editable.move_endpoint('target', 'input2', 'input3', must_change=(connection,)) - with widget.order_endpoints as component_editable: - component_editable.move_endpoint('source', 'output1', 'output2', must_change=(connection,)) - component_editable.move_endpoint('target', 'input1', 'input3') + with widget.order_endpoints as component_editable: + component_editable.move_endpoint('source', 'output1', 'output2', must_change=(connection,)) + component_editable.move_endpoint('target', 'input1', 'input3') - self.assertEqual(operator_targets_count, len(operator.find_endpoints('target'))) - self.assertEqual(operator_sources_count, len(operator.find_endpoints('source'))) - self.assertEqual(widget_targets_count, len(widget.find_endpoints('target'))) - self.assertEqual(widget_sources_count, len(widget.find_endpoints('source'))) + self.assertEqual(operator_targets_count, len(operator.find_endpoints('target'))) + self.assertEqual(operator_sources_count, len(operator.find_endpoints('source'))) + self.assertEqual(widget_targets_count, len(widget.find_endpoints('target'))) + self.assertEqual(widget_sources_count, len(widget.find_endpoints('source'))) - with self.wiring_view as wiring: - operator = wiring.find_draggable_component('operator', id=operator.id) - widget = wiring.find_draggable_component('widget', id=widget.id) + with edit_session.wiring_view as wiring: + operator = wiring.find_draggable_component('operator', id=operator.id) + widget = wiring.find_draggable_component('widget', id=widget.id) - self.assertEqual(operator_targets_count, len(operator.find_endpoints('target'))) - self.assertEqual(operator_sources_count, len(operator.find_endpoints('source'))) - self.assertEqual(widget_targets_count, len(widget.find_endpoints('target'))) - self.assertEqual(widget_sources_count, len(widget.find_endpoints('source'))) + self.assertEqual(operator_targets_count, len(operator.find_endpoints('target'))) + self.assertEqual(operator_sources_count, len(operator.find_endpoints('source'))) + self.assertEqual(widget_targets_count, len(widget.find_endpoints('target'))) + self.assertEqual(widget_sources_count, len(widget.find_endpoints('source'))) - # Ordering endpoints should be disabled for collapsed components - operator.collapse_endpoints() + # Ordering endpoints should be disabled for collapsed components + operator.collapse_endpoints() - menu_dropdown = operator.show_preferences() - menu_dropdown.check(must_be_disabled=("Order endpoints",)) - menu_dropdown.close() + menu_dropdown = operator.show_preferences() + menu_dropdown.check(must_be_disabled=("Order endpoints",)) + menu_dropdown.close() test_ordering_component_endpoints.tags = tags + ('wirecloud-wiring-endpoint-management',) def test_behaviour_engine_basic_features(self): @@ -3042,30 +3077,32 @@ def test_behaviour_engine_basic_features(self): # Enable it self.login(username='user_with_workspaces', next='/user_with_workspaces/WiringTests') - with self.wiring_view as wiring: - with wiring.behaviour_sidebar as sidebar: - sidebar.btn_enable.click() - self.assertFalse(sidebar.disabled) - # Check that there is an initial behaviour - self.assertEqual(len(sidebar.find_behaviours()), 1) - sidebar.active_behaviour.check_info("New behaviour", "No description provided.") + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.behaviour_sidebar as sidebar: + sidebar.btn_enable.click() + self.assertFalse(sidebar.disabled) + # Check that there is an initial behaviour + self.assertEqual(len(sidebar.find_behaviours()), 1) + sidebar.active_behaviour.check_info("New behaviour", "No description provided.") # Check the change is correctly persisted self.reload() - self.wait_wirecloud_ready() - - with self.wiring_view as wiring: - with wiring.behaviour_sidebar as sidebar: - self.assertFalse(sidebar.disabled) - self.assertEqual(len(sidebar.find_behaviours()), 1) - sidebar.active_behaviour.check_info("New behaviour", "No description provided.") - behaviour1 = sidebar.active_behaviour - - # Create a new behaviour - behaviour2 = sidebar.create_behaviour("Title", "Description") - - # Change behaviour order - sidebar.btn_order.click() - behaviour1.change_position(behaviour2) - sidebar.btn_order.click() + self.wait_wirecloud_ready(login=True) + + with self.edit_mode as edit_session: + with edit_session.wiring_view as wiring: + with wiring.behaviour_sidebar as sidebar: + self.assertFalse(sidebar.disabled) + self.assertEqual(len(sidebar.find_behaviours()), 1) + sidebar.active_behaviour.check_info("New behaviour", "No description provided.") + behaviour1 = sidebar.active_behaviour + + # Create a new behaviour + behaviour2 = sidebar.create_behaviour("Title", "Description") + + # Change behaviour order + sidebar.btn_order.click() + behaviour1.change_position(behaviour2) + sidebar.btn_order.click() test_behaviour_engine_basic_features.tags = tags + ('wirecloud-wiring-behaviour-management',)