debian-mirror-gitlab/spec/frontend/packages/shared/utils_spec.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { PackageType, TrackingCategories } from '~/packages/shared/constants';
2020-10-24 23:57:45 +05:30
import {
packageTypeToTrackCategory,
beautifyPath,
getPackageTypeLabel,
getCommitLink,
} from '~/packages/shared/utils';
import { packageList } from '../mock_data';
describe('Packages shared utils', () => {
describe('packageTypeToTrackCategory', () => {
it('prepend UI to package category', () => {
expect(packageTypeToTrackCategory()).toMatchInlineSnapshot(`"UI::undefined"`);
});
2021-03-08 18:12:59 +05:30
it.each(Object.keys(PackageType))('returns a correct category string for %s', (packageKey) => {
2020-10-24 23:57:45 +05:30
const packageName = PackageType[packageKey];
expect(packageTypeToTrackCategory(packageName)).toBe(
`UI::${TrackingCategories[packageName]}`,
);
});
});
describe('beautifyPath', () => {
it('returns a string with spaces around /', () => {
expect(beautifyPath('foo/bar')).toBe('foo / bar');
});
it('does not fail for empty string', () => {
expect(beautifyPath()).toBe('');
});
});
describe('getPackageTypeLabel', () => {
describe.each`
packageType | expectedResult
${'conan'} | ${'Conan'}
${'maven'} | ${'Maven'}
2021-04-17 20:07:23 +05:30
${'npm'} | ${'npm'}
2020-10-24 23:57:45 +05:30
${'nuget'} | ${'NuGet'}
2021-01-03 14:25:43 +05:30
${'pypi'} | ${'PyPI'}
2021-04-29 21:17:54 +05:30
${'rubygems'} | ${'RubyGems'}
2020-10-24 23:57:45 +05:30
${'composer'} | ${'Composer'}
2021-09-30 23:02:18 +05:30
${'debian'} | ${'Debian'}
${'helm'} | ${'Helm'}
2020-10-24 23:57:45 +05:30
${'foo'} | ${null}
`(`package type`, ({ packageType, expectedResult }) => {
it(`${packageType} should show as ${expectedResult}`, () => {
expect(getPackageTypeLabel(packageType)).toBe(expectedResult);
});
});
});
describe('getCommitLink', () => {
it('returns a relative link when isGroup is false', () => {
const link = getCommitLink(packageList[0], false);
expect(link).toContain('../commit');
});
describe('when isGroup is true', () => {
it('returns an absolute link matching project path', () => {
const mavenPackage = packageList[0];
const link = getCommitLink(mavenPackage, true);
expect(link).toContain(`/${mavenPackage.project_path}/commit`);
});
});
});
});