2019-12-27 04:03:10 +08:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
|
|
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
|
|
|
import * as path from 'path';
|
|
|
|
import {PhotoProcessing} from '../../../../../src/backend/model/fileprocessing/PhotoProcessing';
|
|
|
|
|
|
|
|
|
|
|
|
describe('PhotoProcessing', () => {
|
|
|
|
|
|
|
|
// tslint:disable:no-unused-expression
|
|
|
|
it('should generate converted file path', async () => {
|
|
|
|
|
|
|
|
Config.load();
|
|
|
|
Config.Client.Media.Thumbnail.thumbnailSizes = [];
|
2020-01-08 05:28:59 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
2019-12-27 04:03:10 +08:00
|
|
|
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath,
|
|
|
|
Config.Server.Media.Photo.Converting.resolution)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath + 'noPath',
|
|
|
|
Config.Server.Media.Photo.Converting.resolution)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
|
|
|
|
{
|
2019-12-29 07:35:41 +08:00
|
|
|
const convertedPath = PhotoProcessing.generateConvertedPath(photoPath,
|
|
|
|
Config.Server.Media.Photo.Converting.resolution);
|
2019-12-27 04:03:10 +08:00
|
|
|
Config.Server.Media.Photo.Converting.resolution = <any>1;
|
|
|
|
expect(await PhotoProcessing.isValidConvertedPath(convertedPath)).to.be.false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// tslint:disable:no-unused-expression
|
|
|
|
it('should generate converted thumbnail path', async () => {
|
|
|
|
|
|
|
|
Config.load();
|
|
|
|
Config.Server.Media.Photo.Converting.resolution = <any>null;
|
|
|
|
Config.Client.Media.Thumbnail.thumbnailSizes = [10, 20];
|
2020-01-08 05:28:59 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
2019-12-27 04:03:10 +08:00
|
|
|
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
|
|
|
|
|
|
|
|
for (let i = 0; i < Config.Client.Media.Thumbnail.thumbnailSizes.length; ++i) {
|
|
|
|
const thSize = Config.Client.Media.Thumbnail.thumbnailSizes[i];
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath, thSize)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath + 'noPath', thSize)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
2019-12-29 07:35:41 +08:00
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(photoPath, 30)))
|
2019-12-27 04:03:10 +08:00
|
|
|
.to.be.false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|