Skip to content
Permalink
Browse files

dropdown menu fix + gdrive

  • Loading branch information
Arcasias committed Feb 14, 2020
1 parent 56637d4 commit 78136a8af17b8ccbfba1b9121d83867eafce5295
@@ -18,8 +18,8 @@ odoo.define('board.AddToBoardMenu', function (require) {
this.interactive = true;
this.query = useStore(state => state.query, { store: this.env.controlPanelStore });
this.state = useState({
open: false,
name: this.env.action.name || "",
open: false,
});

this.focusOnUpdate = useFocusOnUpdate();
@@ -73,15 +73,17 @@ odoo.define('board.AddToBoardMenu', function (require) {
}
evalutatedContext.dashboard_merge_domains_contexts = false;

this.state.open = false;
Object.assign(this.state, {
name: this.env.action.name || "",
open: false,
});

const result = await this.rpc({
route: '/board/add_to_dashboard',
params: {
action_id: this.env.action.id || false,
context_to_save: evalutatedContext,
domain: domain,
// TODO: include viewType in props or transmit it another way
view_mode: this.props.viewType,
name: this.state.name,
},
@@ -7,19 +7,27 @@ odoo.define('google_drive.Sidebar', function (require) {
class GoogleDriveMenu extends DropdownMenuItem {

async willStart() {
return (this.gdriveItems = []);
if (this.props.viewType === "form" && this.props.activeIds[0]) {
this.gdriveItems = await this.rpc({
args: [this.env.action.res_model, this.props.activeIds[0]],
context: this.props.context,
method: 'get_google_drive_config',
model: 'google.drive.config',
});
this.gdriveItems = await this._getGoogleDocItems();
} else {
this.gdriveItems = [];
}
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

async _getGoogleDocItems() {
const items = await this.rpc({
args: [this.env.action.res_model, this.props.activeIds[0]],
context: this.props.context,
method: 'get_google_drive_config',
model: 'google.drive.config',
});
return items;
}

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
@@ -1,12 +1,14 @@
<templates>
<t t-name="GoogleDriveMenu" owl="1">
<div class="oe_share_gdoc_menu o_menu_item">
<li t-foreach="gdriveItems" t-as="gdriveItem" t-key="gdriveItem_index"
class="oe_share_gdoc dropdown-item"
role="menuitem"
t-esc="gdriveItem.name"
t-on-click="_onGoogleDocItemClick(gdriveItem.id)"
/>
</div>
<li>
<ul class="o_embed_menu">
<li t-foreach="gdriveItems" t-as="gdriveItem" t-key="gdriveItem_index"
role="menuitem"
class="o_menu_item oe_share_gdoc_item dropdown-item"
>
<a href="#" t-esc="gdriveItem.name" t-on-click.prevent="_onGoogleDocItemClick(gdriveItem.id)"/>
</li>
</ul>
</li>
</t>
</templates>
@@ -1,187 +1,144 @@
odoo.define('google_drive.gdrive_integration', function (require) {
"use strict";
//rebuild

const FormView = require('web.FormView');
const testUtils = require('web.test_utils');
const GoogleDriveSideBar = require('google_drive.Sidebar');
const makeTestEnvironment = require('web.test_env');

const createView = testUtils.createView;
const GoogleDriveMenu = require('google_drive.Sidebar');

/*
* @override
* Avoid breaking other tests because of the new route
* that the module introduces
*/
const _getGoogleDocItemsOriginal = GoogleDriveSideBar.prototype._getGoogleDocItems;

async function _getGoogleDocItemsMocked() { }
const _getGoogleDocItemsOriginal = GoogleDriveMenu.prototype._getGoogleDocItems;
GoogleDriveMenu.prototype._getGoogleDocItems = async () => [];

GoogleDriveSideBar.prototype._getGoogleDocItems = _getGoogleDocItemsMocked;

QUnit.module('gdrive_integration', {
QUnit.module('Google Drive Integration', {
beforeEach() {
// For our test to work, the _getGoogleDocItems function needs to be the original
GoogleDriveSideBar.prototype._getGoogleDocItems = _getGoogleDocItemsOriginal;
GoogleDriveMenu.prototype._getGoogleDocItems = _getGoogleDocItemsOriginal;

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' },
},
records: [{
id: 27,
name: 'Cyberdyne Systems',
model_id: 1,
google_drive_resource_id: 'T1000',
}],
},
'ir.attachment': {
fields: {
name: { string: 'Name', type: 'char' }
},
records: [],
}
};
},

afterEach() {
GoogleDriveSideBar.prototype._getGoogleDocItems = _getGoogleDocItemsMocked;
GoogleDriveMenu.prototype._getGoogleDocItems = async () => [];
},
}, function () {
QUnit.module('Google Drive Sidebar');

QUnit.test('rendering of the google drive attachments in Sidebar', async function (assert) {
assert.expect(3);

async function mockRPC(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 [{
id: 27,
name: 'Cyberdyne Systems',
}];
}
if (route === '/web/dataset/call_kw/google.drive.config/search_read') {
return [{
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;
}
return this._super(...arguments);
}

owl.Component.env = makeTestEnvironment({}, mockRPC);

const form = await createView({
model: 'partner',
data: this.data,
const form = await testUtils.createView({
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.
}
},
model: 'partner',
res_id: 1,
mockRPC,
View: FormView,
viewOptions: { hasSidebar: true },
viewOptions: {
action: { res_model: 'partner' },
hasSidebar: true,
},
});
const sidebar = new GoogleDriveSideBar(null, form._getSidebarProps());
await sidebar.mount(testUtils.prepareTarget(), { position: 'first-child' });
const cpHelpers = testUtils.controlPanel.getHelpers(form.el);

const actionToggleButton = [...sidebar.el.querySelectorAll('.o_dropdown_toggler_btn')].find(
el => el.innerText.match("Action")
);
await cpHelpers.toggleSideBar();

// click on gdrive sidebar item
await testUtils.dom.click(actionToggleButton);
await testUtils.dom.click(sidebar.el.querySelector('.oe_share_gdoc'));
assert.containsOnce(form, '.oe_share_gdoc_item',
"The button to the google action should be present");

await cpHelpers.toggleMenuItem("Cyberdyne Systems");

form.destroy();
});

QUnit.test('click on the google drive attachments after switching records', async function (assert) {
assert.expect(3);

async function mockRPC(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 [{
id: 27,
name: 'Cyberdyne Systems',
}];
}
if (route === '/web/dataset/call_kw/google.drive.config/search_read') {
return [{
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;
}
return this._super(...arguments);
}

owl.Component.env = makeTestEnvironment({}, mockRPC);
assert.expect(4);

let currentID;
const form = await createView({
const form = await testUtils.createView({
arch:
`<form string="Partners">
<field name="display_name"/>
</form>`,
data: this.data,
mockRPC,
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: {
action: { res_model: 'partner' },
hasSidebar: true,
ids: [1, 2],
index: 0,
},
});

const actionToggleButton = [...document.querySelectorAll('.o_cp_sidebar .o_dropdown_toggler_btn')].find(
el => el.innerText.match("Action")
);
const cpHelpers = testUtils.controlPanel.getHelpers(form.el);

currentID = 1;
await testUtils.dom.click(actionToggleButton);
await testUtils.dom.click(document.querySelector('.o_cp_sidebar .oe_share_gdoc'));
await cpHelpers.toggleSideBar();
await cpHelpers.toggleMenuItem("Cyberdyne Systems");

await testUtils.dom.click(document.querySelector('.o_cp_pager .o_pager_next'));
await cpHelpers.pagerNext();

currentID = 2;
await testUtils.dom.click(actionToggleButton);
await testUtils.dom.click(document.querySelector('.o_cp_sidebar .oe_share_gdoc'));
await cpHelpers.toggleSideBar();
await cpHelpers.toggleMenuItem("Cyberdyne Systems");

form.destroy();
});
@@ -37,7 +37,6 @@ odoo.define('web.Pager', function (require) {

this.focusOnUpdate = useFocusOnUpdate();
this.focusOnUpdate();
window.useDebug(); // TODO(jum): remove
}

async willUpdateProps() {

0 comments on commit 78136a8

Please sign in to comment.
You can’t perform that action at this time.