From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/lunch/static/tests/lunch_test_utils.js | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 addons/lunch/static/tests/lunch_test_utils.js (limited to 'addons/lunch/static/tests/lunch_test_utils.js') diff --git a/addons/lunch/static/tests/lunch_test_utils.js b/addons/lunch/static/tests/lunch_test_utils.js new file mode 100644 index 00000000..baa7f189 --- /dev/null +++ b/addons/lunch/static/tests/lunch_test_utils.js @@ -0,0 +1,59 @@ +odoo.define('lunch.test_utils', function (require) { +"use strict"; + +const AbstractStorageService = require('web.AbstractStorageService'); +const RamStorage = require('web.RamStorage'); +const {createView} = require('web.test_utils'); + +/** + * Helper to create a lunch view with searchpanel + * + * @param {object} params + */ +async function createLunchView(params) { + params.archs = params.archs || {}; + var searchArch = params.archs[`${params.model},false,search`] || ''; + var searchPanelArch = ` + + + + + `; + searchArch = searchArch.split('')[0] + searchPanelArch + ''; + params.archs[`${params.model},false,search`] = searchArch; + if (!params.services || !params.services.local_storage) { + // the searchPanel uses the localStorage to store/retrieve default + // active category value + params.services = params.services || {}; + const RamStorageService = AbstractStorageService.extend({ + storage: new RamStorage(), + }); + params.services.local_storage = RamStorageService; + } + return createView(params); +} + +/** + * Helper to generate a mockRPC function for the mandatory lunch routes (prefixed by '/lunch') + * + * @param {object} infos + * @param {integer} userLocation + */ +function mockLunchRPC({infos, userLocation}) { + return async function (route) { + if (route === '/lunch/infos') { + return Promise.resolve(infos); + } + if (route === '/lunch/user_location_get') { + return Promise.resolve(userLocation); + } + return this._super.apply(this, arguments); + }; +} + +return { + createLunchView, + mockLunchRPC, +}; + +}); -- cgit v1.2.3