2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2023-08-01 17:16:39 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey, cherrypick contributors
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-03-09 12:48:39 +09:00
|
|
|
import { describe, test, assert, afterEach } from 'vitest';
|
|
|
|
import { render, cleanup, type RenderResult } from '@testing-library/vue';
|
|
|
|
import './init';
|
2023-09-05 18:24:34 +09:00
|
|
|
import type * as Misskey from 'cherrypick-js';
|
2023-04-05 14:30:03 +09:00
|
|
|
import { components } from '@/components';
|
2023-03-09 12:48:39 +09:00
|
|
|
import { directives } from '@/directives';
|
|
|
|
import MkMediaImage from '@/components/MkMediaImage.vue';
|
|
|
|
|
|
|
|
describe('MkMediaImage', () => {
|
2023-09-04 13:33:38 +09:00
|
|
|
const renderMediaImage = (image: Partial<Misskey.entities.DriveFile>): RenderResult => {
|
2023-03-09 12:48:39 +09:00
|
|
|
return render(MkMediaImage, {
|
2023-04-05 14:30:03 +09:00
|
|
|
props: {
|
|
|
|
image: {
|
|
|
|
id: 'xxxxxxxx',
|
|
|
|
createdAt: (new Date()).toJSON(),
|
|
|
|
isSensitive: false,
|
|
|
|
name: 'example.png',
|
|
|
|
thumbnailUrl: null,
|
|
|
|
url: '',
|
|
|
|
type: 'application/octet-stream',
|
|
|
|
size: 1,
|
|
|
|
md5: '15eca7fba0480996e2245f5185bf39f2',
|
|
|
|
blurhash: null,
|
|
|
|
comment: null,
|
|
|
|
properties: {},
|
|
|
|
...image,
|
|
|
|
} as DriveFile,
|
|
|
|
},
|
|
|
|
global: { directives, components },
|
2023-03-09 12:48:39 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Attaching JPG should show no indicator', async () => {
|
|
|
|
const mkMediaImage = renderMediaImage({
|
|
|
|
type: 'image/jpeg',
|
|
|
|
});
|
|
|
|
const [gif, alt] = await Promise.all([
|
|
|
|
mkMediaImage.queryByText('GIF'),
|
|
|
|
mkMediaImage.queryByText('ALT'),
|
|
|
|
]);
|
|
|
|
assert.ok(!gif);
|
|
|
|
assert.ok(!alt);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Attaching GIF should show a GIF indicator', async () => {
|
|
|
|
const mkMediaImage = renderMediaImage({
|
|
|
|
type: 'image/gif',
|
|
|
|
});
|
|
|
|
const [gif, alt] = await Promise.all([
|
|
|
|
mkMediaImage.queryByText('GIF'),
|
|
|
|
mkMediaImage.queryByText('ALT'),
|
|
|
|
]);
|
|
|
|
assert.ok(gif);
|
|
|
|
assert.ok(!alt);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Attaching APNG should show a GIF indicator', async () => {
|
|
|
|
const mkMediaImage = renderMediaImage({
|
|
|
|
type: 'image/apng',
|
|
|
|
});
|
|
|
|
const [gif, alt] = await Promise.all([
|
|
|
|
mkMediaImage.queryByText('GIF'),
|
|
|
|
mkMediaImage.queryByText('ALT'),
|
|
|
|
]);
|
|
|
|
assert.ok(gif);
|
|
|
|
assert.ok(!alt);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Attaching image with an alt message should show an ALT indicator', async () => {
|
|
|
|
const mkMediaImage = renderMediaImage({
|
|
|
|
type: 'image/png',
|
2023-06-20 17:29:46 +09:00
|
|
|
comment: 'CherryPickのロゴです',
|
2023-03-09 12:48:39 +09:00
|
|
|
});
|
|
|
|
const [gif, alt] = await Promise.all([
|
|
|
|
mkMediaImage.queryByText('GIF'),
|
|
|
|
mkMediaImage.queryByText('ALT'),
|
|
|
|
]);
|
|
|
|
assert.ok(!gif);
|
|
|
|
assert.ok(alt);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Attaching GIF image with an alt message should show a GIF and an ALT indicator', async () => {
|
|
|
|
const mkMediaImage = renderMediaImage({
|
|
|
|
type: 'image/gif',
|
2023-06-20 17:29:46 +09:00
|
|
|
comment: 'CherryPickのロゴです',
|
2023-03-09 12:48:39 +09:00
|
|
|
});
|
|
|
|
const [gif, alt] = await Promise.all([
|
|
|
|
mkMediaImage.queryByText('GIF'),
|
|
|
|
mkMediaImage.queryByText('ALT'),
|
|
|
|
]);
|
|
|
|
assert.ok(gif);
|
|
|
|
assert.ok(alt);
|
|
|
|
});
|
|
|
|
});
|