-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(*): search results problems improved
- Loading branch information
Showing
21 changed files
with
378 additions
and
133 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/app/child-dev-project/children/child-block/child-block.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/app/child-dev-project/children/child-photo-service/datatype-load-child-photo.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* This file is part of ndb-core. | ||
* | ||
* ndb-core is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ndb-core is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ndb-core. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { fakeAsync, TestBed, tick } from '@angular/core/testing'; | ||
import { SafeUrl } from '@angular/platform-browser'; | ||
import { EntitySchemaService } from '../../../core/entity/schema/entity-schema.service'; | ||
import { DatabaseField } from '../../../core/entity/database-field.decorator'; | ||
import { Entity } from '../../../core/entity/entity'; | ||
import { ChildPhotoService } from './child-photo.service'; | ||
import { LoadChildPhotoEntitySchemaDatatype } from './datatype-load-child-photo'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
describe('dataType load-child-photo', () => { | ||
let entitySchemaService: EntitySchemaService; | ||
let mockChildPhotoService: jasmine.SpyObj<ChildPhotoService>; | ||
|
||
beforeEach(() => { | ||
mockChildPhotoService = jasmine.createSpyObj('mockChildPhotoService', ['getImageAsyncObservable']); | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
EntitySchemaService, | ||
{ provide: ChildPhotoService, useValue: mockChildPhotoService }, | ||
], | ||
}, | ||
); | ||
|
||
entitySchemaService = TestBed.get(EntitySchemaService); | ||
entitySchemaService.registerSchemaDatatype(new LoadChildPhotoEntitySchemaDatatype(mockChildPhotoService)); | ||
}); | ||
|
||
|
||
it('schema:load-child-photo is removed from rawData to be saved', function () { | ||
class TestEntity extends Entity { | ||
@DatabaseField({dataType: 'load-child-photo'}) photo: SafeUrl; | ||
} | ||
const id = 'test1'; | ||
const entity = new TestEntity(id); | ||
entity.photo = '12345'; | ||
|
||
const rawData = entitySchemaService.transformEntityToDatabaseFormat(entity); | ||
expect(rawData.photo).toBeUndefined(); | ||
}); | ||
|
||
it('schema:load-child-photo is provided through ChildPhotoService on load', fakeAsync(() => { | ||
class TestEntity extends Entity { | ||
@DatabaseField({dataType: 'load-child-photo'}) photo: BehaviorSubject<SafeUrl>; | ||
} | ||
const id = 'test1'; | ||
const entity = new TestEntity(id); | ||
|
||
const defaultImg = 'default-img'; | ||
const mockCloudImg = 'test-img-data'; | ||
|
||
const mockImgObs = new BehaviorSubject(defaultImg); | ||
mockChildPhotoService.getImageAsyncObservable.and.returnValue(mockImgObs); | ||
|
||
const data = { | ||
_id: id, | ||
}; | ||
entitySchemaService.loadDataIntoEntity(entity, data); | ||
|
||
expect(entity.photo.value).toEqual(defaultImg); | ||
|
||
mockImgObs.next(mockCloudImg); | ||
mockImgObs.complete(); | ||
tick(); | ||
expect(entity.photo.value).toEqual(mockCloudImg); | ||
})); | ||
}); |
48 changes: 48 additions & 0 deletions
48
src/app/child-dev-project/children/child-photo-service/datatype-load-child-photo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This file is part of ndb-core. | ||
* | ||
* ndb-core is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* ndb-core is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with ndb-core. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
import { EntitySchemaDatatype } from '../../../core/entity/schema/entity-schema-datatype'; | ||
import { ChildPhotoService } from './child-photo.service'; | ||
import { EntitySchemaField } from '../../../core/entity/schema/entity-schema-field'; | ||
import { EntitySchemaService } from '../../../core/entity/schema/entity-schema.service'; | ||
import { Entity } from '../../../core/entity/entity'; | ||
|
||
/** | ||
* Dynamically load the child's photo through the ChildPhotoService during Entity loading process. | ||
*/ | ||
export class LoadChildPhotoEntitySchemaDatatype implements EntitySchemaDatatype { | ||
public readonly name = 'load-child-photo'; | ||
|
||
constructor( | ||
private childPhotoService: ChildPhotoService, | ||
) { } | ||
|
||
|
||
public transformToDatabaseFormat(value) { | ||
return undefined; | ||
} | ||
|
||
public transformToObjectFormat(value, schemaField: EntitySchemaField, schemaService: EntitySchemaService, parent: Entity) { | ||
const childDummy: any = Object.assign({}, parent); | ||
if (!childDummy.entityId) { | ||
childDummy.entityId = Entity.extractEntityIdFromId(childDummy._id); | ||
} | ||
|
||
return this.childPhotoService.getImageAsyncObservable(childDummy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.