From 0a129284e4856b6485c48a194fd86c3ab5c736e7 Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Wed, 11 Mar 2020 09:38:27 +0000 Subject: [IMP] web,*: Enhance test helpers 1. Test utils helpers adapted to properly instantiate the new Owl control panel 2. New file 'test_utils_control_panel' to create a control panel and use helpers 3. New helper: createComponent (creates a generic component, see jsdoc) 4. Use of the new helpers in the current tests (more in sibling commits) 5. Helper 'addMockEnvironment' is now asynchronous 6. Owl config mode set to 'dev' in test suite (props validation) Part of task 2196029 Co-authored-by: Mathieu Duckerts-Antoine --- addons/web/static/src/js/core/utils.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'addons/web/static/src/js/core/utils.js') diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js index 243f3f51cd0..699a912ccc3 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -628,6 +628,28 @@ var utils = { 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString() ].join(';'); }, + /** + * Returns a string formatted using given values. + * If the value is an object, its keys will replace `%(key)s` expressions. + * If the values are a set of strings, they will replace `%s` expressions. + * If no value is given, the string will not be formatted. + * + * @param {string} string + * @param {(Object|...string)} values + */ + sprintf: function (string, ...values) { + if (values.length === 1 && typeof values[0] === 'object') { + const valuesDict = values[0]; + for (const value in valuesDict) { + string = string.replace(`%(${value})s`, valuesDict[value]); + } + } else { + for (const value of values) { + string = string.replace(/%s/, value); + } + } + return string; + }, /** * Sort an array in place, keeping the initial order for identical values. * -- cgit v1.2.3