summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/helpers/test_utils.js
AgeCommit message (Collapse)Author
2019-03-06[REF] web: adapt code after jQuery updateVincent Schippefilt
Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
2018-12-07[REF] web: move ControlPanel inside controllers/actionsGéry Debongnie
This branch introduces a large-scale reorganization of the component tree generated by the web client. The short version is that now, the control panel is a child of the view controller and no longer a sibling. Graphically (and simplified), we go from this: webClient / | \ ... ... actionManager / \ controlPanel viewController / \ to this: webClient / | \ ... ... actionManager | viewController / | \ ControlPanelController / \ CPRenderer CPModel The motivation is that this work moves the code where it should be. Before this commit, it was kind of weird to have code in the controllers to render buttons outside of their root node (in renderButtons). Also, the action manager had to take care of coordinating search view states between view transitions. So, this work simplifies the code. It also makes it easier to extend. We see day after day that Odoo needs to take care of more complex UI needs, and in many cases, these needs were quite difficult to implement (we prefer spaghettis in our plates, not in our code). The changes in this branch should open the way to implement these features. For example, - it will now be easy to add the possibility of views (for example, the search view or a new ControlPanel view) to add custom buttons (of type action or object) in the control panel. - Another need will be to serialize/ restore the state of the search view across action boundaries (needed by the dashboard). - Another example is the possibility for views to customize easily the presence/absence of sub menus (filters/groupbys/favorites/ time range/...) - Another need is an easier way for views/client action to customize their control panel. This commit also contains a large rewrite of the search view (so it is more inline with our architecture and easier to maintain). Part of task 1893568 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com>
2018-11-26[ADD] web:tests: test utils for drag/drop filesAlexandre Kühn
This commit adds test helper functions to drag and drop files: - `createFile`: create a file that can be used for drag and drop in tests. - `dragoverFile`: to drag a file created from `createFile` over a DOM element. - `dropFile`: to drop a file created from `createFile` on a DOM element. These utility functions are available from `testUtils.file`. Example of usage: ```js var testUtils = require('web.test_utils'); testUtils.file.createFile({ name: 'text.txt', content: 'hello, world', contentType: 'text/plain', }).then(function (file) { testUtils.file.dragoverFile($el, file); testUtils.file.dropFile($el, file); }); ```
2018-11-23[MERGE] forward port branch 12.0 up to b3052b690faChristophe Simonis
2018-11-20[IMP] web: tests: backport of new helpersAaron Bohy
This rev. is a partial backport of abf32b8b, so that the newly introduced helpers are already available in 12.0. closes odoo/odoo#28827
2018-11-20[IMP] web: testUtils: ensure backward compatibilityAaron Bohy
Rev. 7c3d5dc0 recently added new helpers to use in the tests, and moved some existing helpers to testUtils sub groups (like .dom or .mock). This rev. adds a compatibility layer to ease forwardports. closes odoo/odoo#28824
2018-11-19[REF] *: update js test suite to use helpersGéry Debongnie
This rev. introduces robust helpers to use in the JS tests suite to interact with DOM and components, and starts using them (almost) everywhere. All the helpers are exposed though testUtils.js. There are 2 kinds of helpers: 1. Assertions ------------- * assert.containsNone, containsN, containsOnce check that the DOM (or a specific part of the DOM) contains a `selector`. It generates a correct error message automatically. ex: assert.strictEqual(form.$('.o_form_editable'), 1, "msg"); -> assert.containsOnce(form, '.o_form_editable'); * assert.isVisible, isNotVisible check that the DOM has an element visible or not. They also check that the element is actually in the DOM (before most tests didn't verify this). * assert.hasClass, doesNotHaveClass, hasAttrVAlue, check specific properties of a DOM element, and also validate that it is applied on a single existing DOM element (before most tests didn't verify this). ex: assert.notOk(form.$('button').hasClass('btn-primary')); -> assert.doesNotHaveClass(form.$('button'), 'btn-primary'); 2. Utilities ------------ The goal of the utilities is to centralize the definition of many standard components and interactions, ensuring that when we refactor the JS framework, we do not need to change all the tests. Existing mock utilities (addMockEnvironment, intercept, path, patchDate, unpatch and fieldsViewGet) are moved to 'testUtils.mock.*'. Existing DOM utilities are moved to 'testUtils.dom.*'. New dom utilities are created for opendDatePicker, click, clickFirst and clickLast. Helper `click` verifies that there is exactly 1 element visible in the DOM you click on, `clickFirst` and `clickLast` verify that there are more than one element on the DOM. ex: form.$('button').click(); -> testUtils.dom.click(form.$('button')); New Form utilities: (testUtils.form.*) clickEdit, clickSave, clickCreate, clickDiscard, all clicks on the control panel buttons of the form. `reload` reloads the form data. New modal, graph, kanban and pivot utils (testUtils.pivot.*, testUtils.kanban.*, etc.). New fields utils: (testUtils.fields.*) * editInput, editSelect: allow to change the value of a field, using a selector to identify it. They validate that the input exists and trigger the change event automatically. * editAndTrigger: allow to modify a field and trigger specific events after the value change * many2one (testUtils.fields.many2one.*) clickOpenDropdown, clickHighlightedItem, clickItem, searchAndClickItem: use a field name instead of a selector and do all the complex mechanism to open, filter and highlight many2one fields. Joint work with aab, dam, ged, mge, svs and vsc.
2018-11-06[MERGE] forward port branch 12.0 up to dd70c684268Christophe Simonis
2018-10-29[MOV] web, base_import: mobile tests should be in mobile suiteAdrien Dieudonne
This fix some inconsistent error on runbot. In mobile, some views* depend on 'jquery.touchSwipe' library which is lazy loaded. As a result, the views become asynchronous... It's why this library is already loaded before running tests in the mobile test suite. So we can continue to use synchronous views whether in mobile tests or not. But some mobile tests weren't in mobile suite... In desktop, 'jquery.touchSwipe' is lazy loaded and the first test will load it for others. It's why the first one has to be asynchronous: https://github.com/odoo/odoo/commit/da7b59045d246c159f93bc75e3f19c6b1221d31c The inconsistency comes from the fact that all tests are sequential but we can't garantee the execution order. So, if the test mentionned is not the first executed one, an error will occur because the view is not asynchronous. Now, all mobile tests are moved in mobile suite to be sure that 'jquery.touchSwipe' is loaded. We also set the default value for size_class because we want a coherent environment. It is very rare to find mobile devices with more than 474px wide. *: form_view, kanban_view, res_config_settings closes odoo/odoo#28195
2018-10-22[MERGE] forward port branch saas-11.4 up to 3c108977c1eChristophe Simonis
2018-10-17[MERGE] forward port branch saas-11.3 up to 0de06a41326Christophe Simonis
2018-10-16[MERGE] forward port branch 11.0 up to b29b545fe84Christophe Simonis
2018-10-22[MERGE] forward port branch 12.0 up to b81c2bce846Christophe Simonis
2018-10-19[IMP] web: remove es5 shimVincent Schippefilt
The library es5 shim was usefull for older browsers that do not implement completely the es5 specifications, like IE9. As we do not support browsers older than IE11, that fully supports all the features of es5, the library has become useless. Removing this library will remove a little bit of noise in the callstack when debugging. closes odoo/odoo#27877
2018-10-12[FIX] board: translate custom views according to current userLucas Perais (lpe)
Have a user in English, put a sale report as "favorite" (pinned to dashboard app) Change the user's language Before this commit, the pinned view was in English (because it was recorded that way) After this commit, the pinned view is in the user's language. OPW 1890664 closes odoo/odoo#27574
2018-10-01[MERGE] forward port branch saas-11.4 up to 57e387b6452Christophe Simonis
2018-09-20[FIX] web: add mouseenter when triggering a dra&drop in testsVincent Schippefilt
2018-09-17[FIX] web: datepicker: correctly use libAaron Bohy
The datepicker lib has been updated to tempus dominus (BS4) recently, but our code hasn't been adapted correctly to the requirements of the new version of the lib. As a consequence, the datepicker didn't close itself when the input was focused out anymore. This required a slight change in the DomainSelector widget as it produced a crash when a focused datepicker widget is removed from the DOM (before the datepicker is destroyed), e.g. by a call to html() on one of its parent. Task 1878254
2018-09-14[FIX] web:tests: correctly handle parameter 'services'Alexandre Kühn
This commit fixes the handling of the service parameter in a mocked environment: - updated docstring: now an object (previously an array) - no longer used by mocked server (unused parameter) - enforces default value for this parameter (empty object)
2018-09-14[FIX] web: tests: adapt JS tests from forward-port ↵Alexandre Kühn
9c77066f345360429a0920ca4d17af1f84a7ebea The test was failing because it was using an old approach to mock services in JS tests. Also, it provides ajax service in the list of services, which was not supported in a mocked environment. With this commit, when an ajax service is provided in the test, it will use this service instead of using mocked RPCs from the mocked server.
2018-09-14[MERGE] forward port branch saas-11.4 up to 6c103589c15Christophe Simonis
2018-09-13[IMP] mail, web: attachments & messages in debug actions.ThanhDodeurOdoo
- added two new actions to the form view debug action list, both opens list (+ form) views of messages and attachments respectively for which the domain is restricted to the current record. task: 1860031
2018-09-10[FIX] web: ajax must return a promise with abort methodChristophe Matthieu
Remove part in service_mixins who hide this error. Queries must be able to be canceled for better performance. Also in the case of longpolling, if the request is not canceled, wait for a server message or the maximum time (30 sec) to add or delete channels.
2018-08-23[FIX] web: view list grouped renders nicelyVincent Schippefilt
Before this fix, the list grouped did not render correctly when the list was not selectable and there was 1 or 2 fields (the sum in the footer was not aligned on the correct column) Also fixed the fact that the group pager was not displayed if the list had only 1 field and it was grouped
2018-08-17[FIX] web: tests: correctly unpatch classesAlexandre Kühn
Before this commit, `testUtils.unpatch` was incorrectly unpatching a class' properties. That is caused by restoring the properties on the class function itself, instead of the prototype of the class function. This commit fixes this issue by restoring properties on the prototype function of the class on `testUtils.unpatch`.
2018-08-17[DOC] web:tests: add docstring for `testUtils.patchDate`Alexandre Kühn
2018-08-14[IMP] web: add a patchDate function in testUtilsMathieu Duckerts-Antoine
This function allows to properly mock Dates in js Tests
2018-08-13[IMP] web: add options to `dragAndDrop` test util functionChristophe Matthieu
There is now an option `continueMove` that can be used to extend a previous drag done in this function. The option `position` has also been extended to take an object (to precise the move position).
2018-08-13[IMP] web: avoid failed tests affecting the next onesChristophe Matthieu
When using positional clicks (among other examples) in tests, a previous failed test might affect a next one because the assert failures are displayed on the top of tests.
2018-08-13[IMP] web, web_tour: handle iframe in tests and tourMartin Geubelle
In both test util functions (`dragAndDrop`) and tours, using elements in iframe was not supported. As a jQuery selector won't work with an iframe, when using a selector like `div.o_my_class iframe p:first` the tour manager will split the selector, which will result to `$('div.o_my_class iframe').contents().find('p:first')`.
2018-08-09[FIX] web: in the test the mocked services use the tests featuresChristophe Matthieu
Must move the service construction to intercept the request with the test parameters
2018-08-09[IMP] web: remove useless service nameChristophe Matthieu
We use the registry keys as name for the services.
2018-08-01[MERGE] forward port branch saas-11.4 up to 8d9366197e1Christophe Simonis
2018-08-01[MERGE] forward port branch saas-11.3 up to 691dd65e0ecChristophe Simonis
2018-08-01[MERGE] forward port branch saas-11.2 up to 22b31152cadChristophe Simonis
2018-08-01[MERGE] forward port branch 11.0 up to f9e0f6663f0Christophe Simonis
2018-07-31[FIX] web: fix 'drag and drop' test function to work in both directionslen-odoo
The 'drag and drop' function defined in test_utils should be aware of four different cases, moving up or down, above or below another row. We need an offset of one pixel for the function to work when moving down (this is a case of broken symmetry because of <=) Related to opw 1867049 regarding sequences of resequence moves.
2018-07-27[REF] web, *: BS4, update JS media queriesqsm-odoo
* website_quote, website_sale
2018-07-02[REF] mail: JS mail refactoringAlexandre Kühn
---------------------- Summary ---------------------- The purpose of this commit is to improve the JS code of the `mail` module. It applies the new coding guidelines and makes some changes on the design of some modules, such as the old ChatManager module. Here is a short summary of the changes that have been made: 1. New coding guidelines - snake_case to camelCase - prefix private attributes and methods with '_' - jsdoc on most methods - one class per module 2. Rename/Merge some classes - 'chat manager' becomes 'mail manager' (internal) and 'mail service' (external) - 'chat window manager' is now included in mail manager - 'thread' widget now named 'thread widget' 3. New model abstraction for mail objects: - modules 'mail.model.*' - modeling: 0..1 0..1 * * ThreadWindow <------> Thread <-------> Message / \ / \ Thread With Cache Document Thread / | \ / | \ Mailbox Channel Support Channel | | DM - Thread: the superclass of threads. - ThreadWindow: the window component of a thread. - Message: mail objects representing messages. - Thread With Cache: threads that can be used with search view (Discuss app compatible). - Document Thread: represents the thread part of a chatter. - Mailbox: represents what was previously called 'static' channel, e.g. 'Inbox'. - Channel: mail objects representing channels, including livechat. - DM: special kind of Channel for 1:1 communication in the backend. - Support Channel: special channel for im_support module. This new modeling approach let us easily add features on all threads, such as the possibility to put any thread in a small window. ---------------------- Known issues ---------------------- [Already Present in Master] 1. When the Discuss app is in the background with 'Inbox' as the selected Thread, when clicking on a document thread preview in the messaging menu of the systray, the rainbow man appears. 2. When a document with the chatter is in the background, when receiving an inbox notification from this document thread, the document thread is automatically marked as read, which removes the notification right away. 3. Sometimes, opening a DM window from the "blank" thread window does not work. 4. Reply-to feature on Inbox is not working: no message is sent in the document thread. 5. On the first login of admin user with demo data, the inbox counter is wrong (it displays 6, instead of 3). Explanation after investigation: > On page load, it fetches the correct number of Inbox messages (3), but the server notifies of 3 needaction messages right away, so it wrongly assumes these are new needaction messages. > Not possible for web client to detect that these messages should not increment the Inbox counter while keeping same API. 6. Notifications for new document thread messages only work when the user sets 'handle with Odoo' for the Notification Management in the preferences. > due to notifications on the longpoll bus for document thread messages that come from needaction notifications. > requires server-side changes to send notification on the longpoll bus to mentionned user. [New] 7. When receiving a message on a unjoined channel, thread window flickers ('open' > 'close' > 'open') Explanation after investigation: > JS logic: a) On auto-join, ask server to join the channel and get channel infos. b) The info tells the channel is not detached, but JS code makes decision to detach it, and tells server the channel is now detached. c) From (a), server notifies on longpoll bus the state of channel, which is not detached. The web client thinks that the window state of the channel has been changed somewhere else, and the channel is now closed. d) From (b), server notifies on longpoll bus the state of channel, which is detached. The web client opens the thread window of this channel. > The flicker didn't occur before refactoring because the web client was only updating the model of channel when it receives the longpoll notification. > Server behaviour on 1st longpoll notification is necessary for cross-tab synchronization for channel window state. > New design implies that model and view should be synchronized, hence the issue now. > Solution: remove server-side thread window synchronization and replace with client-side synchronization. ---------------------- Hacks ---------------------- The module `im_livechat` now uses mail objects that are compatible with Message and Window objects: Modeling for messages: AbstractMessage / \ / \ LivechatMessage Message - AbstractMessage: message compatible with the thread widget. - LivechatMessage: message used by im_livechat. - Message: message used with the mail manager. Modeling for thread windows: AbstractThreadWindow / \ / \ LivechatWindow ThreadWindow - AbstractThreadWindow: behaviour share between all types of thread windows. - LivechatWindow: window used by im_livechat. - ThreadWindow: window used with mail_manager. The reason for these hacks are twofold: 1. Use the thread widget in the frontend and livechat external lib bundles. 2. Do not have a dependency with the mail manager in the frontend and external lib bundles.
2018-05-29[MERGE] forward port branch saas-11.3 up to 37eed7c509fChristophe Simonis
2018-05-23[IMP] web,mail: improve search view for mobile devicesGéry Debongnie
With this commit, we introduce a better screen to manipulate the search view in a mobile device. Note: most of this work was initially done by suh-odoo, then was adapted and moved to community by myself. task 31464
2018-05-17[MERGE] forward port branch saas-11.2 up to 16552029241Christophe Simonis
2018-05-16[REVERT] "[IMP] mail : display mentions in green color in edit mode"Alexandre Kühn
This reverts commit c778de44c7cd9b7ef5a9a91738164ab0ebd0ca06.
2018-04-16[FIX] web: fix keyboard related crash in client actionsVincent Schippefilt
2018-02-28[FIX] web: increase unit test speedChristophe Matthieu
The method removeSrcAttribute is critical, because each changes trigger this one. this method must be optimized to the maximum to be the fastest. Before this fix, removeSrcAttribute method search the image and iframe for all body nodes instead of search only in the inserted nodes, and the method are very slow.
2018-02-23[MERGE] forward port branch saas-11.2 up to 932e641be17Christophe Simonis
2018-02-22[FIX] web: tests: turn patchWindowGetSelection statelessAlexandre Kühn
test_utils.js contains helper functions, which should be stateless (good practices). This was not the case with patchWindowGetSelection and unpatchWindowGetSelection, so instead we keep only the first function which returns the second one. From the test POV, instead of this: utils.patchWindowGetSelection(); // ... utils.unpatchWindowGetSelection(); It now looks like that: var unpatchWindowGetSelection = utils.patchWindowGetSelection(); // ... unpatchWindowGetSelection();
2018-02-20[FIX] tests : avoid phantomjs to crash because of window.getSelectionVincent Schippefilt
Before this commit, phantomjs was crashing when some code manipulates window.getSelection (such as the composer input in discuss or in the chatter). This commit lets us mock window.getSelection in tests that need this function in order to work properly. Another benefit of this commit is the possibility to simulate the state of window.getSelection in our tests, which enables tests on the composer that were not possible before (e.g. making sure that mentions and emojis are correctly rendered in the input, after the user clicked on them in the dropup menu or the bottom bar.
2018-02-12[MERGE] forward port branch saas-11.2 up to 0f02dcb6391Christophe Simonis
2018-02-12[MERGE] forward port branch saas-11.1 up to c69d00157edChristophe Simonis