mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import configUtils, { transElemText, replaceParams, getProp } from '@/utils/common-config';
|
|
|
|
describe('index', () => {
|
|
it('transElemText', () => {
|
|
const $ = () => 'RSSHub';
|
|
expect(transElemText($, '$()')).toBe('RSSHub');
|
|
});
|
|
|
|
it('replaceParams', () => {
|
|
const $ = () => 'RSSHub';
|
|
const data = {
|
|
params: {
|
|
title: 'RSSHub',
|
|
},
|
|
title: '%title%',
|
|
};
|
|
expect(replaceParams(data, data.title, $)).toBe('RSSHub');
|
|
});
|
|
|
|
it('getProp', () => {
|
|
const $ = () => 'RSSHub';
|
|
const data = {
|
|
title: 'RSSHub',
|
|
};
|
|
expect(getProp(data, ['title'], $)).toBe('RSSHub');
|
|
expect(getProp(data, 'title', $)).toBe('RSSHub');
|
|
});
|
|
|
|
it('all', () => {
|
|
const $ = () => 'RSSHub';
|
|
const data = {
|
|
params: {
|
|
title: '$()',
|
|
},
|
|
title: '%title%',
|
|
};
|
|
expect(getProp(data, ['title'], $)).toBe('RSSHub');
|
|
});
|
|
|
|
it('buildData', async () => {
|
|
const data = await configUtils({
|
|
link: 'http://rsshub.test/buildData',
|
|
url: 'http://rsshub.test/buildData',
|
|
title: `%title%`,
|
|
params: {
|
|
title: 'buildData',
|
|
},
|
|
item: {
|
|
item: '.content li',
|
|
title: `$('a').text() + ' - %title%'`,
|
|
link: `$('a').attr('href')`,
|
|
description: `$('.description').html()`,
|
|
},
|
|
});
|
|
|
|
expect(data).toMatchObject({
|
|
link: 'http://rsshub.test/buildData',
|
|
title: 'buildData',
|
|
item: [
|
|
{
|
|
description: 'RSSHub1',
|
|
guid: undefined,
|
|
link: '/1',
|
|
pubDate: undefined,
|
|
title: '1 - buildData',
|
|
},
|
|
{
|
|
description: 'RSSHub2',
|
|
guid: undefined,
|
|
link: '/2',
|
|
pubDate: undefined,
|
|
title: '2 - buildData',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|