This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • development/sharing/codeability-sharing-platform
1 result
Show changes
Showing
with 0 additions and 1472 deletions
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { StatisticsDetailComponent } from 'app/entities/statistics/statistics-detail.component';
import { Statistics } from 'app/shared/model/statistics.model';
describe('Component Tests', () => {
describe('Statistics Management Detail Component', () => {
let comp: StatisticsDetailComponent;
let fixture: ComponentFixture<StatisticsDetailComponent>;
const route = { data: of({ statistics: new Statistics(123) }) } as any as ActivatedRoute;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [StatisticsDetailComponent],
providers: [{ provide: ActivatedRoute, useValue: route }],
})
.overrideTemplate(StatisticsDetailComponent, '')
.compileComponents();
fixture = TestBed.createComponent(StatisticsDetailComponent);
comp = fixture.componentInstance;
});
describe('OnInit', () => {
it('Should load statistics on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(comp.statistics).toEqual(jasmine.objectContaining({ id: 123 }));
});
});
});
});
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { HttpResponse } from '@angular/common/http';
import { FormBuilder } from '@angular/forms';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { StatisticsUpdateComponent } from 'app/entities/statistics/statistics-update.component';
import { StatisticsService } from 'app/entities/statistics/statistics.service';
import { Statistics } from 'app/shared/model/statistics.model';
describe('Component Tests', () => {
describe('Statistics Management Update Component', () => {
let comp: StatisticsUpdateComponent;
let fixture: ComponentFixture<StatisticsUpdateComponent>;
let service: StatisticsService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [StatisticsUpdateComponent],
providers: [FormBuilder],
})
.overrideTemplate(StatisticsUpdateComponent, '')
.compileComponents();
fixture = TestBed.createComponent(StatisticsUpdateComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(StatisticsService);
});
describe('save', () => {
it('Should call update service on save for existing entity', fakeAsync(() => {
// GIVEN
const entity = new Statistics(123);
spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.update).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
it('Should call create service on save for new entity', fakeAsync(() => {
// GIVEN
const entity = new Statistics();
spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.create).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
});
});
});
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { GitsearchTestModule } from '../../../test.module';
import { StatisticsComponent } from 'app/entities/statistics/statistics.component';
import { StatisticsService } from 'app/entities/statistics/statistics.service';
import { Statistics } from 'app/shared/model/statistics.model';
describe('Component Tests', () => {
describe('Statistics Management Component', () => {
let comp: StatisticsComponent;
let fixture: ComponentFixture<StatisticsComponent>;
let service: StatisticsService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [StatisticsComponent],
providers: [
{
provide: ActivatedRoute,
useValue: {
data: of({
defaultSort: 'id,asc',
}),
queryParamMap: of(
convertToParamMap({
page: '1',
size: '1',
sort: 'id,desc',
})
),
},
},
],
})
.overrideTemplate(StatisticsComponent, '')
.compileComponents();
fixture = TestBed.createComponent(StatisticsComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(StatisticsService);
});
it('Should call load all on init', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new Statistics(123)],
headers,
})
)
);
// WHEN
comp.ngOnInit();
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.statistics && comp.statistics[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should load a page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new Statistics(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.statistics && comp.statistics[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should re-initialize the page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new Statistics(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
comp.reset();
// THEN
expect(comp.page).toEqual(0);
expect(service.query).toHaveBeenCalledTimes(2);
expect(comp.statistics && comp.statistics[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should calculate the sort attribute for an id', () => {
// WHEN
comp.ngOnInit();
const result = comp.sort();
// THEN
expect(result).toEqual(['id,asc']);
});
it('should calculate the sort attribute for a non-id attribute', () => {
// INIT
comp.ngOnInit();
// GIVEN
comp.predicate = 'name';
// WHEN
const result = comp.sort();
// THEN
expect(result).toEqual(['name,asc', 'id']);
});
});
});
import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { StatisticsService } from 'app/entities/statistics/statistics.service';
import { IStatistics, Statistics } from 'app/shared/model/statistics.model';
describe('Service Tests', () => {
describe('Statistics Service', () => {
let injector: TestBed;
let service: StatisticsService;
let httpMock: HttpTestingController;
let elemDefault: IStatistics;
let expectedResult: IStatistics | IStatistics[] | boolean | null;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
expectedResult = null;
injector = getTestBed();
service = injector.get(StatisticsService);
httpMock = injector.get(HttpTestingController);
elemDefault = new Statistics(0, 0, 0, 0);
});
describe('Service methods', () => {
it('should find an element', () => {
const returnedFromService = Object.assign({}, elemDefault);
service.find(123).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(elemDefault);
});
it('should create a Statistics', () => {
const returnedFromService = Object.assign(
{
id: 0,
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.create(new Statistics()).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'POST' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should update a Statistics', () => {
const returnedFromService = Object.assign(
{
views: 1,
downloads: 1,
exerciseID: 1,
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.update(expected).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'PUT' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should return a list of Statistics', () => {
const returnedFromService = Object.assign(
{
views: 1,
downloads: 1,
exerciseID: 1,
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.query().subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush([returnedFromService]);
httpMock.verify();
expect(expectedResult).toContainEqual(expected);
});
it('should delete a Statistics', () => {
service.delete(123).subscribe(resp => (expectedResult = resp.ok));
const req = httpMock.expectOne({ method: 'DELETE' });
req.flush({ status: 200 });
expect(expectedResult);
});
});
afterEach(() => {
httpMock.verify();
});
});
});
import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { EventManager } from 'app/core/util/event-manager.service';
import { GitsearchTestModule } from '../../../test.module';
import { MockEventManager } from '../../../helpers/mock-event-manager.service';
import { MockActiveModal } from '../../../helpers/mock-active-modal.service';
import { UserWatchListDeleteDialogComponent } from 'app/entities/user-watch-list/user-watch-list-delete-dialog.component';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
describe('Component Tests', () => {
describe('UserWatchList Management Delete Component', () => {
let comp: UserWatchListDeleteDialogComponent;
let fixture: ComponentFixture<UserWatchListDeleteDialogComponent>;
let service: UserWatchListService;
let mockEventManager: MockEventManager;
let mockActiveModal: MockActiveModal;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [UserWatchListDeleteDialogComponent],
})
.overrideTemplate(UserWatchListDeleteDialogComponent, '')
.compileComponents();
fixture = TestBed.createComponent(UserWatchListDeleteDialogComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(UserWatchListService);
mockEventManager = TestBed.get(EventManager);
mockActiveModal = TestBed.get(NgbActiveModal);
});
describe('confirmDelete', () => {
it('Should call delete service on confirmDelete', inject(
[],
fakeAsync(() => {
// GIVEN
spyOn(service, 'delete').and.returnValue(of({}));
// WHEN
comp.confirmDelete(123);
tick();
// THEN
expect(service.delete).toHaveBeenCalledWith(123);
expect(mockActiveModal.closeSpy).toHaveBeenCalled();
expect(mockEventManager.broadcastSpy).toHaveBeenCalled();
})
));
it('Should not call delete service on clear', () => {
// GIVEN
spyOn(service, 'delete');
// WHEN
comp.cancel();
// THEN
expect(service.delete).not.toHaveBeenCalled();
expect(mockActiveModal.dismissSpy).toHaveBeenCalled();
});
});
});
});
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { UserWatchListDetailComponent } from 'app/entities/user-watch-list/user-watch-list-detail.component';
import { UserWatchList } from 'app/shared/model/user-watch-list.model';
describe('Component Tests', () => {
describe('UserWatchList Management Detail Component', () => {
let comp: UserWatchListDetailComponent;
let fixture: ComponentFixture<UserWatchListDetailComponent>;
const route = { data: of({ userWatchList: new UserWatchList(123) }) } as any as ActivatedRoute;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [UserWatchListDetailComponent],
providers: [{ provide: ActivatedRoute, useValue: route }],
})
.overrideTemplate(UserWatchListDetailComponent, '')
.compileComponents();
fixture = TestBed.createComponent(UserWatchListDetailComponent);
comp = fixture.componentInstance;
});
describe('OnInit', () => {
it('Should load userWatchList on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(comp.userWatchList).toEqual(jasmine.objectContaining({ id: 123 }));
});
});
});
});
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { HttpResponse } from '@angular/common/http';
import { FormBuilder } from '@angular/forms';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { UserWatchListUpdateComponent } from 'app/entities/user-watch-list/user-watch-list-update.component';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { UserWatchList } from 'app/shared/model/user-watch-list.model';
describe('Component Tests', () => {
describe('UserWatchList Management Update Component', () => {
let comp: UserWatchListUpdateComponent;
let fixture: ComponentFixture<UserWatchListUpdateComponent>;
let service: UserWatchListService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [UserWatchListUpdateComponent],
providers: [FormBuilder],
})
.overrideTemplate(UserWatchListUpdateComponent, '')
.compileComponents();
fixture = TestBed.createComponent(UserWatchListUpdateComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(UserWatchListService);
});
describe('save', () => {
it('Should call update service on save for existing entity', fakeAsync(() => {
// GIVEN
const entity = new UserWatchList(123);
spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.update).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
it('Should call create service on save for new entity', fakeAsync(() => {
// GIVEN
const entity = new UserWatchList();
spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.create).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
});
});
});
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { GitsearchTestModule } from '../../../test.module';
import { UserWatchListComponent } from 'app/entities/user-watch-list/user-watch-list.component';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { UserWatchList } from 'app/shared/model/user-watch-list.model';
describe('Component Tests', () => {
describe('UserWatchList Management Component', () => {
let comp: UserWatchListComponent;
let fixture: ComponentFixture<UserWatchListComponent>;
let service: UserWatchListService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [UserWatchListComponent],
providers: [
{
provide: ActivatedRoute,
useValue: {
data: of({
defaultSort: 'id,asc',
}),
queryParamMap: of(
convertToParamMap({
page: '1',
size: '1',
sort: 'id,desc',
})
),
},
},
],
})
.overrideTemplate(UserWatchListComponent, '')
.compileComponents();
fixture = TestBed.createComponent(UserWatchListComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(UserWatchListService);
});
it('Should call load all on init', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new UserWatchList(123)],
headers,
})
)
);
// WHEN
comp.ngOnInit();
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.userWatchLists && comp.userWatchLists[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should load a page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new UserWatchList(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.userWatchLists && comp.userWatchLists[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should re-initialize the page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new UserWatchList(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
comp.reset();
// THEN
expect(comp.page).toEqual(0);
expect(service.query).toHaveBeenCalledTimes(2);
expect(comp.userWatchLists && comp.userWatchLists[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should calculate the sort attribute for an id', () => {
// WHEN
comp.ngOnInit();
const result = comp.sort();
// THEN
expect(result).toEqual(['id,asc']);
});
it('should calculate the sort attribute for a non-id attribute', () => {
// INIT
comp.ngOnInit();
// GIVEN
comp.predicate = 'name';
// WHEN
const result = comp.sort();
// THEN
expect(result).toEqual(['name,asc', 'id']);
});
});
});
import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { IUserWatchList, UserWatchList } from 'app/shared/model/user-watch-list.model';
import { CheckFrequency } from 'app/shared/model/enumerations/check-frequency.model';
describe('Service Tests', () => {
describe('UserWatchList Service', () => {
let injector: TestBed;
let service: UserWatchListService;
let httpMock: HttpTestingController;
let elemDefault: IUserWatchList;
let expectedResult: IUserWatchList | IUserWatchList[] | boolean | null;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
expectedResult = null;
injector = getTestBed();
service = injector.get(UserWatchListService);
httpMock = injector.get(HttpTestingController);
elemDefault = new UserWatchList(0, 'AAAAAAA', CheckFrequency.NEVER);
});
describe('Service methods', () => {
it('should find an element', () => {
const returnedFromService = Object.assign({}, elemDefault);
service.find(123).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(elemDefault);
});
it('should create a UserWatchList', () => {
const returnedFromService = Object.assign(
{
id: 0,
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.create(new UserWatchList()).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'POST' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should update a UserWatchList', () => {
const returnedFromService = Object.assign(
{
name: 'BBBBBB',
checkFrequency: 'BBBBBB',
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.update(expected).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'PUT' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should return a list of UserWatchList', () => {
const returnedFromService = Object.assign(
{
name: 'BBBBBB',
checkFrequency: 'BBBBBB',
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.query().subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush([returnedFromService]);
httpMock.verify();
expect(expectedResult).toContainEqual(expected);
});
it('should delete a UserWatchList', () => {
service.delete(123).subscribe(resp => (expectedResult = resp.ok));
const req = httpMock.expectOne({ method: 'DELETE' });
req.flush({ status: 200 });
expect(expectedResult);
});
});
afterEach(() => {
httpMock.verify();
});
});
});
import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { EventManager } from 'app/core/util/event-manager.service';
import { GitsearchTestModule } from '../../../test.module';
import { MockEventManager } from '../../../helpers/mock-event-manager.service';
import { MockActiveModal } from '../../../helpers/mock-active-modal.service';
import { WatchListEntryDeleteDialogComponent } from 'app/entities/watch-list-entry/watch-list-entry-delete-dialog.component';
import { WatchListEntryService } from 'app/entities/watch-list-entry/watch-list-entry.service';
describe('Component Tests', () => {
describe('WatchListEntry Management Delete Component', () => {
let comp: WatchListEntryDeleteDialogComponent;
let fixture: ComponentFixture<WatchListEntryDeleteDialogComponent>;
let service: WatchListEntryService;
let mockEventManager: MockEventManager;
let mockActiveModal: MockActiveModal;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [WatchListEntryDeleteDialogComponent],
})
.overrideTemplate(WatchListEntryDeleteDialogComponent, '')
.compileComponents();
fixture = TestBed.createComponent(WatchListEntryDeleteDialogComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(WatchListEntryService);
mockEventManager = TestBed.get(EventManager);
mockActiveModal = TestBed.get(NgbActiveModal);
});
describe('confirmDelete', () => {
it('Should call delete service on confirmDelete', inject(
[],
fakeAsync(() => {
// GIVEN
spyOn(service, 'delete').and.returnValue(of({}));
// WHEN
comp.confirmDelete(123);
tick();
// THEN
expect(service.delete).toHaveBeenCalledWith(123);
expect(mockActiveModal.closeSpy).toHaveBeenCalled();
expect(mockEventManager.broadcastSpy).toHaveBeenCalled();
})
));
it('Should not call delete service on clear', () => {
// GIVEN
spyOn(service, 'delete');
// WHEN
comp.cancel();
// THEN
expect(service.delete).not.toHaveBeenCalled();
expect(mockActiveModal.dismissSpy).toHaveBeenCalled();
});
});
});
});
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { WatchListEntryDetailComponent } from 'app/entities/watch-list-entry/watch-list-entry-detail.component';
import { WatchListEntry } from 'app/shared/model/watch-list-entry.model';
describe('Component Tests', () => {
describe('WatchListEntry Management Detail Component', () => {
let comp: WatchListEntryDetailComponent;
let fixture: ComponentFixture<WatchListEntryDetailComponent>;
const route = { data: of({ watchListEntry: new WatchListEntry(123) }) } as any as ActivatedRoute;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [WatchListEntryDetailComponent],
providers: [{ provide: ActivatedRoute, useValue: route }],
})
.overrideTemplate(WatchListEntryDetailComponent, '')
.compileComponents();
fixture = TestBed.createComponent(WatchListEntryDetailComponent);
comp = fixture.componentInstance;
});
describe('OnInit', () => {
it('Should load watchListEntry on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(comp.watchListEntry).toEqual(jasmine.objectContaining({ id: 123 }));
});
});
});
});
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { HttpResponse } from '@angular/common/http';
import { FormBuilder } from '@angular/forms';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { WatchListEntryUpdateComponent } from 'app/entities/watch-list-entry/watch-list-entry-update.component';
import { WatchListEntryService } from 'app/entities/watch-list-entry/watch-list-entry.service';
import { WatchListEntry } from 'app/shared/model/watch-list-entry.model';
describe('Component Tests', () => {
describe('WatchListEntry Management Update Component', () => {
let comp: WatchListEntryUpdateComponent;
let fixture: ComponentFixture<WatchListEntryUpdateComponent>;
let service: WatchListEntryService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [WatchListEntryUpdateComponent],
providers: [FormBuilder],
})
.overrideTemplate(WatchListEntryUpdateComponent, '')
.compileComponents();
fixture = TestBed.createComponent(WatchListEntryUpdateComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(WatchListEntryService);
});
describe('save', () => {
it('Should call update service on save for existing entity', fakeAsync(() => {
// GIVEN
const entity = new WatchListEntry(123);
spyOn(service, 'update').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.update).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
it('Should call create service on save for new entity', fakeAsync(() => {
// GIVEN
const entity = new WatchListEntry();
spyOn(service, 'create').and.returnValue(of(new HttpResponse({ body: entity })));
comp.updateForm(entity);
// WHEN
comp.save();
tick(); // simulate async
// THEN
expect(service.create).toHaveBeenCalledWith(entity);
expect(comp.isSaving).toEqual(false);
}));
});
});
});
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { ActivatedRoute, convertToParamMap } from '@angular/router';
import { GitsearchTestModule } from '../../../test.module';
import { WatchListEntryComponent } from 'app/entities/watch-list-entry/watch-list-entry.component';
import { WatchListEntryService } from 'app/entities/watch-list-entry/watch-list-entry.service';
import { WatchListEntry } from 'app/shared/model/watch-list-entry.model';
describe('Component Tests', () => {
describe('WatchListEntry Management Component', () => {
let comp: WatchListEntryComponent;
let fixture: ComponentFixture<WatchListEntryComponent>;
let service: WatchListEntryService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [WatchListEntryComponent],
providers: [
{
provide: ActivatedRoute,
useValue: {
data: of({
defaultSort: 'id,asc',
}),
queryParamMap: of(
convertToParamMap({
page: '1',
size: '1',
sort: 'id,desc',
})
),
},
},
],
})
.overrideTemplate(WatchListEntryComponent, '')
.compileComponents();
fixture = TestBed.createComponent(WatchListEntryComponent);
comp = fixture.componentInstance;
service = fixture.debugElement.injector.get(WatchListEntryService);
});
it('Should call load all on init', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new WatchListEntry(123)],
headers,
})
)
);
// WHEN
comp.ngOnInit();
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.watchListEntries && comp.watchListEntries[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should load a page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new WatchListEntry(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.watchListEntries && comp.watchListEntries[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should re-initialize the page', () => {
// GIVEN
const headers = new HttpHeaders().append('link', 'link;link');
spyOn(service, 'query').and.returnValue(
of(
new HttpResponse({
body: [new WatchListEntry(123)],
headers,
})
)
);
// WHEN
comp.loadPage(1);
comp.reset();
// THEN
expect(comp.page).toEqual(0);
expect(service.query).toHaveBeenCalledTimes(2);
expect(comp.watchListEntries && comp.watchListEntries[0]).toEqual(jasmine.objectContaining({ id: 123 }));
});
it('should calculate the sort attribute for an id', () => {
// WHEN
comp.ngOnInit();
const result = comp.sort();
// THEN
expect(result).toEqual(['id,asc']);
});
it('should calculate the sort attribute for a non-id attribute', () => {
// INIT
comp.ngOnInit();
// GIVEN
comp.predicate = 'name';
// WHEN
const result = comp.sort();
// THEN
expect(result).toEqual(['name,asc', 'id']);
});
});
});
import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { WatchListEntryService } from 'app/entities/watch-list-entry/watch-list-entry.service';
import { IWatchListEntry, WatchListEntry } from 'app/shared/model/watch-list-entry.model';
describe('Service Tests', () => {
describe('WatchListEntry Service', () => {
let injector: TestBed;
let service: WatchListEntryService;
let httpMock: HttpTestingController;
let elemDefault: IWatchListEntry;
let expectedResult: IWatchListEntry | IWatchListEntry[] | boolean | null;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
expectedResult = null;
injector = getTestBed();
service = injector.get(WatchListEntryService);
httpMock = injector.get(HttpTestingController);
elemDefault = new WatchListEntry(0, 'AAAAAAA', 'AAAAAAA');
});
describe('Service methods', () => {
it('should find an element', () => {
const returnedFromService = Object.assign({}, elemDefault);
service.find(123).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(elemDefault);
});
it('should create a WatchListEntry', () => {
const returnedFromService = Object.assign(
{
id: 0,
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.create(new WatchListEntry()).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'POST' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should update a WatchListEntry', () => {
const returnedFromService = Object.assign(
{
exerciseId: 'BBBBBB',
exerciseName: 'BBBBBB',
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.update(expected).subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'PUT' });
req.flush(returnedFromService);
expect(expectedResult).toMatchObject(expected);
});
it('should return a list of WatchListEntry', () => {
const returnedFromService = Object.assign(
{
exerciseId: 'BBBBBB',
exerciseName: 'BBBBBB',
},
elemDefault
);
const expected = Object.assign({}, returnedFromService);
service.query().subscribe(resp => (expectedResult = resp.body));
const req = httpMock.expectOne({ method: 'GET' });
req.flush([returnedFromService]);
httpMock.verify();
expect(expectedResult).toContainEqual(expected);
});
it('should delete a WatchListEntry', () => {
service.delete(123).subscribe(resp => (expectedResult = resp.ok));
const req = httpMock.expectOne({ method: 'DELETE' });
req.flush({ status: 200 });
expect(expectedResult);
});
});
afterEach(() => {
httpMock.verify();
});
});
});
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { of } from 'rxjs';
import { GitsearchTestModule } from '../../../test.module';
import { ProfileInfo } from 'app/layouts/profiles/profile-info.model';
import { NavbarComponent } from 'app/layouts/navbar/navbar.component';
import { AccountService } from 'app/core/auth/account.service';
import { ProfileService } from 'app/layouts/profiles/profile.service';
import { FormBuilder } from '@angular/forms';
describe('Component Tests', () => {
describe('Navbar Component', () => {
let comp: NavbarComponent;
let fixture: ComponentFixture<NavbarComponent>;
let accountService: AccountService;
let profileService: ProfileService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [GitsearchTestModule],
declarations: [NavbarComponent],
providers: [
FormBuilder
],
})
.overrideTemplate(NavbarComponent, '')
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NavbarComponent);
comp = fixture.componentInstance;
accountService = TestBed.get(AccountService);
profileService = TestBed.get(ProfileService);
});
/** temporarily disabled should be analysed later
it('Should call profileService.getProfileInfo on init', () => {
// GIVEN
spyOn(profileService, 'getProfileInfo').and.returnValue(of(new ProfileInfo()));
// WHEN
comp.ngOnInit();
// THEN
expect(profileService.getProfileInfo).toHaveBeenCalled();
});
*/
/** temporarily disabled
it('Should call accountService.isAuthenticated on authentication', () => {
// WHEN
comp.isAuthenticated();
// THEN
expect(accountService.isAuthenticated).toHaveBeenCalled();
});
*/
it('Just a fake test to avoid empty test', () => {
// WHEN
comp.isAuthenticated();
// THEN
// expect(accountService).is;
});
/* TODO later
it('Should call searchService.searchPageDetails on search changed', () => {
// WHEN
comp.searchChanged();
// THEN
expect(searchService.searchPageDetails).toHaveBeenCalled();
});
*/
});
});
import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { MessageService, BroadCastMessage } from 'app/shared/service/message-service';
describe('Service Tests', () => {
describe('Message Service', () => {
let injector: TestBed;
let service: MessageService;
let httpMock: HttpTestingController;
let expectedResult: Array<BroadCastMessage>;
let returnedFromService: Array<BroadCastMessage>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
expectedResult = new Array<BroadCastMessage>();
injector = getTestBed();
service = injector.get(MessageService);
httpMock = injector.get(HttpTestingController);
const messageNow: BroadCastMessage = {
message: 'Some Test now Message',
starts_at: new Date(),
ends_at: new Date(new Date().getDate() + 1),
color: 'red',
id: 1,
font: 'unused',
active: true,
target_path: 'unused',
broadcast_type: 'broadcast_type',
dismissable: true,
};
const messageTomorrow: BroadCastMessage = {
message: 'Some Test tomorrwo Message',
starts_at: new Date(new Date().getDate() + 1),
ends_at: new Date(new Date().getDate() + 2),
color: 'red',
id: 2,
font: 'unused',
active: true,
target_path: 'unused',
broadcast_type: 'broadcast_type',
dismissable: true,
};
returnedFromService = new Array<BroadCastMessage>(messageNow, messageTomorrow);
});
describe('Service methods', () => {
it('should get some messages', () => {
expectedResult = service.getMessages(); // this may return an empty list, because webclient may not yet received results
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expectedResult = service.getMessages();
expect(expectedResult).toMatchObject(returnedFromService);
});
});
describe('Service methods', () => {
it('should get some messages', () => {
expectedResult = service.getActiveMessages(); // this may return an empty list, because webclient may not yet received results
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expectedResult = service.getActiveMessages();
const now = new Date();
expect(expectedResult).toMatchObject(returnedFromService.filter(m => m.starts_at <= now && m.ends_at >= now));
});
});
afterEach(() => {
httpMock.verify();
});
});
});
import { ComponentFixture, TestBed, waitForAsync, fakeAsync, tick } from '@angular/core/testing';
import { GitsearchTestModule } from '../../test.module';
import { TeaserContentComponent } from 'app/teaserContent/teaserContent.component';
import { TranslateModule } from '@ngx-translate/core';
import { SearchService } from 'app/search/service/search-service';
import { MockSearchService } from '../../helpers/mock-search.service';
import { TagCloudModule } from 'angular-tag-cloud-module';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, Routes } from '@angular/router';
import { SearchComponent } from 'app/search/search.component';
import { SearchModule } from 'app/search/search.module';
import { GitSearchV2HomeModule } from 'app/home/home.module';
describe('Component Tests', () => {
describe('TeaserContent Component', () => {
let comp: TeaserContentComponent;
let fixture: ComponentFixture<TeaserContentComponent>;
let router: Router;
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'search', component: SearchComponent },
];
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
GitsearchTestModule,
RouterTestingModule.withRoutes(routes),
SearchModule,
GitSearchV2HomeModule,
TagCloudModule,
TranslateModule.forRoot(),
],
declarations: [],
providers: [
{
provide: SearchService,
useClass: MockSearchService,
},
],
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(TeaserContentComponent);
comp = fixture.componentInstance;
router = TestBed.get(Router);
});
it('check setup teaser component', fakeAsync(() => {
// GIVEN
// WHEN
comp.ngOnInit();
tick();
const navigateSpy = spyOn(router, 'navigate').and.returnValue(null);
comp.onKeywordClick({ text: 'keyword1' });
tick();
expect(navigateSpy).toHaveBeenCalledWith(['/search'], { queryParams: { kw: 'keyword1' } });
// THEN
}));
});
});
import Spy = jasmine.Spy;
import { of } from 'rxjs';
import { SpyObject } from './spyobject';
import { PagesService } from 'app/shared/service/pages-service';
export class MockPagesService extends SpyObject {
getSpy: Spy;
getPageSpy: Spy;
getAttachmentURLSpy: Spy;
resetCacheSpy: Spy;
constructor() {
super(PagesService);
this.getSpy = this.spy('get').andReturn(this);
this.getPageSpy = this.spy('getPage').andCallFake((pagePath: string) => {
return of({ path: pagePath, content: '#head \n hello world' });
});
this.getAttachmentURLSpy = this.spy('getAttachmentURL'); // nothing to do
this.resetCacheSpy = this.spy('resetCache').and.returnValue(of('{}'));
}
}
import Spy = jasmine.Spy;
import { of } from 'rxjs';
import { SpyObject } from './spyobject';
import { SearchService } from 'app/search/service/search-service';
export class MockSearchService extends SpyObject {
getSpy: Spy;
keywordsAutoCompleteSpy: Spy;
authorsAutoCompleteSpy: Spy;
plAutoCompleteSpy: Spy;
constructor() {
super(SearchService);
this.getSpy = this.spy('get').andReturn(this);
const keyWordTestData = [
{ target: 'keyword1', hitCount: 5 },
{ target: 'keyword2', hitCount: 3 },
{ target: 'keyword3', hitCount: 2 },
];
this.keywordsAutoCompleteSpy = this.spy('getKeywordsAutoComplete').and.returnValue(of(keyWordTestData));
const authorTestData = [
{ target: 'Michael', hitCount: 5 },
{ target: 'Lukaus', hitCount: 3 },
{ target: 'Eduard', hitCount: 2 },
];
this.authorsAutoCompleteSpy = this.spy('getContributorCreatorAutoComplete').and.returnValue(of(authorTestData));
const programmingTestData = [
{ target: 'Java', hitCount: 5 },
{ target: 'Python', hitCount: 3 },
{ target: 'UML', hitCount: 2 },
];
this.plAutoCompleteSpy = this.spy('getProgrammingLanguageAutoComplete').and.returnValue(of(programmingTestData));
// Add more mock functions!!!
}
}
import Spy = jasmine.Spy;
import { of } from 'rxjs';
import { SpyObject } from './spyobject';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { IUserWatchList, UserWatchList } from 'app/shared/model/user-watch-list.model';
import { CheckFrequency } from 'app/shared/model/enumerations/check-frequency.model';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
export class MockUserWatchListService extends SpyObject {
getSpy: Spy;
findMyWatchlistsSpy: Spy;
querySpy: Spy;
deleteSpy: Spy;
updateSpy: Spy;
createSpy: Spy;
defaultWatchList: IUserWatchList[] = [
{
id: 1,
name: 'My WatchList',
checkFrequency: CheckFrequency.NEVER,
userLogin: 'any',
userId: 0,
},
];
constructor() {
super(UserWatchListService);
const entity = new UserWatchList(123);
this.getSpy = this.spy('get').andReturn(this);
this.findMyWatchlistsSpy = this.spy('findMyWatchlists').andReturn(of({ body: this.defaultWatchList }));
const headers = new HttpHeaders().append('link', 'link;link');
this.querySpy = this.spy('query').and.returnValue(of(new HttpResponse({ body: [entity], headers })));
this.deleteSpy = this.spy('delete').and.returnValue(of({}));
this.updateSpy = this.spy('update').and.returnValue(of(new HttpResponse({ body: entity })));
const newEntity = new UserWatchList();
this.createSpy = this.spy('create').and.returnValue(of(new HttpResponse({ body: newEntity })));
}
}