2018-12-21 06:02:49 +08:00
|
|
|
import {expect} from 'chai';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {MetadataLoader} from '../../../../../src/backend/model/threading/MetadataLoader';
|
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
2018-12-21 06:02:49 +08:00
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
describe('MetadataLoader', () => {
|
|
|
|
|
|
|
|
it('should load png', async () => {
|
2020-01-08 05:28:59 +08:00
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/test_png.png'));
|
2018-12-22 08:14:13 +08:00
|
|
|
delete data.creationDate; // creation time for png not supported
|
2020-09-13 20:43:03 +08:00
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/test_png.json'));
|
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
2018-12-21 06:02:49 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should load jpg', async () => {
|
2020-01-08 05:28:59 +08:00
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
|
2019-01-14 00:38:39 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
2018-12-21 06:02:49 +08:00
|
|
|
});
|
|
|
|
|
2020-02-08 23:31:29 +08:00
|
|
|
it('should load miss dated jpg', async () => {
|
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/date_issue.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/date_issue.json'));
|
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2019-01-19 17:07:06 +08:00
|
|
|
|
|
|
|
it('should load jpg 2', async () => {
|
2020-01-08 05:28:59 +08:00
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/old_photo.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/old_photo.json'));
|
2019-01-19 17:07:06 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2021-03-27 17:23:48 +08:00
|
|
|
describe('should load jpg with proper height and orientation', () => {
|
|
|
|
it('jpg 1', async () => {
|
2021-03-28 19:24:55 +08:00
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif.json'));
|
2021-03-27 17:23:48 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
it('jpg 2', async () => {
|
2021-03-28 19:24:55 +08:00
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/orientation/broken_orientation_exif2.json'));
|
2021-03-27 17:23:48 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-28 19:24:55 +08:00
|
|
|
describe('should read orientation', () => {
|
|
|
|
for (let i = 0; i <= 8; ++i) {
|
|
|
|
it('Landscape ' + i, async () => {
|
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/Landscape_' + i + '.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/orientation/Landscape.json'));
|
|
|
|
expected.orientation = i;
|
|
|
|
delete data.fileSize;
|
|
|
|
delete expected.fileSize;
|
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
it('Portrait ' + i, async () => {
|
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/orientation/Portrait_' + i + '.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/orientation/Portrait.json'));
|
|
|
|
expected.orientation = i;
|
|
|
|
delete data.fileSize;
|
|
|
|
delete expected.fileSize;
|
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-02-16 05:19:30 +08:00
|
|
|
|
2020-12-27 21:35:30 +08:00
|
|
|
it('should load jpg edited with exiftool', async () => {
|
|
|
|
const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/exiftool.jpg'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/exiftool.json'));
|
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-02-16 05:19:30 +08:00
|
|
|
it('should load mp4', async () => {
|
2020-01-08 05:28:59 +08:00
|
|
|
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video.mp4'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/video.json'));
|
2019-02-16 05:19:30 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
|
|
|
|
2020-09-02 19:23:30 +08:00
|
|
|
it('should respect mp4 rotate transformation', async () => {
|
|
|
|
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video_rotate.mp4'));
|
|
|
|
const expected = require(path.join(__dirname, '/../../../assets/video_rotate.json'));
|
2021-03-27 17:23:48 +08:00
|
|
|
delete data.duration;
|
|
|
|
delete expected.duration;
|
2020-09-02 19:23:30 +08:00
|
|
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
|
|
|
});
|
2019-02-16 05:19:30 +08:00
|
|
|
|
2018-12-21 06:02:49 +08:00
|
|
|
});
|