From a9172ad36193073590cfbbc634f7ecc25633a3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Mon, 16 Mar 2020 20:40:20 +0100 Subject: [PATCH] feat(SAI): display Timed Actionlists of creatures (#472) * feat(SAI): display Timed Actionlists of creatures * chore: wip * test: add checks --- .../sai-editor/sai-editor.component.html | 42 ++++++++------- .../timed-actionlist.component.html | 18 ++++++- .../timed-actionlist.component.spec.ts | 54 +++++++++++++++---- .../timed-actionlist.component.ts | 20 ++++--- 4 files changed, 97 insertions(+), 37 deletions(-) diff --git a/src/app/shared/modules/sai-editor/sai-editor.component.html b/src/app/shared/modules/sai-editor/sai-editor.component.html index 0f92ad5e4a..8c8d46af3d 100644 --- a/src/app/shared/modules/sai-editor/sai-editor.component.html +++ b/src/app/shared/modules/sai-editor/sai-editor.component.html @@ -140,16 +140,16 @@
@@ -166,7 +166,7 @@ class="fas fa-info-circle ml-1" [placement]="'auto'" [hidden]="!EVENT_PARAM2_TOOLTIPS[selectedEvent]" [tooltip]="EVENT_PARAM2_TOOLTIPS[selectedEvent]" - > + > maxTimer @@ -510,12 +510,12 @@ [rowHeight]="DTCFG.rowHeight" [selectionType]="DTCFG.selectionType" (select)='editorService.onRowSelection($event)'> - + - + @@ -529,11 +529,17 @@
- - +
+
+

+ Creature's Timed Actionlists + +

+ +
diff --git a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.html b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.html index 8b13789179..90de4f4912 100644 --- a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.html +++ b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.html @@ -1 +1,17 @@ - + + + + + + + + + + diff --git a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.spec.ts b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.spec.ts index 8946cc5d35..c35c03f840 100644 --- a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.spec.ts +++ b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.spec.ts @@ -1,25 +1,59 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { async, TestBed } from '@angular/core/testing'; import { TimedActionlistComponent } from './timed-actionlist.component'; +import { PageObject } from '@keira-testing/page-object'; +import { Component, ViewChild } from '@angular/core'; +import { MysqlQueryService } from '@keira-shared/services/mysql-query.service'; +import { SmartScripts } from '@keira-types/smart-scripts.type'; +import { of } from 'rxjs'; +import { NgxDatatableModule } from '@swimlane/ngx-datatable'; + +@Component({ + template: `` +}) +class TestHostComponent { + @ViewChild(TimedActionlistComponent) child: TimedActionlistComponent; + creatureId: string; +} + +class TimedActionlistPage extends PageObject {} describe('TimedActionlistComponent', () => { - let component: TimedActionlistComponent; - let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ TimedActionlistComponent ] + declarations: [TimedActionlistComponent, TestHostComponent], + imports: [NgxDatatableModule], }) .compileComponents(); })); - beforeEach(() => { - fixture = TestBed.createComponent(TimedActionlistComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + const setup = () => { + const fixture = TestBed.createComponent(TestHostComponent); + const host = fixture.componentInstance; + const page = new TimedActionlistPage(fixture); + const queryService = TestBed.inject(MysqlQueryService); + page.detectChanges(); + return { page, host, queryService }; + }; it('should create', () => { - expect(component).toBeTruthy(); + const { page, queryService, host } = setup(); + const id = '1234'; + const timedActionlists: SmartScripts[] = [new SmartScripts(), new SmartScripts()]; + timedActionlists[0].entryorguid = 111; + timedActionlists[0].id = 1; + timedActionlists[1].entryorguid = 222; + timedActionlists[1].id = 2; + spyOn(queryService, 'getTimedActionlists').and.returnValue(of(timedActionlists)); + + host.creatureId = id; + host.child.ngOnChanges(); + page.detectChanges(); + + expect(page.getDatatableCell('ngx-datatable', 0, 0).innerText).toContain(String(timedActionlists[0].entryorguid)); + expect(page.getDatatableCell('ngx-datatable', 0, 1).innerText).toContain(String(timedActionlists[0].id)); + expect(page.getDatatableCell('ngx-datatable', 1, 0).innerText).toContain(String(timedActionlists[1].entryorguid)); + expect(page.getDatatableCell('ngx-datatable', 1, 1).innerText).toContain(String(timedActionlists[1].id)); }); }); diff --git a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.ts b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.ts index 38c2c76ce7..70aeea3917 100644 --- a/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.ts +++ b/src/app/shared/modules/sai-editor/timed-actionlist/timed-actionlist.component.ts @@ -1,5 +1,9 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core'; +import { Observable } from 'rxjs'; + import { MysqlQueryService } from '@keira-shared/services/mysql-query.service'; +import { SmartScripts } from '@keira-types/smart-scripts.type'; +import { DTCFG } from '@keira-config/datatable.config'; @Component({ selector: 'keira-timed-actionlist', @@ -8,19 +12,19 @@ import { MysqlQueryService } from '@keira-shared/services/mysql-query.service'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class TimedActionlistComponent implements OnChanges { + public readonly DTCFG = DTCFG; @Input() creatureId: string|number; + private _timedActionLists$: Observable; + get timedActionlists$(): Observable { + return this._timedActionLists$; + } + constructor( private queryService: MysqlQueryService, ) { } - /* istanbul ignore next */ // TODO: write test once this component is complete - ngOnChanges(): void { - if (!!this.creatureId) { - this.queryService.getTimedActionlists(this.creatureId).subscribe((result) => { - console.log(result); - }); - } + ngOnChanges() { + this._timedActionLists$ = this.queryService.getTimedActionlists(this.creatureId); } - }