Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Fix QuestTemplateLocale tests
Fix <ngx-datatable-column> to self-closing tags
Add test case to verify string-typed field assignment
  • Loading branch information
vrachv committed Jan 12, 2025
1 parent a0203c7 commit 88827fc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
<i [hidden]="!editorService.isRowSelected(row)" class="fas fa-chevron-right"></i>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column name="Id" prop="ID" [minWidth]="80" [maxWidth]="150"></ngx-datatable-column>
<ngx-datatable-column name="Locale" prop="locale" [minWidth]="200"></ngx-datatable-column>
<ngx-datatable-column name="Title" prop="Title" [minWidth]="200"></ngx-datatable-column>
<ngx-datatable-column name="Id" prop="ID" [minWidth]="80" [maxWidth]="150"/>
<ngx-datatable-column name="Locale" prop="locale" [minWidth]="200"/>
<ngx-datatable-column name="Title" prop="Title" [minWidth]="200"/>
</ngx-datatable>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QuestTemplateLocale } from '@keira/shared/acore-world-model';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { MysqlQueryService } from '@keira/shared/db-layer';
import { of } from 'rxjs';
import { QuestPreviewService } from '../quest-preview/quest-preview.service';
Expand All @@ -9,19 +9,12 @@ import { MultiRowEditorPageObject, TranslateTestingModule } from '@keira/shared/
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';
import { ModalModule } from 'ngx-bootstrap/modal';
import { RouterTestingModule } from '@angular/router/testing';
import { KEIRA_APP_CONFIG_TOKEN, KEIRA_MOCK_CONFIG } from '@keira/shared/config';
import Spy = jasmine.Spy;

class QuestTemplateLocalePage extends MultiRowEditorPageObject<QuestTemplateLocaleComponent> { }

describe('QuestTemplateLocale integration tests', () => {
const id = 1234;
let fixture: ComponentFixture<QuestTemplateLocaleComponent>;
let queryService: MysqlQueryService;
let querySpy: Spy;
let handlerService: QuestHandlerService;
let page: QuestTemplateLocalePage;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand All @@ -30,7 +23,6 @@ describe('QuestTemplateLocale integration tests', () => {
ToastrModule.forRoot(),
ModalModule.forRoot(),
QuestTemplateLocaleComponent,
RouterTestingModule,
TranslateTestingModule,
],
providers: [QuestHandlerService, { provide: KEIRA_APP_CONFIG_TOKEN, useValue: KEIRA_MOCK_CONFIG }],
Expand All @@ -41,12 +33,12 @@ describe('QuestTemplateLocale integration tests', () => {
const originalRow = new QuestTemplateLocale();
originalRow.ID = id;

handlerService = TestBed.inject(QuestHandlerService);
const handlerService = TestBed.inject(QuestHandlerService);
handlerService['_selected'] = `${id}`;
handlerService.isNew = creatingNew;

queryService = TestBed.inject(MysqlQueryService);
querySpy = spyOn(queryService, 'query').and.returnValue(of([]));
const queryService = TestBed.inject(MysqlQueryService);
const querySpy = spyOn(queryService, 'query').and.returnValue(of([]));
spyOn(queryService, 'queryValue').and.returnValue(of());

spyOn(queryService, 'selectAll').and.returnValue(of(creatingNew ? [] : [originalRow]));
Expand All @@ -55,16 +47,17 @@ describe('QuestTemplateLocale integration tests', () => {
initializeServicesSpy.and.callThrough();
}

fixture = TestBed.createComponent(QuestTemplateLocaleComponent);
page = new QuestTemplateLocalePage(fixture);
const fixture = TestBed.createComponent(QuestTemplateLocaleComponent);
const page = new QuestTemplateLocalePage(fixture);
fixture.autoDetectChanges(true);
fixture.detectChanges();

return { handlerService, queryService, querySpy, page };
}

describe('Creating new', () => {
beforeEach(() => setup(true));

it('should correctly initialise', () => {
const { page } = setup(true);
page.expectDiffQueryToBeEmpty();
page.expectFullQueryToBeEmpty();
expect(page.formError.hidden).toBe(true);
Expand All @@ -84,6 +77,7 @@ describe('QuestTemplateLocale integration tests', () => {
});

it('should correctly update the unsaved status', () => {
const { page, handlerService } = setup(true);
expect(handlerService.isQuestTemplateLocaleUnsaved).toBe(false);
page.addNewRow();
expect(handlerService.isQuestTemplateLocaleUnsaved).toBe(true);
Expand All @@ -92,6 +86,7 @@ describe('QuestTemplateLocale integration tests', () => {
});

it('adding new rows and executing the query should correctly work', () => {
const { page, querySpy } = setup(true);
const expectedQuery =
'DELETE FROM `quest_template_locale` WHERE (`ID` = 1234) AND (`locale` IN (\'0\', \'1\', \'2\'));\n' +
'INSERT INTO `quest_template_locale` (`ID`, `locale`, `Title`, `Details`, `Objectives`, `EndText`, `CompletedText`, ' +
Expand All @@ -115,6 +110,7 @@ describe('QuestTemplateLocale integration tests', () => {
});

it('adding a row and changing its values should correctly update the queries', () => {
const { page } = setup(true);
page.addNewRow();
page.expectDiffQueryToContain(
'DELETE FROM `quest_template_locale` WHERE (`ID` = 1234) AND (`locale` IN (\'0\'));\n' +
Expand Down Expand Up @@ -173,6 +169,7 @@ describe('QuestTemplateLocale integration tests', () => {
});

it('adding a row changing its values and duplicate it should correctly update the queries', () => {
const { page } = setup(true);
page.addNewRow();
page.setInputValueById('title', '1');
page.setInputValueById('completed-text', '2');
Expand Down
15 changes: 14 additions & 1 deletion libs/shared/base-abstract-classes/src/core.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ export const MOCK_EXTRA_ID = 'extra_id';

export class MockEntity extends TableRow {
id: number = 0;
guid: number = 0;
guid: number | string = 0;
name: string = '';
}

export class MockEntityWithGuidString extends MockEntity {
override guid: number | string = '';
}

export class MockEntityExtra extends MockEntity {
extra_id?: any = 0;
}
Expand Down Expand Up @@ -77,6 +81,15 @@ export class MockMultiRowEditorService extends MultiRowEditorService<MockEntity>
}
}

@Injectable({
providedIn: 'root',
})
export class MockMultiRowEditorWithGuidStringService extends MultiRowEditorService<MockEntityWithGuidString> {
constructor(protected override handlerService: MockHandlerService) {
super(MockEntityWithGuidString, MOCK_TABLE, MOCK_ID, MOCK_ID_2, handlerService);
}
}

@Injectable({
providedIn: 'root',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MockEntityExtra,
MockMultiRowEditorExtraService,
MockMultiRowEditorService,
MockMultiRowEditorWithGuidStringService,
} from '../../core.mock';

describe('MultiRowEditorService', () => {
Expand All @@ -31,9 +32,13 @@ describe('MultiRowEditorService', () => {
);

function setup(
config: { loadedEntityId?: number; nextRowId?: number; newRows?: (MockEntity | MockEntityExtra)[]; extra?: boolean } = {},
config: { loadedEntityId?: number; nextRowId?: number; newRows?: (MockEntity | MockEntityExtra)[]; extra?: boolean, withGuidString?: boolean } = {},
) {
const service = config.extra ? TestBed.inject(MockMultiRowEditorExtraService) : TestBed.inject(MockMultiRowEditorService);
const service = config.extra
? TestBed.inject(MockMultiRowEditorExtraService)
: config.withGuidString
? TestBed.inject(MockMultiRowEditorWithGuidStringService)
: TestBed.inject(MockMultiRowEditorService);

const updateDiffQuerySpy = spyOn<any>(service, 'updateDiffQuery');
const updateFullQuerySpy = spyOn<any>(service, 'updateFullQuery');
Expand Down Expand Up @@ -331,6 +336,15 @@ describe('MultiRowEditorService', () => {

expect(service['_nextRowId']).toEqual(5);
});

it('it should assign nextId as a string to string-typed field', () => {
const nextRowId = 3;
const { service } = setup({ nextRowId, newRows: [], withGuidString: true });

service.addNewRow();

expect(typeof service.newRows[0][MOCK_ID_2]).toBe('string');
});
});

describe('isFormIdUnique()', () => {
Expand Down

0 comments on commit 88827fc

Please sign in to comment.