summaryrefslogtreecommitdiff
path: root/addons/google_drive/static
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-03-11 09:38:30 +0000
committerJulien Mougenot <jum@odoo.com>2020-03-13 14:08:33 +0000
commit804507ef4925cafdf5349a3b7fa1e41dbca87ff7 (patch)
tree09a097ffb347dae1c9dc7879be261ec734f70d4f /addons/google_drive/static
parentbb8eb766a84b9fd06007d3fb4ab9a29b70097738 (diff)
[REF] *: Adapt all module tests to the new control panel
Use of the new control panel helpers to increase consistency and change the assertions according to the new DOM/behaviour (e.g. components removed instead of turning invisible). Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/google_drive/static')
-rw-r--r--addons/google_drive/static/tests/gdrive_test.js265
1 files changed, 114 insertions, 151 deletions
diff --git a/addons/google_drive/static/tests/gdrive_test.js b/addons/google_drive/static/tests/gdrive_test.js
index 158330376bd..b04ebf27c26 100644
--- a/addons/google_drive/static/tests/gdrive_test.js
+++ b/addons/google_drive/static/tests/gdrive_test.js
@@ -1,166 +1,129 @@
odoo.define('google_drive.gdrive_integration', function (require) {
-"use strict";
-//rebuild
-var FormView = require('web.FormView');
-var testUtils = require('web.test_utils');
-var GoogleDriveSideBar = require('google_drive.sidebar');
-
-var createView = testUtils.createView;
-
-/*
- * @override
- * Avoid breaking other tests because of the new route
- * that the module introduces
- */
-var _addGoogleDocItemsOriginal = GoogleDriveSideBar.prototype._addGoogleDocItems;
-
-var _addGoogleDocItemsMocked = function (model, resID) {
- return Promise.resolve();
-};
-
-GoogleDriveSideBar.prototype._addGoogleDocItems = _addGoogleDocItemsMocked;
-
-QUnit.module('gdrive_integration', {
- beforeEach: function () {
- // For our test to work, the _addGoogleDocItems function needs to be the original
- GoogleDriveSideBar.prototype._addGoogleDocItems = _addGoogleDocItemsOriginal;
-
- this.data = {
- partner: {
- fields: {
- display_name: {string: "Displayed name", type: "char", searchable: true},
+ "use strict";
+
+ const FormView = require('web.FormView');
+ const testUtils = require('web.test_utils');
+
+ const cpHelpers = testUtils.controlPanel;
+
+ QUnit.module('Google Drive Integration', {
+ beforeEach() {
+ this.data = {
+ partner: {
+ fields: {
+ display_name: { string: "Displayed name", type: "char", searchable: true },
+ },
+ records: [
+ { id: 1, display_name: "Locomotive Breath" },
+ { id: 2, display_name: "Hey Macarena" },
+ ],
},
- records: [{
- id: 1,
- display_name: "Locomotive Breath",
- }, {
- id: 2,
- display_name: "Hey Macarena",
- }],
- },
- 'google.drive.config': {
- fields: {
- model_id: {string: 'Model', type: 'int'},
- name: {string: 'Name', type: 'char'},
- google_drive_resource_id: {string: 'Resource ID', type: 'char'},
+ };
+ },
+ }, function () {
+
+ QUnit.module('Google Drive ActionMenus');
+
+ QUnit.test('rendering of the google drive attachments in action menus', async function (assert) {
+ assert.expect(3);
+
+ const form = await testUtils.createView({
+ actionMenusRegistry: true,
+ arch:
+ `<form string="Partners">
+ <field name="display_name"/>
+ </form>`,
+ data: this.data,
+ async mockRPC(route, args) {
+ switch (route) {
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
+ assert.deepEqual(args.args, ['partner', 1],
+ 'The route to get google drive config should have been called');
+ return [{
+ id: 27,
+ name: 'Cyberdyne Systems',
+ }];
+ case '/web/dataset/call_kw/google.drive.config/search_read':
+ return [{
+ google_drive_resource_id: "T1000",
+ google_drive_client_id: "cyberdyne.org",
+ id: 1,
+ }];
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
+ assert.deepEqual(args.args, [27, 1, 'T1000'],
+ 'The route to get the Google url should have been called');
+ return; // do not return anything or it will open a new tab.
+ }
},
- records: [{
- id: 27,
- name: 'Cyberdyne Systems',
- model_id: 1,
- google_drive_resource_id: 'T1000',
- }],
- },
- 'ir.attachment': {
- fields: {
- name: {string: 'Name', type:'char'}
+ model: 'partner',
+ res_id: 1,
+ View: FormView,
+ viewOptions: {
+ hasActionMenus: true,
},
- records: [],
- }
- };
- },
-
- afterEach: function() {
- GoogleDriveSideBar.prototype._addGoogleDocItems = _addGoogleDocItemsMocked;
- }
+ });
+ await cpHelpers.toggleActionMenu(form);
-}, function () {
- QUnit.module('Google Drive Sidebar');
+ assert.containsOnce(form, '.oe_share_gdoc_item',
+ "The button to the google action should be present");
- QUnit.test('rendering of the google drive attachments in Sidebar', async function (assert) {
- assert.expect(3);
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
- var form = await createView({
- View: FormView,
- model: 'partner',
- data: this.data,
- arch: '<form string="Partners">' +
- '<field name="display_name"/>' +
- '</form>',
- res_id: 1,
- viewOptions: {hasSidebar: true},
- mockRPC: function (route, args) {
- if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_config') {
- assert.deepEqual(args.args, ['partner', 1],
- 'The route to get google drive config should have been called');
- return Promise.resolve([{id: 27, name: 'Cyberdyne Systems'}]);
- }
- if (route === '/web/dataset/call_kw/google.drive.config/search_read'){
- return Promise.resolve([{google_drive_resource_id: "T1000",
- google_drive_client_id: "cyberdyne.org",
- id: 1}]);
- }
- if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_url') {
- assert.deepEqual(args.args, [27, 1, 'T1000'],
- 'The route to get the Google url should have been called');
- // We don't return anything useful, otherwise it will open a new tab
- return Promise.resolve();
- }
- return this._super.apply(this, arguments);
- },
+ form.destroy();
});
- var $googleAction = form.sidebar.$('.oe_share_gdoc');
-
- assert.strictEqual($googleAction.length, 1,
- 'The button to the google action should be present');
-
- // click on gdrive sidebar item
- await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click($googleAction);
+ QUnit.test('click on the google drive attachments after switching records', async function (assert) {
+ assert.expect(4);
+
+ let currentID;
+ const form = await testUtils.createView({
+ actionMenusRegistry: true,
+ arch:
+ `<form string="Partners">
+ <field name="display_name"/>
+ </form>`,
+ data: this.data,
+ async mockRPC(route, args) {
+ switch (route) {
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
+ assert.deepEqual(args.args, ['partner', currentID],
+ 'The route to get google drive config should have been called');
+ return [{
+ id: 27,
+ name: 'Cyberdyne Systems',
+ }];
+ case '/web/dataset/call_kw/google.drive.config/search_read':
+ return [{
+ google_drive_resource_id: "T1000",
+ google_drive_client_id: "cyberdyne.org",
+ id: 1,
+ }];
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
+ assert.deepEqual(args.args, [27, currentID, 'T1000'],
+ 'The route to get the Google url should have been called');
+ return; // do not return anything or it will open a new tab.
+ }
+ },
+ model: 'partner',
+ res_id: 1,
+ View: FormView,
+ viewOptions: {
+ hasActionMenus: true,
+ ids: [1, 2],
+ index: 0,
+ },
+ });
+ currentID = 1;
+ await cpHelpers.toggleActionMenu(form);
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
- form.destroy();
- });
+ await cpHelpers.pagerNext(form);
- QUnit.test('click on the google drive attachments after switching records', async function (assert) {
- assert.expect(3);
+ currentID = 2;
+ await cpHelpers.toggleActionMenu(form);
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
- var currentID;
- var form = await createView({
- View: FormView,
- model: 'partner',
- data: this.data,
- arch: '<form string="Partners">' +
- '<field name="display_name"/>' +
- '</form>',
- res_id: 1,
- viewOptions: {
- hasSidebar: true,
- ids: [1, 2],
- index: 0,
- },
- mockRPC: function (route, args) {
- if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_config') {
- assert.deepEqual(args.args, ['partner', 1],
- 'The route to get google drive config should have been called');
- return Promise.resolve([{id: 27, name: 'Cyberdyne Systems'}]);
- }
- if (route === '/web/dataset/call_kw/google.drive.config/search_read'){
- return Promise.resolve([{google_drive_resource_id: "T1000",
- google_drive_client_id: "cyberdyne.org",
- id: 1}]);
- }
- if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_url') {
- assert.deepEqual(args.args, [27, currentID, 'T1000'],
- 'The route to get the Google url should have been called');
- // We don't return anything useful, otherwise it will open a new tab
- return Promise.resolve();
- }
- return this._super.apply(this, arguments);
- },
+ form.destroy();
});
-
- currentID = 1;
- await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click(form.sidebar.$('.oe_share_gdoc'));
-
- await testUtils.dom.click(form.pager.$('.o_pager_next'));
- currentID = 2;
- await testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)'));
- await testUtils.dom.click(form.sidebar.$('.oe_share_gdoc'));
-
- form.destroy();
});
});
-
-});