1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/test/backend/unit/model/fileprocessing/PhotoProcessing.spec.ts

64 lines
2.3 KiB
TypeScript
Raw Normal View History

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', () => {
2022-04-05 01:37:31 +08:00
/* eslint-disable no-unused-expressions,@typescript-eslint/no-unused-expressions */
2019-12-27 04:03:10 +08:00
it('should generate converted file path', async () => {
Config.load();
Config.Client.Media.Thumbnail.thumbnailSizes = [];
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);
Config.Server.Media.Photo.Converting.resolution = (1 as any);
2019-12-27 04:03:10 +08:00
expect(await PhotoProcessing.isValidConvertedPath(convertedPath)).to.be.false;
}
});
2022-04-05 01:37:31 +08:00
/* eslint-disable no-unused-expressions,@typescript-eslint/no-unused-expressions */
2019-12-27 04:03:10 +08:00
it('should generate converted thumbnail path', async () => {
Config.load();
Config.Server.Media.Photo.Converting.resolution = (null as any);
2019-12-27 04:03:10 +08:00
Config.Client.Media.Thumbnail.thumbnailSizes = [10, 20];
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
2019-12-27 04:03:10 +08:00
const photoPath = path.join(ProjectPath.ImageFolder, 'test_png.png');
for (const thSize of Config.Client.Media.Thumbnail.thumbnailSizes) {
2019-12-27 04:03:10 +08:00
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;
});
});