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';
|
2023-10-14 23:54:21 +08:00
|
|
|
import {PhotoProcessing} from '../../../../../src/backend/model/fileaccess/fileprocessing/PhotoProcessing';
|
2019-12-27 04:03:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
describe('PhotoProcessing', () => {
|
|
|
|
|
2023-11-27 05:47:57 +08:00
|
|
|
it('should generate converted gif file path', async () => {
|
|
|
|
|
|
|
|
await Config.load();
|
2024-01-03 18:06:19 +08:00
|
|
|
Config.Media.Photo.thumbnailSizes = [];
|
2023-11-27 05:47:57 +08:00
|
|
|
ProjectPath.ImageFolder = path.join(__dirname, './../../../assets');
|
|
|
|
const gifPath = path.join(ProjectPath.ImageFolder, 'earth.gif');
|
|
|
|
|
|
|
|
|
2024-01-03 18:06:19 +08:00
|
|
|
for (const thSize of Config.Media.Photo.thumbnailSizes) {
|
|
|
|
Config.Media.Photo.animateGif = true;
|
|
|
|
|
|
|
|
expect(await PhotoProcessing
|
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(gifPath, thSize)))
|
|
|
|
.to.be.true;
|
|
|
|
|
|
|
|
Config.Media.Photo.animateGif = false;
|
|
|
|
expect(await PhotoProcessing
|
|
|
|
.isValidConvertedPath(PhotoProcessing.generateConvertedPath(gifPath, thSize)))
|
|
|
|
.to.be.true;
|
|
|
|
}
|
2023-11-27 05:47:57 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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 () => {
|
|
|
|
|
2023-09-21 03:37:33 +08:00
|
|
|
await Config.load();
|
2024-01-03 18:06:19 +08:00
|
|
|
Config.Media.Photo.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');
|
|
|
|
|
2024-01-03 18:06:19 +08:00
|
|
|
for (const thSize of Config.Media.Photo.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;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|