0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/unit/webui/utils/package.spec.js

113 lines
3.6 KiB
JavaScript
Raw Normal View History

import {
formatLicense,
formatRepository,
formatDate,
formatDateDistance,
getLastUpdatedPackageTime,
getRecentReleases,
formatAuthor, DEFAULT_USER
} from '../../../../src/webui/utils/package';
import { packageMeta } from '../components/store/packageMeta';
describe('formatLicense', () => {
2018-12-05 13:30:08 -05:00
test('should check license field different values', () => {
expect(formatLicense('MIT')).toEqual('MIT');
});
2018-12-05 13:30:08 -05:00
test('should check license field for object value', () => {
const license = { type: 'ISC', url: 'https://opensource.org/licenses/ISC' };
expect(formatLicense(license)).toEqual('ISC');
});
2018-12-05 13:30:08 -05:00
test('should check license field for other value', () => {
expect(formatLicense(null)).toBeNull();
expect(formatLicense({})).toBeNull();
expect(formatLicense([])).toBeNull();
});
});
describe('formatRepository', () => {
2018-12-05 13:30:08 -05:00
test('should check repository field different values', () => {
const repository = 'https://github.com/verdaccio/verdaccio';
expect(formatRepository(repository)).toEqual(repository);
});
2018-12-05 13:30:08 -05:00
test('should check repository field for object value', () => {
const license = {
type: 'git',
url: 'https://github.com/verdaccio/verdaccio'
};
expect(formatRepository(license)).toEqual(license.url);
});
2018-12-05 13:30:08 -05:00
test('should check repository field for other value', () => {
expect(formatRepository(null)).toBeNull();
expect(formatRepository({})).toBeNull();
expect(formatRepository([])).toBeNull();
});
});
describe('formatAuthor', () => {
2018-12-05 13:30:08 -05:00
test('should check author field different values', () => {
const author = 'verdaccioNpm';
expect(formatAuthor(author).name).toEqual(author);
});
2018-12-05 13:30:08 -05:00
test('should check author field for object value', () => {
const user = {
name: 'Verdaccion NPM',
email: 'verdaccio@verdaccio.org',
url: 'https://verdaccio.org'
};
expect(formatAuthor(user).avatar).toEqual('');
expect(formatAuthor(user).email).toEqual(user.email);
expect(formatAuthor(user).name).toEqual(user.name);
});
2018-12-05 13:30:08 -05:00
test('should check author field for other value', () => {
expect(formatAuthor(null).name).toEqual(DEFAULT_USER);
expect(formatAuthor({}).name).toEqual(DEFAULT_USER);
expect(formatAuthor([]).name).toEqual(DEFAULT_USER);
});
});
describe('formatDate', () => {
2018-12-05 13:30:08 -05:00
test('should format the date', () => {
const date = 1532211072138;
Package Refactor (#1145) * chore: fix unit test, forgotten line on merge chore: add node 11 to circleci (#1153) chore: fix the use of Node 11 in CircleCI (#1154) refactor: added css in js, new design, added types feat: added Tag component refactor: added modifiers refactor: replaced by polished ellipsis refactor: added types, new design and css in js refactor: removed ul. it needs refactor refactor: changed media queries refactor: changed icon height refactor: changed Header media queries refactor: removed margin top refactor: updated snapshots refactor: removed unnecessary format author refactor: added license icon & changed size refactor: changed media queries refactor: added icon size refactor: changed media queries refactor: updated snap refactor: replaced Description by Details refactor: updated tests refactor: fixed modifiers type feat: created missed types fix: fixed types fix: fixed prop type fix: fixed undefined prop refactor: replaced label by name refactor: updated snap refactor: moved polished to dev refactor: changed formatAuthor and pkg author type fix: removed incorrect meta's type refactor: removed polished refactor: added spacing & ellipsis mixin refactor: added modifier type refactor: changed datetime format refactor: updated snapshots refactor: rreplaced polished by mixins func * refactor: updated styled * fix: added missed semicolon * refactor: updated media * refactor: updated tests * refactor: organized modifiers * refactor: removed unused imports * refactor: design adjusts * refactor: updated snapshot * refactor: changed minor things * refactor: updated snapshots * refactor: commented tests. fix later
2018-12-13 13:05:47 -05:00
expect(formatDate(date)).toEqual('21.07.2018, 22:11:12');
});
});
describe('formatDateDistance', () => {
2018-12-05 13:30:08 -05:00
test('should calculate the distance', () => {
const dateOneMonthAgo = () => {
const date = new Date();
date.setMonth(date.getMonth() - 1);
return date;
};
const date = dateOneMonthAgo();
expect(formatDateDistance(date)).toEqual('about 1 month');
});
});
describe('getLastUpdatedPackageTime', () => {
2018-12-05 13:30:08 -05:00
test('should get the last update time', () => {
const lastUpdated = packageMeta._uplinks;
expect(getLastUpdatedPackageTime(lastUpdated)).toEqual(
Package Refactor (#1145) * chore: fix unit test, forgotten line on merge chore: add node 11 to circleci (#1153) chore: fix the use of Node 11 in CircleCI (#1154) refactor: added css in js, new design, added types feat: added Tag component refactor: added modifiers refactor: replaced by polished ellipsis refactor: added types, new design and css in js refactor: removed ul. it needs refactor refactor: changed media queries refactor: changed icon height refactor: changed Header media queries refactor: removed margin top refactor: updated snapshots refactor: removed unnecessary format author refactor: added license icon & changed size refactor: changed media queries refactor: added icon size refactor: changed media queries refactor: updated snap refactor: replaced Description by Details refactor: updated tests refactor: fixed modifiers type feat: created missed types fix: fixed types fix: fixed prop type fix: fixed undefined prop refactor: replaced label by name refactor: updated snap refactor: moved polished to dev refactor: changed formatAuthor and pkg author type fix: removed incorrect meta's type refactor: removed polished refactor: added spacing & ellipsis mixin refactor: added modifier type refactor: changed datetime format refactor: updated snapshots refactor: rreplaced polished by mixins func * refactor: updated styled * fix: added missed semicolon * refactor: updated media * refactor: updated tests * refactor: organized modifiers * refactor: removed unused imports * refactor: design adjusts * refactor: updated snapshot * refactor: changed minor things * refactor: updated snapshots * refactor: commented tests. fix later
2018-12-13 13:05:47 -05:00
'22.07.2018, 22:11:12'
);
});
2018-12-05 13:30:08 -05:00
test('should get the last update time for blank uplink', () => {
const lastUpdated = {};
expect(getLastUpdatedPackageTime(lastUpdated)).toEqual('');
});
});
describe('getRecentReleases', () => {
2018-12-05 13:30:08 -05:00
test('should get the recent releases', () => {
const { time } = packageMeta;
const result = [
Package Refactor (#1145) * chore: fix unit test, forgotten line on merge chore: add node 11 to circleci (#1153) chore: fix the use of Node 11 in CircleCI (#1154) refactor: added css in js, new design, added types feat: added Tag component refactor: added modifiers refactor: replaced by polished ellipsis refactor: added types, new design and css in js refactor: removed ul. it needs refactor refactor: changed media queries refactor: changed icon height refactor: changed Header media queries refactor: removed margin top refactor: updated snapshots refactor: removed unnecessary format author refactor: added license icon & changed size refactor: changed media queries refactor: added icon size refactor: changed media queries refactor: updated snap refactor: replaced Description by Details refactor: updated tests refactor: fixed modifiers type feat: created missed types fix: fixed types fix: fixed prop type fix: fixed undefined prop refactor: replaced label by name refactor: updated snap refactor: moved polished to dev refactor: changed formatAuthor and pkg author type fix: removed incorrect meta's type refactor: removed polished refactor: added spacing & ellipsis mixin refactor: added modifier type refactor: changed datetime format refactor: updated snapshots refactor: rreplaced polished by mixins func * refactor: updated styled * fix: added missed semicolon * refactor: updated media * refactor: updated tests * refactor: organized modifiers * refactor: removed unused imports * refactor: design adjusts * refactor: updated snapshot * refactor: changed minor things * refactor: updated snapshots * refactor: commented tests. fix later
2018-12-13 13:05:47 -05:00
{ time: '14.12.2017, 15:43:27', version: '2.7.1' },
{ time: '05.12.2017, 23:25:06', version: '2.7.0' },
{ time: '08.11.2017, 22:47:16', version: '2.6.6' }
];
expect(getRecentReleases(time)).toEqual(result);
expect(getRecentReleases()).toEqual([]);
});
});