Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export interface PoJobSchedulerInternal {
dayOfMonth?: number;

frequency?: object;

rangeLimitHour?: string;

rangeLimitDay?: number;

daysOfWeek?: Array<string>;

executionParameter?: object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,36 @@ describe('PoPageJobSchedulerBaseComponent:', () => {
expect(component).toBeTruthy();
});

describe('Properties:', () => {
it('value: should set `model`', fakeAsync(() => {
const returnValue: PoJobSchedulerInternal = {
firstExecution: new Date('2019-02-04'),
firstExecutionHour: '06:45',
periodicity: 'single',
recurrent: true
};
const jobSchedulerInternal = {
firstExecution: new Date('2019-02-04'),
periodicity: 'single',
recurrent: true
};

spyOn(component['poPageJobSchedulerService'], 'convertToJobSchedulerInternal').and.returnValue(returnValue);
component.value = jobSchedulerInternal;

expect(component.model).toEqual(returnValue);
}));
});

describe('Methods:', () => {
it('ngOnDestroy: should call unsubscribe', () => {
const spyUnsubscribe = spyOn(component['_subscription'], 'unsubscribe');

component.ngOnDestroy();

expect(spyUnsubscribe).toHaveBeenCalled();
});

it('loadData: should set `model` with `new PoPageJobSchedulerInternal()` and exit of method if `id` is invalid.', () => {
const invalidId = 0;
component.model = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class PoPageJobSchedulerBaseComponent implements OnDestroy {
* ```
*
* > Veja mais sobre paginação e filtros no [Guia de implementação de APIs](guides/api).
* Caso seja informada a propriedade `p-parameters` não serão realizadas as requisições de processos e nem de parametros automaticamente.
*
* Também é possível fazer um agendamento de um processo específico, sem que seja necessário um endpoint para busca desses
* processos. Então, caso o endpoint `{service-api}/processes` não seja válido, será apresentado um campo de entrada de
Expand Down Expand Up @@ -112,8 +113,9 @@ export class PoPageJobSchedulerBaseComponent implements OnDestroy {
* {
* "firstExecution": "2018-12-07T00:00:01-00:00",
* "recurrent": true,
* "daily": { "hour": 10, "minute": 12 },
* "processID": "ac0405"
* "monthly": { "day": 1, "hour": 10, "minute": 0 },
* "processID": "ac0405",
* "rangeExecutions: { "frequency": { "type": "hour", "value": 2 }, "rangeLimit": { "hour": 18, "minute": 0, "day": 20 } }
* }
* ```
*
Expand Down Expand Up @@ -147,9 +149,11 @@ export class PoPageJobSchedulerBaseComponent implements OnDestroy {
* ```
* {
* "firstExecution": "2018-12-07T00:00:01-00:00",
* "recurrent": false,
* "daily": { "hour": 11, "minute": 30 },
* "processID": "ac0405"
* "recurrent": true,
* "processID": "ac0405",
* "monthly": { "day": 1, "hour": 10, "minute": 0 },
* "processID": "ac0405",
* "rangeExecutions: { "frequency": { "type": "hour", "value": 2 }, "rangeLimit": { "hour": 18, "minute": 0, "day": 20 } }
* }
* ```
*/
Expand All @@ -166,6 +170,10 @@ export class PoPageJobSchedulerBaseComponent implements OnDestroy {
*/
@Input('p-parameters') parameters: Array<PoDynamicFormField> = [];

@Input('p-value') set value(value: any) {
this.model = this.poPageJobSchedulerService.convertToJobSchedulerInternal(value);
}

model: PoJobSchedulerInternal = new PoPageJobSchedulerInternal();

private _subscription = new Subscription();
Expand All @@ -178,7 +186,7 @@ export class PoPageJobSchedulerBaseComponent implements OnDestroy {

protected loadData(id: string | number) {
if (!id) {
this.model = new PoPageJobSchedulerInternal();
this.model = this.model || new PoPageJobSchedulerInternal();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
p-placeholder="HH:mm"
p-required
[p-disabled]="isEdit"
[p-label]="literals.hour"
[p-label]="literals.time"
[p-pattern]="timePattern"
>
</po-input>
Expand All @@ -44,13 +44,41 @@
p-required
[p-label]="literals.periodicity"
[p-options]="periodicityOptions"
(p-change)="onChangePeriodicityOptions($event)"
>
</po-radio-group>

<ng-container *ngIf="value.periodicity !== 'single'">
<po-divider class="po-md-12" [p-label]="literals.periodicityData"> </po-divider>
<div class="po-row">
<po-switch
class="po-md-12"
name="containsFrequency"
[(ngModel)]="containsFrequency"
[p-label]="literals.frequency"
[p-label-off]="literals.no"
[p-label-on]="literals.yes"
(p-change)="onChangeContainsFrequency($event)"
>
</po-switch>
<ng-container *ngIf="containsFrequency">
<po-radio-group
class="po-md-10"
name="frequencyType"
p-required
[(ngModel)]="value.frequency.type"
[p-columns]="3"
[p-options]="frequencyOptions"
(p-change)="onChangeFrequencyOptions()"
>
</po-radio-group>

<po-number class="po-md-2" name="frequencyValue" p-required [(ngModel)]="value.frequency.value"> </po-number>
</ng-container>
</div>

<div class="po-row">
<po-divider class="po-md-12" [p-label]="literals.periodicityData"> </po-divider>

<ng-container *ngTemplateOutlet="periodicityTemplates[value.periodicity]"> </ng-container>
</div>

Expand Down Expand Up @@ -126,7 +154,20 @@
[(ngModel)]="value.dayOfMonth"
p-required
[p-error-pattern]="'Dia inválido'"
[p-label]="literals.day"
[p-label]="dayLabel"
[p-max]="31"
[p-pattern]="dayPattern"
>
</po-number>

<po-number
*ngIf="containsFrequency"
class="po-md-3"
name="rangeLimitDay"
[(ngModel)]="value.rangeLimitDay"
p-required
[p-error-pattern]="'Dia inválido'"
[p-label]="literals.endDay"
[p-max]="31"
[p-pattern]="dayPattern"
>
Expand All @@ -144,7 +185,21 @@
p-mask-format-model
p-placeholder="HH:mm"
p-required
[p-label]="literals.hour"
[p-label]="hourLabel"
[p-pattern]="timePattern"
>
</po-input>

<po-input
*ngIf="containsFrequency && value.frequency.type !== 'day'"
class="po-md-2"
name="rangeLimitHour"
[(ngModel)]="value.rangeLimitHour"
p-mask="99:99"
p-mask-format-model
p-placeholder="HH:mm"
p-required
[p-label]="literals.endTime"
[p-pattern]="timePattern"
>
</po-input>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
expectPropertiesValues(component, 'value', validValues, validValues);
});

it('value: should set `containsFrequency` with true if value.frequency.value', () => {
component.value = { frequency: { value: 2 } };

expect(component.containsFrequency).toBeTrue();
});

it('value: should set `containsFrequency` with false if value.frequency.value is undefined', () => {
component.value = { frequency: undefined };

expect(component.containsFrequency).toBeFalse();
});

it('startDateFirstExecution: should return `Date` if `isEdit` is false', () => {
component.isEdit = false;

Expand All @@ -61,6 +73,30 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
expect(component.startDateFirstExecution instanceof Date).toBe(false);
expect(component.startDateFirstExecution).toBeUndefined();
});

it('hourLabel: should return `literals.startTime` if `containsFrequency`', () => {
component.containsFrequency = true;
const result = component.hourLabel;
expect(result).toEqual(component.literals.startTime);
});

it('hourLabel: should return `literals.time` if `containsFrequency` is false', () => {
component.containsFrequency = false;
const result = component.hourLabel;
expect(result).toEqual(component.literals.time);
});

it('dayLabel: should return `literals.startDay` if `containsFrequency`', () => {
component.containsFrequency = true;
const result = component.dayLabel;
expect(result).toEqual(component.literals.startDay);
});

it('dayLabel: should return `literals.day` if `containsFrequency` is false', () => {
component.containsFrequency = false;
const result = component.dayLabel;
expect(result).toEqual(component.literals.day);
});
});

describe('Methods:', () => {
Expand All @@ -74,24 +110,58 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
expect(component['subscribeProcessIdValueChanges']).toHaveBeenCalled();
}));

it('ngAfterViewInit: should update `frequencyOption.disabled` if `frequencyOption.value` is equal to `day`', fakeAsync(() => {
component.value.periodicity = 'daily';
component.frequencyOptions = [
{ label: 'Day', value: 'day' },
{ label: 'Hour', value: 'hour' },
{ label: 'minute', value: 'minute' }
];
const expectedValue = [
{ label: 'Day', value: 'day', disabled: true },
{ label: 'Hour', value: 'hour', disabled: false },
{ label: 'minute', value: 'minute', disabled: false }
];

component.ngAfterViewInit();

tick(50);

expect(component.frequencyOptions).toEqual(expectedValue);
}));

it('ngOnInit: should call `checkExistsProcessesAPI` and set `periodicityTemplates`, `periodicityOptions` and `weekDays`', () => {
component.periodicityTemplates = undefined;
component.periodicityOptions = undefined;
component.frequencyOptions = undefined;
component.weekDays = undefined;

spyOn(component, <any>'checkExistsProcessesAPI');
spyOn(component, <any>'getPeriodicityOptions').and.callThrough();
spyOn(component, <any>'getWeekDays').and.callThrough();
spyOn(component, <any>'getFrequencyOptions').and.callThrough();

component.ngOnInit();

expect(typeof component.periodicityTemplates === 'object').toBe(true);
expect(component.periodicityOptions instanceof Array).toBe(true);
expect(component.weekDays instanceof Array).toBe(true);
expect(component.frequencyOptions instanceof Array).toBe(true);

expect(component['checkExistsProcessesAPI']).toHaveBeenCalled();
expect(component['getPeriodicityOptions']).toHaveBeenCalled();
expect(component['getWeekDays']).toHaveBeenCalled();
expect(component['getFrequencyOptions']).toHaveBeenCalled();
});

it('ngOnInit: shouldn`t call `checkExistsProcessesAPI` if `noParameters` is false', () => {
component.noParameters = false;

spyOn(component, <any>'checkExistsProcessesAPI');

component.ngOnInit();

expect(component['checkExistsProcessesAPI']).not.toHaveBeenCalled();
});

it('checkExistsProcessesAPI: should subscribe `getHeadProcesses` and on error set `existProcessAPI` to false', () => {
Expand Down Expand Up @@ -126,6 +196,15 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
expect(weekDays.length).toBe(weekDaysLength);
});

it('getFrequencyOptions: should return 3 options', () => {
const frequencyOptionsLength = 3;

const frequencyOptions = component['getFrequencyOptions']();

expect(frequencyOptions instanceof Array).toBe(true);
expect(frequencyOptions.length).toBe(frequencyOptionsLength);
});

it('subscribeProcessIdValueChanges: should call `changeProcess.emit` when subscribe `processID.valueChanges`', () => {
const processId = 1;
component['form'] = <any>{
Expand All @@ -144,6 +223,60 @@ describe('PoPageJobSchedulerExecutionComponent:', () => {
expect(component['form'].controls.processID.valueChanges.subscribe).toHaveBeenCalled();
expect(component.changeProcess.emit).toHaveBeenCalledWith({ processId, existAPI: component.existProcessAPI });
});

it('changeContainsFrequency: should update `value.frequency` if `containsfrequency`', () => {
const containsFrequency = true;
const expectedValue = { type: 'hour', value: null };

component.onChangeContainsFrequency(containsFrequency);

expect(component.value.frequency).toEqual(expectedValue);
});

it('changeContainsFrequency: should update `value.frequency` with empty object if `containsfrequency` is false', () => {
const containsFrequency = false;
const expectedValue = {};

component.onChangeContainsFrequency(containsFrequency);

expect(component.value.frequency).toEqual(expectedValue);
});

it('changeContainsFrequency: should update `value.rangeLimitHour`, `value.rangeLimitDay` and `value.dayOfMonth` with null', () => {
const containsFrequency = false;

component.onChangeContainsFrequency(containsFrequency);

expect(component.value.rangeLimitHour).toBeNull();
expect(component.value.rangeLimitDay).toBeNull();
expect(component.value.dayOfMonth).toBeNull();
});

it('onChangePeriodicityOptions: should update `frequencyOptions` and `value.frequency.type`', () => {
const periodicity = 'daily';
component.value.frequency = {};
component.frequencyOptions = [
{ label: 'Day', value: 'day' },
{ label: 'Hour', value: 'hour' },
{ label: 'minute', value: 'minute' }
];
const expectedValue = [
{ label: 'Day', value: 'day', disabled: true },
{ label: 'Hour', value: 'hour', disabled: false },
{ label: 'minute', value: 'minute', disabled: false }
];

component.onChangePeriodicityOptions(periodicity);

expect(component.frequencyOptions).toEqual(expectedValue);
expect(component.value.frequency.type).toBeNull();
});

it('onChangeFrequencyOptions: should update `value.rangeLimitHour` with `null`', () => {
component.onChangeFrequencyOptions();

expect(component.value.rangeLimitHour).toBeNull();
});
});

describe('Templates:', () => {
Expand Down
Loading