1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

bixing tests

This commit is contained in:
Patrik J. Braun 2018-11-24 14:51:47 +01:00
parent 930c1a2933
commit 8ef3d7d0b6
3 changed files with 40 additions and 7 deletions

View File

@ -103,7 +103,7 @@ describe('GalleryManager', () => {
removeIds(selected); removeIds(selected);
subDir.isPartial = true; subDir.isPartial = true;
delete subDir.directories; delete subDir.directories;
expect(selected).to.deep.equal(parent); expect(Utils.clone(selected)).to.deep.equal(Utils.clone(parent));
}); });
@ -137,7 +137,7 @@ describe('GalleryManager', () => {
delete subDir.parent; delete subDir.parent;
removeIds(selected); removeIds(selected);
// selected.directories[0].parent = selected; // selected.directories[0].parent = selected;
expect(selected).to.deep.equal(subDir); expect(Utils.clone(selected)).to.deep.equal(Utils.clone(subDir));
}); });

View File

@ -19,7 +19,7 @@ import {MediaDimensionEntity} from '../../../../../backend/model/sql/enitites/Me
import {OrientationTypes} from 'ts-exif-parser'; import {OrientationTypes} from 'ts-exif-parser';
import {Utils} from '../../../../../common/Utils'; import {Utils} from '../../../../../common/Utils';
import {TestHelper} from './TestHelper'; import {TestHelper} from './TestHelper';
import {afterEach, beforeEach, describe, it} from '@angular/core/testing/src/testing_internal'; import {VideoEntity} from '../../../../../backend/model/sql/enitites/VideoEntity';
describe('SearchManager', () => { describe('SearchManager', () => {
@ -30,6 +30,7 @@ describe('SearchManager', () => {
const dir = TestHelper.getDirectoryEntry(); const dir = TestHelper.getDirectoryEntry();
const p = TestHelper.getPhotoEntry1(dir); const p = TestHelper.getPhotoEntry1(dir);
const p2 = TestHelper.getPhotoEntry2(dir); const p2 = TestHelper.getPhotoEntry2(dir);
const v = TestHelper.getVideoEntry1(dir);
const setUpSqlDB = async () => { const setUpSqlDB = async () => {
if (fs.existsSync(dbPath)) { if (fs.existsSync(dbPath)) {
@ -49,6 +50,7 @@ describe('SearchManager', () => {
await conn.getRepository(DirectoryEntity).save(p.directory); await conn.getRepository(DirectoryEntity).save(p.directory);
await pr.save(p); await pr.save(p);
await pr.save(p2); await pr.save(p2);
await conn.getRepository(VideoEntity).save(v);
await SQLConnection.close(); await SQLConnection.close();
}; };
@ -99,8 +101,10 @@ describe('SearchManager', () => {
new AutoCompleteItem('wars dir', SearchTypes.directory), new AutoCompleteItem('wars dir', SearchTypes.directory),
new AutoCompleteItem('Research City', SearchTypes.position)].sort(cmp)); new AutoCompleteItem('Research City', SearchTypes.position)].sort(cmp));
expect((await sm.autocomplete('sw')).sort(cmp)).to.deep.equal([new AutoCompleteItem('sw1', SearchTypes.image), expect((await sm.autocomplete('sw')).sort(cmp)).to.deep.equal([new AutoCompleteItem('sw1', SearchTypes.photo),
new AutoCompleteItem('sw2', SearchTypes.image)].sort(cmp)); new AutoCompleteItem('sw2', SearchTypes.photo), new AutoCompleteItem(v.name, SearchTypes.video)].sort(cmp));
expect((await sm.autocomplete(v.name)).sort(cmp)).to.deep.equal([new AutoCompleteItem(v.name, SearchTypes.video)]);
}); });
@ -112,7 +116,7 @@ describe('SearchManager', () => {
searchText: 'sw', searchText: 'sw',
searchType: null, searchType: null,
directories: [], directories: [],
media: [p, p2], media: [p, p2,v],
resultOverflow: false resultOverflow: false
})); }));
@ -156,7 +160,7 @@ describe('SearchManager', () => {
expect(Utils.clone(await sm.instantSearch('sw'))).to.deep.equal(Utils.clone({ expect(Utils.clone(await sm.instantSearch('sw'))).to.deep.equal(Utils.clone({
searchText: 'sw', searchText: 'sw',
directories: [], directories: [],
media: [p, p2], media: [p, p2,v],
resultOverflow: false resultOverflow: false
})); }));

View File

@ -9,6 +9,7 @@ import * as path from 'path';
import {OrientationTypes} from 'ts-exif-parser'; import {OrientationTypes} from 'ts-exif-parser';
import {DirectoryEntity} from '../../../../../backend/model/sql/enitites/DirectoryEntity'; import {DirectoryEntity} from '../../../../../backend/model/sql/enitites/DirectoryEntity';
import {Utils} from '../../../../../common/Utils'; import {Utils} from '../../../../../common/Utils';
import {VideoEntity, VideoMetadataEntity} from '../../../../../backend/model/sql/enitites/VideoEntity';
export class TestHelper { export class TestHelper {
@ -65,6 +66,28 @@ export class TestHelper {
return d; return d;
} }
public static getVideoEntry(dir: DirectoryEntity) {
const sd = new MediaDimensionEntity();
sd.height = 200;
sd.width = 200;
const m = new VideoMetadataEntity();
m.keywords = null;
m.size = sd;
m.creationDate = Date.now();
m.fileSize = 123456789;
m.duration = 10000;
m.bitRate = 4000;
const d = new VideoEntity();
d.name = 'test video.jpg';
d.directory = dir;
d.metadata = m;
return d;
}
public static getPhotoEntry1(dir: DirectoryEntity) { public static getPhotoEntry1(dir: DirectoryEntity) {
const p = TestHelper.getPhotoEntry(dir); const p = TestHelper.getPhotoEntry(dir);
@ -75,6 +98,12 @@ export class TestHelper {
return p; return p;
} }
public static getVideoEntry1(dir: DirectoryEntity) {
const p = TestHelper.getVideoEntry(dir);
p.name = 'swVideo';
return p;
}
public static getPhotoEntry2(dir: DirectoryEntity) { public static getPhotoEntry2(dir: DirectoryEntity) {
const p = TestHelper.getPhotoEntry(dir); const p = TestHelper.getPhotoEntry(dir);