0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-03-04 02:02:39 -05:00

chore: update it to test

This commit is contained in:
Juan Picado @jotadeveloper 2018-12-05 19:30:08 +01:00
parent fdbe51e7fa
commit f4e9d3208a
No known key found for this signature in database
GPG key ID: 18AC54485952D158
21 changed files with 84 additions and 84 deletions

View file

@ -55,33 +55,33 @@ describe('/ (Verdaccio Page)', () => {
await page.close();
});
it('should load without error', async () => {
test('should load without error', async () => {
const text = await page.evaluate(() => document.body.textContent);
// FIXME: perhaps it is not the best approach
expect(text).toContain('Powered by');
});
it('should match title with no packages published', async () => {
test('should match title with no packages published', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card__title').textContent);
expect(text).toMatch('No Package Published Yet');
});
it('should match title with first step', async () => {
test('should match title with first step', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card').textContent);
expect(text).toContain('$ npm adduser --registry http://0.0.0.0:55558');
});
it('should match title with second step', async () => {
test('should match title with second step', async () => {
const text = await page.evaluate(() => document.querySelector('#help-card').textContent);
expect(text).toContain('$ npm publish --registry http://0.0.0.0:55558');
});
it('should match button Login to sign in', async () => {
test('should match button Login to sign in', async () => {
await evaluateSignIn();
});
it('should click on sign in button', async () => {
test('should click on sign in button', async () => {
const signInButton = await page.$('#header--button-login');
await signInButton.click();
await page.waitFor(1000);
@ -90,7 +90,7 @@ describe('/ (Verdaccio Page)', () => {
expect(signInDialog).not.toBeNull();
});
it('should log in an user', async () => {
test('should log in an user', async () => {
// we open the dialog
await logIn();
// check whether user is logged
@ -98,7 +98,7 @@ describe('/ (Verdaccio Page)', () => {
expect(buttonLogout).toBeDefined();
});
it('should logout an user', async () => {
test('should logout an user', async () => {
// we assume the user is logged already
await clickElement('#header--button-account', { clickCount: 1, delay: 500 });
await page.waitFor(1000);
@ -107,7 +107,7 @@ describe('/ (Verdaccio Page)', () => {
await evaluateSignIn();
});
it('should check registry info dialog', async () => {
test('should check registry info dialog', async () => {
const registryInfoButton = await page.$('#header--button-registryInfo');
registryInfoButton.click();
await page.waitFor(500);
@ -119,7 +119,7 @@ describe('/ (Verdaccio Page)', () => {
closeButton.click();
});
it('should publish a package', async () => {
test('should publish a package', async () => {
await global.__SERVER__.putPackage(scopedPackageMetadata.name, scopedPackageMetadata);
await page.waitFor(1000);
await page.reload();
@ -129,7 +129,7 @@ describe('/ (Verdaccio Page)', () => {
expect(packagesList).toHaveLength(1);
});
it('should navigate to the package detail', async () => {
test('should navigate to the package detail', async () => {
const packagesList = await getPackages();
const packageItem = packagesList[0];
await packageItem.focus();
@ -139,12 +139,12 @@ describe('/ (Verdaccio Page)', () => {
expect(readmeText).toMatch('test');
});
it('should contains last sync information', async () => {
test('should contains last sync information', async () => {
const versionList = await page.$$('.sidebar-info .last-sync-item');
expect(versionList).toHaveLength(3);
});
it('should publish a protected package', async () => {
test('should publish a protected package', async () => {
await page.goto('http://0.0.0.0:55552');
await page.waitFor(500);
await global.__SERVER_PROTECTED__.putPackage(protectedPackageMetadata.name, protectedPackageMetadata);

View file

@ -37,7 +37,7 @@ describe('App', () => {
beforeEach(() => {
wrapper = mount(<App />);
});
it('loadLogo: set logo url in state', async () => {
test('loadLogo: set logo url in state', async () => {
const { loadLogo } = wrapper.instance();
await loadLogo();
expect(wrapper.state().logoUrl).toEqual(
@ -45,7 +45,7 @@ describe('App', () => {
);
});
it('toggleLoginModal: should toggle the value in state', () => {
test('toggleLoginModal: should toggle the value in state', () => {
const { toggleLoginModal } = wrapper.instance();
expect(wrapper.state().showLoginModal).toBeFalsy();
toggleLoginModal();
@ -53,7 +53,7 @@ describe('App', () => {
expect(wrapper.state('error')).toEqual({});
});
it('isUserAlreadyLoggedIn: token already available in storage', async () => {
test('isUserAlreadyLoggedIn: token already available in storage', async () => {
storage.setItem('username', 'verdaccio');
storage.setItem('token', generateTokenWithTimeRange(24));
@ -64,7 +64,7 @@ describe('App', () => {
expect(wrapper.state('user').username).toEqual('verdaccio');
});
it('handleLogout - logouts the user and clear localstorage', async () => {
test('handleLogout - logouts the user and clear localstorage', async () => {
const { handleLogout } = wrapper.instance();
storage.setItem('username', 'verdaccio');
storage.setItem('token', 'xxxx.TOKEN.xxxx');
@ -74,7 +74,7 @@ describe('App', () => {
expect(wrapper.state('isUserLoggedIn')).toBeFalsy();
});
it('doLogin - login the user successfully', async () => {
test('doLogin - login the user successfully', async () => {
const { doLogin } = wrapper.instance();
await doLogin('sam', '1234');
const result = {
@ -88,7 +88,7 @@ describe('App', () => {
expect(wrapper.state('user')).toEqual(result);
});
it('doLogin - authentication failure', async () => {
test('doLogin - authentication failure', async () => {
const { doLogin } = wrapper.instance();
await doLogin('sam', '12345');
console.log(API_ERROR.BAD_USERNAME_PASSWORD);

View file

@ -7,12 +7,12 @@ import { shallow } from 'enzyme';
import Infos from '../../../../../src/webui/components/PackageSidebar/modules/Infos/index';
describe('<PackageSidebar /> : <Infos />', () => {
it('should load the component without props', () => {
test('should load the component without props', () => {
const wrapper = shallow(<Infos/>);
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the Info component with props', () => {
test('should load the Info component with props', () => {
const props = {
homepage: 'https://www.verdaccio.org',
license: 'MIT',
@ -22,7 +22,7 @@ describe('<PackageSidebar /> : <Infos />', () => {
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the Info component with homepage only', () => {
test('should load the Info component with homepage only', () => {
const props = {
homepage: 'https://www.verdaccio.org'
}
@ -30,7 +30,7 @@ describe('<PackageSidebar /> : <Infos />', () => {
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the Info component with license only', () => {
test('should load the Info component with license only', () => {
const props = {
license: 'MIT',
}
@ -38,7 +38,7 @@ describe('<PackageSidebar /> : <Infos />', () => {
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the Info component with repository only', () => {
test('should load the Info component with repository only', () => {
const props = { repository: 'https://github.com/verdaccio/verdaccio' };
const wrapper = shallow(<Infos {...props} />);
expect(wrapper.html()).toMatchSnapshot();

View file

@ -7,12 +7,12 @@ import { shallow } from 'enzyme';
import LastSync from '../../../../../src/webui/components/PackageSidebar/modules/LastSync/index';
describe('<PackageSidebar /> : <LastSync />', () => {
it('should check the default props condition', () => {
test('should check the default props condition', () => {
const wrapper = shallow(<LastSync/>);
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the LastSync component and match snapshot', () => {
test('should load the LastSync component and match snapshot', () => {
const props = {
lastUpdated: '2017/12/14, 15:43:52',
recentReleases: [

View file

@ -9,12 +9,12 @@ import MaintainerInfo from '../../../../../src/webui/components/PackageSidebar/m
console.error = jest.fn();
describe('<PackageSidebar /> : <Maintainers /> <MaintainerInfo />', () => {
it('should throw error for required props', () => {
test('should throw error for required props', () => {
shallow(<MaintainerInfo />);
expect(console.error).toBeCalled();
});
it('should load the component and match with snapshot', () => {
test('should load the component and match with snapshot', () => {
const props = {
title: 'test-title',
name: 'test',

View file

@ -16,12 +16,12 @@ describe('<PackageSidebar /> : <Maintainers />', () => {
instance = wrapper.instance();
});
it('should match with the props', () => {
test('should match with the props', () => {
expect(wrapper.props().packageMeta).toEqual(packageMeta);
expect(wrapper.html()).toMatchSnapshot();
});
it('author shoule be equal to User NPM', () => {
test('author shoule be equal to User NPM', () => {
expect(instance.author).toEqual({
avatar:
'https://www.gravatar.com/avatar/a5a236ba477ee98908600c40cda74f4a',
@ -30,11 +30,11 @@ describe('<PackageSidebar /> : <Maintainers />', () => {
});
});
it('should get all the contributors with false for showAllContributors', () => {
test('should get all the contributors with false for showAllContributors', () => {
expect(instance.showAllContributors).toBeFalsy();
});
it('should get unique contributors', () => {
test('should get unique contributors', () => {
const result = [
{
avatar:
@ -70,7 +70,7 @@ describe('<PackageSidebar /> : <Maintainers />', () => {
expect(instance.uniqueContributors).toEqual(result);
});
it('should click on handleShowAllContributors', () => {
test('should click on handleShowAllContributors', () => {
wrapper.find('button').simulate('click');
expect(wrapper.state('showAllContributors')).toBeTruthy();
});

View file

@ -9,11 +9,11 @@ import Module from '../../../../../src/webui/components/PackageSidebar/Module/in
console.error = jest.fn();
describe('<PackageSidebar /> : <Module />', () => {
it('should error for required props', () => {
test('should error for required props', () => {
shallow(<Module />);
expect(console.error).toBeCalled();
});
it('should load module component', () => {
test('should load module component', () => {
const props = {
title: 'Test title',
description: 'Test description',

View file

@ -9,11 +9,11 @@ import ModuleContentPlaceholder from '../../../../../src/webui/components/Packag
console.error = jest.fn();
describe('<PackageSidebar /> : <ModuleContentPlaceholder />', () => {
it('should error for required props', () => {
test('should error for required props', () => {
shallow(<ModuleContentPlaceholder />);
expect(console.error).toBeCalled();
});
it('should load module component', () => {
test('should load module component', () => {
const props = {
text: 'Test text'
};

View file

@ -14,7 +14,7 @@ jest.mock('../../../../../src/webui/utils/api', () => ({
console.error = jest.fn();
describe('<PackageSidebar /> component', () => {
it('should throw error for the required props', () => {
test('should throw error for the required props', () => {
const wrapper = mount(<PackageSidebar />);
const { loadPackageData } = wrapper.instance();
expect(console.error).toBeCalled();
@ -24,7 +24,7 @@ describe('<PackageSidebar /> component', () => {
});
});
it('should load the packageMeta', () => {
test('should load the packageMeta', () => {
const wrapper = mount(<PackageSidebar packageName={'verdaccio'} />);
const { loadPackageData } = wrapper.instance();
loadPackageData('verdaccio').then(response => {

View file

@ -14,7 +14,7 @@ describe('<Footer /> component', () => {
wrapper = mount(<Footer />);
});
it('should load the initial state of Footer component', () => {
test('should load the initial state of Footer component', () => {
expect(wrapper.html()).toMatchSnapshot();
});
});

View file

@ -7,7 +7,7 @@ import Help from '../../../../src/webui/components/Help/index';
describe('<Help /> component', () => {
it('should render the component in default state', () => {
test('should render the component in default state', () => {
const wrapper = shallow(<Help />);
expect(wrapper.html()).toMatchSnapshot();
});

View file

@ -25,12 +25,12 @@ const event = {
};
describe('<LoginModal />', () => {
it('should load the component in default state', () => {
test('should load the component in default state', () => {
const wrapper = mount(<LoginModal />);
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the component with props', () => {
test('should load the component with props', () => {
const props = {
visibility: true,
error: {
@ -45,7 +45,7 @@ describe('<LoginModal />', () => {
expect(wrapper.html()).toMatchSnapshot();
});
it('onCancel: should close the login modal', () => {
test('onCancel: should close the login modal', () => {
const props = {
visibility: true,
error: {
@ -61,7 +61,7 @@ describe('<LoginModal />', () => {
expect(props.onCancel).toHaveBeenCalled();
});
it('setCredentials - should set username and password in state', () => {
test('setCredentials - should set username and password in state', () => {
const props = {
visibility: true,
error: {},
@ -78,7 +78,7 @@ describe('<LoginModal />', () => {
expect(wrapper.state('form').password.value).toEqual('1234');
});
it('validateCredentials: should validate credentials', async () => {
test('validateCredentials: should validate credentials', async () => {
const props = {
visibility: true,
error: {},
@ -106,7 +106,7 @@ describe('<LoginModal />', () => {
expect(submitCredentials).toHaveBeenCalledTimes(1);
});
it('submitCredentials: should submit credentials', async () => {
test('submitCredentials: should submit credentials', async () => {
const props = {
onSubmit: jest.fn(),
};

View file

@ -9,12 +9,12 @@ import NoItems from '../../../../src/webui/components/NoItems/index';
console.error = jest.fn();
describe('<NoItem /> component', () => {
it('should load the component in default state', () => {
test('should load the component in default state', () => {
const wrapper = mount(<NoItems />);
expect(wrapper.html()).toMatchSnapshot();
});
it('should set html from props', () => {
test('should set html from props', () => {
const props = {
text: 'This is a test string'
};

View file

@ -9,12 +9,12 @@ import NotFound from '../../../../src/webui/components/NotFound/index';
console.error = jest.fn();
describe('<NotFound /> component', () => {
it('should load the component in default state', () => {
test('should load the component in default state', () => {
const wrapper = mount(<NotFound pkg='test' />);
expect(wrapper.html()).toMatchSnapshot();
});
it('should set html from props', () => {
test('should set html from props', () => {
const props = {
pkg: 'verdaccio'
};

View file

@ -19,7 +19,7 @@ const dateOneMonthAgo = () => {
}
describe('<Package /> component', () => {
it('should load the component', () => {
test('should load the component', () => {
const props = {
name: 'verdaccio',
version: '1.0.0',
@ -50,7 +50,7 @@ describe('<Package /> component', () => {
expect(wrapper.html()).toMatchSnapshot();
});
it('should load the component without author', () => {
test('should load the component without author', () => {
const props = {
name: 'verdaccio',
version: '1.0.0',

View file

@ -10,12 +10,12 @@ import {WEB_TITLE} from '../../../../src/lib/constants';
console.error = jest.fn();
describe('<PackageDetail /> component', () => {
it('should give error for required props', () => {
test('should give error for required props', () => {
shallow(<PackageDetail />);
expect(console.error).toBeCalled();
});
it('should load the component', () => {
test('should load the component', () => {
const props = {
readMe: 'Test readme',
packageName: WEB_TITLE

View file

@ -9,7 +9,7 @@ import Help from '../../../../src/webui/components/Help/index';
import { BrowserRouter } from 'react-router-dom';
describe('<PackageList /> component', () => {
it('should load the component with no packages', () => {
test('should load the component with no packages', () => {
const props = {
packages: [],
help: true
@ -21,7 +21,7 @@ describe('<PackageList /> component', () => {
});
it('should load the component with packages', () => {
test('should load the component with packages', () => {
const props = {
packages: [
{

View file

@ -7,12 +7,12 @@ import { shallow, mount } from 'enzyme';
import Readme from '../../../../src/webui/components/Readme/index';
describe('<Readme /> component', () => {
it('should load the component in default state', () => {
test('should load the component in default state', () => {
const wrapper = mount(<Readme description='test' />);
expect(wrapper.html()).toMatchSnapshot();
});
it('should dangerously set html', () => {
test('should dangerously set html', () => {
const wrapper = shallow(<Readme description='<h1>This is a test string</h1>' />);
expect(wrapper.html()).toEqual(
'<div class="markdown-body"><h1>This is a test string</h1></div>'

View file

@ -13,30 +13,30 @@ jest.mock('.../../../../src/webui/utils/api', () => ({
}));
describe('isTokenExpire', () => {
it('isTokenExpire - token is not present', () => {
test('isTokenExpire - token is not present', () => {
expect(isTokenExpire()).toBeTruthy();
});
it('isTokenExpire - token is not a valid payload', () => {
test('isTokenExpire - token is not a valid payload', () => {
expect(isTokenExpire('not_a_valid_token')).toBeTruthy();
});
it('isTokenExpire - token should not expire in 24 hrs range', () => {
test('isTokenExpire - token should not expire in 24 hrs range', () => {
const token = generateTokenWithTimeRange(24);
expect(isTokenExpire(token)).toBeFalsy();
});
it('isTokenExpire - token should expire for current time', () => {
test('isTokenExpire - token should expire for current time', () => {
const token = generateTokenWithTimeRange();
expect(isTokenExpire(token)).toBeTruthy();
});
it('isTokenExpire - token expiration is not available', () => {
test('isTokenExpire - token expiration is not available', () => {
const token = generateTokenWithOutExpiration();
expect(isTokenExpire(token)).toBeTruthy();
});
it('isTokenExpire - token is not a valid json token', () => {
test('isTokenExpire - token is not a valid json token', () => {
const token = generateTokenWithExpirationAsString();
const result = [
'Invalid token:',
@ -49,7 +49,7 @@ describe('isTokenExpire', () => {
});
describe('makeLogin', () => {
it('makeLogin - should give error for blank username and password', async () => {
test('makeLogin - should give error for blank username and password', async () => {
const result = {
error: {
description: "Username or password can't be empty!",
@ -61,14 +61,14 @@ describe('makeLogin', () => {
expect(login).toEqual(result);
});
it('makeLogin - should login successfully', async () => {
test('makeLogin - should login successfully', async () => {
const { username, password } = { username: 'sam', password: '1234' };
const result = { token: 'TEST_TOKEN', username: 'sam' };
const login = await makeLogin(username, password);
expect(login).toEqual(result);
});
it('makeLogin - login should failed with 401', async () => {
test('makeLogin - login should failed with 401', async () => {
const result = {
error: {
description: 'bad username/password, access denied',
@ -82,7 +82,7 @@ describe('makeLogin', () => {
expect(login).toEqual(result);
});
it('makeLogin - login should failed with when no data is sent', async () => {
test('makeLogin - login should failed with when no data is sent', async () => {
const result = {
error: {
title: 'Unable to login',

View file

@ -5,7 +5,7 @@ jest.mock('../../../../src/webui/utils/api', () => ({
}));
describe('logo', () => {
it('loadLogo - should load verdaccio logo', async () => {
test('loadLogo - should load verdaccio logo', async () => {
const url = await logo();
expect(url).toEqual('http://localhost/-/static/logo.png');
});

View file

@ -11,14 +11,14 @@ import {
import { packageMeta } from '../components/store/packageMeta';
describe('formatLicense', () => {
it('should check license field different values', () => {
test('should check license field different values', () => {
expect(formatLicense('MIT')).toEqual('MIT');
});
it('should check license field for object value', () => {
test('should check license field for object value', () => {
const license = { type: 'ISC', url: 'https://opensource.org/licenses/ISC' };
expect(formatLicense(license)).toEqual('ISC');
});
it('should check license field for other value', () => {
test('should check license field for other value', () => {
expect(formatLicense(null)).toBeNull();
expect(formatLicense({})).toBeNull();
expect(formatLicense([])).toBeNull();
@ -26,18 +26,18 @@ describe('formatLicense', () => {
});
describe('formatRepository', () => {
it('should check repository field different values', () => {
test('should check repository field different values', () => {
const repository = 'https://github.com/verdaccio/verdaccio';
expect(formatRepository(repository)).toEqual(repository);
});
it('should check repository field for object value', () => {
test('should check repository field for object value', () => {
const license = {
type: 'git',
url: 'https://github.com/verdaccio/verdaccio'
};
expect(formatRepository(license)).toEqual(license.url);
});
it('should check repository field for other value', () => {
test('should check repository field for other value', () => {
expect(formatRepository(null)).toBeNull();
expect(formatRepository({})).toBeNull();
expect(formatRepository([])).toBeNull();
@ -45,11 +45,11 @@ describe('formatRepository', () => {
});
describe('formatAuthor', () => {
it('should check author field different values', () => {
test('should check author field different values', () => {
const author = 'verdaccioNpm';
expect(formatAuthor(author)).toEqual(author);
});
it('should check author field for object value', () => {
test('should check author field for object value', () => {
const license = {
name: 'Verdaccion NPM',
email: 'verdaccio@verdaccio.org',
@ -57,7 +57,7 @@ describe('formatAuthor', () => {
};
expect(formatAuthor(license)).toEqual('Verdaccion NPM');
});
it('should check author field for other value', () => {
test('should check author field for other value', () => {
expect(formatAuthor(null)).toBeNull();
expect(formatAuthor({})).toBeNull();
expect(formatAuthor([])).toBeNull();
@ -65,14 +65,14 @@ describe('formatAuthor', () => {
});
describe('formatDate', () => {
it('should format the date', () => {
test('should format the date', () => {
const date = 1532211072138;
expect(formatDate(date)).toEqual('2018/07/21, 22:11:12');
});
});
describe('formatDateDistance', () => {
it('should calculate the distance', () => {
test('should calculate the distance', () => {
const dateOneMonthAgo = () => {
const date = new Date();
date.setMonth(date.getMonth() - 1);
@ -84,20 +84,20 @@ describe('formatDateDistance', () => {
});
describe('getLastUpdatedPackageTime', () => {
it('should get the last update time', () => {
test('should get the last update time', () => {
const lastUpdated = packageMeta._uplinks;
expect(getLastUpdatedPackageTime(lastUpdated)).toEqual(
'2018/07/22, 22:11:12'
);
});
it('should get the last update time for blank uplink', () => {
test('should get the last update time for blank uplink', () => {
const lastUpdated = {};
expect(getLastUpdatedPackageTime(lastUpdated)).toEqual('');
});
});
describe('getRecentReleases', () => {
it('should get the recent releases', () => {
test('should get the recent releases', () => {
const { time } = packageMeta;
const result = [
{ time: '2017/12/14, 15:43:27', version: '2.7.1' },