Pull request fixes
This commit is contained in:
parent
b4a5a88943
commit
e5dee21926
|
@ -348,11 +348,6 @@ let actions = {
|
||||||
await this.clearInput('vn-searchbar');
|
await this.clearInput('vn-searchbar');
|
||||||
await this.write('vn-searchbar', searchValue);
|
await this.write('vn-searchbar', searchValue);
|
||||||
await this.waitToClick('vn-searchbar vn-icon[icon="search"]');
|
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();
|
await this.waitForContentLoaded();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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', () => {
|
xdescribe('clone', () => {
|
||||||
it('should return to the items index by clicking the return to items button', async() => {
|
it('should return to the items index by clicking the return to items button', async() => {
|
||||||
await page.waitToClick(selectors.itemBasicData.goToItemIndexButton);
|
await page.waitToClick(selectors.itemBasicData.goToItemIndexButton);
|
||||||
|
|
|
@ -69,10 +69,11 @@ export default class Searchbar extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onStateChange(transition) {
|
onStateChange(transition) {
|
||||||
if (!this.element.parentNode
|
let ignoreHandler =
|
||||||
|| transition == this.transition)
|
!this.element.parentNode
|
||||||
return;
|
|| transition == this.transition;
|
||||||
|
|
||||||
|
if (ignoreHandler) return;
|
||||||
this.fetchStateFilter();
|
this.fetchStateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,13 +198,13 @@ export default class Searchbar extends Component {
|
||||||
let opts;
|
let opts;
|
||||||
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
let oneResult = this.autoState
|
let isOneResult = this.autoState
|
||||||
&& source != 'state'
|
&& source != 'state'
|
||||||
&& !angular.equals(filter, {})
|
&& !angular.equals(filter, {})
|
||||||
&& data
|
&& data
|
||||||
&& data.length == 1;
|
&& data.length == 1;
|
||||||
|
|
||||||
if (oneResult) {
|
if (isOneResult) {
|
||||||
let baseDepth = this.baseState.split('.').length;
|
let baseDepth = this.baseState.split('.').length;
|
||||||
let stateParts = this.$state.current.name
|
let stateParts = this.$state.current.name
|
||||||
.split('.')
|
.split('.')
|
||||||
|
@ -275,10 +276,6 @@ export default class Searchbar extends Component {
|
||||||
return this.model.applyFilter(where ? {where} : null, params)
|
return this.model.applyFilter(where ? {where} : null, params)
|
||||||
.then(() => this.model.data);
|
.then(() => this.model.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClear() {
|
|
||||||
if (this.model) this.model.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnSearchbar', {
|
ngModule.vnComponent('vnSearchbar', {
|
||||||
|
|
|
@ -8,9 +8,35 @@ describe('Component vnSearchbar', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let filter = {id: 1, search: 'needle'};
|
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();
|
$scope = $rootScope.$new();
|
||||||
$state = _$state_;
|
$state = _$state_;
|
||||||
$params = $state.params;
|
$params = $state.params;
|
||||||
|
@ -19,7 +45,6 @@ describe('Component vnSearchbar', () => {
|
||||||
|
|
||||||
$element = angular.element(`<div></div>`);
|
$element = angular.element(`<div></div>`);
|
||||||
controller = $componentController('vnSearchbar', {$element, $scope});
|
controller = $componentController('vnSearchbar', {$element, $scope});
|
||||||
controller.panel = 'vn-client-search-panel';
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('$postLink()', () => {
|
describe('$postLink()', () => {
|
||||||
|
@ -158,12 +183,68 @@ describe('Component vnSearchbar', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('doSearch()', () => {
|
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');
|
jest.spyOn($state, 'go');
|
||||||
|
|
||||||
controller.autoState = false;
|
controller.autoState = false;
|
||||||
controller.searchState = 'search.state';
|
controller.searchState = 'search.state';
|
||||||
controller.doSearch(filter);
|
controller.onFilter(filter, 'any');
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
let queryParams = {q: JSON.stringify(filter)};
|
let queryParams = {q: JSON.stringify(filter)};
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
import isMobile from './is-mobile';
|
import isMobile from './is-mobile';
|
||||||
|
|
||||||
export default function focus(element) {
|
export default function focus(element) {
|
||||||
if (isMobile) return;
|
if (isMobile || !element) return;
|
||||||
setTimeout(() => element.focus(), 10);
|
setTimeout(() => element.focus(), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function select(element) {
|
export function select(element) {
|
||||||
if (isMobile) return;
|
if (isMobile || !element) return;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
element.focus();
|
element.focus();
|
||||||
if (element.select)
|
if (element.select)
|
||||||
|
|
|
@ -17,7 +17,7 @@ core.run(vnInterceptor => {
|
||||||
vnInterceptor.setApiPath(null);
|
vnInterceptor.setApiPath(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.ngModule = function(moduleName) {
|
window.ngModule = function(moduleName, fn) {
|
||||||
return angular.mock.module(moduleName, function($provide, $translateProvider) {
|
return angular.mock.module(moduleName, function($provide, $translateProvider) {
|
||||||
// Avoid unexpected request warnings caused by angular translate
|
// Avoid unexpected request warnings caused by angular translate
|
||||||
// https://angular-translate.github.io/docs/#/guide/22_unit-testing-with-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');
|
$translateProvider.useLoader('customLocaleLoader');
|
||||||
});
|
}, fn);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue