Added ACL + unit tests
gitea/salix/pipeline/head Something is wrong with the build of this commit
Details
gitea/salix/pipeline/head Something is wrong with the build of this commit
Details
This commit is contained in:
parent
91e739547b
commit
2f9d80be7a
|
@ -4,8 +4,8 @@
|
|||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<div class="vn-w-lg">
|
||||
<vn-card class="vn-pa-sm calendars" style="position:relative" >
|
||||
<vn-icon icon="info" color-marginal style="position: absolute; top: 16px;right: 16px"
|
||||
<vn-card class="vn-pa-sm calendars">
|
||||
<vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal
|
||||
vn-tooltip="To start adding absences, click an absence type from the right menu and then on the day you want to add an absence">
|
||||
</vn-icon>
|
||||
<vn-calendar
|
||||
|
@ -30,7 +30,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="vn-pt-md" style="overflow: hidden;">
|
||||
<vn-chip ng-repeat="absenceType in absenceTypes" class="selectable"
|
||||
<vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}"
|
||||
ng-click="$ctrl.pick(absenceType)">
|
||||
<vn-avatar
|
||||
ng-style="{backgroundColor: absenceType.rgb}">
|
||||
|
|
|
@ -44,8 +44,16 @@ class Controller extends Section {
|
|||
set worker(value) {
|
||||
this._worker = value;
|
||||
|
||||
if (value)
|
||||
if (value) {
|
||||
this.refresh().then(() => this.repaint());
|
||||
this.getIsSubordinate();
|
||||
}
|
||||
}
|
||||
|
||||
getIsSubordinate() {
|
||||
this.$http.get(`Workers/${this.worker.id}/isSubordinate`).then(res =>
|
||||
this.isSubordinate = res.data
|
||||
);
|
||||
}
|
||||
|
||||
onData(data) {
|
||||
|
@ -98,6 +106,7 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
pick(absenceType) {
|
||||
if (!this.isSubordinate) return;
|
||||
if (absenceType == this.absenceType)
|
||||
absenceType = null;
|
||||
|
||||
|
|
|
@ -12,8 +12,9 @@ describe('Worker', () => {
|
|||
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$scope = $rootScope.$new();
|
||||
$httpBackend = _$httpBackend_;
|
||||
const $element = angular.element('<vn-worker-calencar></vn-worker-calencar>');
|
||||
const $element = angular.element('<vn-worker-calendar></vn-worker-calendar>');
|
||||
controller = $componentController('vnWorkerCalendar', {$element, $scope});
|
||||
controller.isSubordinate = true;
|
||||
}));
|
||||
|
||||
describe('started property', () => {
|
||||
|
@ -44,6 +45,8 @@ describe('Worker', () => {
|
|||
|
||||
describe('worker() setter', () => {
|
||||
it(`should perform a get query and set the reponse data on the model`, () => {
|
||||
jest.spyOn(controller, 'getIsSubordinate').mockReturnThis();
|
||||
|
||||
let today = new Date();
|
||||
|
||||
let tomorrow = new Date(today.getTime());
|
||||
|
@ -73,11 +76,14 @@ describe('Worker', () => {
|
|||
expect(events[tomorrow.getTime()].name).toEqual('Easter');
|
||||
expect(events[yesterday.getTime()].name).toEqual('Leave');
|
||||
expect(events[yesterday.getTime()].color).toEqual('#bbb');
|
||||
expect(controller.getIsSubordinate).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDay()', () => {
|
||||
it(`should set the day element style`, () => {
|
||||
jest.spyOn(controller, 'getIsSubordinate').mockReturnThis();
|
||||
|
||||
let today = new Date();
|
||||
|
||||
$httpBackend.whenRoute('GET', 'WorkerCalendars/absences')
|
||||
|
@ -99,5 +105,54 @@ describe('Worker', () => {
|
|||
expect(dayNumber.style.backgroundColor).toEqual('rgb(0, 0, 0)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('pick()', () => {
|
||||
it(`should set the absenceType property to null if they match with the current one`, () => {
|
||||
const absenceType = {id: 1, name: 'Holiday'};
|
||||
controller.absenceType = absenceType;
|
||||
controller.pick(absenceType);
|
||||
|
||||
expect(controller.absenceType).toBeNull();
|
||||
});
|
||||
|
||||
it(`should set the absenceType property`, () => {
|
||||
const absenceType = {id: 1, name: 'Holiday'};
|
||||
const expectedAbsence = {id: 2, name: 'Leave of absence'};
|
||||
controller.absenceType = absenceType;
|
||||
controller.pick(expectedAbsence);
|
||||
|
||||
expect(controller.absenceType).toEqual(expectedAbsence);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSelection()', () => {
|
||||
it(`should show an snackbar message if no absence type is selected`, () => {
|
||||
jest.spyOn(controller.vnApp, 'showMessage').mockReturnThis();
|
||||
|
||||
const $event = {};
|
||||
const $days = [];
|
||||
controller.onSelection($event, $days);
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Choose an absence type from the right menu');
|
||||
});
|
||||
|
||||
it(`should call to the create() method`, () => {
|
||||
jest.spyOn(controller, 'create').mockReturnThis();
|
||||
|
||||
const selectedDay = new Date();
|
||||
const $event = {
|
||||
target: {
|
||||
closest: () => {
|
||||
return {$ctrl: {}};
|
||||
}
|
||||
}
|
||||
};
|
||||
const $days = [selectedDay];
|
||||
controller.absenceType = {id: 1};
|
||||
controller.onSelection($event, $days);
|
||||
|
||||
expect(controller.create).toHaveBeenCalledWith(jasmine.any(Object), selectedDay);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,4 +3,5 @@ Holidays: Vacaciones
|
|||
Used: Utilizados
|
||||
of: de
|
||||
days: días
|
||||
Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha
|
||||
Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha
|
||||
To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
vn-worker-calendar {
|
||||
.calendars {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
|
@ -29,4 +30,10 @@ vn-worker-calendar {
|
|||
text-align: center;
|
||||
color: white
|
||||
}
|
||||
|
||||
vn-icon[icon="info"] {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue