Skip to content
Next Next commit
added test
  • Loading branch information
daros10 committed Mar 25, 2020
commit 22b7119d3593a459013cc04ff2656e3612d298a2
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ describe('TimeClockComponent', () => {
let fixture: ComponentFixture<TimeClockComponent>;
let de: DebugElement;

function setup() {
const fixture = TestBed.createComponent(TimeClockComponent);
const app = fixture.debugElement.componentInstance;
return { fixture, app };
}

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TimeClockComponent, ProjectListHoverComponent]
Expand All @@ -32,14 +26,6 @@ describe('TimeClockComponent', () => {
expect(component).toBeTruthy();
});

it('should have p tag as \'Dario clocked out at 00:00:00\'', async(() => {
const { fixture } = setup();
fixture.detectChanges();
const compile = fixture.debugElement.nativeElement;
const ptag = compile.querySelector('p');
expect(ptag.textContent).toBe('Dario clocked out at 00:00:00');
}));

it('should set showfileds as true', () => {
const show = true;
component.setShowFields(show);
Expand All @@ -62,44 +48,188 @@ describe('TimeClockComponent', () => {
expect(component.setShowFields).toHaveBeenCalledWith(true);
});

it('should have button text as Options', async(() => {
const { fixture } = setup();
fixture.detectChanges();
const x = document.getElementById('optionsContainer');
const ptag = x.querySelector('button');
expect(ptag.textContent).toBe(' Options ');
}));

it('should set Clock In', () => {
const { fixture } = setup();
fixture.detectChanges();
const x = document.getElementById('clockInOutContainer');
const ptag = x.querySelector('button');
expect(ptag.textContent).toBe('Clock In');
/* ---------------------- EMPLOYE CLOCK IN ------------------------------------- */
it('should be verify the init state of vars' , () => {
expect(component.isClockIn).toBeTruthy();
expect(component.isEnterTechnology).toBeFalsy();
expect(component.showAlertEnterTecnology).toBeFalsy();
expect(component.showFields).toBeFalsy();
expect(component.execOnlyOneTimeCounter).toBeFalsy();
expect(component.execOnlyOneTimeClockIn).toBeFalsy();
expect(component.isClockInEnable).toBeFalsy();
expect(component.isHidenForm).toBeTruthy();

expect(component.hourCounterRealTime).toEqual(0);
expect(component.minuteCounterRealTime).toEqual(0);
expect(component.secondsCounterRealTime).toEqual(0);

expect(component.hour).toEqual(0);
expect(component.minute).toEqual(0);
expect(component.seconds).toEqual(0);
});

it('should be change state of isClockInEnale, isClockIn, isHidenForm when function is called' , () => {
component.employeClockIn();
expect(component.isClockInEnable).toBeTruthy();
expect(component.isClockIn).toBeFalsy();
});

it('the function should return false' , () => {
expect(component.employeClockIn()).toEqual(false);
});

it('should be called to intern methods of employeClockIn' , () => {
spyOn(component, 'startTimer');
spyOn(component, 'setArrivalAndDepartureTimes');

component.employeClockIn();

expect(component.startTimer).toHaveBeenCalled();
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
});

/* ---------------------- EMPLOYE CLOCK OUT ------------------------------------- */
it('should enter if and assign the value to vars' , () => {
component.isEnterTechnology = false;
component.employeClockOut();
expect(component.isClockIn).toBeFalsy();
expect(component.showAlertEnterTecnology).toBeTruthy();
});

it('should enter if and not called to intern methods' , () => {
component.isEnterTechnology = false;
spyOn(component, 'setDefaultValuesToFields');
spyOn(component, 'pauseTimer');
spyOn(component, 'setArrivalAndDepartureTimes');
component.employeClockOut();
expect(component.setDefaultValuesToFields).not.toHaveBeenCalled();
expect(component.pauseTimer).not.toHaveBeenCalled();
expect(component.setArrivalAndDepartureTimes).not.toHaveBeenCalled();

});

it('should enter else and execute internal methods' , () => {
component.isEnterTechnology = true;

spyOn(component, 'setDefaultValuesToFields');
spyOn(component, 'pauseTimer');
spyOn(component, 'setArrivalAndDepartureTimes');

component.employeClockOut();

expect(component.setDefaultValuesToFields).toHaveBeenCalled();
expect(component.pauseTimer).toHaveBeenCalled();
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();

});

/* ---------------------- ENTER TECHNOLOGY ------------------------------------- */
it('should enter if and assign the value to var' , () => {
const dataTechnology = 'Angular';
component.enterTechnology(dataTechnology);
expect(component.isEnterTechnology).toBeTruthy();
});

it('should setVartToEmpty called', () => {
spyOn(component, 'setDefaultValuesToFields');
component.setDefaultValuesToFields();
expect(component.setDefaultValuesToFields).toHaveBeenCalled();
it('should enter else and assign the value to var ' , () => {
const dataTechnology = '';
component.enterTechnology(dataTechnology);
expect(component.isEnterTechnology).toBeFalsy();
});

it('should employeClockIn called', () => {
spyOn(component, 'employeClockIn');
component.employeClockIn();
expect(component.employeClockIn).toHaveBeenCalled();
/* ---------------------- SET SHOW FIELDS ------------------------------------- */
it('should execute all internal methods' , () => {
const show = true;
component.isClockInEnable = false;
component.execOnlyOneTimeCounter = false;

spyOn(component, 'startTimer');
spyOn(component, 'setArrivalAndDepartureTimes');

component.setShowFields(show);

expect(component.isHidenForm).toBeFalsy();
expect(component.isClockIn).toBeFalsy();
expect(component.showFields).toEqual(show);
expect(component.startTimer).toHaveBeenCalled();
expect(component.execOnlyOneTimeCounter).toBeTruthy();
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
});

it('should employeClockOut called', () => {
spyOn(component, 'employeClockOut');
component.employeClockOut();
expect(component.employeClockOut).toHaveBeenCalled();
it('should not call nested if internal methods' , () => {
const show = true;
component.isClockInEnable = false;
component.execOnlyOneTimeCounter = true;

spyOn(component, 'startTimer');
spyOn(component, 'setArrivalAndDepartureTimes');

component.setShowFields(show);

expect(component.isHidenForm).toBeFalsy();
expect(component.isClockIn).toBeFalsy();
expect(component.showFields).toEqual(show);
expect(component.startTimer).not.toHaveBeenCalled();
expect(component.execOnlyOneTimeCounter).toBeTruthy();
expect(component.setArrivalAndDepartureTimes).toHaveBeenCalled();
});

it('should enterTechnolofy called', () => {
spyOn(component, 'enterTechnology');
component.enterTechnology('');
expect(component.enterTechnology).toHaveBeenCalled();
it('shouldn not execute any main if method' , () => {
const show = true;
component.isClockInEnable = true;
component.execOnlyOneTimeCounter = true;

spyOn(component, 'startTimer');
spyOn(component, 'setArrivalAndDepartureTimes');

component.setShowFields(show);

expect(component.isHidenForm).toBeFalsy();
expect(component.isClockIn).toBeTruthy();
expect(component.showFields).toEqual(undefined);
expect(component.startTimer).not.toHaveBeenCalled();
expect(component.execOnlyOneTimeCounter).toBeTruthy();
expect(component.setArrivalAndDepartureTimes).not.toHaveBeenCalled();
});

/* ---------------------- TIMER ------------------------------------- */
it('should be var not equal to zero' , () => {
component.timer();
expect(component.secondsCounterRealTime).not.toEqual(0);
});

/* ---------------------- ARRIVALS ------------------------------------- */
it('should execute intern methods of arrivals' , () => {
const currentDate = new Date();
component.execOnlyOneTimeClockIn = false;
component.setArrivalAndDepartureTimes();
expect(component.hour).toEqual(currentDate.getHours());
expect(component.minute).toEqual(currentDate.getMinutes());
expect(component.seconds).toEqual(currentDate.getSeconds());
expect(component.execOnlyOneTimeClockIn).toEqual(true);

});

it('should not execute intern methods of arrivals' , () => {
component.execOnlyOneTimeClockIn = true;
component.setArrivalAndDepartureTimes();
expect(component.hour).toEqual(0);
expect(component.minute).toEqual(0);
expect(component.seconds).toEqual(0);
expect(component.execOnlyOneTimeClockIn).toEqual(true);
});

/* ---------------------- DEFAULT FIELDS ------------------------------------- */
it('set values to empty' , () => {
component.setDefaultValuesToFields();
expect(component.isHidenForm).toBeTruthy();
expect(component.isClockIn).toBeTruthy();
expect(component.isEnterTechnology).toBeFalsy();
expect(component.showAlertEnterTecnology).toBeFalsy();
expect(component.execOnlyOneTimeClockIn).toBeFalsy();
expect(component.execOnlyOneTimeCounter).toBeFalsy();
expect(component.isClockInEnable).toBeFalsy();

});
});