From c6b2db9a792a13089aaf52971072d00812c2b6f7 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sat, 7 Mar 2020 13:52:02 +0100 Subject: [PATCH 1/9] Savepoint --- front/core/components/searchbar/searchbar.js | 153 ++++++++++--------- front/core/components/slot/index.js | 6 + front/salix/module.js | 5 +- modules/zone/front/index/index.html | 15 +- modules/zone/front/index/index.js | 68 +++------ modules/zone/front/main/index.html | 12 +- modules/zone/front/main/index.js | 25 ++- 7 files changed, 148 insertions(+), 136 deletions(-) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index a82324877..f8099caf1 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -13,8 +13,11 @@ import './style.scss'; * * @property {Object} filter A key-value object with filter parameters * @property {SearchPanel} panel The panel used for advanced searches + * @property {CrudModel} model The model used for searching + * @property {Function} exprBuilder If defined, is used to build each non-null param expresion + * @property {Function} onSearch Function to call when search is submited */ -export default class Controller extends Component { +export default class Searchbar extends Component { constructor($element, $) { super($element, $); this.searchState = '.'; @@ -26,6 +29,9 @@ export default class Controller extends Component { $postLink() { this.onStateChange(); + + if (this.$state.is(this.searchState) && this.filter !== null) + this.doSearch(); } $onDestroy() { @@ -58,8 +64,9 @@ export default class Controller extends Component { onStateChange() { let filter = null; + let isIndex = this.$state.is(this.searchState); - if (this.$state.is(this.searchState)) { + if (isIndex) { if (this.$params.q) { try { filter = JSON.parse(this.$params.q); @@ -72,6 +79,11 @@ export default class Controller extends Component { } this.filter = filter; + + if (isIndex) + this.doSearch(); + else if (this.model) + this.model.clear(); } openPanel(event) { @@ -100,25 +112,21 @@ export default class Controller extends Component { this.$.popover.hide(); filter = compact(filter); filter = filter != null ? filter : {}; - this.doSearch(filter); + this.goSearch(filter); } onSubmit() { - this.doSearch(this.fromBar()); + this.goSearch(this.fromBar()); } removeParam(index) { this.params.splice(index, 1); - this.doSearch(this.fromBar()); + this.goSearch(this.fromBar()); } - doSearch(filter) { + goSearch(filter) { this.filter = filter; - - let opts = this.$state.is(this.searchState) - ? {location: 'replace'} : null; - this.$state.go(this.searchState, - {q: JSON.stringify(filter)}, opts); + this.doSearch(); } fromBar() { @@ -171,61 +179,6 @@ export default class Controller extends Component { this.params.push({chip, key, value}); }); } -} - -ngModule.vnComponent('vnSearchbar', { - controller: Controller, - template: require('./searchbar.html'), - bindings: { - searchState: '@?', - filter: ' this.onStateChange()); - - this.fetchFilter(); - } - - $postLink() { - if (this.filter !== null) - this.doSearch(); - } - - $onDestroy() { - this.deregisterCallback(); - } - - fetchFilter() { - if (this.$state.params.q) { - try { - this.filter = JSON.parse(this.$state.params.q); - } catch (e) { - console.error(e); - } - } else - this.filter = null; - } - - onStateChange() { - this.fetchFilter(); - this.doSearch(); - } doSearch() { let filter = this.filter; @@ -257,25 +210,81 @@ class AutoSearch { this.model.applyFilter( where ? {where} : null, hasParams ? userParams : null - ); + ).then(() => this.onModelFilter()); } else this.model.clear(); } } + onModelFilter() { + let params; + let opts; + let data = this.model.data; + let currentState = this.$state.current.name; + let stateParts = currentState.split('.'); + let baseState = stateParts[0]; + let subState = stateParts[1]; + + if (this.goState && data && data.length == 1) { + switch (subState) { + case 'index': + subState = 'card.summary'; + break; + case 'card': + subState += `.${stateParts[2]}`; + break; + } + + if (this.goStateParams) + params = this.goStateParams({$row: data[0]}); + } else { + if (subState == 'index') + opts = {location: 'replace'}; + subState = `index`; + params = {q: JSON.stringify(this.filter)}; + } + + this.$state.go(`${baseState}.${subState}`, params, opts); + } + exprBuilder(param, value) { return {[param]: value}; } } -AutoSearch.$inject = ['$state', '$transitions']; + +ngModule.vnComponent('vnSearchbar', { + controller: Searchbar, + template: require('./searchbar.html'), + bindings: { + searchState: '@?', + filter: ' - + model="model"> {{::zone.id}} @@ -61,7 +52,7 @@ diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index 4ee44ada0..aa69e30b6 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -1,55 +1,10 @@ import ngModule from '../module'; export default class Controller { - constructor($scope, $http, $state) { - this.$scope = $scope; + constructor($, $http, $state) { + this.$ = $; this.$http = $http; this.$state = $state; - this.filter = { - include: { - relation: 'agencyMode', - scope: {fields: ['name']} - } - }; - } - - exprBuilder(param, value) { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {id: value} - : {name: {like: `%${value}%`}}; - case 'name': - return {[param]: {like: `%${value}%`}}; - case 'agencyModeFk': - return {[param]: value}; - } - } - - /** - * Clones a zone and all its properties - * @param {Object} event - Event object - * @param {Object} zone - Selected item - */ - clone(event, zone) { - this.stopEvent(event); - this.selectedZone = zone; - this.$scope.clone.show(); - } - - /** - * Clone response callback - * @param {String} response - Response string (['accept', 'cancel']) - */ - onCloneAccept(response) { - if (!(response == 'accept' && this.selectedZone)) return; - const query = `Zones/${this.selectedZone.id}/clone`; - this.$http.post(query).then(res => { - if (res && res.data) - this.$state.go('zone.card.basicData', {id: res.data.id}); - }); - - this.selectedZone = null; } /** @@ -60,13 +15,28 @@ export default class Controller { preview(event, zone) { this.stopEvent(event); this.selectedZone = zone; - this.$scope.summary.show(); + this.$.summary.show(); } /** - * Prevents normal event propagation + * Clones a zone and all its properties * @param {Object} event - Event object + * @param {Object} zone - Selected item */ + clone(event, zone) { + this.stopEvent(event); + this.selectedZone = zone; + this.$.clone.show(); + } + + onCloneAccept() { + return this.$http.post(`Zones/${this.selectedZone.id}/clone`) + .then(res => { + this.selectedZone = null; + this.$state.go('zone.card.basicData', {id: res.data.id}); + }); + } + stopEvent(event) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/modules/zone/front/main/index.html b/modules/zone/front/main/index.html index 230bf7f6d..d6e63a1a6 100644 --- a/modules/zone/front/main/index.html +++ b/modules/zone/front/main/index.html @@ -1,8 +1,18 @@ + + + info="Search zone by id or name" + model="model" + expr-builder="$ctrl.exprBuilder(param, value)" + go-state="zone.card.summary" + go-state-params="{id: $row.id}"> diff --git a/modules/zone/front/main/index.js b/modules/zone/front/main/index.js index 3e8890310..3be60c5a1 100644 --- a/modules/zone/front/main/index.js +++ b/modules/zone/front/main/index.js @@ -1,7 +1,30 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Zone extends ModuleMain {} +export default class Zone extends ModuleMain { + constructor($element, $) { + super($element, $); + this.filter = { + include: { + relation: 'agencyMode', + scope: {fields: ['name']} + } + }; + } + + exprBuilder(param, value) { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {id: value} + : {name: {like: `%${value}%`}}; + case 'name': + return {[param]: {like: `%${value}%`}}; + case 'agencyModeFk': + return {[param]: value}; + } + } +} ngModule.vnComponent('vnZone', { controller: Zone, From 9d1bc8eb542322a0044888a563f5a1067bdf762c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 13 Mar 2020 20:33:12 +0100 Subject: [PATCH 2/9] First functional version (No tests) --- front/core/components/searchbar/searchbar.js | 200 +++++++++++-------- front/salix/module.js | 2 +- modules/claim/front/index/index.html | 12 +- modules/claim/front/index/index.js | 7 - modules/claim/front/main/index.html | 11 +- modules/client/front/index/index.html | 13 +- modules/client/front/index/index.js | 27 --- modules/client/front/main/index.html | 12 +- modules/client/front/main/index.js | 28 ++- modules/entry/front/index/index.html | 12 +- modules/entry/front/index/index.js | 7 - modules/entry/front/main/index.html | 10 +- modules/invoiceOut/front/index/index.html | 13 +- modules/invoiceOut/front/index/index.js | 7 - modules/invoiceOut/front/main/index.html | 10 +- modules/item/front/index/index.html | 11 +- modules/item/front/index/index.js | 8 - modules/item/front/main/index.html | 11 +- modules/order/front/index/index.html | 16 +- modules/order/front/index/index.js | 7 - modules/order/front/main/index.html | 11 +- modules/route/front/index/index.html | 12 +- modules/route/front/index/index.js | 7 - modules/route/front/main/index.html | 11 +- modules/ticket/front/index/index.html | 12 +- modules/ticket/front/index/index.js | 24 --- modules/ticket/front/main/index.html | 11 +- modules/ticket/front/main/index.js | 20 +- modules/travel/front/index/index.html | 11 +- modules/travel/front/index/index.js | 23 --- modules/travel/front/main/index.html | 11 +- modules/travel/front/main/index.js | 20 +- modules/worker/front/index/index.html | 11 +- modules/worker/front/index/index.js | 9 +- modules/worker/front/main/index.html | 10 +- modules/zone/front/location/index.html | 36 ++-- modules/zone/front/main/index.html | 7 +- 37 files changed, 314 insertions(+), 356 deletions(-) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index f8099caf1..b9c761874 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -21,17 +21,23 @@ export default class Searchbar extends Component { constructor($element, $) { super($element, $); this.searchState = '.'; + this.autoState = true; - let criteria = {}; this.deregisterCallback = this.$transitions.onSuccess( - criteria, () => this.onStateChange()); + {}, transition => this.onStateChange(transition)); } $postLink() { - this.onStateChange(); + if (this.autoState) { + if (!this.baseState) { + let stateParts = this.$state.current.name.split('.'); + this.baseState = stateParts[0]; + } - if (this.$state.is(this.searchState) && this.filter !== null) - this.doSearch(); + this.searchState = `${this.baseState}.index`; + } + + this.fetchStateFilter(this.autoLoad); } $onDestroy() { @@ -62,11 +68,18 @@ export default class Searchbar extends Component { if (value == null) this.params = []; } - onStateChange() { - let filter = null; - let isIndex = this.$state.is(this.searchState); + onStateChange(transition) { + if (!this.element.parentNode + || transition == this.transition) + return; + + this.fetchStateFilter(); + } + + fetchStateFilter(autoLoad) { + if (this.$state.is(this.searchState)) { + let filter = null; - if (isIndex) { if (this.$params.q) { try { filter = JSON.parse(this.$params.q); @@ -75,15 +88,12 @@ export default class Searchbar extends Component { } } - focus(this.element.querySelector('vn-textfield input')); - } + if (!filter && autoLoad) + filter = {}; - this.filter = filter; - - if (isIndex) - this.doSearch(); - else if (this.model) - this.model.clear(); + this.doSearch(filter, 'state'); + } else + this.clearSearch(); } openPanel(event) { @@ -112,21 +122,16 @@ export default class Searchbar extends Component { this.$.popover.hide(); filter = compact(filter); filter = filter != null ? filter : {}; - this.goSearch(filter); + this.doSearch(filter, 'panel'); } onSubmit() { - this.goSearch(this.fromBar()); + this.doSearch(this.fromBar(), 'bar'); } removeParam(index) { this.params.splice(index, 1); - this.goSearch(this.fromBar()); - } - - goSearch(filter) { - this.filter = filter; - this.doSearch(); + this.doSearch(this.fromBar(), 'bar'); } fromBar() { @@ -180,75 +185,94 @@ export default class Searchbar extends Component { }); } - doSearch() { - let filter = this.filter; - if (filter == null && this.autoload) - filter = {}; - - if (this.onSearch) - this.onSearch({$params: filter}); - - if (this.model) { - if (filter !== null) { - let where = buildFilter(filter, - (param, value) => this.exprBuilder({param, value})); - - let userParams = {}; - let hasParams = false; - - if (this.paramBuilder) { - for (let param in filter) { - let value = filter[param]; - if (value == null) continue; - let expr = this.paramBuilder({param, value}); - if (expr) { - Object.assign(userParams, expr); - hasParams = true; - } - } - } - this.model.applyFilter( - where ? {where} : null, - hasParams ? userParams : null - ).then(() => this.onModelFilter()); - } else - this.model.clear(); - } + clearSearch() { + if (!this.filter) return; + if (this.model) this.model.clear(); + this.filter = null; } - onModelFilter() { + doSearch(filter, source) { + let promise; + + if (this.model) + promise = this.modelSearch(filter); + else if (this.onSearch) + promise = this.onSearch({$params: filter}); + + promise = promise || this.$q.resolve(); + promise.then(data => this.onFilter(filter, source, data)); + } + + modelSearch(filter) { + if (filter === null) { + this.model.clear(); + return this.$q.resolve(); + } + + let where = null; + let params = null; + + if (this.exprBuilder) { + where = buildFilter(filter, + (param, value) => this.exprBuilder({param, value})); + } else { + params = Object.assign({}, filter); + + if (this.fetchParams) + params = this.fetchParams({$params: params}); + } + + return this.model.applyFilter(where ? {where} : null, params) + .then(() => this.model.data); + } + + onFilter(filter, source, data) { + let state; let params; let opts; - let data = this.model.data; - let currentState = this.$state.current.name; - let stateParts = currentState.split('.'); - let baseState = stateParts[0]; - let subState = stateParts[1]; - if (this.goState && data && data.length == 1) { + if (data && data.length == 1 && this.autoState && source != 'state') { + let baseDepth = this.baseState.split('.').length; + let stateParts = this.$state.current.name + .split('.') + .slice(baseDepth); + + let subState = stateParts[0]; + switch (subState) { - case 'index': - subState = 'card.summary'; - break; case 'card': - subState += `.${stateParts[2]}`; + subState += `.${stateParts[1]}`; + if (stateParts.length >= 3) + subState += '.index'; break; + default: + subState = 'card.summary'; } - if (this.goStateParams) - params = this.goStateParams({$row: data[0]}); + if (this.singleParams) + params = this.singleParams({$row: data[0]}); + + state = `${this.baseState}.${subState}`; + filter = null; } else { - if (subState == 'index') + state = this.searchState; + + if (filter) + params = {q: JSON.stringify(filter)}; + if (this.$state.is(state)) opts = {location: 'replace'}; - subState = `index`; - params = {q: JSON.stringify(this.filter)}; } - this.$state.go(`${baseState}.${subState}`, params, opts); + this.filter = filter; + + if (source != 'state') + this.transition = this.$state.go(state, params, opts).transition; + if (source != 'bar') + focus(this.element.querySelector('vn-textfield input')); } - exprBuilder(param, value) { - return {[param]: value}; + singleParams(params) { + return {id: params.$row.id}; } } @@ -256,27 +280,29 @@ ngModule.vnComponent('vnSearchbar', { controller: Searchbar, template: require('./searchbar.html'), bindings: { - searchState: '@?', filter: ' - + model="model"> {{::claim.id}} diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index 21464fea9..1e9724987 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -43,13 +43,6 @@ export default class Controller { onDescriptorLoad() { this.$.popover.relocate(); } - - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } } Controller.$inject = ['$scope']; diff --git a/modules/claim/front/main/index.html b/modules/claim/front/main/index.html index e733162b1..c66c02f14 100644 --- a/modules/claim/front/main/index.html +++ b/modules/claim/front/main/index.html @@ -1,8 +1,15 @@ + + + info="Search claim by id or client name" + model="model"> diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html index f3c3fb728..a501b68cf 100644 --- a/modules/client/front/index/index.html +++ b/modules/client/front/index/index.html @@ -1,13 +1,6 @@ - - + + model="model">
diff --git a/modules/client/front/index/index.js b/modules/client/front/index/index.js index 51dd41dea..054944f9d 100644 --- a/modules/client/front/index/index.js +++ b/modules/client/front/index/index.js @@ -7,33 +7,6 @@ export default class Controller { this.clientSelected = null; } - exprBuilder(param, value) { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {id: value} - : {name: {like: `%${value}%`}}; - case 'phone': - return { - or: [ - {phone: value}, - {mobile: value} - ] - }; - case 'name': - case 'socialName': - case 'city': - return {[param]: {like: `%${value}%`}}; - case 'email': - return {[param]: {like: `%${value}%`}}; - case 'id': - case 'fi': - case 'postcode': - case 'salesPersonFk': - return {[param]: value}; - } - } - openSummary(client, event) { if (event.defaultPrevented) return; event.preventDefault(); diff --git a/modules/client/front/main/index.html b/modules/client/front/main/index.html index 1ae1d211b..cab796c1f 100644 --- a/modules/client/front/main/index.html +++ b/modules/client/front/main/index.html @@ -1,8 +1,16 @@ + + + info="Search client by id or name" + model="model" + expr-builder="$ctrl.exprBuilder(param, value)"> diff --git a/modules/client/front/main/index.js b/modules/client/front/main/index.js index 890165a19..cae95c1dd 100644 --- a/modules/client/front/main/index.js +++ b/modules/client/front/main/index.js @@ -1,7 +1,33 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Client extends ModuleMain {} +export default class Client extends ModuleMain { + exprBuilder(param, value) { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {id: value} + : {name: {like: `%${value}%`}}; + case 'phone': + return { + or: [ + {phone: value}, + {mobile: value} + ] + }; + case 'name': + case 'socialName': + case 'city': + case 'email': + return {[param]: {like: `%${value}%`}}; + case 'id': + case 'fi': + case 'postcode': + case 'salesPersonFk': + return {[param]: value}; + } + } +} ngModule.vnComponent('vnClient', { controller: Client, diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html index 60bbe46d5..9dfaa7e34 100644 --- a/modules/entry/front/index/index.html +++ b/modules/entry/front/index/index.html @@ -1,13 +1,5 @@ - - + model="model"> - diff --git a/modules/entry/front/index/index.js b/modules/entry/front/index/index.js index 53d2f45e0..7368cc05e 100644 --- a/modules/entry/front/index/index.js +++ b/modules/entry/front/index/index.js @@ -5,13 +5,6 @@ export default class Controller { this.$ = $scope; } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - showTravelDescriptor(event, travelFk) { if (event.defaultPrevented) return; event.preventDefault(); diff --git a/modules/entry/front/main/index.html b/modules/entry/front/main/index.html index 44b1b2b4e..07009b7b0 100644 --- a/modules/entry/front/main/index.html +++ b/modules/entry/front/main/index.html @@ -1,8 +1,14 @@ + + + info="Search entrys by id" + model="model"> diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html index c798b8bc6..ad7c363ce 100644 --- a/modules/invoiceOut/front/index/index.html +++ b/modules/invoiceOut/front/index/index.html @@ -1,16 +1,9 @@ - - + model="model"> + class="vn-w-md"> @@ -27,7 +20,7 @@ - {{::invoiceOut.ref | dashIfEmpty}} diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index dd8219fae..46ad6bc3f 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -32,13 +32,6 @@ export default class Controller { event.preventDefault(); event.stopImmediatePropagation(); } - - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } } Controller.$inject = ['$scope', 'vnToken']; diff --git a/modules/invoiceOut/front/main/index.html b/modules/invoiceOut/front/main/index.html index 18e72ed5e..df65fd217 100644 --- a/modules/invoiceOut/front/main/index.html +++ b/modules/invoiceOut/front/main/index.html @@ -1,8 +1,14 @@ + + + info="Search invoices by reference" + model="model"> diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index c83ce5ed1..154c64bb1 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -1,12 +1,5 @@ - - + model="model"> - diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 087021577..968c7b027 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -21,13 +21,6 @@ class Controller { event.stopImmediatePropagation(); } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - showItemDescriptor(event, itemFk) { if (event.defaultPrevented) return; @@ -39,7 +32,6 @@ class Controller { this.$.itemDescriptor.show(); } - showWorkerDescriptor(event, workerFk) { if (event.defaultPrevented) return; diff --git a/modules/item/front/main/index.html b/modules/item/front/main/index.html index 758bfd55e..55ef00b75 100644 --- a/modules/item/front/main/index.html +++ b/modules/item/front/main/index.html @@ -1,9 +1,16 @@ + + + suggested-filter="{isActive: true}" + model="model"> diff --git a/modules/order/front/index/index.html b/modules/order/front/index/index.html index 20dd4a231..b16a1b25d 100644 --- a/modules/order/front/index/index.html +++ b/modules/order/front/index/index.html @@ -1,12 +1,6 @@ - - + + model="model"> - + {{::order.id}} diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index 8cf289796..10940eb27 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -8,13 +8,6 @@ export default class Controller { this.ticketSelected = null; } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; diff --git a/modules/order/front/main/index.html b/modules/order/front/main/index.html index 09d498599..1aca6a48d 100644 --- a/modules/order/front/main/index.html +++ b/modules/order/front/main/index.html @@ -1,8 +1,15 @@ + + + info="Search orders by id" + model="model"> diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index c01112928..ab8b1364b 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -1,13 +1,5 @@ - - + model="model"> - {{::route.id | dashIfEmpty}} diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 8fdde810c..735581265 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -24,13 +24,6 @@ export default class Controller { this.routeSelected = route; this.$.summary.show(); } - - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } } Controller.$inject = ['$scope', 'vnToken']; diff --git a/modules/route/front/main/index.html b/modules/route/front/main/index.html index f6e097b24..2be8ab467 100644 --- a/modules/route/front/main/index.html +++ b/modules/route/front/main/index.html @@ -1,9 +1,16 @@ + + + filter="$ctrl.filter" + model="model"> diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index b303c3ae7..a0efea467 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -1,13 +1,5 @@ - - + model="model"> - diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 05dc23c08..a4606bb72 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -38,30 +38,6 @@ export default class Controller { this.$.balanceCreateDialog.description += description.join(', '); } - getScopeDates(days) { - const today = new Date(); - today.setHours(0, 0, 0, 0); - - const daysOnward = new Date(today); - daysOnward.setDate(today.getDate() + days); - daysOnward.setHours(23, 59, 59, 999); - - return {from: today, to: daysOnward}; - } - - onSearch(params) { - if (params) { - if (typeof(params.scopeDays) === 'number') - Object.assign(params, this.getScopeDates(params.scopeDays)); - // Set default params to 1 scope days - else if (Object.entries(params).length == 0) - params = this.getScopeDates(1); - - this.$.model.applyFilter(null, params); - } else - this.$.model.clear(); - } - goToLines(event, ticketFk) { this.preventDefault(event); let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html index 7e058f45d..bcb77cca5 100644 --- a/modules/ticket/front/main/index.html +++ b/modules/ticket/front/main/index.html @@ -1,8 +1,15 @@ + + + info="Search ticket by id or alias" + model="model" + fetch-params="$ctrl.fetchParams($params)"> diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index d6100daa3..bd4718176 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -1,7 +1,25 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Ticket extends ModuleMain {} +export default class Ticket extends ModuleMain { + fetchParams($params) { + if (!Object.entries($params).length) + $params.scopeDays = 1; + + if (typeof $params.scopeDays === 'number') { + const from = new Date(); + from.setHours(0, 0, 0, 0); + + const to = new Date(from.getTime()); + to.setDate(to.getDate() + $params.scopeDays); + to.setHours(23, 59, 59, 999); + + Object.assign($params, {from, to}); + } + + return $params; + } +} ngModule.vnComponent('vnTicket', { controller: Ticket, diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 3af99eb6b..ba0272d3f 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -1,13 +1,6 @@ - - + + model="model"> + + info="Search travels by id" + model="model" + fetch-params="$ctrl.fetchParams($params)"> diff --git a/modules/travel/front/main/index.js b/modules/travel/front/main/index.js index 3be713973..f04cc750d 100644 --- a/modules/travel/front/main/index.js +++ b/modules/travel/front/main/index.js @@ -1,7 +1,25 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; -export default class Travel extends ModuleMain {} +export default class Travel extends ModuleMain { + fetchParams($params) { + if (!Object.entries($params).length) + $params.scopeDays = 1; + + if (typeof $params.scopeDays === 'number') { + const shippedFrom = new Date(); + shippedFrom.setHours(0, 0, 0, 0); + + const shippedTo = new Date(shippedFrom.getTime()); + shippedTo.setDate(shippedTo.getDate() + $params.scopeDays); + shippedTo.setHours(23, 59, 59, 999); + + Object.assign($params, {shippedFrom, shippedTo}); + } + + return $params; + } +} ngModule.vnComponent('vnTravel', { controller: Travel, diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html index 56dde4609..dfab7f16a 100644 --- a/modules/worker/front/index/index.html +++ b/modules/worker/front/index/index.html @@ -1,12 +1,5 @@ - - + model="model">
diff --git a/modules/worker/front/index/index.js b/modules/worker/front/index/index.js index 1cc9a8f92..1b585f013 100644 --- a/modules/worker/front/index/index.js +++ b/modules/worker/front/index/index.js @@ -9,13 +9,6 @@ export default class Controller { }); } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - preview(event, worker) { if (event.defaultPrevented) return; @@ -26,7 +19,6 @@ export default class Controller { this.$.preview.show(); } - goToTimeControl(event, workerId) { if (event.defaultPrevented) return; @@ -34,6 +26,7 @@ export default class Controller { event.stopPropagation(); this.$state.go('worker.card.timeControl', {id: workerId}, {absolute: true}); } + onMoreChange(callback) { callback.call(this); } diff --git a/modules/worker/front/main/index.html b/modules/worker/front/main/index.html index 826a7905f..51948fedf 100644 --- a/modules/worker/front/main/index.html +++ b/modules/worker/front/main/index.html @@ -1,8 +1,14 @@ + + + info="Search workers by id, firstName, lastName or user name" + model="model"> diff --git a/modules/zone/front/location/index.html b/modules/zone/front/location/index.html index 4b3523a1f..20755f916 100644 --- a/modules/zone/front/location/index.html +++ b/modules/zone/front/location/index.html @@ -4,25 +4,25 @@ filter="::$ctrl.filter"> - + + - -
- - - - - + + + + +
diff --git a/modules/zone/front/main/index.html b/modules/zone/front/main/index.html index d6e63a1a6..d5a2b2b38 100644 --- a/modules/zone/front/main/index.html +++ b/modules/zone/front/main/index.html @@ -6,13 +6,10 @@ + expr-builder="$ctrl.exprBuilder(param, value)"> From 8629bc25cde164ee72fda91f48bb4ded0a842941 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 16 Mar 2020 18:08:44 +0100 Subject: [PATCH 3/9] Back & Front tests passed --- front/core/components/searchbar/searchbar.js | 144 +++++++++--------- .../components/searchbar/searchbar.spec.js | 45 ++++-- modules/travel/front/index/index.js | 6 +- modules/travel/front/index/index.spec.js | 45 +----- modules/travel/front/main/index.spec.js | 24 +++ .../zone/front/{index => main}/index.spec.js | 9 +- 6 files changed, 144 insertions(+), 129 deletions(-) create mode 100644 modules/travel/front/main/index.spec.js rename modules/zone/front/{index => main}/index.spec.js (74%) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index b9c761874..3ccc2a316 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -77,9 +77,9 @@ export default class Searchbar extends Component { } fetchStateFilter(autoLoad) { - if (this.$state.is(this.searchState)) { - let filter = null; + let filter = null; + if (this.$state.is(this.searchState)) { if (this.$params.q) { try { filter = JSON.parse(this.$params.q); @@ -90,10 +90,9 @@ export default class Searchbar extends Component { if (!filter && autoLoad) filter = {}; + } - this.doSearch(filter, 'state'); - } else - this.clearSearch(); + this.doSearch(filter, 'state'); } openPanel(event) { @@ -185,28 +184,78 @@ export default class Searchbar extends Component { }); } - clearSearch() { - if (!this.filter) return; - if (this.model) this.model.clear(); - this.filter = null; - } - doSearch(filter, source) { - let promise; - - if (this.model) - promise = this.modelSearch(filter); - else if (this.onSearch) - promise = this.onSearch({$params: filter}); - + if (filter === this.filter) return; + let promise = this.onSearch({$params: filter}); promise = promise || this.$q.resolve(); promise.then(data => this.onFilter(filter, source, data)); } - modelSearch(filter) { + onFilter(filter, source, data) { + let state; + let params; + let opts; + + if (filter) { + let oneResult = this.autoState + && source != 'state' + && data + && data.length == 1; + + if (oneResult) { + let baseDepth = this.baseState.split('.').length; + let stateParts = this.$state.current.name + .split('.') + .slice(baseDepth); + + let subState = stateParts[0]; + + switch (subState) { + case 'card': + subState += `.${stateParts[1]}`; + if (stateParts.length >= 3) + subState += '.index'; + break; + default: + subState = 'card.summary'; + } + + if (this.stateParams) + params = this.stateParams({$row: data[0]}); + + state = `${this.baseState}.${subState}`; + filter = null; + } else { + state = this.searchState; + + if (filter) + params = {q: JSON.stringify(filter)}; + if (this.$state.is(state)) + opts = {location: 'replace'}; + } + } + + this.filter = filter; + + if (source != 'state') + this.transition = this.$state.go(state, params, opts).transition; + if (source != 'bar') + focus(this.element.querySelector('vn-textfield input')); + } + + // Default search handlers + + stateParams(params) { + return {id: params.$row.id}; + } + + onSearch(args) { + if (!this.model) return; + let filter = args.$params; + if (filter === null) { this.model.clear(); - return this.$q.resolve(); + return; } let where = null; @@ -226,53 +275,8 @@ export default class Searchbar extends Component { .then(() => this.model.data); } - onFilter(filter, source, data) { - let state; - let params; - let opts; - - if (data && data.length == 1 && this.autoState && source != 'state') { - let baseDepth = this.baseState.split('.').length; - let stateParts = this.$state.current.name - .split('.') - .slice(baseDepth); - - let subState = stateParts[0]; - - switch (subState) { - case 'card': - subState += `.${stateParts[1]}`; - if (stateParts.length >= 3) - subState += '.index'; - break; - default: - subState = 'card.summary'; - } - - if (this.singleParams) - params = this.singleParams({$row: data[0]}); - - state = `${this.baseState}.${subState}`; - filter = null; - } else { - state = this.searchState; - - if (filter) - params = {q: JSON.stringify(filter)}; - if (this.$state.is(state)) - opts = {location: 'replace'}; - } - - this.filter = filter; - - if (source != 'state') - this.transition = this.$state.go(state, params, opts).transition; - if (source != 'bar') - focus(this.element.querySelector('vn-textfield input')); - } - - singleParams(params) { - return {id: params.$row.id}; + onClear() { + if (this.model) this.model.clear(); } } @@ -285,11 +289,11 @@ ngModule.vnComponent('vnSearchbar', { panel: '@', info: '@?', onSearch: '&?', - model: ' { describe('$postLink()', () => { it(`should fetch the filter from the state if it's in the filter state`, () => { + jest.spyOn(controller, 'doSearch'); + + controller.autoState = false; controller.$postLink(); - expect(controller.filter).toEqual(filter); - expect(controller.searchString).toBe('needle'); - expect(controller.params.length).toBe(1); + expect(controller.doSearch).toHaveBeenCalledWith(filter, 'state'); }); it(`should not fetch the filter from the state if not in the filter state`, () => { + jest.spyOn(controller, 'doSearch'); + + controller.autoState = false; controller.searchState = 'other.state'; controller.$postLink(); - expect(controller.filter).toBeNull(); - expect(controller.searchString).toBeNull(); - expect(controller.params.length).toBe(0); + expect(controller.doSearch).toHaveBeenCalledWith(null, 'state'); }); }); @@ -67,6 +69,14 @@ describe('Component vnSearchbar', () => { expect(chips.negated).toBe('not negated'); expect(chips.myObjectProp).toBe('myObjectProp'); }); + + it(`should clear the filter when null`, () => { + controller.filter = null; + + expect(controller.filter).toBeNull(); + expect(controller.searchString).toBeNull(); + expect(controller.params.length).toBe(0); + }); }); describe('shownFilter() getter', () => { @@ -98,6 +108,7 @@ describe('Component vnSearchbar', () => { describe('onPanelSubmit()', () => { it(`should compact and define the filter`, () => { controller.$.popover = {hide: jasmine.createSpy('hide')}; + jest.spyOn(controller, 'doSearch'); const filter = { id: 1, @@ -110,42 +121,54 @@ describe('Component vnSearchbar', () => { }; controller.onPanelSubmit(filter); - expect(controller.filter).toEqual({ + expect(controller.doSearch).toHaveBeenCalledWith({ id: 1, myObject: {keepThis: true}, myArray: [true] - }); + }, 'panel'); }); }); describe('onSubmit()', () => { it(`should define the filter`, () => { + jest.spyOn(controller, 'doSearch'); + controller.filter = filter; controller.searchString = 'mySearch'; controller.onSubmit(); - expect(controller.filter).toEqual({id: 1, search: 'mySearch'}); + expect(controller.doSearch).toHaveBeenCalledWith({ + id: 1, + search: 'mySearch' + }, 'bar'); }); }); describe('removeParam()', () => { it(`should remove the parameter from the filter`, () => { + jest.spyOn(controller, 'doSearch'); + controller.filter = filter; controller.removeParam(0); - expect(controller.filter).toEqual({search: 'needle'}); + expect(controller.doSearch).toHaveBeenCalledWith({ + search: 'needle' + }, 'bar'); }); }); describe('doSearch()', () => { it(`should go to the search state and pass the filter as query param`, () => { jest.spyOn($state, 'go'); + + controller.autoState = false; controller.searchState = 'search.state'; controller.doSearch(filter); + $scope.$apply(); let queryParams = {q: JSON.stringify(filter)}; - expect($state.go).toHaveBeenCalledWith('search.state', queryParams, null); + expect($state.go).toHaveBeenCalledWith('search.state', queryParams, undefined); expect(controller.filter).toEqual(filter); }); }); diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index ca45f8452..fe2f7e8a9 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -1,9 +1,8 @@ import ngModule from '../module'; export default class Controller { - constructor($scope) { - this.$ = $scope; - this.ticketSelected = null; + constructor($) { + this.$ = $; } preview(event, travel) { @@ -13,7 +12,6 @@ export default class Controller { event.stopImmediatePropagation(); } } - Controller.$inject = ['$scope']; ngModule.component('vnTravelIndex', { diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 5affc7c1a..15247a1e1 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -1,64 +1,31 @@ import './index.js'; describe('Travel Component vnTravelIndex', () => { - let $componentController; let controller; - let $window; - let travels = [{ + let travel = { id: 1, warehouseInFk: 1, totalEntries: 3, isDelivered: false - }, { - id: 2, - warehouseInFk: 1, - total: 4, - isDelivered: true - }, { - id: 3, - warehouseInFk: 1, - total: 2, - isDelivered: true - }]; + }; - beforeEach(angular.mock.module('travel', $translateProvider => { - $translateProvider.translations('en', {}); - })); + beforeEach(ngModule('travel')); - beforeEach(angular.mock.inject((_$componentController_, $rootScope) => { - $componentController = _$componentController_; + beforeEach(angular.mock.inject(($componentController, $rootScope) => { let $scope = $rootScope.$new(); - controller = $componentController('vnTravelIndex', $scope); + controller = $componentController('vnTravelIndex', {$scope}); controller.$.summary = {show: jasmine.createSpy('show')}; })); describe('preview()', () => { it('should show the dialog summary', () => { let event = new MouseEvent('click', { - view: $window, bubbles: true, cancelable: true }); - controller.preview(event, travels[0]); + controller.preview(event, travel); expect(controller.$.summary.show).toHaveBeenCalledWith(); }); }); - - describe('getScopeDates()', () => { - it('should return a range of dates', () => { - let days = 2; // never put 1 or anything higher than 2 - let result = controller.getScopeDates(days); - - let from = new Date(result.shippedFrom).getTime(); - let to = new Date(result.shippedTo).getTime(); - let range = to - from; - - const dayInMilliseconds = 24 * 60 * 60 * 1000; - - let millisecondsPerAddedDay = dayInMilliseconds - 1; - - expect(range - dayInMilliseconds).toEqual(dayInMilliseconds + millisecondsPerAddedDay); - }); - }); }); diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js new file mode 100644 index 000000000..2abcb0a33 --- /dev/null +++ b/modules/travel/front/main/index.spec.js @@ -0,0 +1,24 @@ +import './index.js'; + +describe('Travel Component vnTravel', () => { + let controller; + + beforeEach(ngModule('travel')); + + beforeEach(angular.mock.inject($componentController => { + let $element = angular.element(`
`); + controller = $componentController('vnTravel', {$element}); + })); + + describe('fetchParams()', () => { + it('should return a range of dates with passed scope days', () => { + let params = controller.fetchParams({scopeDays: 2}); + + let from = params.shippedFrom.getTime(); + let to = params.shippedTo.getTime() + 1; + let msInDay = 86400 * 1000; + + expect(to - from).toEqual(3 * msInDay); + }); + }); +}); diff --git a/modules/zone/front/index/index.spec.js b/modules/zone/front/main/index.spec.js similarity index 74% rename from modules/zone/front/index/index.spec.js rename to modules/zone/front/main/index.spec.js index 69ce934cd..d8d283ad1 100644 --- a/modules/zone/front/index/index.spec.js +++ b/modules/zone/front/main/index.spec.js @@ -1,14 +1,13 @@ import './index.js'; -describe('Zone Component vnZoneIndex', () => { - let $componentController; +describe('Zone Component vnZone', () => { let controller; beforeEach(ngModule('zone')); - beforeEach(angular.mock.inject(_$componentController_ => { - $componentController = _$componentController_; - controller = $componentController('vnZoneIndex'); + beforeEach(angular.mock.inject($componentController => { + let $element = angular.element(`
`); + controller = $componentController('vnZone', {$element}); })); describe('exprBuilder()', () => { From 27eaa328e5f8c6024bf2f65f2f3ca12dc9f540a1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 16 Mar 2020 18:33:49 +0100 Subject: [PATCH 4/9] Merge --- modules/travel/front/index/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index f83672744..c819284c2 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -67,7 +67,7 @@
From 176e38c144983487934529e43e8c4c9ae4d5e469 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 16 Mar 2020 18:54:22 +0100 Subject: [PATCH 5/9] Merge fixes --- front/core/components/searchbar/searchbar.js | 1 + front/salix/components/section/index.js | 5 +++ modules/travel/front/index/index.html | 2 +- modules/travel/front/index/index.js | 13 ++------ modules/travel/front/index/index.spec.js | 3 +- modules/zone/front/index/index.html | 2 +- modules/zone/front/index/index.js | 34 +++----------------- 7 files changed, 17 insertions(+), 43 deletions(-) diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 3ccc2a316..2e43afee2 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -199,6 +199,7 @@ export default class Searchbar extends Component { if (filter) { let oneResult = this.autoState && source != 'state' + && !angular.equals(filter, {}) && data && data.length == 1; diff --git a/front/salix/components/section/index.js b/front/salix/components/section/index.js index a0c7484b4..c34459147 100644 --- a/front/salix/components/section/index.js +++ b/front/salix/components/section/index.js @@ -7,6 +7,11 @@ export default class Section extends Component { super($element, $); this.element.classList.add('vn-section'); } + + stopEvent(event) { + event.preventDefault(); + event.stopImmediatePropagation(); + } } ngModule.vnComponent('vnSection', { diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index c819284c2..1cb176d13 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -22,7 +22,7 @@ - {{::travel.id}} diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index f6e7372ef..707f320cb 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -1,10 +1,7 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($) { - this.$ = $; - } - +export default class Controller extends Section { preview(event, travel) { this.stopEvent(event); this.travelSelected = travel; @@ -27,13 +24,7 @@ export default class Controller { }); this.$state.go('travel.create', {q: params}); } - - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } } -Controller.$inject = ['$scope']; ngModule.component('vnTravelIndex', { template: require('./index.html'), diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 9f69a466c..e49100d67 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -13,7 +13,8 @@ describe('Travel Component vnTravelIndex', () => { beforeEach(angular.mock.inject(($componentController, $rootScope) => { let $scope = $rootScope.$new(); - controller = $componentController('vnTravelIndex', {$scope}); + let $element = angular.element('
'); + controller = $componentController('vnTravelIndex', {$element, $scope}); controller.$.summary = {show: jasmine.createSpy('show')}; })); diff --git a/modules/zone/front/index/index.html b/modules/zone/front/index/index.html index d85f53b46..64450e451 100644 --- a/modules/zone/front/index/index.html +++ b/modules/zone/front/index/index.html @@ -52,7 +52,7 @@ diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index aa69e30b6..9750a949f 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -1,50 +1,26 @@ import ngModule from '../module'; +import Section from 'salix/components/section'; -export default class Controller { - constructor($, $http, $state) { - this.$ = $; - this.$http = $http; - this.$state = $state; - } - - /** - * Opens a summary modal - * @param {Object} event - Event object - * @param {Object} zone - Selected item - */ +export default class Controller extends Section { preview(event, zone) { this.stopEvent(event); this.selectedZone = zone; this.$.summary.show(); } - /** - * Clones a zone and all its properties - * @param {Object} event - Event object - * @param {Object} zone - Selected item - */ clone(event, zone) { this.stopEvent(event); - this.selectedZone = zone; - this.$.clone.show(); + this.$.clone.show(zone); } - onCloneAccept() { - return this.$http.post(`Zones/${this.selectedZone.id}/clone`) + onCloneAccept(zone) { + return this.$http.post(`Zones/${zone.id}/clone`) .then(res => { - this.selectedZone = null; this.$state.go('zone.card.basicData', {id: res.data.id}); }); } - - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } } -Controller.$inject = ['$scope', '$http', '$state']; - ngModule.component('vnZoneIndex', { template: require('./index.html'), controller: Controller From b4a5a889437a183f54a285b1f4cf1643cdef4cab Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 17 Mar 2020 14:01:25 +0100 Subject: [PATCH 6/9] E2E fixed --- e2e/helpers/extensions.js | 10 ++-- e2e/paths/02-client/14_balance.spec.js | 13 +---- e2e/paths/04-item/01_summary.spec.js | 40 +++------------ e2e/paths/04-item/08_create_and_clone.spec.js | 3 +- e2e/paths/04-item/09_regularize.spec.js | 50 ++----------------- e2e/paths/05-ticket/12_descriptor.spec.js | 25 +--------- front/core/components/searchbar/searchbar.js | 2 +- modules/ticket/front/weekly/index.html | 7 ++- modules/ticket/front/weekly/index.js | 9 ---- package-lock.json | 6 +-- 10 files changed, 28 insertions(+), 137 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 1e91864d5..0361ce35a 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -348,11 +348,11 @@ let actions = { await this.clearInput('vn-searchbar'); await this.write('vn-searchbar', searchValue); await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); - await this.waitForNumberOfElements('.search-result', 1); - await this.waitForContentLoaded(); - await this.evaluate(() => { - return document.querySelector('.search-result').click(); - }); + // await this.waitForNumberOfElements('.search-result', 1); + // await this.waitForContentLoaded(); + // await this.evaluate(() => { + // return document.querySelector('.search-result').click(); + // }); await this.waitForContentLoaded(); }, diff --git a/e2e/paths/02-client/14_balance.spec.js b/e2e/paths/02-client/14_balance.spec.js index 0d020831e..ef7930c8d 100644 --- a/e2e/paths/02-client/14_balance.spec.js +++ b/e2e/paths/02-client/14_balance.spec.js @@ -116,18 +116,7 @@ describe('Client balance path', () => { }); it('should now search for the user Petter Parker', async() => { - await page.write(selectors.clientsIndex.topbarSearch, 'Petter Parker'); - await page.waitToClick(selectors.clientsIndex.searchButton); - await page.waitForNumberOfElements(selectors.clientsIndex.searchResult, 1); - let resultCount = await page.countElement(selectors.clientsIndex.searchResult); - - expect(resultCount).toEqual(1); - }); - - it(`should click on the search result to access to the client's balance`, async() => { - await page.waitForTextInElement(selectors.clientsIndex.searchResult, 'Petter Parker'); - await page.waitToClick(selectors.clientsIndex.searchResult); - await page.waitForContentLoaded(); + await page.accessToSearchResult('Petter Parker'); await page.waitToClick(selectors.clientBalance.balanceButton); let url = await page.expectURL('/balance'); diff --git a/e2e/paths/04-item/01_summary.spec.js b/e2e/paths/04-item/01_summary.spec.js index 97fef9ca9..01e730668 100644 --- a/e2e/paths/04-item/01_summary.spec.js +++ b/e2e/paths/04-item/01_summary.spec.js @@ -16,15 +16,9 @@ describe('Item summary path', () => { it('should search for an item', async() => { await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon longbow 2m'); + await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon'); await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1); - const result = await page.countElement(selectors.itemsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result summary button to open the item summary popup`, async() => { + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 3); await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon longbow 2m'); await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); const isVisible = await page.isVisible(selectors.itemSummary.basicData); @@ -75,24 +69,18 @@ describe('Item summary path', () => { it('should search for other item', async() => { await page.clearInput('vn-searchbar'); await page.waitToClick(selectors.itemsIndex.searchButton); - await page.write(selectors.itemsIndex.topbarSearch, 'Melee weapon combat fist 15cm'); + await page.write(selectors.itemsIndex.topbarSearch, 'Melee Reinforced'); await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1); - const result = await page.countElement(selectors.itemsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should now click on the search result summary button to open the item summary popup`, async() => { + await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 2); await page.waitToClick(selectors.itemsIndex.searchResultPreviewButton); await page.waitForSelector(selectors.itemSummary.basicData, {visible: true}); }); it(`should now check the item summary preview shows fields from basic data`, async() => { - await page.waitForTextInElement(selectors.itemSummary.basicData, 'Melee weapon combat fist 15cm'); + await page.waitForTextInElement(selectors.itemSummary.basicData, 'Melee Reinforced weapon combat fist 15cm'); const result = await page.waitToGetProperty(selectors.itemSummary.basicData, 'innerText'); - expect(result).toContain('Melee weapon combat fist 15cm'); + expect(result).toContain('Melee Reinforced weapon combat fist 15cm'); }); it(`should now check the item summary preview shows fields from tags`, async() => { @@ -102,13 +90,6 @@ describe('Item summary path', () => { expect(result).toContain('Silver'); }); - it(`should now check the item summary preview shows fields from niche`, async() => { - await page.waitForTextInElement(selectors.itemSummary.niche, 'A4'); - const result = await page.waitToGetProperty(selectors.itemSummary.niche, 'innerText'); - - expect(result).toContain('A4'); - }); - it(`should now check the item summary preview shows fields from botanical`, async() => { await page.waitForTextInElement(selectors.itemSummary.botanical, '-'); const result = await page.waitToGetProperty(selectors.itemSummary.botanical, 'innerText'); @@ -116,20 +97,13 @@ describe('Item summary path', () => { expect(result).toContain('-'); }); - it(`should now check the item summary preview shows fields from barcode`, async() => { - await page.waitForTextInElement(selectors.itemSummary.barcode, '4'); - const result = await page.waitToGetProperty(selectors.itemSummary.barcode, 'innerText'); - - expect(result).toContain('4'); - }); - it(`should now close the summary popup`, async() => { await page.closePopup(); await page.waitForSelector(selectors.itemSummary.basicData, {hidden: true}); }); it(`should navigate to the one of the items detailed section`, async() => { - await page.waitToClick(selectors.itemsIndex.searchResult); + await page.accessToSearchResult('Melee weapon combat fist 15cm'); let url = await page.expectURL('summary'); expect(url).toBe(true); diff --git a/e2e/paths/04-item/08_create_and_clone.spec.js b/e2e/paths/04-item/08_create_and_clone.spec.js index 32d0ff23b..7665388d7 100644 --- a/e2e/paths/04-item/08_create_and_clone.spec.js +++ b/e2e/paths/04-item/08_create_and_clone.spec.js @@ -63,7 +63,6 @@ describe('Item Create/Clone path', () => { expect(result).toEqual('Infinity Gauntlet'); - result = await page .waitToGetProperty(selectors.itemBasicData.type, 'value'); @@ -81,7 +80,7 @@ describe('Item Create/Clone path', () => { }); }); - describe('clone', () => { + xdescribe('clone', () => { it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); await page.wait(selectors.itemsIndex.createItemButton); diff --git a/e2e/paths/04-item/09_regularize.spec.js b/e2e/paths/04-item/09_regularize.spec.js index 22e215905..838b24cf0 100644 --- a/e2e/paths/04-item/09_regularize.spec.js +++ b/e2e/paths/04-item/09_regularize.spec.js @@ -33,17 +33,7 @@ describe('Item regularize path', () => { }); it('should search for an specific item', async() => { - await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon pistol 9mm'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1); - const resultCount = await page.countElement(selectors.itemsIndex.searchResult); - - expect(resultCount).toEqual(1); - }); - - it(`should click on the search result to access to the summary`, async() => { - await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon pistol 9mm'); - await page.waitToClick(selectors.itemsIndex.searchResult); + await page.accessToSearchResult('Ranged weapon pistol 9mm'); let url = await page.expectURL('/summary'); expect(url).toBe(true); @@ -88,18 +78,9 @@ describe('Item regularize path', () => { }); it('should search for the ticket with alias missing', async() => { + await page.accessToSearchResult('Carol Danvers'); await page.keyboard.press('Escape'); - await page.write(selectors.ticketsIndex.topbarSearch, 'missing'); - await page.keyboard.press('Enter'); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result to access to the ticket summary`, async() => { - await page.waitForTextInElement(selectors.ticketsIndex.searchResult, 'Missing'); - await page.waitToClick(selectors.ticketsIndex.searchResult); + await page.accessToSearchResult('missing'); let url = await page.expectURL('/summary'); expect(url).toBe(true); @@ -130,18 +111,7 @@ describe('Item regularize path', () => { }); it('should search for the item once again', async() => { - await page.clearInput(selectors.itemsIndex.topbarSearch); - await page.write(selectors.itemsIndex.topbarSearch, 'Ranged weapon pistol 9mm'); - await page.waitToClick(selectors.itemsIndex.searchButton); - await page.waitForNumberOfElements(selectors.itemsIndex.searchResult, 1); - const resultCount = await page.countElement(selectors.itemsIndex.searchResult); - - expect(resultCount).toEqual(1); - }); - - it(`should click on the search result to access to the item tax`, async() => { - await page.waitForTextInElement(selectors.itemsIndex.searchResult, 'Ranged weapon pistol 9mm'); - await page.waitToClick(selectors.itemsIndex.searchResult); + await page.accessToSearchResult('Ranged weapon pistol 9mm'); let url = await page.expectURL('/summary'); expect(url).toBe(true); @@ -172,17 +142,7 @@ describe('Item regularize path', () => { }); it('should search for the ticket with id 25 once again', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '25'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should now click on the search result to access to the ticket summary`, async() => { - await page.waitForTextInElement(selectors.ticketsIndex.searchResult, '25'); - await page.waitToClick(selectors.ticketsIndex.searchResult); + await page.accessToSearchResult('25'); let url = await page.expectURL('/summary'); expect(url).toBe(true); diff --git a/e2e/paths/05-ticket/12_descriptor.spec.js b/e2e/paths/05-ticket/12_descriptor.spec.js index a718da71e..59691d380 100644 --- a/e2e/paths/05-ticket/12_descriptor.spec.js +++ b/e2e/paths/05-ticket/12_descriptor.spec.js @@ -17,17 +17,7 @@ describe('Ticket descriptor path', () => { describe('Delete ticket', () => { it('should search for an specific ticket', async() => { - await page.write(selectors.ticketsIndex.topbarSearch, '18'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should click on the search result to access to the ticket summary`, async() => { - await page.waitForTextInElement(selectors.ticketsIndex.searchResult, 'Cerebro'); - await page.waitToClick(selectors.ticketsIndex.searchResult); + await page.accessToSearchResult('18'); let url = await page.expectURL('/summary'); expect(url).toBe(true); @@ -78,18 +68,7 @@ describe('Ticket descriptor path', () => { describe('add stowaway', () => { it('should search for a ticket', async() => { - await page.clearInput(selectors.ticketsIndex.topbarSearch); - await page.write(selectors.ticketsIndex.topbarSearch, '16'); - await page.waitToClick(selectors.ticketsIndex.searchButton); - await page.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1); - const result = await page.countElement(selectors.ticketsIndex.searchResult); - - expect(result).toEqual(1); - }); - - it(`should now click on the search result to access to the ticket summary`, async() => { - await page.waitForTextInElement(selectors.ticketsIndex.searchResult, 'Many Places'); - await page.waitToClick(selectors.ticketsIndex.searchResult); + await page.accessToSearchResult('16'); let url = await page.expectURL('/summary'); expect(url).toBe(true); diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index 2e43afee2..b8da899db 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -13,9 +13,9 @@ import './style.scss'; * * @property {Object} filter A key-value object with filter parameters * @property {SearchPanel} panel The panel used for advanced searches + * @property {Function} onSearch Function to call when search is submited * @property {CrudModel} model The model used for searching * @property {Function} exprBuilder If defined, is used to build each non-null param expresion - * @property {Function} onSearch Function to call when search is submited */ export default class Searchbar extends Component { constructor($element, $) { diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index 552179ced..40ae04106 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -10,12 +10,11 @@ + info="Search weekly ticket by id or client id" + auto-state="false" + model="model"> - - diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index 7668264f6..f15576e9f 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -33,14 +33,6 @@ export default class Controller { event.stopImmediatePropagation(); } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - - showClientDescriptor(event, clientFk) { this.$.clientDescriptor.clientFk = clientFk; this.$.clientDescriptor.parent = event.target; @@ -85,7 +77,6 @@ export default class Controller { } } - Controller.$inject = ['$scope', 'vnApp', '$translate', '$http']; ngModule.component('vnTicketWeeklyIndex', { diff --git a/package-lock.json b/package-lock.json index ab01db432..8648fe476 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8354,7 +8354,7 @@ }, "kind-of": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", "dev": true }, @@ -9990,7 +9990,7 @@ }, "jasmine-core": { "version": "2.99.1", - "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", + "resolved": "http://registry.npmjs.org/jasmine-core/-/jasmine-core-2.99.1.tgz", "integrity": "sha1-5kAN8ea1bhMLYcS80JPap/boyhU=", "dev": true }, @@ -17968,7 +17968,7 @@ }, "xmlbuilder": { "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", + "resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" }, "xmlcreate": { From e5dee219267bc8fad1010a95f6851470fbeebe98 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 18 Mar 2020 13:54:05 +0100 Subject: [PATCH 7/9] Pull request fixes --- e2e/helpers/extensions.js | 5 - e2e/paths/04-item/08_create_and_clone.spec.js | 3 + front/core/components/searchbar/searchbar.js | 15 ++- .../components/searchbar/searchbar.spec.js | 91 ++++++++++++++++++- front/core/lib/focus.js | 4 +- jest-front.js | 4 +- 6 files changed, 99 insertions(+), 23 deletions(-) diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 0361ce35a..440085d85 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -348,11 +348,6 @@ let actions = { await this.clearInput('vn-searchbar'); await this.write('vn-searchbar', searchValue); await this.waitToClick('vn-searchbar vn-icon[icon="search"]'); - // await this.waitForNumberOfElements('.search-result', 1); - // await this.waitForContentLoaded(); - // await this.evaluate(() => { - // return document.querySelector('.search-result').click(); - // }); await this.waitForContentLoaded(); }, diff --git a/e2e/paths/04-item/08_create_and_clone.spec.js b/e2e/paths/04-item/08_create_and_clone.spec.js index 7665388d7..d06ef4682 100644 --- a/e2e/paths/04-item/08_create_and_clone.spec.js +++ b/e2e/paths/04-item/08_create_and_clone.spec.js @@ -80,6 +80,9 @@ describe('Item Create/Clone path', () => { }); }); + // Issue #2201 + // When there is just one result you're redirected automatically to it, so + // it's not possible to use the clone option. xdescribe('clone', () => { it('should return to the items index by clicking the return to items button', async() => { await page.waitToClick(selectors.itemBasicData.goToItemIndexButton); diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js index b8da899db..640ed48d6 100644 --- a/front/core/components/searchbar/searchbar.js +++ b/front/core/components/searchbar/searchbar.js @@ -69,10 +69,11 @@ export default class Searchbar extends Component { } onStateChange(transition) { - if (!this.element.parentNode - || transition == this.transition) - return; + let ignoreHandler = + !this.element.parentNode + || transition == this.transition; + if (ignoreHandler) return; this.fetchStateFilter(); } @@ -197,13 +198,13 @@ export default class Searchbar extends Component { let opts; if (filter) { - let oneResult = this.autoState + let isOneResult = this.autoState && source != 'state' && !angular.equals(filter, {}) && data && data.length == 1; - if (oneResult) { + if (isOneResult) { let baseDepth = this.baseState.split('.').length; let stateParts = this.$state.current.name .split('.') @@ -275,10 +276,6 @@ export default class Searchbar extends Component { return this.model.applyFilter(where ? {where} : null, params) .then(() => this.model.data); } - - onClear() { - if (this.model) this.model.clear(); - } } ngModule.vnComponent('vnSearchbar', { diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index 9d51dfd65..95035f504 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -8,9 +8,35 @@ describe('Component vnSearchbar', () => { let $scope; let filter = {id: 1, search: 'needle'}; - beforeEach(ngModule('vnCore')); + beforeEach(ngModule('vnCore', $stateProvider => { + $stateProvider + .state('foo', { + abstract: true + }) + .state('foo.index', { + url: '/foo/index' + }) + .state('foo.card', { + abstract: true + }) + .state('foo.card.summary', { + url: '/foo/:id/summary' + }) + .state('foo.card.bar', { + url: '/foo/:id/bar' + }) + .state('foo.card.baz', { + abstract: true + }) + .state('foo.card.baz.index', { + url: '/foo/:id/bar' + }) + .state('foo.card.baz.edit', { + url: '/foo/:id/bar' + }); + })); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$state_) => { + beforeEach(inject(($componentController, $rootScope, _$state_) => { $scope = $rootScope.$new(); $state = _$state_; $params = $state.params; @@ -19,7 +45,6 @@ describe('Component vnSearchbar', () => { $element = angular.element(`
`); controller = $componentController('vnSearchbar', {$element, $scope}); - controller.panel = 'vn-client-search-panel'; })); describe('$postLink()', () => { @@ -158,12 +183,68 @@ describe('Component vnSearchbar', () => { }); describe('doSearch()', () => { - it(`should go to the search state and pass the filter as query param`, () => { + it(`should do the filter`, () => { + jest.spyOn(controller, 'onSearch'); + jest.spyOn(controller, 'onFilter'); + + controller.doSearch(filter, 'any'); + $scope.$apply(); + + expect(controller.onSearch).toHaveBeenCalledWith({$params: filter}); + expect(controller.onFilter).toHaveBeenCalledWith(filter, 'any', undefined); + }); + }); + + describe('onFilter()', () => { + it(`should go to the summary state when one result`, () => { + jest.spyOn($state, 'go'); + + let data = [{id: 1}]; + + controller.baseState = 'foo'; + controller.onFilter(filter, 'any', data); + $scope.$apply(); + + expect($state.go).toHaveBeenCalledWith('foo.card.summary', {id: 1}, undefined); + expect(controller.filter).toEqual(null); + }); + + it(`should keep the same card state when one result and it's already inside any card state`, () => { + $state.go('foo.card.bar', {id: 1}); + $scope.$apply(); + + jest.spyOn($state, 'go'); + let data = [{id: 1}]; + + controller.baseState = 'foo'; + controller.onFilter(filter, 'any', data); + $scope.$apply(); + + expect($state.go).toHaveBeenCalledWith('foo.card.bar', {id: 1}, undefined); + expect(controller.filter).toEqual(null); + }); + + it(`should keep the same card state but index when one result and it's already in card state but inside more than three-nested states`, () => { + $state.go('foo.card.baz.edit', {id: 1}); + $scope.$apply(); + + jest.spyOn($state, 'go'); + let data = [{id: 1}]; + + controller.baseState = 'foo'; + controller.onFilter(filter, 'any', data); + $scope.$apply(); + + expect($state.go).toHaveBeenCalledWith('foo.card.baz.index', {id: 1}, undefined); + expect(controller.filter).toEqual(null); + }); + + it(`should go to the search state when multiple results and pass the filter as query param`, () => { jest.spyOn($state, 'go'); controller.autoState = false; controller.searchState = 'search.state'; - controller.doSearch(filter); + controller.onFilter(filter, 'any'); $scope.$apply(); let queryParams = {q: JSON.stringify(filter)}; diff --git a/front/core/lib/focus.js b/front/core/lib/focus.js index 8b997d920..6e19e1184 100644 --- a/front/core/lib/focus.js +++ b/front/core/lib/focus.js @@ -2,12 +2,12 @@ import isMobile from './is-mobile'; export default function focus(element) { - if (isMobile) return; + if (isMobile || !element) return; setTimeout(() => element.focus(), 10); } export function select(element) { - if (isMobile) return; + if (isMobile || !element) return; setTimeout(() => { element.focus(); if (element.select) diff --git a/jest-front.js b/jest-front.js index 5d6c342c0..ab88dd473 100644 --- a/jest-front.js +++ b/jest-front.js @@ -17,7 +17,7 @@ core.run(vnInterceptor => { vnInterceptor.setApiPath(null); }); -window.ngModule = function(moduleName) { +window.ngModule = function(moduleName, fn) { return angular.mock.module(moduleName, function($provide, $translateProvider) { // Avoid unexpected request warnings caused by angular translate // https://angular-translate.github.io/docs/#/guide/22_unit-testing-with-angular-translate @@ -30,5 +30,5 @@ window.ngModule = function(moduleName) { }); $translateProvider.useLoader('customLocaleLoader'); - }); + }, fn); }; From ab822c6061d00fc5b086ed6e00b4fb6368a0fba8 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 18 Mar 2020 14:06:06 +0100 Subject: [PATCH 8/9] Code fix --- jest-front.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jest-front.js b/jest-front.js index ab88dd473..3b481ad7c 100644 --- a/jest-front.js +++ b/jest-front.js @@ -17,8 +17,8 @@ core.run(vnInterceptor => { vnInterceptor.setApiPath(null); }); -window.ngModule = function(moduleName, fn) { - return angular.mock.module(moduleName, function($provide, $translateProvider) { +window.ngModule = function(moduleName, ...args) { + let fns = [moduleName, function($provide, $translateProvider) { // Avoid unexpected request warnings caused by angular translate // https://angular-translate.github.io/docs/#/guide/22_unit-testing-with-angular-translate $provide.factory('customLocaleLoader', function($q) { @@ -30,5 +30,10 @@ window.ngModule = function(moduleName, fn) { }); $translateProvider.useLoader('customLocaleLoader'); - }, fn); + }]; + + if (args.length) + fns = fns.concat(args); + + return angular.mock.module(...fns); }; From acac77ad76111cc13aa42e0af0e4b670d0bd20fe Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 18 Mar 2020 15:59:03 +0100 Subject: [PATCH 9/9] Test fixes --- front/core/components/searchbar/searchbar.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index 95035f504..e4f58d294 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -29,10 +29,10 @@ describe('Component vnSearchbar', () => { abstract: true }) .state('foo.card.baz.index', { - url: '/foo/:id/bar' + url: '/foo/:id/baz/index' }) .state('foo.card.baz.edit', { - url: '/foo/:id/bar' + url: '/foo/:id/baz/:bazId/edit' }); })); @@ -225,7 +225,7 @@ describe('Component vnSearchbar', () => { }); it(`should keep the same card state but index when one result and it's already in card state but inside more than three-nested states`, () => { - $state.go('foo.card.baz.edit', {id: 1}); + $state.go('foo.card.baz.edit', {id: 1, bazId: 1}); $scope.$apply(); jest.spyOn($state, 'go');