Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
8f45888a6b
|
@ -0,0 +1,85 @@
|
|||
import './popover';
|
||||
|
||||
describe('Component vnPopover', () => {
|
||||
let $componentController;
|
||||
let $httpBackend;
|
||||
let $timeout;
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_, _$document_) => {
|
||||
$componentController = _$componentController_;
|
||||
$timeout = _$timeout_;
|
||||
$timeout.cancel = () => {};
|
||||
$element = angular.element(`<div class="shown"></div>`);
|
||||
$httpBackend = _$httpBackend_;
|
||||
_$httpBackend_.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
controller = $componentController('vnPopover', {$httpBackend, $element});
|
||||
}));
|
||||
|
||||
describe('show()', () => {
|
||||
it(`should do nothing if _shown is defined in the controller`, () => {
|
||||
controller._shown = true;
|
||||
|
||||
spyOn(controller, 'relocate');
|
||||
|
||||
controller.show();
|
||||
|
||||
expect(controller.relocate).not.toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should not call on onOpen() as it is not defined in the controller`, () => {
|
||||
controller.show();
|
||||
|
||||
expect(controller.onOpen).toBeUndefined();
|
||||
});
|
||||
|
||||
it(`should call onOpen() if its defined`, () => {
|
||||
controller.onOpen = () => {};
|
||||
|
||||
spyOn(controller, 'onOpen');
|
||||
|
||||
controller.show();
|
||||
|
||||
expect(controller.onOpen).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('hide()', () => {
|
||||
it(`should do nothing if _shown is defined in the controller`, () => {
|
||||
controller._shown = false;
|
||||
|
||||
controller.hide();
|
||||
|
||||
expect($element[0].classList).toContain('shown');
|
||||
});
|
||||
|
||||
it(`should set _shown property to false and then call onClose() if its defined`, () => {
|
||||
controller._shown = true;
|
||||
controller.onClose = () => {};
|
||||
spyOn(controller, 'onClose');
|
||||
|
||||
controller.hide();
|
||||
$timeout.flush();
|
||||
|
||||
expect(controller._shown).toBeFalsy();
|
||||
expect(controller.onClose).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should set _shown property to false and then call deregisterCallback() if its defined`, () => {
|
||||
controller._shown = true;
|
||||
controller.deregisterCallback = () => {};
|
||||
spyOn(controller, 'deregisterCallback');
|
||||
|
||||
controller.hide();
|
||||
|
||||
expect(controller._shown).toBeFalsy();
|
||||
expect(controller.deregisterCallback).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -14,7 +14,16 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.getCurrentWorkerMana = async ctx => {
|
||||
let loggedWorkerId = ctx.req.accessToken.userId;
|
||||
return await Self.rawSql(`SELECT used AS mana FROM vn.manaSpellers WHERE worker = ?`, [loggedWorkerId]);
|
||||
let currentClientId = ctx.req.accessToken.userId;
|
||||
let currentWorker = await Self.app.models.Worker.findOne({
|
||||
where: {userFk: currentClientId},
|
||||
fields: 'id'
|
||||
});
|
||||
let currentWorkerMana = await Self.app.models.WorkerMana.findOne({
|
||||
where: {workerFk: currentWorker.id},
|
||||
fields: 'amount'
|
||||
});
|
||||
|
||||
return currentWorkerMana ? currentWorkerMana.amount : 0;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue