diff --git a/src/test/javascript/e2e/entities/likes/likes.page-object.ts b/src/test/javascript/e2e/entities/likes/likes.page-object.ts new file mode 100644 index 0000000000000000000000000000000000000000..761c64aca1137efe518b1cb33d7855652d699777 --- /dev/null +++ b/src/test/javascript/e2e/entities/likes/likes.page-object.ts @@ -0,0 +1,88 @@ +import { element, by, ElementFinder } from 'protractor'; + +export class LikesComponentsPage { + createButton = element(by.id('jh-create-entity')); + deleteButtons = element.all(by.css('jhi-likes div table .btn-danger')); + title = element.all(by.css('jhi-likes div h2#page-heading span')).first(); + noResult = element(by.id('no-result')); + entities = element(by.id('entities')); + + async clickOnCreateButton(): Promise<void> { + await this.createButton.click(); + } + + async clickOnLastDeleteButton(): Promise<void> { + await this.deleteButtons.last().click(); + } + + async countDeleteButtons(): Promise<number> { + return this.deleteButtons.count(); + } + + async getTitle(): Promise<string> { + return this.title.getAttribute('jhiTranslate'); + } +} + +export class LikesUpdatePage { + pageTitle = element(by.id('jhi-likes-heading')); + saveButton = element(by.id('save-entity')); + cancelButton = element(by.id('cancel-save')); + + dateInput = element(by.id('field_date')); + userIDInput = element(by.id('field_userID')); + projectIDInput = element(by.id('field_projectID')); + + async getPageTitle(): Promise<string> { + return this.pageTitle.getAttribute('jhiTranslate'); + } + + async setDateInput(date: string): Promise<void> { + await this.dateInput.sendKeys(date); + } + + async getDateInput(): Promise<string> { + return await this.dateInput.getAttribute('value'); + } + + async setUserIDInput(userID: string): Promise<void> { + await this.userIDInput.sendKeys(userID); + } + + async getUserIDInput(): Promise<string> { + return await this.userIDInput.getAttribute('value'); + } + + async setProjectIDInput(projectID: string): Promise<void> { + await this.projectIDInput.sendKeys(projectID); + } + + async getProjectIDInput(): Promise<string> { + return await this.projectIDInput.getAttribute('value'); + } + + async save(): Promise<void> { + await this.saveButton.click(); + } + + async cancel(): Promise<void> { + await this.cancelButton.click(); + } + + getSaveButton(): ElementFinder { + return this.saveButton; + } +} + +export class LikesDeleteDialog { + private dialogTitle = element(by.id('jhi-delete-likes-heading')); + private confirmButton = element(by.id('jhi-confirm-delete-likes')); + + async getDialogTitle(): Promise<string> { + return this.dialogTitle.getAttribute('jhiTranslate'); + } + + async clickOnConfirmButton(): Promise<void> { + await this.confirmButton.click(); + } +} diff --git a/src/test/javascript/e2e/entities/likes/likes.spec.ts b/src/test/javascript/e2e/entities/likes/likes.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..445cf5e1361f0a18f861fcddd441b4d3870460b6 --- /dev/null +++ b/src/test/javascript/e2e/entities/likes/likes.spec.ts @@ -0,0 +1,73 @@ +import { browser, ExpectedConditions as ec, promise } from 'protractor'; +import { NavBarPage, SignInPage } from '../../page-objects/jhi-page-objects'; + +import { LikesComponentsPage, LikesDeleteDialog, LikesUpdatePage } from './likes.page-object'; + +const expect = chai.expect; + +describe('Likes e2e test', () => { + let navBarPage: NavBarPage; + let signInPage: SignInPage; + let likesComponentsPage: LikesComponentsPage; + let likesUpdatePage: LikesUpdatePage; + let likesDeleteDialog: LikesDeleteDialog; + + before(async () => { + await browser.get('/'); + navBarPage = new NavBarPage(); + signInPage = await navBarPage.getSignInPage(); + await signInPage.autoSignInUsing('admin', 'admin'); + await browser.wait(ec.visibilityOf(navBarPage.entityMenu), 5000); + }); + + it('should load Likes', async () => { + await navBarPage.goToEntity('likes'); + likesComponentsPage = new LikesComponentsPage(); + await browser.wait(ec.visibilityOf(likesComponentsPage.title), 5000); + expect(await likesComponentsPage.getTitle()).to.eq('gitsearchApp.likes.home.title'); + await browser.wait(ec.or(ec.visibilityOf(likesComponentsPage.entities), ec.visibilityOf(likesComponentsPage.noResult)), 1000); + }); + + it('should load create Likes page', async () => { + await likesComponentsPage.clickOnCreateButton(); + likesUpdatePage = new LikesUpdatePage(); + expect(await likesUpdatePage.getPageTitle()).to.eq('gitsearchApp.likes.home.createOrEditLabel'); + await likesUpdatePage.cancel(); + }); + + it('should create and save Likes', async () => { + const nbButtonsBeforeCreate = await likesComponentsPage.countDeleteButtons(); + + await likesComponentsPage.clickOnCreateButton(); + + await promise.all([ + likesUpdatePage.setDateInput('2000-12-31'), + likesUpdatePage.setUserIDInput('5'), + likesUpdatePage.setProjectIDInput('5'), + ]); + + expect(await likesUpdatePage.getDateInput()).to.eq('2000-12-31', 'Expected date value to be equals to 2000-12-31'); + expect(await likesUpdatePage.getUserIDInput()).to.eq('5', 'Expected userID value to be equals to 5'); + expect(await likesUpdatePage.getProjectIDInput()).to.eq('5', 'Expected projectID value to be equals to 5'); + + await likesUpdatePage.save(); + expect(await likesUpdatePage.getSaveButton().isPresent(), 'Expected save button disappear').to.be.false; + + expect(await likesComponentsPage.countDeleteButtons()).to.eq(nbButtonsBeforeCreate + 1, 'Expected one more entry in the table'); + }); + + it('should delete last Likes', async () => { + const nbButtonsBeforeDelete = await likesComponentsPage.countDeleteButtons(); + await likesComponentsPage.clickOnLastDeleteButton(); + + likesDeleteDialog = new LikesDeleteDialog(); + expect(await likesDeleteDialog.getDialogTitle()).to.eq('gitsearchApp.likes.delete.question'); + await likesDeleteDialog.clickOnConfirmButton(); + + expect(await likesComponentsPage.countDeleteButtons()).to.eq(nbButtonsBeforeDelete - 1); + }); + + after(async () => { + await navBarPage.autoSignOut(); + }); +}); diff --git a/src/test/javascript/spec/app/entities/likes/likes-delete-dialog.component.spec.ts b/src/test/javascript/spec/app/entities/likes/likes-delete-dialog.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..e229024b529e1aa7a20d8240c1d943bd2df31220 --- /dev/null +++ b/src/test/javascript/spec/app/entities/likes/likes-delete-dialog.component.spec.ts @@ -0,0 +1,65 @@ +import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; +import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; +import { of } from 'rxjs'; +import { JhiEventManager } from 'ng-jhipster'; + +import { GitsearchTestModule } from '../../../test.module'; +import { MockEventManager } from '../../../helpers/mock-event-manager.service'; +import { MockActiveModal } from '../../../helpers/mock-active-modal.service'; +import { LikesDeleteDialogComponent } from 'app/entities/likes/likes-delete-dialog.component'; +import { LikesService } from 'app/entities/likes/likes.service'; + +describe('Component Tests', () => { + describe('Likes Management Delete Component', () => { + let comp: LikesDeleteDialogComponent; + let fixture: ComponentFixture<LikesDeleteDialogComponent>; + let service: LikesService; + let mockEventManager: MockEventManager; + let mockActiveModal: MockActiveModal; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [GitsearchTestModule], + declarations: [LikesDeleteDialogComponent], + }) + .overrideTemplate(LikesDeleteDialogComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(LikesDeleteDialogComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(LikesService); + mockEventManager = TestBed.get(JhiEventManager); + 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(); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/likes/likes-detail.component.spec.ts b/src/test/javascript/spec/app/entities/likes/likes-detail.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..319925a35bdee083881b42ad4fe8f7c82c777b71 --- /dev/null +++ b/src/test/javascript/spec/app/entities/likes/likes-detail.component.spec.ts @@ -0,0 +1,37 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ActivatedRoute } from '@angular/router'; +import { of } from 'rxjs'; + +import { GitsearchTestModule } from '../../../test.module'; +import { LikesDetailComponent } from 'app/entities/likes/likes-detail.component'; +import { Likes } from 'app/shared/model/likes.model'; + +describe('Component Tests', () => { + describe('Likes Management Detail Component', () => { + let comp: LikesDetailComponent; + let fixture: ComponentFixture<LikesDetailComponent>; + const route = ({ data: of({ likes: new Likes(123) }) } as any) as ActivatedRoute; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [GitsearchTestModule], + declarations: [LikesDetailComponent], + providers: [{ provide: ActivatedRoute, useValue: route }], + }) + .overrideTemplate(LikesDetailComponent, '') + .compileComponents(); + fixture = TestBed.createComponent(LikesDetailComponent); + comp = fixture.componentInstance; + }); + + describe('OnInit', () => { + it('Should load likes on init', () => { + // WHEN + comp.ngOnInit(); + + // THEN + expect(comp.likes).toEqual(jasmine.objectContaining({ id: 123 })); + }); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/likes/likes-update.component.spec.ts b/src/test/javascript/spec/app/entities/likes/likes-update.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b9e257de3064a7fb4fcda3a66e5e0571cd823cc --- /dev/null +++ b/src/test/javascript/spec/app/entities/likes/likes-update.component.spec.ts @@ -0,0 +1,61 @@ +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 { LikesUpdateComponent } from 'app/entities/likes/likes-update.component'; +import { LikesService } from 'app/entities/likes/likes.service'; +import { Likes } from 'app/shared/model/likes.model'; + +describe('Component Tests', () => { + describe('Likes Management Update Component', () => { + let comp: LikesUpdateComponent; + let fixture: ComponentFixture<LikesUpdateComponent>; + let service: LikesService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [GitsearchTestModule], + declarations: [LikesUpdateComponent], + providers: [FormBuilder], + }) + .overrideTemplate(LikesUpdateComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(LikesUpdateComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(LikesService); + }); + + describe('save', () => { + it('Should call update service on save for existing entity', fakeAsync(() => { + // GIVEN + const entity = new Likes(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 Likes(); + 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); + })); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/likes/likes.component.spec.ts b/src/test/javascript/spec/app/entities/likes/likes.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d61bfaeb60630638f24989a287afd92f227aa57f --- /dev/null +++ b/src/test/javascript/spec/app/entities/likes/likes.component.spec.ts @@ -0,0 +1,49 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { HttpHeaders, HttpResponse } from '@angular/common/http'; + +import { GitsearchTestModule } from '../../../test.module'; +import { LikesComponent } from 'app/entities/likes/likes.component'; +import { LikesService } from 'app/entities/likes/likes.service'; +import { Likes } from 'app/shared/model/likes.model'; + +describe('Component Tests', () => { + describe('Likes Management Component', () => { + let comp: LikesComponent; + let fixture: ComponentFixture<LikesComponent>; + let service: LikesService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [GitsearchTestModule], + declarations: [LikesComponent], + }) + .overrideTemplate(LikesComponent, '') + .compileComponents(); + + fixture = TestBed.createComponent(LikesComponent); + comp = fixture.componentInstance; + service = fixture.debugElement.injector.get(LikesService); + }); + + 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 Likes(123)], + headers, + }) + ) + ); + + // WHEN + comp.ngOnInit(); + + // THEN + expect(service.query).toHaveBeenCalled(); + expect(comp.likes && comp.likes[0]).toEqual(jasmine.objectContaining({ id: 123 })); + }); + }); +}); diff --git a/src/test/javascript/spec/app/entities/likes/likes.service.spec.ts b/src/test/javascript/spec/app/entities/likes/likes.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..11116dfd338d76510678de785ac909fc106c4a3d --- /dev/null +++ b/src/test/javascript/spec/app/entities/likes/likes.service.spec.ts @@ -0,0 +1,131 @@ +import { TestBed, getTestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import * as moment from 'moment'; +import { DATE_FORMAT } from 'app/shared/constants/input.constants'; +import { LikesService } from 'app/entities/likes/likes.service'; +import { ILikes, Likes } from 'app/shared/model/likes.model'; + +describe('Service Tests', () => { + describe('Likes Service', () => { + let injector: TestBed; + let service: LikesService; + let httpMock: HttpTestingController; + let elemDefault: ILikes; + let expectedResult: ILikes | ILikes[] | boolean | null; + let currentDate: moment.Moment; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + }); + expectedResult = null; + injector = getTestBed(); + service = injector.get(LikesService); + httpMock = injector.get(HttpTestingController); + currentDate = moment(); + + elemDefault = new Likes(0, currentDate, 0, 0); + }); + + describe('Service methods', () => { + it('should find an element', () => { + const returnedFromService = Object.assign( + { + date: currentDate.format(DATE_FORMAT), + }, + 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 Likes', () => { + const returnedFromService = Object.assign( + { + id: 0, + date: currentDate.format(DATE_FORMAT), + }, + elemDefault + ); + + const expected = Object.assign( + { + date: currentDate, + }, + returnedFromService + ); + + service.create(new Likes()).subscribe(resp => (expectedResult = resp.body)); + + const req = httpMock.expectOne({ method: 'POST' }); + req.flush(returnedFromService); + expect(expectedResult).toMatchObject(expected); + }); + + it('should update a Likes', () => { + const returnedFromService = Object.assign( + { + date: currentDate.format(DATE_FORMAT), + userID: 1, + projectID: 1, + }, + elemDefault + ); + + const expected = Object.assign( + { + date: currentDate, + }, + 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 Likes', () => { + const returnedFromService = Object.assign( + { + date: currentDate.format(DATE_FORMAT), + userID: 1, + projectID: 1, + }, + elemDefault + ); + + const expected = Object.assign( + { + date: currentDate, + }, + 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 Likes', () => { + service.delete(123).subscribe(resp => (expectedResult = resp.ok)); + + const req = httpMock.expectOne({ method: 'DELETE' }); + req.flush({ status: 200 }); + expect(expectedResult); + }); + }); + + afterEach(() => { + httpMock.verify(); + }); + }); +});