Merge branch 'master' into juanpicado-patch-1

This commit is contained in:
Juan Picado @jotadeveloper 2019-09-13 23:52:33 -07:00 committed by GitHub
commit b03e6d6c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 35386 additions and 4120 deletions

View File

@ -1,31 +1,25 @@
version: 2
aliases:
- &repo_path
~/ui-theme
- &defaults
working_directory: ~/ui-theme
- &node11_executor
working_directory: *repo_path
- &node_latest_executor
docker:
- image: circleci/node:11.10.1
- &node8_executor
- image: circleci/node:latest
- &node_lts_executor
docker:
- image: circleci/node:8
- &node10_executor
docker:
- image: circleci/node:10
- image: circleci/node:lts
- &default_executor
<<: *node10_executor
- &repo_key
repo-{{ .Branch }}-{{ .Revision }}
- &coverage_key
coverage-{{ .Branch }}-{{ .Revision }}
- &base_config_key
base-config-{{ .Branch }}-{{ .Revision }}
<<: *node_latest_executor
- &yarn_cache_key
yarn-sha-{{ checksum "yarn.lock" }}
- &coverage_key
coverage-{{ .Branch }}-{{ .Revision }}
- &restore_repo
restore_cache:
keys:
- *repo_key
attach_workspace:
at: *repo_path
- &ignore_non_dev_branches
filters:
tags:
@ -36,7 +30,7 @@ aliases:
- &execute_on_release
filters:
tags:
only: /(v)?[0-9]+(\.[0-9]+)*/
only: /v?[0-9]+(\.[0-9]+)*([-+\.][a-zA-Z0-9]+)*/
branches:
ignore:
- /.*/
@ -48,21 +42,11 @@ jobs:
steps:
- *restore_repo
- checkout
- restore_cache:
key: *base_config_key
- run:
name: 'Base environment setup'
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- save_cache:
key: *base_config_key
paths:
- ~/.npmrc
- ~/.gitconfig
- restore_cache:
key: *yarn_cache_key
- run:
name: Install Js dependencies
command: yarn install --no-progress --registry https://registry.verdaccio.org --no-lockfile
name: Install dependencies
command: yarn install --frozen-lockfile
- run:
name: Build project
command: yarn run build
@ -72,10 +56,20 @@ jobs:
- ~/.yarn
- ~/.cache/yarn
- node_modules
- save_cache:
key: *repo_key
- persist_to_workspace:
root: *repo_path
paths:
- ~/ui-theme
- ./*
lint:
<<: *defaults
<<: *default_executor
steps:
- *restore_repo
- run:
name: Lint code
command: yarn lint
test_bundlesize:
<<: *defaults
<<: *default_executor
@ -85,37 +79,28 @@ jobs:
name: Test BundleSize
command: yarn test:size
test_node11:
test_node_latest:
<<: *defaults
<<: *node11_executor
<<: *node_latest_executor
steps:
- *restore_repo
- run:
name: Test with Node 11
name: Test with Node (Latest)
command: yarn test
test_node8:
<<: *defaults
<<: *node8_executor
steps:
- *restore_repo
- run:
name: Test with Node 8
command: yarn test
test_node10:
<<: *defaults
<<: *node10_executor
steps:
- *restore_repo
- run:
name: Test with Node 10
command: yarn run test
- save_cache:
key: *coverage_key
paths:
- coverage
test_node_lts:
<<: *defaults
<<: *node_lts_executor
steps:
- *restore_repo
- run:
name: Test with Node (LTS)
command: yarn test
coverage:
<<: *defaults
<<: *default_executor
@ -140,8 +125,9 @@ jobs:
<<: *default_executor
steps:
- *restore_repo
- restore_cache:
key: *base_config_key
- run:
name: 'Setup publish credentials'
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Publish
command: yarn publish
@ -152,29 +138,31 @@ workflows:
jobs:
- prepare:
<<: *ignore_non_dev_branches
- test_node11:
requires:
- prepare
<<: *ignore_non_dev_branches
- test_node8:
requires:
- prepare
<<: *ignore_non_dev_branches
- test_node10:
- lint:
requires:
- prepare
<<: *ignore_non_dev_branches
- test_bundlesize:
requires:
- test_node11
- test_node8
- test_node10
- prepare
<<: *ignore_non_dev_branches
- test_node_latest:
requires:
- prepare
<<: *ignore_non_dev_branches
- test_node_lts:
requires:
- prepare
<<: *ignore_non_dev_branches
- coverage:
requires:
- test_bundlesize
- test_node_latest
<<: *ignore_non_dev_branches
- publish_package:
requires:
- lint
- test_bundlesize
- test_node_latest
- test_node_lts
- coverage
<<: *execute_on_release

View File

@ -13,7 +13,8 @@
"prettier",
"verdaccio",
"jsx-a11y",
"codeceptjs"
"codeceptjs",
"react-hooks"
],
"settings": {
"react": {
@ -107,6 +108,8 @@
2,
"always"
],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"verdaccio/jsx-no-style": ["warn"],
"verdaccio/jsx-spread": ["warn"],
"jest/expect-expect": 0,

67
.github/main.workflow vendored
View File

@ -1,67 +0,0 @@
################################################
# Workflow for a github release when a tag is
# pushed
################################################
workflow "github release" {
resolves = [
"release.github",
"release.lint",
]
on = "push"
}
action "release.filter" {
uses = "actions/bin/filter@master"
args = "tag v*"
}
action "release.install" {
uses = "docker://node:10"
needs = ["release.filter"]
args = "yarn install"
}
action "release.build" {
uses = "docker://node:10"
needs = ["release.install"]
args = "yarn run build"
}
action "release.lint" {
uses = "docker://node:10"
needs = ["release.install"]
args = "yarn run lint"
}
action "release.test" {
uses = "docker://node:10"
needs = ["release.build"]
args = "yarn run test"
}
action "release.auth" {
needs = ["release.test"]
uses = "actions/bin/filter@master"
args = ["actor", "octocat", "torvalds"]
}
action "release.npm.publish" {
needs = ["release.auth"]
uses = "docker://node:10"
args = "sh scripts/publish.sh"
secrets = [
"REGISTRY_AUTH_TOKEN",
]
env = {
REGISTRY_URL = "registry.npmjs.org"
}
}
action "release.github" {
needs = ["release.npm.publish"]
uses = "docker://node:10"
args = "sh scripts/github-release.sh"
secrets = [
"GITHUB_TOKEN",
]
}

View File

@ -1,28 +1,28 @@
name: Node CI
name: CI
on: [push]
on: push
jobs:
ci:
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
build_test_lint:
name: Node ${{ matrix.node_version }} and ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node_version: [8, 10, 12]
node_version: [10, 12]
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
version: ${{ matrix.node_version }}
- name: Use Yarn 1.17.2
run: |
npm install -g yarn@1.17.2
- name: yarn build
run: |
yarn install
yarn lint
yarn build
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Lint
run: yarn lint

View File

@ -1,4 +1,5 @@
{
"endOfLine": "auto",
"useTabs": false,
"printWidth": 160,
"tabWidth": 2,

View File

@ -1,2 +1 @@
save-prefix ""
registry "http://registry.npmjs.org/"

View File

@ -1,7 +1,31 @@
# Change Log
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [0.3.0](https://github.com/verdaccio/ui/compare/v0.2.4...v0.3.0) (2019-09-01)
### Features
* add browser features to browse by version ([#125](https://github.com/verdaccio/ui/issues/125)) ([1904179](https://github.com/verdaccio/ui/commit/1904179))
### [0.2.4](https://github.com/verdaccio/ui/compare/v0.2.3...v0.2.4) (2019-08-31)
### Features
* update material-ui@4.x ([#123](https://github.com/verdaccio/ui/issues/123)) ([67d7188](https://github.com/verdaccio/ui/commit/67d7188))
### [0.2.3](https://github.com/verdaccio/ui/compare/v0.2.2...v0.2.3) (2019-08-25)
### Bug Fixes
* missing headers on search endpoint with token ([#121](https://github.com/verdaccio/ui/issues/121)) ([ac58730](https://github.com/verdaccio/ui/commit/ac58730))
* refactoring version page / fix issue not found page [#100](https://github.com/verdaccio/ui/issues/100) ([#117](https://github.com/verdaccio/ui/issues/117)) ([97e8448](https://github.com/verdaccio/ui/commit/97e8448))
* remove ToReplaceByVerdaccio [#108](https://github.com/verdaccio/ui/issues/108) ([#122](https://github.com/verdaccio/ui/issues/122)) ([5a9bd60](https://github.com/verdaccio/ui/commit/5a9bd60))
* **api:** correctly handle responses with missing content-type header ([2049022](https://github.com/verdaccio/ui/commit/2049022))
<a name="0.2.2"></a>
## [0.2.2](https://github.com/verdaccio/ui/compare/v0.2.1...v0.2.2) (2019-07-29)

View File

@ -1,36 +0,0 @@
module.exports = {
name: 'verdaccio-ui-jest',
verbose: true,
collectCoverage: true,
testEnvironment: 'jest-environment-jsdom-global',
moduleFileExtensions: ['js', 'ts', 'tsx'],
testURL: 'http://localhost',
rootDir: '..',
setupFiles: ['<rootDir>/test/setup.js'],
transformIgnorePatterns: ['<rootDir>/node_modules/(?!react-syntax-highlighter)'],
modulePathIgnorePatterns: ['<rootDir>/coverage', '<rootDir>/scripts', '<rootDir>/.circleci', '<rootDir>/tools', '<rootDir>/build', '<rootDir>/.vscode/'],
snapshotSerializers: ['enzyme-to-json/serializer', 'jest-emotion'],
moduleNameMapper: {
'\\.(s?css)$': '<rootDir>/node_modules/identity-obj-proxy',
'github-markdown-css': '<rootDir>/node_modules/identity-obj-proxy',
'\\.(png)$': '<rootDir>/node_modules/identity-obj-proxy',
'\\.(svg)$': '<rootDir>/test/unit/empty.ts',
},
};
// module.exports = {
// name: 'verdaccio-unit-jest',
// verbose: true,
// collectCoverage: true,
// testEnvironment: 'jest-environment-jsdom-global',
// testURL: 'http://localhost',
// testRegex: '../src/components/CopyToClipBoard/CopyToClipBoard.test.tsx',
// setupFiles: ['./setup.ts'],
// // Some unit tests rely on data folders that look like packages. This confuses jest-hast-map
// // when it tries to scan for package.json files.
// modulePathIgnorePatterns: ['<rootDir>/coverage', '<rootDir>/scripts', '<rootDir>/.circleci', '<rootDir>/tools', '<rootDir>/build', '<rootDir>/.vscode/'],
// // testPathIgnorePatterns: ['__snapshots__', '<rootDir>/build'],
// snapshotSerializers: ['enzyme-to-json/serializer', 'jest-emotion'],
// // coveragePathIgnorePatterns: ['node_modules', 'fixtures', '<rootDir>/src/api/debug', '<rootDir>/test'],
// // transformIgnorePatterns: ['<rootDir>/node_modules/(?!react-syntax-highlighter)'],
// };

View File

@ -3,6 +3,7 @@ const { defaults } = require('jest-config');
module.exports = {
name: 'verdaccio-ui-jest',
verbose: true,
automock: false,
collectCoverage: true,
testEnvironment: 'jest-environment-jsdom-global',
moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],

View File

@ -5,6 +5,7 @@
import 'raf/polyfill';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { GlobalWithFetchMock } from 'jest-fetch-mock';
// @ts-ignore : Only a void function can be called with the 'new' keyword
configure({ adapter: new Adapter() });
@ -14,6 +15,10 @@ global.__APP_VERSION__ = '1.0.0';
// @ts-ignore : Property '__VERDACCIO_BASENAME_UI_OPTIONS' does not exist on type 'Global'.
global.__VERDACCIO_BASENAME_UI_OPTIONS = {};
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
customGlobal.fetch = require('jest-fetch-mock');
customGlobal.fetchMock = customGlobal.fetch;
// mocking few DOM methods
// @ts-ignore : Property 'document' does not exist on type 'Global'.
if (global.document) {

View File

@ -1,6 +1,6 @@
{
"name": "@verdaccio/ui-theme",
"version": "0.2.2",
"version": "0.3.0",
"description": "Verdaccio User Interface",
"author": {
"name": "Verdaccio Core Team"
@ -13,26 +13,28 @@
"devDependencies": {
"@commitlint/cli": "8.1.0",
"@commitlint/config-conventional": "8.1.0",
"@material-ui/core": "3.9.3",
"@material-ui/icons": "3.0.2",
"@material-ui/core": "4.3.3",
"@material-ui/icons": "4.2.1",
"@material-ui/styles": "4.3.3",
"@octokit/rest": "16.28.7",
"@testing-library/react": "9.1.3",
"@types/enzyme": "3.10.3",
"@types/lodash": "4.14.136",
"@types/material-ui": "0.21.6",
"@types/node": "12.7.1",
"@types/react": "16.9.1",
"@types/react-dom": "16.8.5",
"@types/react-router-dom": "4.3.4",
"@types/validator": "10.11.2",
"@types/jest": "24.0.18",
"@types/lodash": "4.14.138",
"@types/node": "12.7.3",
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"@types/react-router-dom": "4.3.5",
"@types/validator": "10.11.3",
"@verdaccio/babel-preset": "2.0.0",
"@verdaccio/eslint-config": "2.0.0",
"@verdaccio/types": "8.0.0-next.2",
"@verdaccio/types": "8.0.0",
"autosuggest-highlight": "3.1.1",
"babel-loader": "8.0.6",
"bundlesize": "0.18.0",
"codeceptjs": "2.2.1",
"codecov": "3.5.0",
"concurrently": "4.1.1",
"concurrently": "4.1.2",
"cross-env": "5.2.0",
"css-loader": "3.2.0",
"date-fns": "1.30.1",
@ -45,22 +47,25 @@
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.0",
"eslint-plugin-react": "7.14.3",
"eslint-plugin-react-hooks": "2.0.1",
"eslint-plugin-verdaccio": "2.0.0",
"file-loader": "4.2.0",
"friendly-errors-webpack-plugin": "1.7.0",
"get-stdin": "6.0.0",
"github-markdown-css": "3.0.1",
"html-webpack-plugin": "3.2.0",
"husky": "3.0.3",
"husky": "3.0.4",
"identity-obj-proxy": "3.0.0",
"in-publish": "2.0.0",
"jest": "24.8.0",
"jest": "24.9.0",
"jest-emotion": "10.0.14",
"jest-environment-jsdom": "24.8.0",
"jest-environment-jsdom": "24.9.0",
"jest-environment-jsdom-global": "1.2.0",
"jest-environment-node": "24.8.0",
"jest-environment-node": "24.9.0",
"jest-fetch-mock": "2.1.2",
"js-base64": "2.5.1",
"js-yaml": "3.13.1",
"lint-staged": "8.2.1",
"localstorage-memory": "1.0.3",
"mini-css-extract-plugin": "0.8.0",
"node-mocks-http": "1.7.6",
@ -74,7 +79,7 @@
"react-autosuggest": "9.4.3",
"react-dom": "16.9.0",
"react-emotion": "9.2.12",
"react-hot-loader": "4.12.10",
"react-hot-loader": "4.12.11",
"react-router": "5.0.1",
"react-router-dom": "5.0.1",
"resolve-url-loader": "3.1.0",
@ -93,15 +98,15 @@
"uglifyjs-webpack-plugin": "2.2.0",
"url-loader": "2.1.0",
"validator": "11.1.0",
"verdaccio": "4.2.1",
"verdaccio-auth-memory": "1.1.5",
"verdaccio-memory": "2.0.0",
"webpack": "4.39.1",
"verdaccio": "4.2.2",
"verdaccio-auth-memory": "8.0.0",
"verdaccio-memory": "8.0.0",
"webpack": "4.39.3",
"webpack-bundle-analyzer": "3.4.1",
"webpack-bundle-size-analyzer": "3.0.0",
"webpack-cli": "3.3.6",
"webpack-cli": "3.3.7",
"webpack-dev-server": "3.8.0",
"webpack-merge": "4.2.1",
"webpack-merge": "4.2.2",
"whatwg-fetch": "3.0.0",
"xss": "1.0.6"
},
@ -139,7 +144,7 @@
"scripts": {
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"release": "standard-version -a -s",
"release": "standard-version -a",
"test:clean": "npx jest --clearCache",
"test:acceptance": "codeceptjs run --steps",
"test:acceptance:server": "concurrently --kill-others \"npm run verdaccio:server\" \"npm run test:acceptance\"",
@ -147,7 +152,7 @@
"test:size": "bundlesize",
"lint": "npm run lint:js && npm run lint:css",
"lint:js": "npm run type-check && eslint . --ext .js,.ts,.tsx",
"lint:css": "stylelint 'src/**/styles.ts'",
"lint:css": "stylelint \"src/**/styles.ts\"",
"coverage:publish": "codecov",
"pre:webpack": "rimraf static/*",
"prepublish": "in-publish && npm run build || not-in-publish",
@ -164,9 +169,25 @@
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
"pre-commit": "lint-staged",
"commit-msg": "commitlint -e $GIT_PARAMS"
}
},
"lint-staged": {
"relative": true,
"linters": {
"*.{js,tsx,ts}": [
"eslint",
"prettier --write"
],
"*": [
"git add"
]
},
"ignore": [
"*.json"
]
},
"license": "MIT",
"commitlint": {
"extends": [

View File

@ -4579,6 +4579,70 @@
"tarball": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz"
},
"maintainers": [
{
"name": "dmethvin",
"email": "dave.methvin@gmail.com"
},
{
"name": "mgol",
"email": "m.goleb@gmail.com"
},
{
"name": "scott.gonzalez",
"email": "scott.gonzalez@gmail.com"
},
{
"name": "timmywil",
"email": "4timmywil@gmail.com"
},
{
"name": "dmethvin",
"email": "dave.methvin@gmail.com"
},
{
"name": "mgol",
"email": "m.goleb@gmail.com"
},
{
"name": "scott.gonzalez",
"email": "scott.gonzalez@gmail.com"
},
{
"name": "timmywil",
"email": "4timmywil@gmail.com"
},
{
"name": "dmethvin",
"email": "dave.methvin@gmail.com"
},
{
"name": "mgol",
"email": "m.goleb@gmail.com"
},
{
"name": "scott.gonzalez",
"email": "scott.gonzalez@gmail.com"
},
{
"name": "timmywil",
"email": "4timmywil@gmail.com"
},
{
"name": "dmethvin",
"email": "dave.methvin@gmail.com"
},
{
"name": "mgol",
"email": "m.goleb@gmail.com"
},
{
"name": "scott.gonzalez",
"email": "scott.gonzalez@gmail.com"
},
{
"name": "timmywil",
"email": "4timmywil@gmail.com"
},
{
"name": "dmethvin",
"email": "dave.methvin@gmail.com"

File diff suppressed because one or more lines are too long

38
src/App/AppError.tsx Normal file
View File

@ -0,0 +1,38 @@
import React, { Component } from 'react';
export interface ErrorProps {
children: any;
}
export interface ErrorAppState {
hasError: boolean;
error: any;
info: any;
}
export default class ErrorBoundary extends Component<ErrorProps, ErrorAppState> {
constructor(props) {
super(props);
this.state = { hasError: false, error: null, info: null };
}
componentDidCatch(error, info) {
this.setState({ hasError: true, error, info });
}
render() {
const { hasError, error, info } = this.state;
const { children } = this.props;
if (hasError) {
return (
<>
<h1>{'Something went wrong.'}</h1>
<p>{`error: ${error}`}</p>
<p>{`info: ${JSON.stringify(info)}`}</p>
</>
);
}
return children;
}
}

View File

@ -1,13 +1,8 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import { mount } from 'enzyme';
import { ActionBar } from './ActionBar';
describe('<ActionBar /> component', () => {
beforeEach(() => {
jest.resetModules();
});
test('should render the component in default state', () => {
const packageMeta = {
const mockPackageMeta = jest.fn(() => ({
latest: {
homepage: 'https://verdaccio.tld',
bugs: {
@ -17,53 +12,47 @@ describe('<ActionBar /> component', () => {
tarball: 'https://verdaccio.tld/download',
},
},
};
}));
jest.doMock('../../pages/version/Version', () => ({
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
return component.children({ packageMeta: mockPackageMeta() });
},
}));
const ActionBar = require('./ActionBar').default;
const wrapper = shallow(<ActionBar />);
describe('<ActionBar /> component', () => {
beforeEach(() => {
jest.resetModules();
jest.resetAllMocks();
});
test('should render the component in default state', () => {
const wrapper = mount(<ActionBar />);
expect(wrapper.html()).toMatchSnapshot();
});
test('when there is no action bar data', () => {
const packageMeta = {
// @ts-ignore
mockPackageMeta.mockImplementation(() => ({
latest: {},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const ActionBar = require('./ActionBar').default;
const wrapper = shallow(<ActionBar />);
const wrapper = mount(<ActionBar />);
// FIXME: this only renders the DetailContextConsumer, thus
// the wrapper will be always empty
expect(wrapper.html()).toEqual('');
});
test('when there is a button to download a tarball', () => {
const packageMeta = {
// @ts-ignore
mockPackageMeta.mockImplementation(() => ({
latest: {
dist: {
tarball: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz',
},
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const ActionBar = require('./ActionBar').default;
const wrapper = mount(<ActionBar />);
expect(wrapper.html()).toMatchSnapshot();

View File

@ -6,7 +6,7 @@ import HomeIcon from '@material-ui/icons/Home';
import List from '@material-ui/core/List';
import Tooltip from '@material-ui/core/Tooltip';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/Version';
import { Fab, ActionListItem } from './styles';
import { isURL, extractFileName, downloadFile } from '../../utils/url';
import api from '../../utils/api';
@ -49,6 +49,12 @@ class ActionBar extends Component {
return (
<DetailContextConsumer>
{context => {
const { packageMeta } = context;
if (!packageMeta) {
return null;
}
return this.renderActionBar(context as VersionPageConsumerProps);
}}
</DetailContextConsumer>
@ -65,12 +71,18 @@ class ActionBar extends Component {
private renderActionBar = ({ packageMeta }) => {
// @ts-ignore
const { latest: { bugs: { url: issue } = {}, homepage, dist: { tarball } = {} } = {} } = packageMeta;
const { latest } = packageMeta;
if (!latest) {
return null;
}
const { homepage, bugs, dist } = latest;
const actionsMap = {
homepage,
issue,
tarball,
issue: bugs ? bugs.url : null,
tarball: dist ? dist.tarball : null,
};
const renderList = Object.keys(actionsMap).reduce((component: React.ReactElement[], value, key) => {
@ -108,7 +120,9 @@ class ActionBar extends Component {
if (renderList.length > 0) {
return (
<List>
<ActionListItem alignItems={'flex-start'}>{renderList}</ActionListItem>
<ActionListItem alignItems={'flex-start'} button={true}>
{renderList}
</ActionListItem>
</List>
);
}
@ -117,4 +131,4 @@ class ActionBar extends Component {
};
}
export default ActionBar;
export { ActionBar };

View File

@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<ActionBar /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-padding-2\\"><li class=\\"MuiListItem-root-5 MuiListItem-default-8 MuiListItem-gutters-13 MuiListItem-alignItemsFlexStart-10 css-9q3x3c eux6shq0\\"><a href=\\"https://verdaccio.tld\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z\\"></path><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path></svg></span></button></a><a href=\\"https://verdaccio.tld/bugs\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5c-.49 0-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z\\"></path></svg></span></button></a><button class=\\"MuiButtonBase-root-35 MuiFab-root-25 MuiFab-sizeSmall-33 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Download tarball\\"><span class=\\"MuiFab-label-26\\"><svg class=\\"MuiSvgIcon-root-38\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z\\"></path></svg></span></button></li></ul>"`;
exports[`<ActionBar /> component should render the component in default state 1`] = `""`;
exports[`<ActionBar /> component when there is a button to download a tarball 1`] = `"<ul class=\\"MuiList-root-47 MuiList-padding-48\\"><li class=\\"MuiListItem-root-51 MuiListItem-default-54 MuiListItem-gutters-59 MuiListItem-alignItemsFlexStart-56 css-9q3x3c eux6shq0\\"><button class=\\"MuiButtonBase-root-81 MuiFab-root-71 MuiFab-sizeSmall-79 css-96oxa0 eux6shq1\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Download tarball\\"><span class=\\"MuiFab-label-72\\"><svg class=\\"MuiSvgIcon-root-84\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z\\"></path></svg></span><span class=\\"MuiTouchRipple-root-93\\"></span></button></li></ul>"`;
exports[`<ActionBar /> component when there is a button to download a tarball 1`] = `"<ul class=\\"MuiList-root MuiList-padding\\"><div class=\\"MuiButtonBase-root MuiListItem-root css-9q3x3c eux6shq0 MuiListItem-gutters MuiListItem-button MuiListItem-alignItemsFlexStart\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><button class=\\"MuiButtonBase-root MuiFab-root css-96oxa0 eux6shq1 MuiFab-sizeSmall\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Download tarball\\"><span class=\\"MuiFab-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z\\"></path></svg></span><span class=\\"MuiTouchRipple-root\\"></span></button><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@ -1,9 +1,28 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Authors from './Author';
const mockPackageMeta = jest.fn(() => ({
latest: {
homepage: 'https://verdaccio.tld',
bugs: {
url: 'https://verdaccio.tld/bugs',
},
dist: {
tarball: 'https://verdaccio.tld/download',
},
},
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta: mockPackageMeta() });
},
}));
describe('<Author /> component', () => {
beforeEach(() => {
jest.resetModules();
jest.resetAllMocks();
});
test('should render the component in default state', () => {
@ -20,14 +39,10 @@ describe('<Author /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
const wrapper = mount(<Authors />);
expect(wrapper.html()).toMatchSnapshot();
});
@ -39,14 +54,10 @@ describe('<Author /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
const wrapper = mount(<Authors />);
expect(wrapper.html()).toEqual('');
});
@ -63,14 +74,10 @@ describe('<Author /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Author = require('./Author').default;
const wrapper = shallow(<Author />);
const wrapper = mount(<Authors />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -2,10 +2,9 @@ import React, { Component, ReactNode, ReactElement } from 'react';
import Avatar from '@material-ui/core/Avatar';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import { DetailContextConsumer } from '../../pages/version/Version';
import { Heading, AuthorListItem } from './styles';
import { DetailContextConsumer } from '../../pages/Version';
import { Heading, AuthorListItem, AuthorListItemText } from './styles';
import { isEmail } from '../../utils/url';
class Authors extends Component {
@ -13,7 +12,13 @@ class Authors extends Component {
return (
<DetailContextConsumer>
{context => {
return context && context.packageMeta && this.renderAuthor(context.packageMeta);
const { packageMeta } = context;
if (!packageMeta) {
return null;
}
return this.renderAuthor(packageMeta);
}}
</DetailContextConsumer>
);
@ -31,8 +36,8 @@ class Authors extends Component {
);
}
public renderAuthor = packageMeta => {
const { author, name: packageName, version } = packageMeta.latest;
public renderAuthor = ({ latest }) => {
const { author, name: packageName, version } = latest;
if (!author) {
return null;
@ -40,10 +45,10 @@ class Authors extends Component {
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
return (
<List subheader={<Heading variant={'subheading'}>{'Author'}</Heading>}>
<AuthorListItem>
<List subheader={<Heading variant={'subtitle1'}>{'Author'}</Heading>}>
<AuthorListItem button={true}>
{this.renderLinkForMail(author.email, avatarComponent, packageName, version)}
<ListItemText primary={author.name} />
<AuthorListItemText primary={author.name} />
</AuthorListItem>
</List>
);

View File

@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Author /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-padding-2 MuiList-subheader-4\\"><h3 class=\\"MuiTypography-root-5 MuiTypography-subheading-12 css-hyrz44 e1xuehjw0\\">Author</h3><li class=\\"MuiListItem-root-41 MuiListItem-default-44 MuiListItem-gutters-49 css-z8a2h0 e1xuehjw1\\"><a href=\\"mailto:verdaccio.user@verdaccio.org?subject=verdaccio@4.0.0\\" target=\\"_top\\"><div class=\\"MuiAvatar-root-53\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img-55\\"/></div></a><div class=\\"MuiListItemText-root-56\\"><span class=\\"MuiTypography-root-5 MuiTypography-subheading-12 MuiListItemText-primary-59\\">verdaccio user</span></div></li></ul>"`;
exports[`<Author /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-xugzlj e1xuehjw1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><a href=\\"mailto:verdaccio.user@verdaccio.org?subject=verdaccio@4.0.0\\" target=\\"_top\\"><div class=\\"MuiAvatar-root\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div></a><div class=\\"MuiListItemText-root css-1vhg3jx e1xuehjw2\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">verdaccio user</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;
exports[`<Author /> component should render the component when there is no author email 1`] = `"<ul class=\\"MuiList-root-62 MuiList-padding-63 MuiList-subheader-65\\"><h3 class=\\"MuiTypography-root-66 MuiTypography-subheading-73 css-hyrz44 e1xuehjw0\\">Author</h3><li class=\\"MuiListItem-root-102 MuiListItem-default-105 MuiListItem-gutters-110 css-z8a2h0 e1xuehjw1\\"><div class=\\"MuiAvatar-root-114\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img-116\\"/></div><div class=\\"MuiListItemText-root-117\\"><span class=\\"MuiTypography-root-66 MuiTypography-subheading-73 MuiListItemText-primary-120\\">verdaccio user</span></div></li></ul>"`;
exports[`<Author /> component should render the component when there is no author email 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-xugzlj e1xuehjw1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div><div class=\\"MuiListItemText-root css-1vhg3jx e1xuehjw2\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">verdaccio user</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@ -2,6 +2,7 @@ import styled from 'react-emotion';
import ListItem from '@material-ui/core/ListItem';
import Typography from '@material-ui/core/Typography';
import { fontWeight } from '../../utils/styles/sizes';
import ListItemText from '@material-ui/core/ListItemText';
export const Heading = styled(Typography)({
'&&': {
@ -11,7 +12,16 @@ export const Heading = styled(Typography)({
});
export const AuthorListItem = styled(ListItem)({
'&&': {
paddingLeft: 0,
paddingRight: 0,
padding: 0,
},
'&&:hover': {
backgroundColor: 'transparent',
},
});
export const AuthorListItemText = styled(ListItemText)({
'&&': {
padding: '0 10px',
margin: 0,
},
});

View File

@ -0,0 +1,32 @@
import React, { FC } from 'react';
import Avatar from '@material-ui/core/Avatar';
import Tooltip from '@material-ui/core/Tooltip';
import { isEmail } from '../../utils/url';
export interface AvatarDeveloper {
name: string;
packageName: string;
version: string;
avatar: string;
email: string;
}
const AvatarTooltip: FC<AvatarDeveloper> = ({ name, packageName, version, avatar, email }) => {
const avatarComponent = <Avatar aria-label={name} src={avatar} />;
function renderLinkForMail(email, avatarComponent, packageName, version): JSX.Element {
if (!email || isEmail(email) === false) {
return avatarComponent;
}
return (
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
{avatarComponent}
</a>
);
}
return <Tooltip title={name}>{renderLinkForMail(email, avatarComponent, packageName, version)}</Tooltip>;
};
export { AvatarTooltip };

View File

@ -0,0 +1,4 @@
import { AvatarTooltip } from './AvatarTooltip';
export { AvatarTooltip };
export default AvatarTooltip;

View File

@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import CopyToClipBoard from './CopyToClipBoard';
import { CopyIcon } from './styles';
@ -8,7 +8,7 @@ describe('<CopyToClipBoard /> component', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<CopyToClipBoard text={'copy text'} />);
wrapper = mount(<CopyToClipBoard text={'copy text'} />);
});
test('render the component', () => {

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<CopyToClipBoard /> component render the component 1`] = `"<div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">copy text</span><button class=\\"MuiButtonBase-root-15 MuiIconButton-root-9 css-56v3u0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-14\\"><svg class=\\"MuiSvgIcon-root-18\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span></button></div>"`;
exports[`<CopyToClipBoard /> component render the component 1`] = `"<div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">copy text</span><button class=\\"MuiButtonBase-root MuiIconButton-root css-0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root\\"></span></button></div>"`;

View File

@ -19,8 +19,4 @@ export const ClipBoardCopyText = styled('span')({
},
});
export const CopyIcon = styled(IconButton)({
'&&': {
margin: '0 0 0 10px',
},
});
export const CopyIcon = styled(IconButton)({});

View File

@ -2,7 +2,7 @@ import React, { Component, Fragment, ReactElement } from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import CardContent from '@material-ui/core/CardContent';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/Version';
import { CardWrap, Heading, Tags, Tag } from './styles';
import NoItems from '../NoItems';
@ -32,7 +32,7 @@ class DepDetail extends Component<DepDetailProps, DepDetailState> {
public render(): ReactElement<HTMLElement> {
const { name, version } = this.state;
const tagText = `${name}@${version}`;
return <Tag className={'dep-tag'} clickable={true} component={'div'} label={tagText} onClick={this.handleOnClick} />;
return <Tag className={'dep-tag'} clickable={true} label={tagText} onClick={this.handleOnClick} />;
}
private handleOnClick = () => {
@ -57,7 +57,7 @@ class DependencyBlock extends Component<{ title: string; dependencies: [] }> {
return (
<CardWrap>
<CardContent>
<Heading variant="subheading">{`${title} (${deps.length})`}</Heading>
<Heading variant="subtitle1">{`${title} (${deps.length})`}</Heading>
<Tags>{this.renderTags(deps, enableLoading)}</Tags>
</CardContent>
</CardWrap>

View File

@ -1,6 +1,6 @@
import React, { Component, ReactElement, Fragment } from 'react';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/Version';
import Readme from '../Readme';
import Versions from '../Versions';
import { preventXSS } from '../../utils/sec-utils';
@ -14,6 +14,11 @@ interface DetailContainerState {
tabPosition: number;
}
export const README_LABEL = 'Readme';
export const DEPS_LABEL = 'Dependencies';
export const VERSION_LABEL = 'Versions';
export const UPLINKS_LABEL = 'Uplinks';
class DetailContainer<P> extends Component<P, DetailContainerState> {
public state = {
tabPosition: 0,
@ -37,10 +42,10 @@ class DetailContainer<P> extends Component<P, DetailContainerState> {
private renderListTabs(tabPosition: number): React.ReactElement<HTMLElement> {
return (
<Tabs indicatorColor={'primary'} onChange={this.handleChange} textColor={'primary'} value={tabPosition} variant={'fullWidth'}>
<Tab id={'readme-tab'} label={'Readme'} />
<Tab id={'dependencies-tab'} label={'Dependencies'} />
<Tab id={'versions-tab'} label={'Versions'} />
<Tab id={'uplinks-tab'} label={'Uplinks'} />
<Tab data-testid={'readme-tab'} id={'readme-tab'} label={README_LABEL} />
<Tab data-testid={'dependencies-tab'} id={'dependencies-tab'} label={DEPS_LABEL} />
<Tab data-testid={'versions-tab'} id={'versions-tab'} label={VERSION_LABEL} />
<Tab data-testid={'uplinks-tab'} id={'uplinks-tab'} label={UPLINKS_LABEL} />
</Tabs>
);
}

View File

@ -1,10 +1,10 @@
import React, { Component, ReactElement } from 'react';
import React, { ReactElement } from 'react';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import List from '@material-ui/core/List';
import ActionBar from '../ActionBar/ActionBar';
import { ActionBar } from '../ActionBar/ActionBar';
import Author from '../Author';
import Developers from '../Developers';
import Dist from '../Dist/Dist';
@ -12,76 +12,64 @@ import Engine from '../Engines/Engines';
import Install from '../Install';
import Repository from '../Repository/Repository';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { DetailContext } from '../../pages/Version';
import { TitleListItem, TitleListItemText } from './styles';
class DetailSidebar extends Component {
public render(): ReactElement<HTMLElement> {
return <DetailContextConsumer>{context => this.renderSideBar(context as VersionPageConsumerProps)}</DetailContextConsumer>;
}
private renderSideBar = ({ packageName, packageMeta }): ReactElement<HTMLElement> => {
const renderLatestDescription = (description, version, isLatest: boolean = true) => {
return (
<div className={'sidebar-info'}>
<Card>
<CardContent>
{this.renderTitle(packageName, packageMeta)}
{this.renderActionBar()}
{this.renderCopyCLI()}
{this.renderRepository()}
{this.renderEngine()}
{this.renderDist()}
{this.renderAuthor()}
{this.renderMaintainers()}
{this.renderContributors()}
</CardContent>
</Card>
</div>
<span>
<div>{description}</div>
{version ? <small>{`${isLatest ? 'Latest v' : 'v'}${version}`}</small> : null}
</span>
);
};
private renderTitle = (packageName, packageMeta) => {
const renderCopyCLI = () => <Install />;
const renderMaintainers = () => <Developers type="maintainers" />;
const renderContributors = () => <Developers type="contributors" />;
const renderRepository = () => <Repository />;
const renderAuthor = () => <Author />;
const renderEngine = () => <Engine />;
const renderDist = () => <Dist />;
const renderActionBar = () => <ActionBar />;
const renderTitle = (packageName, packageVersion, packageMeta) => {
const version = packageVersion ? packageVersion : packageMeta.latest.version;
const isLatest = typeof packageVersion === 'undefined';
return (
<List className="detail-info">
<TitleListItem alignItems="flex-start">
<TitleListItemText primary={<b>{packageName}</b>} secondary={packageMeta.latest.description} />
<TitleListItem alignItems="flex-start" button={true}>
<TitleListItemText primary={<b>{packageName}</b>} secondary={renderLatestDescription(packageMeta.latest.description, version, isLatest)} />
</TitleListItem>
</List>
);
};
private renderCopyCLI = () => {
return <Install />;
};
private renderMaintainers = () => {
return <Developers type="maintainers" />;
};
private renderContributors = () => {
return <Developers type="contributors" />;
};
private renderRepository = () => {
return <Repository />;
};
private renderAuthor = () => {
return <Author />;
};
private renderEngine = () => {
return <Engine />;
};
private renderDist = () => {
return <Dist />;
};
private renderActionBar = () => {
return <ActionBar />;
};
function renderSideBar(packageName, packageVersion, packageMeta): ReactElement<HTMLElement> {
return (
<div className={'sidebar-info'}>
<Card>
<CardContent>
{renderTitle(packageName, packageVersion, packageMeta)}
{renderActionBar()}
{renderCopyCLI()}
{renderRepository()}
{renderEngine()}
{renderDist()}
{renderAuthor()}
{renderMaintainers()}
{renderContributors()}
</CardContent>
</Card>
</div>
);
}
const DetailSidebar = () => {
const { packageName, packageMeta, packageVersion } = React.useContext(DetailContext);
return renderSideBar(packageName, packageVersion, packageMeta);
};
export default DetailSidebar;

View File

@ -0,0 +1,104 @@
import React from 'react';
import { mount } from 'enzyme';
import Developers, { DevelopersType } from './Developers';
import { Fab } from './styles';
import { DetailContextProvider } from '../../pages/Version';
describe('test Developers', () => {
const packageMeta = {
latest: {
packageName: 'foo',
version: '1.0.0',
maintainers: [
{
name: 'dmethvin',
email: 'dave.methvin@gmail.com',
},
{
name: 'mgol',
email: 'm.goleb@gmail.com',
},
],
contributors: [
{
name: 'dmethvin',
email: 'dave.methvin@gmail.com',
},
{
name: 'mgol',
email: 'm.goleb@gmail.com',
},
],
},
};
test('should render the component with no items', () => {
const type: DevelopersType = 'maintainers';
const packageMeta = {
latest: {},
};
const wrapper = mount(
// @ts-ignore
<DetailContextProvider value={{ packageMeta }}>
<Developers type={type} />
</DetailContextProvider>
);
expect(wrapper).toMatchSnapshot();
});
test('should render the component for maintainers with items', () => {
const type: DevelopersType = 'maintainers';
const wrapper = mount(
// @ts-ignore
<DetailContextProvider value={{ packageMeta }}>
<Developers type={type} />
</DetailContextProvider>
);
expect(wrapper).toMatchSnapshot();
});
test('should render the component for contributors with items', () => {
const type: DevelopersType = 'contributors';
const wrapper = mount(
// @ts-ignore
<DetailContextProvider value={{ packageMeta }}>
<Developers type={type} />
</DetailContextProvider>
);
expect(wrapper).toMatchSnapshot();
});
test('should test onClick the component avatar', () => {
const type: DevelopersType = 'contributors';
const packageMeta = {
latest: {
packageName: 'foo',
version: '1.0.0',
contributors: [
{
name: 'dmethvin',
email: 'dave.methvin@gmail.com',
},
{
name: 'dmethvin2',
email: 'dave2.methvin@gmail.com',
},
],
},
};
const wrapper = mount(
// @ts-ignore
<DetailContextProvider value={{ packageMeta }}>
<Developers type={type} visibleMax={1} />
</DetailContextProvider>
);
const item2 = wrapper.find(Fab);
// TODO: I am not sure here how to verify the method inside the component was called.
item2.simulate('click');
});
});

View File

@ -1,79 +1,59 @@
import React, { Component } from 'react';
import Avatar from '@material-ui/core/Avatar';
import React, { FC, Fragment } from 'react';
import Add from '@material-ui/icons/Add';
import Tooltip from '@material-ui/core/Tooltip';
import { DetailContextConsumer } from '../../pages/version/Version';
import { DetailContext } from '../../pages/Version';
import { AvatarTooltip } from '../AvatarTooltip';
import { Details, Heading, Content, Fab } from './styles';
import { isEmail } from '../../utils/url';
export type DevelopersType = 'contributors' | 'maintainers';
interface Props {
type: 'contributors' | 'maintainers';
}
interface State {
visibleDevs: number;
type: DevelopersType;
visibleMax?: number;
}
class Developers extends Component<Props, State> {
public state = {
visibleDevs: 6,
export const VISIBLE_MAX = 6;
const Developers: FC<Props> = ({ type, visibleMax }) => {
const [visibleDevs, setVisibleDevs] = React.useState<number>(visibleMax || VISIBLE_MAX);
const { packageMeta } = React.useContext(DetailContext);
const handleLoadMore = () => {
setVisibleDevs(visibleDevs + VISIBLE_MAX);
};
public render(): JSX.Element {
return (
<DetailContextConsumer>
{({ packageMeta }) => {
const { type } = this.props;
const developerType = packageMeta && packageMeta.latest[type];
if (!developerType || developerType.length === 0) return null;
return this.renderDevelopers(developerType, packageMeta);
}}
</DetailContextConsumer>
);
}
const renderDeveloperDetails = ({ name, avatar, email }, packageMeta) => {
const { name: packageName, version } = packageMeta.latest;
public handleLoadMore = () => {
this.setState(prev => ({ visibleDevs: prev.visibleDevs + 6 }));
return <AvatarTooltip avatar={avatar} email={email} name={name} packageName={packageName} version={version} />;
};
private renderDevelopers = (developers, packageMeta) => {
const { type } = this.props;
const { visibleDevs } = this.state;
const renderDevelopers = (developers, packageMeta) => {
const listVisibleDevelopers = developers.slice(0, visibleDevs);
return (
<>
<Heading variant={'subheading'}>{type}</Heading>
<Fragment>
<Heading variant={'subtitle1'}>{type}</Heading>
<Content>
{developers.slice(0, visibleDevs).map(developer => (
<Details key={developer.email}>{this.renderDeveloperDetails(developer, packageMeta)}</Details>
{listVisibleDevelopers.map(developer => (
<Details key={developer.email}>{renderDeveloperDetails(developer, packageMeta)}</Details>
))}
{visibleDevs < developers.length && (
<Fab onClick={this.handleLoadMore} size="small">
<Fab onClick={handleLoadMore} size="small">
<Add />
</Fab>
)}
</Content>
</>
</Fragment>
);
};
private renderLinkForMail(email, avatarComponent, packageName, version): JSX.Element {
if (!email || isEmail(email) === false) {
return avatarComponent;
}
return (
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
{avatarComponent}
</a>
);
const developerList = packageMeta && packageMeta.latest[type];
if (!developerList || developerList.length === 0) {
return null;
}
private renderDeveloperDetails = ({ name, avatar, email }, packageMeta) => {
const { name: packageName, version } = packageMeta.latest;
const avatarComponent = <Avatar aria-label={name} src={avatar} />;
return <Tooltip title={name}>{this.renderLinkForMail(email, avatarComponent, packageName, version)}</Tooltip>;
return renderDevelopers(developerList, packageMeta);
};
}
export default Developers;

View File

@ -0,0 +1,487 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`test Developers should render the component for contributors with items 1`] = `
<Developers
type="contributors"
>
<Styled(WithStyles(ForwardRef(Typography)))
variant="subtitle1"
>
<WithStyles(ForwardRef(Typography))
className="css-18tsvng emotion-0"
variant="subtitle1"
>
<ForwardRef(Typography)
className="css-18tsvng emotion-0"
classes={
Object {
"alignCenter": "MuiTypography-alignCenter",
"alignJustify": "MuiTypography-alignJustify",
"alignLeft": "MuiTypography-alignLeft",
"alignRight": "MuiTypography-alignRight",
"body1": "MuiTypography-body1",
"body2": "MuiTypography-body2",
"button": "MuiTypography-button",
"caption": "MuiTypography-caption",
"colorError": "MuiTypography-colorError",
"colorInherit": "MuiTypography-colorInherit",
"colorPrimary": "MuiTypography-colorPrimary",
"colorSecondary": "MuiTypography-colorSecondary",
"colorTextPrimary": "MuiTypography-colorTextPrimary",
"colorTextSecondary": "MuiTypography-colorTextSecondary",
"displayBlock": "MuiTypography-displayBlock",
"displayInline": "MuiTypography-displayInline",
"gutterBottom": "MuiTypography-gutterBottom",
"h1": "MuiTypography-h1",
"h2": "MuiTypography-h2",
"h3": "MuiTypography-h3",
"h4": "MuiTypography-h4",
"h5": "MuiTypography-h5",
"h6": "MuiTypography-h6",
"noWrap": "MuiTypography-noWrap",
"overline": "MuiTypography-overline",
"paragraph": "MuiTypography-paragraph",
"root": "MuiTypography-root",
"srOnly": "MuiTypography-srOnly",
"subtitle1": "MuiTypography-subtitle1",
"subtitle2": "MuiTypography-subtitle2",
}
}
variant="subtitle1"
>
<h6
className="MuiTypography-root css-18tsvng emotion-0 MuiTypography-subtitle1"
>
contributors
</h6>
</ForwardRef(Typography)>
</WithStyles(ForwardRef(Typography))>
</Styled(WithStyles(ForwardRef(Typography)))>
<Styled(div)>
<div
className="css-mkcn9c emotion-5"
>
<Styled(span)
key="dave.methvin@gmail.com"
>
<span
className="css-dvxtzn emotion-3"
>
<AvatarTooltip
email="dave.methvin@gmail.com"
name="dmethvin"
version="1.0.0"
>
<WithStyles(Tooltip)
title="dmethvin"
>
<Tooltip
classes={
Object {
"popper": "MuiTooltip-popper",
"popperInteractive": "MuiTooltip-popperInteractive",
"tooltip": "MuiTooltip-tooltip",
"tooltipPlacementBottom": "MuiTooltip-tooltipPlacementBottom",
"tooltipPlacementLeft": "MuiTooltip-tooltipPlacementLeft",
"tooltipPlacementRight": "MuiTooltip-tooltipPlacementRight",
"tooltipPlacementTop": "MuiTooltip-tooltipPlacementTop",
"touch": "MuiTooltip-touch",
}
}
title="dmethvin"
>
<a
aria-describedby={null}
className=""
href="mailto:dave.methvin@gmail.com?subject=undefined@1.0.0"
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
target="_top"
title="dmethvin"
>
<WithStyles(ForwardRef(Avatar))
aria-label="dmethvin"
>
<ForwardRef(Avatar)
aria-label="dmethvin"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</a>
<ForwardRef(Popper)
anchorEl={
<a
class=""
href="mailto:dave.methvin@gmail.com?subject=undefined@1.0.0"
target="_top"
title="dmethvin"
>
<div
aria-label="dmethvin"
class="MuiAvatar-root MuiAvatar-colorDefault"
/>
</a>
}
className="MuiTooltip-popper"
id={null}
open={false}
placement="bottom"
transition={true}
/>
</Tooltip>
</WithStyles(Tooltip)>
</AvatarTooltip>
</span>
</Styled(span)>
<Styled(span)
key="m.goleb@gmail.com"
>
<span
className="css-dvxtzn emotion-3"
>
<AvatarTooltip
email="m.goleb@gmail.com"
name="mgol"
version="1.0.0"
>
<WithStyles(Tooltip)
title="mgol"
>
<Tooltip
classes={
Object {
"popper": "MuiTooltip-popper",
"popperInteractive": "MuiTooltip-popperInteractive",
"tooltip": "MuiTooltip-tooltip",
"tooltipPlacementBottom": "MuiTooltip-tooltipPlacementBottom",
"tooltipPlacementLeft": "MuiTooltip-tooltipPlacementLeft",
"tooltipPlacementRight": "MuiTooltip-tooltipPlacementRight",
"tooltipPlacementTop": "MuiTooltip-tooltipPlacementTop",
"touch": "MuiTooltip-touch",
}
}
title="mgol"
>
<a
aria-describedby={null}
className=""
href="mailto:m.goleb@gmail.com?subject=undefined@1.0.0"
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
target="_top"
title="mgol"
>
<WithStyles(ForwardRef(Avatar))
aria-label="mgol"
>
<ForwardRef(Avatar)
aria-label="mgol"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</a>
<ForwardRef(Popper)
anchorEl={
<a
class=""
href="mailto:m.goleb@gmail.com?subject=undefined@1.0.0"
target="_top"
title="mgol"
>
<div
aria-label="mgol"
class="MuiAvatar-root MuiAvatar-colorDefault"
/>
</a>
}
className="MuiTooltip-popper"
id={null}
open={false}
placement="bottom"
transition={true}
/>
</Tooltip>
</WithStyles(Tooltip)>
</AvatarTooltip>
</span>
</Styled(span)>
</div>
</Styled(div)>
</Developers>
`;
exports[`test Developers should render the component for maintainers with items 1`] = `
<Developers
type="maintainers"
>
<Styled(WithStyles(ForwardRef(Typography)))
variant="subtitle1"
>
<WithStyles(ForwardRef(Typography))
className="css-18tsvng emotion-0"
variant="subtitle1"
>
<ForwardRef(Typography)
className="css-18tsvng emotion-0"
classes={
Object {
"alignCenter": "MuiTypography-alignCenter",
"alignJustify": "MuiTypography-alignJustify",
"alignLeft": "MuiTypography-alignLeft",
"alignRight": "MuiTypography-alignRight",
"body1": "MuiTypography-body1",
"body2": "MuiTypography-body2",
"button": "MuiTypography-button",
"caption": "MuiTypography-caption",
"colorError": "MuiTypography-colorError",
"colorInherit": "MuiTypography-colorInherit",
"colorPrimary": "MuiTypography-colorPrimary",
"colorSecondary": "MuiTypography-colorSecondary",
"colorTextPrimary": "MuiTypography-colorTextPrimary",
"colorTextSecondary": "MuiTypography-colorTextSecondary",
"displayBlock": "MuiTypography-displayBlock",
"displayInline": "MuiTypography-displayInline",
"gutterBottom": "MuiTypography-gutterBottom",
"h1": "MuiTypography-h1",
"h2": "MuiTypography-h2",
"h3": "MuiTypography-h3",
"h4": "MuiTypography-h4",
"h5": "MuiTypography-h5",
"h6": "MuiTypography-h6",
"noWrap": "MuiTypography-noWrap",
"overline": "MuiTypography-overline",
"paragraph": "MuiTypography-paragraph",
"root": "MuiTypography-root",
"srOnly": "MuiTypography-srOnly",
"subtitle1": "MuiTypography-subtitle1",
"subtitle2": "MuiTypography-subtitle2",
}
}
variant="subtitle1"
>
<h6
className="MuiTypography-root css-18tsvng emotion-0 MuiTypography-subtitle1"
>
maintainers
</h6>
</ForwardRef(Typography)>
</WithStyles(ForwardRef(Typography))>
</Styled(WithStyles(ForwardRef(Typography)))>
<Styled(div)>
<div
className="css-mkcn9c emotion-5"
>
<Styled(span)
key="dave.methvin@gmail.com"
>
<span
className="css-dvxtzn emotion-3"
>
<AvatarTooltip
email="dave.methvin@gmail.com"
name="dmethvin"
version="1.0.0"
>
<WithStyles(Tooltip)
title="dmethvin"
>
<Tooltip
classes={
Object {
"popper": "MuiTooltip-popper",
"popperInteractive": "MuiTooltip-popperInteractive",
"tooltip": "MuiTooltip-tooltip",
"tooltipPlacementBottom": "MuiTooltip-tooltipPlacementBottom",
"tooltipPlacementLeft": "MuiTooltip-tooltipPlacementLeft",
"tooltipPlacementRight": "MuiTooltip-tooltipPlacementRight",
"tooltipPlacementTop": "MuiTooltip-tooltipPlacementTop",
"touch": "MuiTooltip-touch",
}
}
title="dmethvin"
>
<a
aria-describedby={null}
className=""
href="mailto:dave.methvin@gmail.com?subject=undefined@1.0.0"
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
target="_top"
title="dmethvin"
>
<WithStyles(ForwardRef(Avatar))
aria-label="dmethvin"
>
<ForwardRef(Avatar)
aria-label="dmethvin"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="dmethvin"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</a>
<ForwardRef(Popper)
anchorEl={
<a
class=""
href="mailto:dave.methvin@gmail.com?subject=undefined@1.0.0"
target="_top"
title="dmethvin"
>
<div
aria-label="dmethvin"
class="MuiAvatar-root MuiAvatar-colorDefault"
/>
</a>
}
className="MuiTooltip-popper"
id={null}
open={false}
placement="bottom"
transition={true}
/>
</Tooltip>
</WithStyles(Tooltip)>
</AvatarTooltip>
</span>
</Styled(span)>
<Styled(span)
key="m.goleb@gmail.com"
>
<span
className="css-dvxtzn emotion-3"
>
<AvatarTooltip
email="m.goleb@gmail.com"
name="mgol"
version="1.0.0"
>
<WithStyles(Tooltip)
title="mgol"
>
<Tooltip
classes={
Object {
"popper": "MuiTooltip-popper",
"popperInteractive": "MuiTooltip-popperInteractive",
"tooltip": "MuiTooltip-tooltip",
"tooltipPlacementBottom": "MuiTooltip-tooltipPlacementBottom",
"tooltipPlacementLeft": "MuiTooltip-tooltipPlacementLeft",
"tooltipPlacementRight": "MuiTooltip-tooltipPlacementRight",
"tooltipPlacementTop": "MuiTooltip-tooltipPlacementTop",
"touch": "MuiTooltip-touch",
}
}
title="mgol"
>
<a
aria-describedby={null}
className=""
href="mailto:m.goleb@gmail.com?subject=undefined@1.0.0"
onBlur={[Function]}
onFocus={[Function]}
onMouseLeave={[Function]}
onMouseOver={[Function]}
onTouchEnd={[Function]}
onTouchStart={[Function]}
target="_top"
title="mgol"
>
<WithStyles(ForwardRef(Avatar))
aria-label="mgol"
>
<ForwardRef(Avatar)
aria-label="mgol"
classes={
Object {
"colorDefault": "MuiAvatar-colorDefault",
"img": "MuiAvatar-img",
"root": "MuiAvatar-root",
}
}
>
<div
aria-label="mgol"
className="MuiAvatar-root MuiAvatar-colorDefault"
/>
</ForwardRef(Avatar)>
</WithStyles(ForwardRef(Avatar))>
</a>
<ForwardRef(Popper)
anchorEl={
<a
class=""
href="mailto:m.goleb@gmail.com?subject=undefined@1.0.0"
target="_top"
title="mgol"
>
<div
aria-label="mgol"
class="MuiAvatar-root MuiAvatar-colorDefault"
/>
</a>
}
className="MuiTooltip-popper"
id={null}
open={false}
placement="bottom"
transition={true}
/>
</Tooltip>
</WithStyles(Tooltip)>
</AvatarTooltip>
</span>
</Styled(span)>
</div>
</Styled(div)>
</Developers>
`;
exports[`test Developers should render the component with no items 1`] = `
<Developers
type="maintainers"
/>
`;

View File

@ -1,6 +1,7 @@
import styled from 'react-emotion';
import Typography from '@material-ui/core/Typography';
import { default as MuiFab } from '@material-ui/core/Fab';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes';

View File

@ -1,5 +1,24 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Dist from './Dist';
const mockPackageMeta = jest.fn(() => ({
latest: {
homepage: 'https://verdaccio.tld',
bugs: {
url: 'https://verdaccio.tld/bugs',
},
dist: {
tarball: 'https://verdaccio.tld/download',
},
},
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta: mockPackageMeta() });
},
}));
describe('<Dist /> component', () => {
beforeEach(() => {
@ -18,14 +37,11 @@ describe('<Dist /> component', () => {
license: '',
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Dist = require('./Dist').default;
const wrapper = shallow(<Dist />);
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
@ -41,14 +57,11 @@ describe('<Dist /> component', () => {
license: 'MIT',
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Dist = require('./Dist').default;
const wrapper = shallow(<Dist />);
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
@ -67,14 +80,11 @@ describe('<Dist /> component', () => {
},
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
const Dist = require('./Dist').default;
const wrapper = shallow(<Dist />);
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const wrapper = mount(<Dist />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -2,7 +2,7 @@ import React, { Component } from 'react';
import List from '@material-ui/core/List';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
import { Heading, DistListItem, DistChips } from './styles';
import fileSizeSI from '../../utils/file-size';
import { PackageMetaInterface } from 'types/packageMeta';
@ -46,8 +46,8 @@ class Dist extends Component {
const { dist, license } = packageMeta && packageMeta.latest;
return (
<List subheader={<Heading variant="subheading">{'Latest Distribution'}</Heading>}>
<DistListItem>{this.renderChips(dist, license)}</DistListItem>
<List subheader={<Heading variant="subtitle1">{'Latest Distribution'}</Heading>}>
<DistListItem button={true}>{this.renderChips(dist, license)}</DistListItem>
</List>
);
};

View File

@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Dist /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-padding-2 MuiList-subheader-4\\"><h3 class=\\"MuiTypography-root-5 MuiTypography-subheading-12 css-hyrz44 estxrtg0\\">Latest Distribution</h3><li class=\\"MuiListItem-root-41 MuiListItem-default-44 MuiListItem-gutters-49 css-z8a2h0 estxrtg1\\"><div role=\\"button\\" class=\\"MuiChip-root-53 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-72\\"><b>file count</b>: 7</span></div><div role=\\"button\\" class=\\"MuiChip-root-53 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-72\\"><b>size</b>: 10.00 Bytes</span></div></li></ul>"`;
exports[`<Dist /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-z8a2h0 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;
exports[`<Dist /> component should render the component with license as object 1`] = `"<ul class=\\"MuiList-root-155 MuiList-padding-156 MuiList-subheader-158\\"><h3 class=\\"MuiTypography-root-159 MuiTypography-subheading-166 css-hyrz44 estxrtg0\\">Latest Distribution</h3><li class=\\"MuiListItem-root-195 MuiListItem-default-198 MuiListItem-gutters-203 css-z8a2h0 estxrtg1\\"><div role=\\"button\\" class=\\"MuiChip-root-207 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-226\\"><b>file count</b>: 7</span></div><div role=\\"button\\" class=\\"MuiChip-root-207 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-226\\"><b>size</b>: 10.00 Bytes</span></div><div role=\\"button\\" class=\\"MuiChip-root-207 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-226\\"><b>license</b>: MIT</span></div></li></ul>"`;
exports[`<Dist /> component should render the component with license as object 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-z8a2h0 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>license</b>: MIT</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;
exports[`<Dist /> component should render the component with license as string 1`] = `"<ul class=\\"MuiList-root-78 MuiList-padding-79 MuiList-subheader-81\\"><h3 class=\\"MuiTypography-root-82 MuiTypography-subheading-89 css-hyrz44 estxrtg0\\">Latest Distribution</h3><li class=\\"MuiListItem-root-118 MuiListItem-default-121 MuiListItem-gutters-126 css-z8a2h0 estxrtg1\\"><div role=\\"button\\" class=\\"MuiChip-root-130 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-149\\"><b>file count</b>: 7</span></div><div role=\\"button\\" class=\\"MuiChip-root-130 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-149\\"><b>size</b>: 10.00 Bytes</span></div><div role=\\"button\\" class=\\"MuiChip-root-130 css-1le6jk6 estxrtg2\\" tabindex=\\"-1\\"><span class=\\"MuiChip-label-149\\"><b>license</b>: MIT</span></div></li></ul>"`;
exports[`<Dist /> component should render the component with license as string 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-z8a2h0 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-1le6jk6 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>license</b>: MIT</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@ -1,12 +1,31 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Engine from './Engines';
jest.mock('./img/node.png', () => '');
jest.mock('../Install/img/npm.svg', () => '');
const mockPackageMeta = jest.fn(() => ({
latest: {
homepage: 'https://verdaccio.tld',
bugs: {
url: 'https://verdaccio.tld/bugs',
},
dist: {
tarball: 'https://verdaccio.tld/download',
},
},
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta: mockPackageMeta() });
},
}));
describe('<Engines /> component', () => {
beforeEach(() => {
jest.resetModules();
jest.resetAllMocks();
});
test('should render the component in default state', () => {
@ -19,14 +38,10 @@ describe('<Engines /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Engines = require('./Engines').default;
const wrapper = shallow(<Engines />);
const wrapper = mount(<Engine />);
expect(wrapper.html()).toMatchSnapshot();
});
@ -35,14 +50,10 @@ describe('<Engines /> component', () => {
latest: {},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Engines = require('./Engines').default;
const wrapper = shallow(<Engines />);
const wrapper = mount(<Engine />);
expect(wrapper.html()).toEqual('');
});
@ -53,14 +64,10 @@ describe('<Engines /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Engines = require('./Engines').default;
const wrapper = shallow(<Engines />);
const wrapper = mount(<Engine />);
expect(wrapper.html()).toEqual('');
});
});

View File

@ -5,7 +5,7 @@ import Grid from '@material-ui/core/Grid';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version';
import { Heading, EngineListItem } from './styles';
// @ts-ignore
import node from './img/node.png';
@ -60,8 +60,8 @@ class Engine extends Component {
private renderListItems = (heading, text) => {
return (
<List subheader={<Heading variant={'subheading'}>{text.split('-').join(' ')}</Heading>}>
<EngineListItem>
<List subheader={<Heading variant={'subtitle1'}>{text.split('-').join(' ')}</Heading>}>
<EngineListItem button={true}>
{ICONS[text]}
<ListItemText primary={heading} />
</EngineListItem>

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Engines /> component should render the component in default state 1`] = `"<div class=\\"MuiGrid-container-1\\"><div class=\\"MuiGrid-item-2 MuiGrid-grid-xs-6-35\\"><ul class=\\"MuiList-root-98 MuiList-padding-99 MuiList-subheader-101\\"><h3 class=\\"MuiTypography-root-102 MuiTypography-subheading-109 css-hyrz44 et66bt70\\">node JS</h3><li class=\\"MuiListItem-root-138 MuiListItem-default-141 MuiListItem-gutters-146 css-dt93b2 et66bt71\\"><div class=\\"MuiAvatar-root-150 MuiAvatar-colorDefault-151\\"></div><div class=\\"MuiListItemText-root-153\\"><span class=\\"MuiTypography-root-102 MuiTypography-subheading-109 MuiListItemText-primary-156\\">&gt;= 0.1.98</span></div></li></ul></div><div class=\\"MuiGrid-item-2 MuiGrid-grid-xs-6-35\\"><ul class=\\"MuiList-root-98 MuiList-padding-99 MuiList-subheader-101\\"><h3 class=\\"MuiTypography-root-102 MuiTypography-subheading-109 css-hyrz44 et66bt70\\">NPM version</h3><li class=\\"MuiListItem-root-138 MuiListItem-default-141 MuiListItem-gutters-146 css-dt93b2 et66bt71\\"><div class=\\"MuiAvatar-root-150 MuiAvatar-colorDefault-151\\"></div><div class=\\"MuiListItemText-root-153\\"><span class=\\"MuiTypography-root-102 MuiTypography-subheading-109 MuiListItemText-primary-156\\">&gt;3</span></div></li></ul></div></div>"`;
exports[`<Engines /> component should render the component in default state 1`] = `"<div class=\\"MuiGrid-root MuiGrid-container\\"><div class=\\"MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6\\"><ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 et66bt70 MuiTypography-subtitle1\\">node JS</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-dt93b2 et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-colorDefault\\"></div><div class=\\"MuiListItemText-root\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">&gt;= 0.1.98</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul></div><div class=\\"MuiGrid-root MuiGrid-item MuiGrid-grid-xs-6\\"><ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 et66bt70 MuiTypography-subtitle1\\">NPM version</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-dt93b2 et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-colorDefault\\"></div><div class=\\"MuiListItemText-root\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">&gt;3</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul></div></div>"`;

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Footer /> component should load the initial state of Footer component 1`] = `"<div class=\\"css-i0nj2g ezbsl480\\"><div class=\\"css-hzfs9b ezbsl481\\"><div class=\\"css-d8nsp7 ezbsl482\\"> Made with<span class=\\"css-1so4oe0 ezbsl487\\">♥</span>on<span class=\\"css-1ie354y ezbsl484\\"><svg class=\\"ezbsl485 css-1kgp95j ek145dl0\\"><title>Earth</title><use xlink:href=\\"[object Object]#earth\\"></use></svg><span class=\\"css-8631ip ezbsl486\\"><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>Spain</title><use xlink:href=\\"[object Object]#spain\\"></use></svg><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>Nicaragua</title><use xlink:href=\\"[object Object]#nicaragua\\"></use></svg><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>India</title><use xlink:href=\\"[object Object]#india\\"></use></svg><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>Brazil</title><use xlink:href=\\"[object Object]#brazil\\"></use></svg><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>China</title><use xlink:href=\\"[object Object]#china\\"></use></svg><svg class=\\"ezbsl488 css-f1ndto ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg></span></span></div><div class=\\"css-1wbzdyy ezbsl483\\">Powered by<span class=\\"ezbsl488 css-i15wza ek145dl1\\" name=\\"verdaccio\\" title=\\"Verdaccio\\"><img alt=\\"Verdaccio\\" src=\\"[object Object]\\" class=\\"css-1ncdhax ek145dl2\\"></span>/ v.1.0.0</div></div></div>"`;
exports[`<Footer /> component should load the initial state of Footer component 1`] = `"<div class=\\"css-i0nj2g ezbsl480\\"><div class=\\"css-hzfs9b ezbsl481\\"><div class=\\"css-d8nsp7 ezbsl482\\"> Made with<span class=\\"css-1so4oe0 ezbsl487\\">♥</span>on<span class=\\"css-1ie354y ezbsl484\\"><svg class=\\"ezbsl485 css-tsfgle ek145dl0\\"><title>Earth</title><use xlink:href=\\"[object Object]#earth\\"></use></svg><span class=\\"css-8631ip ezbsl486\\"><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>Spain</title><use xlink:href=\\"[object Object]#spain\\"></use></svg><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>Nicaragua</title><use xlink:href=\\"[object Object]#nicaragua\\"></use></svg><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>India</title><use xlink:href=\\"[object Object]#india\\"></use></svg><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>Brazil</title><use xlink:href=\\"[object Object]#brazil\\"></use></svg><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>China</title><use xlink:href=\\"[object Object]#china\\"></use></svg><svg class=\\"ezbsl488 css-13b76ay ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg></span></span></div><div class=\\"css-1wbzdyy ezbsl483\\">Powered by<span class=\\"ezbsl488 css-i15wza ek145dl1\\" name=\\"verdaccio\\" title=\\"Verdaccio\\"><img alt=\\"Verdaccio\\" src=\\"[object Object]\\" class=\\"css-1ncdhax ek145dl2\\"></span>/ v.1.0.0</div></div></div>"`;

View File

@ -32,7 +32,7 @@ interface Props {
}
interface State {
anchorEl?: null | HTMLElement | ((element: HTMLElement) => HTMLElement);
anchorEl?: null | Element | ((element: Element) => Element);
openInfoDialog: boolean;
registryUrl: string;
showMobileNavBar: boolean;

View File

@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Header /> component with logged in state should load the component in logged in state 1`] = `"<div><header class=\\"MuiPaper-root-10 MuiPaper-elevation4-16 MuiAppBar-root-1 MuiAppBar-positionStatic-5 MuiAppBar-colorPrimary-8 css-rfunvc e1jf5lit8\\"><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-1pwdmmq e1jf5lit0\\"><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-1vacr9s e1jf5lit3\\"><a class=\\"css-1dk30lc\\" href=\\"/\\"><div class=\\"css-1sifsqk em793ed0\\"></div></a></div><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-m61s5i e1jf5lit2\\"><a href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\" class=\\"MuiButtonBase-root-55 MuiIconButton-root-49 MuiIconButton-colorInherit-50\\" tabindex=\\"0\\" role=\\"button\\" title=\\"Documentation\\"><span class=\\"MuiIconButton-label-54\\"><svg class=\\"MuiSvgIcon-root-58\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z\\"></path></svg></span></a><button class=\\"MuiButtonBase-root-55 MuiIconButton-root-49 MuiIconButton-colorInherit-50\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-registryInfo\\" title=\\"Registry Information\\"><span class=\\"MuiIconButton-label-54\\"><svg class=\\"MuiSvgIcon-root-58\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\\"></path></svg></span></button><button class=\\"MuiButtonBase-root-55 MuiIconButton-root-49 MuiIconButton-colorInherit-50\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-account\\"><span class=\\"MuiIconButton-label-54\\"><svg class=\\"MuiSvgIcon-root-58\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z\\"></path><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path></svg></span></button></div></div></header></div>"`;
exports[`<Header /> component with logged in state should load the component in logged in state 1`] = `"<div><header class=\\"MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic css-rfunvc e1jf5lit8 MuiAppBar-colorPrimary\\"><div class=\\"MuiToolbar-root MuiToolbar-regular css-1pwdmmq e1jf5lit0 MuiToolbar-gutters\\"><div class=\\"MuiToolbar-root MuiToolbar-regular css-1vacr9s e1jf5lit3 MuiToolbar-gutters\\"><a class=\\"css-1dk30lc\\" href=\\"/\\"><div class=\\"css-1sifsqk em793ed0\\"></div></a></div><div class=\\"MuiToolbar-root MuiToolbar-regular css-m61s5i e1jf5lit2 MuiToolbar-gutters\\"><a href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\" class=\\"MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\" title=\\"Documentation\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z\\"></path></svg></span></a><button class=\\"MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-registryInfo\\" title=\\"Registry Information\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\\"></path></svg></span></button><button class=\\"MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-account\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z\\"></path></svg></span></button></div></div></header></div>"`;
exports[`<Header /> component with logged out state should load the component in logged out state 1`] = `"<div><header class=\\"MuiPaper-root-10 MuiPaper-elevation4-16 MuiAppBar-root-1 MuiAppBar-positionStatic-5 MuiAppBar-colorPrimary-8 css-rfunvc e1jf5lit8\\"><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-1pwdmmq e1jf5lit0\\"><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-1vacr9s e1jf5lit3\\"><a class=\\"css-1dk30lc\\" href=\\"/\\"><div class=\\"css-1sifsqk em793ed0\\"></div></a></div><div class=\\"MuiToolbar-root-37 MuiToolbar-regular-39 MuiToolbar-gutters-38 css-m61s5i e1jf5lit2\\"><a href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\" class=\\"MuiButtonBase-root-55 MuiIconButton-root-49 MuiIconButton-colorInherit-50\\" tabindex=\\"0\\" role=\\"button\\" title=\\"Documentation\\"><span class=\\"MuiIconButton-label-54\\"><svg class=\\"MuiSvgIcon-root-58\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z\\"></path></svg></span></a><button class=\\"MuiButtonBase-root-55 MuiIconButton-root-49 MuiIconButton-colorInherit-50\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-registryInfo\\" title=\\"Registry Information\\"><span class=\\"MuiIconButton-label-54\\"><svg class=\\"MuiSvgIcon-root-58\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\\"></path></svg></span></button><button class=\\"MuiButtonBase-root-55 MuiButton-root-85 MuiButton-text-87 MuiButton-flat-90 MuiButton-colorInherit-106\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-login\\"><span class=\\"MuiButton-label-86\\">Login</span></button></div></div></header></div>"`;
exports[`<Header /> component with logged out state should load the component in logged out state 1`] = `"<div><header class=\\"MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic css-rfunvc e1jf5lit8 MuiAppBar-colorPrimary\\"><div class=\\"MuiToolbar-root MuiToolbar-regular css-1pwdmmq e1jf5lit0 MuiToolbar-gutters\\"><div class=\\"MuiToolbar-root MuiToolbar-regular css-1vacr9s e1jf5lit3 MuiToolbar-gutters\\"><a class=\\"css-1dk30lc\\" href=\\"/\\"><div class=\\"css-1sifsqk em793ed0\\"></div></a></div><div class=\\"MuiToolbar-root MuiToolbar-regular css-m61s5i e1jf5lit2 MuiToolbar-gutters\\"><a href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\" class=\\"MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\" title=\\"Documentation\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z\\"></path></svg></span></a><button class=\\"MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-registryInfo\\" title=\\"Registry Information\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z\\"></path></svg></span></button><button class=\\"MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"header--button-login\\"><span class=\\"MuiButton-label\\">Login</span></button></div></div></header></div>"`;

View File

@ -1,10 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Help from './Help';
describe('<Help /> component', () => {
test('should render the component in default state', () => {
const wrapper = shallow(<Help />);
const wrapper = mount(<Help />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -12,7 +12,7 @@ import { CardStyled as Card, HelpTitle } from './styles';
function renderHeadingClipboardSegments(title: string, text: string): React.ReactNode {
return (
<Fragment>
<Typography variant={'body2'}>{title}</Typography>
<Typography variant={'body1'}>{title}</Typography>
<CopyToClipBoard text={text} />
</Fragment>
);
@ -24,7 +24,7 @@ const Help: React.FC = () => {
return (
<Card id="help-card">
<CardContent>
<Typography component="h2" gutterBottom={true} id="help-card__title" variant="headline">
<Typography component="h2" gutterBottom={true} id="help-card__title" variant="h5">
{'No Package Published Yet.'}
</Typography>
<HelpTitle color="textSecondary" gutterBottom={true}>

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Help /> component should render the component in default state 1`] = `"<div class=\\"MuiPaper-root-2 MuiPaper-elevation1-5 MuiPaper-rounded-3 MuiCard-root-1 css-ryznli e1wgaou60\\" id=\\"help-card\\"><div class=\\"MuiCardContent-root-29\\"><h2 class=\\"MuiTypography-root-30 MuiTypography-headline-35 MuiTypography-gutterBottom-57\\" id=\\"help-card__title\\">No Package Published Yet.</h2><p class=\\"MuiTypography-root-30 MuiTypography-body1-39 MuiTypography-colorTextSecondary-63 MuiTypography-gutterBottom-57 css-zg2fwz e1wgaou61\\">To publish your first package just:</p><p class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">1. Login</p><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">npm adduser --registry http://localhost</span><button class=\\"MuiButtonBase-root-80 MuiIconButton-root-74 css-56v3u0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-79\\"><svg class=\\"MuiSvgIcon-root-83\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span></button></div><p class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">2. Publish</p><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">npm publish --registry http://localhost</span><button class=\\"MuiButtonBase-root-80 MuiIconButton-root-74 css-56v3u0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-79\\"><svg class=\\"MuiSvgIcon-root-83\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span></button></div><p class=\\"MuiTypography-root-30 MuiTypography-body2-38\\">3. Refresh this page.</p></div><div class=\\"MuiCardActions-root-92\\"><a class=\\"MuiButtonBase-root-80 MuiButton-root-95 MuiButton-text-97 MuiButton-textPrimary-98 MuiButton-flat-100 MuiButton-flatPrimary-101 MuiButton-sizeSmall-118 MuiCardActions-action-94\\" tabindex=\\"0\\" role=\\"button\\" href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\"><span class=\\"MuiButton-label-96\\">Learn More</span></a></div></div>"`;
exports[`<Help /> component should render the component in default state 1`] = `"<div class=\\"MuiPaper-root MuiPaper-elevation1 MuiCard-root css-ryznli e1wgaou60 MuiPaper-rounded\\" id=\\"help-card\\"><div class=\\"MuiCardContent-root\\"><h2 class=\\"MuiTypography-root MuiTypography-h5 MuiTypography-gutterBottom\\" id=\\"help-card__title\\">No Package Published Yet.</h2><p class=\\"MuiTypography-root css-zg2fwz e1wgaou61 MuiTypography-body1 MuiTypography-colorTextSecondary MuiTypography-gutterBottom\\">To publish your first package just:</p><p class=\\"MuiTypography-root MuiTypography-body1\\">1. Login</p><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">npm adduser --registry http://localhost</span><button class=\\"MuiButtonBase-root MuiIconButton-root css-0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root\\"></span></button></div><p class=\\"MuiTypography-root MuiTypography-body1\\">2. Publish</p><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\">npm publish --registry http://localhost</span><button class=\\"MuiButtonBase-root MuiIconButton-root css-0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root\\"></span></button></div><p class=\\"MuiTypography-root MuiTypography-body2\\">3. Refresh this page.</p></div><div class=\\"MuiCardActions-root MuiCardActions-spacing\\"><a class=\\"MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeSmall\\" tabindex=\\"0\\" aria-disabled=\\"false\\" href=\\"https://verdaccio.org/docs/en/installation\\" target=\\"_blank\\"><span class=\\"MuiButton-label\\">Learn More</span><span class=\\"MuiTouchRipple-root\\"></span></a></div></div>"`;

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Icon /> component should render the component in default state 1`] = `"<svg class=\\"css-3skwlp ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg>"`;
exports[`<Icon /> component should render the component in default state 1`] = `"<svg class=\\"css-snirlv ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg>"`;

View File

@ -21,7 +21,7 @@ const getSize = (size: Breakpoint): string => {
const commonStyle = ({ size = 'sm' as Breakpoint, pointer, modifiers = null }): string => css`
&& {
display: inline-block;
cursor: ${pointer ? 'pointer' : 'default'};
cursor: ${pointer ? 'pointer' : 'Developers'};
${getSize(size)};
${modifiers && modifiers};
}

View File

@ -1,11 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Install from './Install';
describe('<Install /> component', () => {
test('should render the component in default state', () => {
const wrapper = shallow(<Install />);
const wrapper = mount(<Install />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -1,9 +1,8 @@
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import React, { Component } from 'react';
// @ts-ignore
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/Version';
import CopyToClipBoard from '../CopyToClipBoard';
// logos of package managers
@ -11,7 +10,7 @@ import npm from './img/npm.svg';
import pnpm from './img/pnpm.svg';
import yarn from './img/yarn.svg';
import { Heading, InstallItem, PackageMangerAvatar } from './styles';
import { Heading, InstallItem, PackageMangerAvatar, InstallListItemText } from './styles';
class Install extends Component {
public render(): JSX.Element {
@ -27,7 +26,7 @@ class Install extends Component {
public renderCopyCLI = ({ packageName = '' }: Partial<VersionPageConsumerProps>) => {
return (
<>
<List subheader={<Heading variant={'subheading'}>{'Installation'}</Heading>}>{this.renderListItems(packageName)}</List>
<List subheader={<Heading variant={'subtitle1'}>{'Installation'}</Heading>}>{this.renderListItems(packageName)}</List>
</>
);
};
@ -35,17 +34,17 @@ class Install extends Component {
public renderListItems = (packageName: string) => {
return (
<>
<InstallItem>
<InstallItem button={true}>
<PackageMangerAvatar alt={'npm logo'} src={npm} />
<ListItemText primary={<CopyToClipBoard text={`npm install ${packageName}`} />} secondary={'Install using NPM'} />
<InstallListItemText primary={<CopyToClipBoard text={`npm install ${packageName}`} />} secondary={'Install using NPM'} />
</InstallItem>
<InstallItem>
<InstallItem button={true}>
<PackageMangerAvatar alt={'yarn logo'} src={yarn} />
<ListItemText primary={<CopyToClipBoard text={`yarn add ${packageName}`} />} secondary={'Install using Yarn'} />
<InstallListItemText primary={<CopyToClipBoard text={`yarn add ${packageName}`} />} secondary={'Install using Yarn'} />
</InstallItem>
<InstallItem>
<InstallItem button={true}>
<PackageMangerAvatar alt={'pnpm logo'} src={pnpm} />
<ListItemText primary={<CopyToClipBoard text={`pnpm install ${packageName}`} />} secondary={'Install using PNPM'} />
<InstallListItemText primary={<CopyToClipBoard text={`pnpm install ${packageName}`} />} secondary={'Install using PNPM'} />
</InstallItem>
</>
);

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Install /> component should render the component in default state 1`] = `""`;
exports[`<Install /> component should render the component in default state 1`] = `null`;

View File

@ -1,5 +1,6 @@
import Avatar from '@material-ui/core/Avatar';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import Typography from '@material-ui/core/Typography';
import styled from 'react-emotion';
import { fontWeight } from '../../utils/styles/sizes';
@ -15,10 +16,21 @@ export const InstallItem = styled(ListItem)({
'&&': {
padding: 0,
},
'&&:hover': {
backgroundColor: 'transparent',
},
});
export const InstallListItemText = styled(ListItemText)({
'&&': {
padding: '0 10px',
margin: 0,
},
});
export const PackageMangerAvatar = styled(Avatar)({
'&&': {
borderRadius: '0px',
padding: '0',
},
});

View File

@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Label from './Label';
@ -8,7 +8,7 @@ describe('<Label /> component', () => {
text: 'test',
};
test('should render the component in default state', () => {
const wrapper = shallow(<Label text={props.text} />);
const wrapper = mount(<Label text={props.text} />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Link from './Link';
@ -8,7 +8,7 @@ describe('<Link /> component', () => {
to: 'https://github.com/verdaccio/ui',
};
test('should render the component in default state', () => {
const wrapper = shallow(<Link blank={true} to={props.to} />);
const wrapper = mount(<Link blank={true} to={props.to} />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -6,7 +6,7 @@ import Spinner from '../Spinner';
import { Wrapper, Badge } from './styles';
const Loading: React.FC = () => (
<Wrapper>
<Wrapper data-testid="loading">
<Badge>
<Logo size={Size.Big} />
</Badge>

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Loading /> component should render the component in default state 1`] = `"<div class=\\"css-1221txa eimgwje0\\"><div class=\\"css-bxochs eimgwje1\\"><div class=\\"css-ge0nak em793ed0\\"></div></div><div class=\\"css-vqrgi e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root-1 MuiCircularProgress-colorPrimary-4 MuiCircularProgress-indeterminate-3 css-15gl0ho e1ag4h8b1\\" style=\\"width:50px;height:50px\\" role=\\"progressbar\\"><svg class=\\"MuiCircularProgress-svg-6\\" viewBox=\\"22 22 44 44\\"><circle class=\\"MuiCircularProgress-circle-7 MuiCircularProgress-circleIndeterminate-9\\" cx=\\"44\\" cy=\\"44\\" r=\\"20.2\\" fill=\\"none\\" stroke-width=\\"3.6\\"></circle></svg></div></div></div>"`;
exports[`<Loading /> component should render the component in default state 1`] = `"<div data-testid=\\"loading\\" class=\\"css-1221txa eimgwje0\\"><div class=\\"css-bxochs eimgwje1\\"><div class=\\"css-ge0nak em793ed0\\"></div></div><div class=\\"css-vqrgi e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root css-15gl0ho e1ag4h8b1 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate\\" style=\\"width:50px;height:50px\\" role=\\"progressbar\\"><svg class=\\"MuiCircularProgress-svg\\" viewBox=\\"22 22 44 44\\"><circle class=\\"MuiCircularProgress-circle MuiCircularProgress-circleIndeterminate\\" cx=\\"44\\" cy=\\"44\\" r=\\"20.2\\" fill=\\"none\\" stroke-width=\\"3.6\\"></circle></svg></div></div></div>"`;

View File

@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<LoginModal /> should load the component in default state 1`] = `"<div role=\\"dialog\\" class=\\"MuiModal-root-15 MuiDialog-root-1\\" id=\\"login--form-container\\"><div class=\\"MuiBackdrop-root-17\\" aria-hidden=\\"true\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\"></div><div class=\\"MuiDialog-container-4 MuiDialog-scrollPaper-2\\" role=\\"document\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\" tabindex=\\"-1\\"><div class=\\"MuiPaper-root-19 MuiPaper-elevation24-45 MuiPaper-rounded-20 MuiDialog-paper-5 MuiDialog-paperScrollPaper-6 MuiDialog-paperWidthXs-8 MuiDialog-paperFullWidth-13\\"><form novalidate=\\"\\"><div class=\\"MuiDialogTitle-root-46\\"><h2 class=\\"MuiTypography-root-47 MuiTypography-title-53\\">Login</h2></div><div class=\\"MuiDialogContent-root-83\\"><div class=\\"MuiFormControl-root-84 MuiFormControl-fullWidth-87\\"><label class=\\"MuiFormLabel-root-99 MuiFormLabel-required-104 MuiInputLabel-required-92 MuiInputLabel-root-88 MuiInputLabel-formControl-93 MuiInputLabel-animated-96\\" data-shrink=\\"false\\" for=\\"username\\">Username<span class=\\"MuiFormLabel-asterisk-105\\">*</span></label><div class=\\"MuiInputBase-root-119 MuiInput-root-106 MuiInput-underline-110 MuiInputBase-formControl-120 MuiInput-formControl-107\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input-129 MuiInput-input-114\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiFormControl-root-84 MuiFormControl-fullWidth-87 css-164r41r\\"><label class=\\"MuiFormLabel-root-99 MuiFormLabel-required-104 MuiInputLabel-required-92 MuiInputLabel-root-88 MuiInputLabel-formControl-93 MuiInputLabel-animated-96\\" data-shrink=\\"false\\" for=\\"password\\">Password<span class=\\"MuiFormLabel-asterisk-105\\">*</span></label><div class=\\"MuiInputBase-root-119 MuiInput-root-106 MuiInput-underline-110 MuiInputBase-formControl-120 MuiInput-formControl-107\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input-129 MuiInput-input-114 MuiInputBase-inputType-132 MuiInput-inputType-117\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" value=\\"\\"></div></div></div><div class=\\"MuiDialogActions-root-136 dialog-footer\\"><button class=\\"MuiButtonBase-root-164 MuiButton-root-138 MuiButton-text-140 MuiButton-flat-143 MuiButton-colorInherit-159 MuiDialogActions-action-137\\" tabindex=\\"0\\" type=\\"button\\" id=\\"login--form-cancel\\"><span class=\\"MuiButton-label-139\\">Cancel</span><span class=\\"MuiTouchRipple-root-167\\"></span></button><button class=\\"MuiButtonBase-root-164 MuiButtonBase-disabled-165 MuiButton-root-138 MuiButton-text-140 MuiButton-flat-143 MuiButton-disabled-158 MuiButton-colorInherit-159 MuiDialogActions-action-137\\" tabindex=\\"-1\\" type=\\"submit\\" disabled=\\"\\" id=\\"login--form-submit\\"><span class=\\"MuiButton-label-139\\">Login</span></button></div></form></div></div></div>"`;
exports[`<LoginModal /> should load the component in default state 1`] = `"<div role=\\"presentation\\" class=\\"MuiDialog-root\\" id=\\"login--form-container\\" style=\\"position: fixed; z-index: 1300; right: 0px; bottom: 0px; top: 0px; left: 0px;\\"><div class=\\"MuiBackdrop-root\\" aria-hidden=\\"true\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\"></div><div tabindex=\\"0\\" data-test=\\"sentinelStart\\"></div><div class=\\"MuiDialog-container MuiDialog-scrollPaper\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\" role=\\"document\\" tabindex=\\"-1\\"><div class=\\"MuiPaper-root MuiPaper-elevation24 MuiDialog-paper MuiDialog-paperScrollPaper MuiDialog-paperWidthXs MuiDialog-paperFullWidth MuiPaper-rounded\\" role=\\"dialog\\"><form novalidate=\\"\\"><div class=\\"MuiDialogTitle-root\\"><h2 class=\\"MuiTypography-root MuiTypography-h6\\">Login</h2></div><div class=\\"MuiDialogContent-root\\"><div class=\\"MuiFormControl-root MuiFormControl-fullWidth\\"><label class=\\"MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-required Mui-required\\" data-shrink=\\"false\\" for=\\"username\\">Username<span class=\\"MuiFormLabel-asterisk MuiInputLabel-asterisk\\">*</span></label><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-formControl MuiInput-formControl\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input MuiInput-input\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiFormControl-root css-164r41r MuiFormControl-fullWidth\\"><label class=\\"MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-required Mui-required\\" data-shrink=\\"false\\" for=\\"password\\">Password<span class=\\"MuiFormLabel-asterisk MuiInputLabel-asterisk\\">*</span></label><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-formControl MuiInput-formControl\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input MuiInput-input\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" value=\\"\\"></div></div></div><div class=\\"MuiDialogActions-root dialog-footer MuiDialogActions-spacing\\"><button class=\\"MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"login--form-cancel\\"><span class=\\"MuiButton-label\\">Cancel</span><span class=\\"MuiTouchRipple-root\\"></span></button><button class=\\"MuiButtonBase-root MuiButton-root MuiButton-text Mui-disabled MuiButton-colorInherit Mui-disabled\\" tabindex=\\"-1\\" type=\\"submit\\" disabled=\\"\\" id=\\"login--form-submit\\"><span class=\\"MuiButton-label\\">Login</span></button></div></form></div></div><div tabindex=\\"0\\" data-test=\\"sentinelEnd\\"></div></div>"`;
exports[`<LoginModal /> should load the component with props 1`] = `"<div role=\\"dialog\\" class=\\"MuiModal-root-15 MuiDialog-root-1\\" id=\\"login--form-container\\"><div class=\\"MuiBackdrop-root-17\\" aria-hidden=\\"true\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\"></div><div class=\\"MuiDialog-container-4 MuiDialog-scrollPaper-2\\" role=\\"document\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\" tabindex=\\"-1\\"><div class=\\"MuiPaper-root-19 MuiPaper-elevation24-45 MuiPaper-rounded-20 MuiDialog-paper-5 MuiDialog-paperScrollPaper-6 MuiDialog-paperWidthXs-8 MuiDialog-paperFullWidth-13\\"><form novalidate=\\"\\"><div class=\\"MuiDialogTitle-root-46\\"><h2 class=\\"MuiTypography-root-47 MuiTypography-title-53\\">Login</h2></div><div class=\\"MuiDialogContent-root-83\\"><div class=\\"MuiTypography-root-47 MuiTypography-body1-56 MuiPaper-root-19 MuiPaper-elevation6-27 MuiSnackbarContent-root-174 css-11e09xf\\" role=\\"alertdialog\\"><div class=\\"MuiSnackbarContent-message-175\\"><div class=\\"css-70qvj9\\" id=\\"client-snackbar\\"><svg class=\\"MuiSvgIcon-root-177 css-1mbwbu9\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\\"></path></svg><span><div><strong>Error Title</strong></div><div>Error Description</div></span></div></div></div><div class=\\"MuiFormControl-root-84 MuiFormControl-fullWidth-87\\"><label class=\\"MuiFormLabel-root-99 MuiFormLabel-required-104 MuiInputLabel-required-92 MuiInputLabel-root-88 MuiInputLabel-formControl-93 MuiInputLabel-animated-96\\" data-shrink=\\"false\\" for=\\"username\\">Username<span class=\\"MuiFormLabel-asterisk-105\\">*</span></label><div class=\\"MuiInputBase-root-119 MuiInput-root-106 MuiInput-underline-110 MuiInputBase-formControl-120 MuiInput-formControl-107\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input-129 MuiInput-input-114\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiFormControl-root-84 MuiFormControl-fullWidth-87 css-164r41r\\"><label class=\\"MuiFormLabel-root-99 MuiFormLabel-required-104 MuiInputLabel-required-92 MuiInputLabel-root-88 MuiInputLabel-formControl-93 MuiInputLabel-animated-96\\" data-shrink=\\"false\\" for=\\"password\\">Password<span class=\\"MuiFormLabel-asterisk-105\\">*</span></label><div class=\\"MuiInputBase-root-119 MuiInput-root-106 MuiInput-underline-110 MuiInputBase-formControl-120 MuiInput-formControl-107\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input-129 MuiInput-input-114 MuiInputBase-inputType-132 MuiInput-inputType-117\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" value=\\"\\"></div></div></div><div class=\\"MuiDialogActions-root-136 dialog-footer\\"><button class=\\"MuiButtonBase-root-164 MuiButton-root-138 MuiButton-text-140 MuiButton-flat-143 MuiButton-colorInherit-159 MuiDialogActions-action-137\\" tabindex=\\"0\\" type=\\"button\\" id=\\"login--form-cancel\\"><span class=\\"MuiButton-label-139\\">Cancel</span><span class=\\"MuiTouchRipple-root-167\\"></span></button><button class=\\"MuiButtonBase-root-164 MuiButtonBase-disabled-165 MuiButton-root-138 MuiButton-text-140 MuiButton-flat-143 MuiButton-disabled-158 MuiButton-colorInherit-159 MuiDialogActions-action-137\\" tabindex=\\"-1\\" type=\\"submit\\" disabled=\\"\\" id=\\"login--form-submit\\"><span class=\\"MuiButton-label-139\\">Login</span></button></div></form></div></div></div>"`;
exports[`<LoginModal /> should load the component with props 1`] = `"<div role=\\"presentation\\" class=\\"MuiDialog-root\\" id=\\"login--form-container\\" style=\\"position: fixed; z-index: 1300; right: 0px; bottom: 0px; top: 0px; left: 0px;\\"><div class=\\"MuiBackdrop-root\\" aria-hidden=\\"true\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\"></div><div tabindex=\\"0\\" data-test=\\"sentinelStart\\"></div><div class=\\"MuiDialog-container MuiDialog-scrollPaper\\" style=\\"opacity: 1; webkit-transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;\\" role=\\"document\\" tabindex=\\"-1\\"><div class=\\"MuiPaper-root MuiPaper-elevation24 MuiDialog-paper MuiDialog-paperScrollPaper MuiDialog-paperWidthXs MuiDialog-paperFullWidth MuiPaper-rounded\\" role=\\"dialog\\"><form novalidate=\\"\\"><div class=\\"MuiDialogTitle-root\\"><h2 class=\\"MuiTypography-root MuiTypography-h6\\">Login</h2></div><div class=\\"MuiDialogContent-root\\"><div class=\\"MuiTypography-root MuiPaper-root MuiPaper-elevation6 MuiSnackbarContent-root css-11e09xf MuiTypography-body2\\" role=\\"alertdialog\\"><div class=\\"MuiSnackbarContent-message\\"><div class=\\"css-70qvj9\\" id=\\"client-snackbar\\"><svg class=\\"MuiSvgIcon-root css-1mbwbu9\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z\\"></path></svg><span><div><strong>Error Title</strong></div><div>Error Description</div></span></div></div></div><div class=\\"MuiFormControl-root MuiFormControl-fullWidth\\"><label class=\\"MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-required Mui-required\\" data-shrink=\\"false\\" for=\\"username\\">Username<span class=\\"MuiFormLabel-asterisk MuiInputLabel-asterisk\\">*</span></label><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-formControl MuiInput-formControl\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input MuiInput-input\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiFormControl-root css-164r41r MuiFormControl-fullWidth\\"><label class=\\"MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-required Mui-required\\" data-shrink=\\"false\\" for=\\"password\\">Password<span class=\\"MuiFormLabel-asterisk MuiInputLabel-asterisk\\">*</span></label><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-formControl MuiInput-formControl\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input MuiInput-input\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" value=\\"\\"></div></div></div><div class=\\"MuiDialogActions-root dialog-footer MuiDialogActions-spacing\\"><button class=\\"MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-colorInherit\\" tabindex=\\"0\\" type=\\"button\\" id=\\"login--form-cancel\\"><span class=\\"MuiButton-label\\">Cancel</span><span class=\\"MuiTouchRipple-root\\"></span></button><button class=\\"MuiButtonBase-root MuiButton-root MuiButton-text Mui-disabled MuiButton-colorInherit Mui-disabled\\" tabindex=\\"-1\\" type=\\"submit\\" disabled=\\"\\" id=\\"login--form-submit\\"><span class=\\"MuiButton-label\\">Login</span></button></div></form></div></div><div tabindex=\\"0\\" data-test=\\"sentinelEnd\\"></div></div>"`;

View File

@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<NoItem /> component should load the component in default state 1`] = `"<h6 class=\\"MuiTypography-root-1 MuiTypography-subtitle1-19 MuiTypography-gutterBottom-28\\">test</h6>"`;
exports[`<NoItem /> component should load the component in default state 1`] = `"<h6 class=\\"MuiTypography-root MuiTypography-subtitle1 MuiTypography-gutterBottom\\">test</h6>"`;
exports[`<NoItem /> component should set html from props 1`] = `"<h6 class=\\"MuiTypography-root-1 MuiTypography-subtitle1-19 MuiTypography-gutterBottom-28\\">This is a test string</h6>"`;
exports[`<NoItem /> component should set html from props 1`] = `"<h6 class=\\"MuiTypography-root MuiTypography-subtitle1 MuiTypography-gutterBottom\\">This is a test string</h6>"`;

View File

@ -1,46 +1,43 @@
import ListItem from '@material-ui/core/ListItem';
import Typography from '@material-ui/core/Typography';
import withWidth, { isWidthUp } from '@material-ui/core/withWidth';
import React from 'react';
import React, { useCallback } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import PackageImg from './img/package.svg';
import { Card, EmptyPackage, Heading, Inner, List, Wrapper } from './styles';
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
export const NOT_FOUND_TEXT = "Sorry, we couldn't find it...";
export const NOT_FOUND_TEXT = `Sorry, we couldn't find it...`;
export const LABEL_NOT_FOUND = `The page you're looking for doesn't exist.`;
export const LABEL_FOOTER_NOT_FOUND = 'Perhaps these links will help find what you are looking for:';
export type NotFoundProps = RouteComponentProps & { width: Breakpoint; history };
const NotFound: React.FC<NotFoundProps> = ({ history, width }) => {
const handleGoTo = (to: string): (() => void | undefined) => () => {
history.push(to);
};
const HOME_LABEL = 'Home';
const handleGoBack = (): ((e: React.MouseEvent<HTMLElement, MouseEvent>) => void | undefined) => () => {
history.goBack();
};
const renderSubTitle = (): JSX.Element => (
<Typography variant="subtitle1">
<div>{LABEL_NOT_FOUND}</div>
<div>{LABEL_FOOTER_NOT_FOUND}</div>
</Typography>
);
const NotFound: React.FC<NotFoundProps> = ({ history, width }) => {
const handleGomHome = useCallback(() => {
history.push('/');
}, [history]);
const renderList = (): JSX.Element => (
<List>
<ListItem button={true} divider={true} onClick={handleGoTo('/')}>
{'Home'}
</ListItem>
<ListItem button={true} divider={true} onClick={handleGoBack()}>
{'Back'}
<ListItem button={true} divider={true} onClick={handleGomHome}>
{HOME_LABEL}
</ListItem>
</List>
);
const renderSubTitle = (): JSX.Element => (
<Typography variant="subtitle1">
<div>{"The page you're looking for doesn't exist."}</div>
<div>{'Perhaps these links will help find what you are looking for:'}</div>
</Typography>
);
return (
<Wrapper>
<Wrapper data-testid="404">
<Inner>
<EmptyPackage alt="404 - Page not found" src={PackageImg} />
<Heading className="not-found-text" variant={isWidthUp('sm', width) ? 'h2' : 'h4'}>

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<NotFound /> component should load the component in default state 1`] = `<withRouter(WithTheme(WithWidth(NotFound))) />`;
exports[`<NotFound /> component should load the component in default state 1`] = `<withRouter(WithWidth(NotFound)) />`;

View File

@ -174,7 +174,7 @@ const Package: React.FC<PackageInterface> = ({
return (
<PackageList className={'package'}>
<ListItem alignItems={'flex-start'}>{renderPackageListItemText()}</ListItem>
<PackageListItem alignItems={'flex-start'}>
<PackageListItem alignItems={'flex-start'} button={true}>
{renderAuthorInfo()}
{renderVersionInfo()}
{renderPublishedInfo()}

View File

@ -1,5 +1,5 @@
import React from 'react';
import { shallow, mount } from 'enzyme';
import { mount } from 'enzyme';
import Readme from './Readme';
describe('<Readme /> component', () => {
@ -9,7 +9,7 @@ describe('<Readme /> component', () => {
});
test('should dangerously set html', () => {
const wrapper = shallow(<Readme description="<h1>This is a test string</h1>" />);
const wrapper = mount(<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>');
expect(wrapper.html()).toMatchSnapshot();
});

View File

@ -1,11 +1,30 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Repository from './Repository';
jest.mock('./img/git.png', () => '');
const mockPackageMeta = jest.fn(() => ({
latest: {
homepage: 'https://verdaccio.tld',
bugs: {
url: 'https://verdaccio.tld/bugs',
},
dist: {
tarball: 'https://verdaccio.tld/download',
},
},
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta: mockPackageMeta() });
},
}));
describe('<Repository /> component', () => {
beforeEach(() => {
jest.resetModules();
jest.resetAllMocks();
});
test('should render the component in default state', () => {
@ -18,14 +37,10 @@ describe('<Repository /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Repository = require('./Repository').default;
const wrapper = shallow(<Repository />);
const wrapper = mount(<Repository />);
expect(wrapper.html()).toMatchSnapshot();
});
@ -34,14 +49,10 @@ describe('<Repository /> component', () => {
latest: {},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Repository = require('./Repository').default;
const wrapper = shallow(<Repository />);
const wrapper = mount(<Repository />);
expect(wrapper.html()).toEqual('');
});
@ -55,14 +66,10 @@ describe('<Repository /> component', () => {
},
};
jest.doMock('../../pages/version/Version', () => ({
DetailContextConsumer: component => {
return component.children({ packageMeta });
},
}));
// @ts-ignore
mockPackageMeta.mockImplementation(() => packageMeta);
const Repository = require('./Repository').default;
const wrapper = shallow(<Repository />);
const wrapper = mount(<Repository />);
expect(wrapper.html()).toEqual('');
});
});

View File

@ -3,12 +3,11 @@
import React, { Component, Fragment, ReactElement } from 'react';
import Avatar from '@material-ui/core/Avatar';
import List from '@material-ui/core/List';
import ListItemText from '@material-ui/core/ListItemText';
import { DetailContextConsumer } from '../../pages/version/Version';
import { DetailContextConsumer } from '../../pages/Version';
import CopyToClipBoard from '../CopyToClipBoard';
import { Heading, GithubLink, RepositoryListItem } from './styles';
import { Heading, GithubLink, RepositoryListItem, RepositoryListItemText } from './styles';
import git from './img/git.png';
import { isURL } from '../../utils/url';
@ -41,10 +40,10 @@ class Repository extends Component {
return (
<Fragment>
<List dense={true} subheader={<Heading variant="subheading">{'Repository'}</Heading>}>
<RepositoryListItem>
<List dense={true} subheader={<Heading variant="subtitle1">{'Repository'}</Heading>}>
<RepositoryListItem button={true}>
<Avatar src={git} />
<ListItemText primary={this.renderContent(url)} />
<RepositoryListItemText primary={this.renderContent(url)} />
</RepositoryListItem>
</List>
</Fragment>

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Repository /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root-1 MuiList-dense-3 MuiList-padding-2 MuiList-subheader-4\\"><h3 class=\\"MuiTypography-root-5 MuiTypography-subheading-12 css-hyrz44 e1wmjxnh0\\">Repository</h3><li class=\\"MuiListItem-root-41 MuiListItem-default-44 MuiListItem-dense-45 MuiListItem-gutters-49 css-z8a2h0 e1wmjxnh4\\"><div class=\\"MuiAvatar-root-53 MuiAvatar-colorDefault-54\\"></div><div class=\\"MuiListItemText-root-56 MuiListItemText-dense-58\\"><span class=\\"MuiTypography-root-5 MuiTypography-subheading-12 MuiListItemText-primary-59 MuiListItemText-textDense-61\\"><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\"><a href=\\"git+https://github.com/verdaccio/ui.git\\" target=\\"_blank\\" class=\\"css-15gl0ho e1wmjxnh2\\">git+https://github.com/verdaccio/ui.git</a></span><button class=\\"MuiButtonBase-root-76 MuiIconButton-root-70 css-56v3u0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label-75\\"><svg class=\\"MuiSvgIcon-root-79\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span></button></div></span></div></li></ul>"`;
exports[`<Repository /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root MuiList-dense MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-hyrz44 e1wmjxnh0 MuiTypography-subtitle1\\">Repository</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-xugzlj e1wmjxnh4 MuiListItem-dense MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-colorDefault\\"></div><div class=\\"MuiListItemText-root css-1vhg3jx e1wmjxnh5 MuiListItemText-dense\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body2\\"><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-1m8aenu eb8w2fo1\\"><a href=\\"git+https://github.com/verdaccio/ui.git\\" target=\\"_blank\\" class=\\"css-15gl0ho e1wmjxnh2\\">git+https://github.com/verdaccio/ui.git</a></span><button class=\\"MuiButtonBase-root MuiIconButton-root css-0 eb8w2fo2\\" tabindex=\\"0\\" type=\\"button\\" title=\\"Copy to Clipboard\\"><span class=\\"MuiIconButton-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm-1 4l6 6v10c0 1.1-.9 2-2 2H7.99C6.89 23 6 22.1 6 21l.01-14c0-1.1.89-2 1.99-2h7zm-1 7h5.5L14 6.5V12z\\"></path></svg></span><span class=\\"MuiTouchRipple-root\\"></span></button></div></span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@ -6,6 +6,7 @@ import Typography from '@material-ui/core/Typography';
import Github from '../../icons/GitHub';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes';
import ListItemText from '@material-ui/core/ListItemText';
export const Heading = styled(Typography)({
'&&': {
@ -36,7 +37,16 @@ export const GithubLogo = styled(Github)({
export const RepositoryListItem = styled(ListItem)({
'&&': {
paddingLeft: 0,
paddingRight: 0,
padding: 0,
},
'&&:hover': {
backgroundColor: 'transparent',
},
});
export const RepositoryListItemText = styled(ListItemText)({
'&&': {
padding: '0 10px',
margin: 0,
},
});

View File

@ -5,7 +5,7 @@ import { BrowserRouter } from 'react-router-dom';
import Search from './Search';
const SEARCH_FILE_PATH = './Search';
const API_FILE_PATH = '../../utils/api';
const API_FILE_PATH = '../../utils/calls';
const URL_FILE_PATH = '../../utils/url';
// Global mocks
@ -165,8 +165,7 @@ describe('<Search /> component test', () => {
const suggestions = [{ name: 'verdaccio' }, { name: 'verdaccio-htpasswd' }];
jest.doMock(API_FILE_PATH, () => ({
request(url: string) {
expect(url).toEqual('search/verdaccio');
callSearch(url: string) {
return Promise.resolve(apiResponse);
},
}));
@ -194,7 +193,7 @@ describe('<Search /> component test', () => {
test('handleFetchPackages: when browser cancel a request', async () => {
const apiResponse = { name: 'AbortError' };
jest.doMock(API_FILE_PATH, () => ({ request: jest.fn(() => Promise.reject(apiResponse)) }));
jest.doMock(API_FILE_PATH, () => ({ callSearch: jest.fn(() => Promise.reject(apiResponse)) }));
const Search = require(SEARCH_FILE_PATH).Search;
@ -219,8 +218,7 @@ describe('<Search /> component test', () => {
const apiResponse = { name: 'BAD_REQUEST' };
jest.doMock(API_FILE_PATH, () => ({
request(url) {
expect(url).toEqual('search/verdaccio');
callSearch(url) {
return Promise.reject(apiResponse);
},
}));

View File

@ -6,9 +6,9 @@ import { default as IconSearch } from '@material-ui/icons/Search';
import InputAdornment from '@material-ui/core/InputAdornment';
import debounce from 'lodash/debounce';
import API from '../../utils/api';
import AutoComplete from '../AutoComplete';
import colors from '../../utils/styles/colors';
import { callSearch } from '../../utils/calls';
export interface State {
search: string;
@ -148,7 +148,7 @@ export class Search extends Component<RouteComponentProps<{}>, State> {
const signal = controller.signal;
// Keep track of search requests.
this.requestList.push(controller);
const suggestions = await API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal });
const suggestions = await callSearch(value, signal);
// @ts-ignore
this.setState({
suggestions,

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Search /> component test should load the component in default state 1`] = `"<div class=\\"css-1crzyyo e1rflf270\\"><div role=\\"combobox\\" aria-haspopup=\\"listbox\\" aria-owns=\\"react-autowhatever-1\\" aria-expanded=\\"false\\" class=\\"react-autosuggest__container\\"><div class=\\"MuiFormControl-root-1 MuiFormControl-fullWidth-4 react-autosuggest__input\\" aria-autocomplete=\\"list\\" aria-controls=\\"react-autowhatever-1\\"><div class=\\"MuiInputBase-root-18 MuiInput-root-5 css-n9ojyg MuiInput-underline-9 MuiInputBase-fullWidth-27 MuiInput-fullWidth-12 MuiInputBase-formControl-19 MuiInput-formControl-6 MuiInputBase-adornedStart-22\\"><div class=\\"MuiInputAdornment-root-35 MuiInputAdornment-positionStart-37 css-16qv2i2\\"><svg class=\\"MuiSvgIcon-root-40\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z\\"></path><path fill=\\"none\\" d=\\"M0 0h24v24H0z\\"></path></svg></div><input aria-invalid=\\"false\\" autocomplete=\\"off\\" class=\\"MuiInputBase-input-28 MuiInput-input-13 css-hodoyq MuiInputBase-inputAdornedStart-33\\" placeholder=\\"Search Packages\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiPaper-root-49 MuiPaper-elevation2-53 react-autosuggest__suggestions-container css-cfo6a e1rflf271\\" id=\\"react-autowhatever-1\\" role=\\"listbox\\"></div></div></div>"`;
exports[`<Search /> component test should load the component in default state 1`] = `"<div class=\\"css-1crzyyo e1rflf270\\"><div role=\\"combobox\\" aria-haspopup=\\"listbox\\" aria-owns=\\"react-autowhatever-1\\" aria-expanded=\\"false\\" class=\\"react-autosuggest__container\\"><div class=\\"MuiFormControl-root MuiTextField-root react-autosuggest__input MuiFormControl-fullWidth\\" aria-autocomplete=\\"list\\" aria-controls=\\"react-autowhatever-1\\"><div class=\\"MuiInputBase-root MuiInput-root css-n9ojyg MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart\\"><div class=\\"MuiInputAdornment-root css-16qv2i2 MuiInputAdornment-positionStart\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><path d=\\"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z\\"></path></svg></div><input aria-invalid=\\"false\\" autocomplete=\\"off\\" class=\\"MuiInputBase-input MuiInput-input css-hodoyq MuiInputBase-inputAdornedStart\\" placeholder=\\"Search Packages\\" type=\\"text\\" value=\\"\\"></div></div><div class=\\"MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container css-cfo6a e1rflf271\\" id=\\"react-autowhatever-1\\" role=\\"listbox\\"></div></div></div>"`;

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Spinner /> component should render the component in default state 1`] = `"<div class=\\"css-vqrgi e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root-1 MuiCircularProgress-colorPrimary-4 MuiCircularProgress-indeterminate-3 css-15gl0ho e1ag4h8b1\\" style=\\"width:50px;height:50px\\" role=\\"progressbar\\"><svg class=\\"MuiCircularProgress-svg-6\\" viewBox=\\"22 22 44 44\\"><circle class=\\"MuiCircularProgress-circle-7 MuiCircularProgress-circleIndeterminate-9\\" cx=\\"44\\" cy=\\"44\\" r=\\"20.2\\" fill=\\"none\\" stroke-width=\\"3.6\\"></circle></svg></div></div>"`;
exports[`<Spinner /> component should render the component in default state 1`] = `"<div class=\\"css-vqrgi e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root css-15gl0ho e1ag4h8b1 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate\\" style=\\"width:50px;height:50px\\" role=\\"progressbar\\"><svg class=\\"MuiCircularProgress-svg\\" viewBox=\\"22 22 44 44\\"><circle class=\\"MuiCircularProgress-circle MuiCircularProgress-circleIndeterminate\\" cx=\\"44\\" cy=\\"44\\" r=\\"20.2\\" fill=\\"none\\" stroke-width=\\"3.6\\"></circle></svg></div></div>"`;

View File

@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import TextField from './TextField';
@ -9,7 +9,7 @@ describe('<TextField /> component', () => {
value: 'test',
};
test('should render the component in default state', () => {
const wrapper = shallow(<TextField name={props.name} value={props.value} />);
const wrapper = mount(<TextField name={props.name} value={props.value} />);
expect(wrapper.html()).toMatchSnapshot();
});
});

View File

@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<TextField /> component should render the component in default state 1`] = `"<div class=\\"MuiFormControl-root-1\\"><div class=\\"MuiInputBase-root-18 MuiInput-root-5 MuiInput-underline-9 MuiInputBase-formControl-19 MuiInput-formControl-6\\"><input type=\\"text\\" aria-invalid=\\"false\\" class=\\"MuiInputBase-input-28 MuiInput-input-13\\" name=\\"test\\" value=\\"test\\"/></div></div>"`;
exports[`<TextField /> component should render the component in default state 1`] = `"<div class=\\"MuiFormControl-root MuiTextField-root\\"><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-formControl MuiInput-formControl\\"><input aria-invalid=\\"false\\" class=\\"MuiInputBase-input MuiInput-input\\" name=\\"test\\" type=\\"text\\" value=\\"test\\"></div></div>"`;

View File

@ -2,7 +2,7 @@ import React, { ReactElement } from 'react';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import { DetailContextConsumer } from '../../pages/version/Version';
import { DetailContextConsumer } from '../../pages/Version';
import NoItems from '../NoItems';
import { formatDateDistance } from '../../utils/package';
@ -45,7 +45,7 @@ class UpLinks extends React.PureComponent<{}> {
return (
uplinks && (
<>
<Heading variant="subheading">{'Uplinks'}</Heading>
<Heading variant="subtitle1">{'Uplinks'}</Heading>
{this.renderUpLinksList(uplinks)}
</>
)

View File

@ -1,11 +1,74 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router';
import Versions from './Versions';
import Versions, { LABEL_CURRENT_TAGS, LABEL_VERSION_HISTORY } from './Versions';
import data from './__partials__/data.json';
describe('<Versions /> component', () => {
test('should render the component in default state', () => {
const wrapper = shallow(<Versions />);
import { render, cleanup } from '@testing-library/react';
const mockPackageMeta = jest.fn(() => ({
packageName: 'foo',
packageMeta: data,
}));
jest.mock('../../pages/Version', () => ({
DetailContextConsumer: component => {
return component.children({ ...mockPackageMeta() });
},
}));
describe('<Version /> component', () => {
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
cleanup();
});
// FIXME: this test is not deterministic (writes `N days ago` in the snapshot, where N is random number)
test.skip('should render the component in default state', () => {
const wrapper = mount(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(wrapper.html()).toMatchSnapshot();
});
test('should render versions', () => {
const { getByText } = render(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(getByText(LABEL_VERSION_HISTORY)).toBeTruthy();
expect(getByText(LABEL_CURRENT_TAGS)).toBeTruthy();
// pick some versions
expect(getByText('2.3.0')).toBeTruthy();
expect(getByText('canary')).toBeTruthy();
});
test('should not render versions', () => {
const request = {
packageName: 'foo',
};
// @ts-ignore
mockPackageMeta.mockImplementation(() => request);
const { queryByText } = render(
<MemoryRouter>
<Versions />
</MemoryRouter>
);
expect(queryByText(LABEL_VERSION_HISTORY)).toBeFalsy();
expect(queryByText(LABEL_CURRENT_TAGS)).toBeFalsy();
});
test.todo('should click on version link');
});

View File

@ -1,56 +1,85 @@
import { DetailContextConsumer } from '../../pages/version/Version';
import { formatDateDistance } from '../../utils/package';
import { Heading, Spacer, ListItemText } from './styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import React, { ReactElement } from 'react';
import List from '@material-ui/core/List';
import { Link as RouterLink } from 'react-router-dom';
import Link from '@material-ui/core/Link';
import ListItem from '@material-ui/core/ListItem';
import { DetailContextConsumer } from '../../pages/Version';
import { formatDateDistance } from '../../utils/package';
import { DIST_TAGS } from '../../../lib/constants';
const NOT_AVAILABLE = 'Not available';
import { Heading, Spacer, ListItemText } from './styles';
export const NOT_AVAILABLE = 'Not available';
export const LABEL_CURRENT_TAGS = 'Current Tags';
export const LABEL_VERSION_HISTORY = 'Version History';
class Versions extends React.PureComponent {
public render(): ReactElement<HTMLDivElement> {
return (
<DetailContextConsumer>
{context => {
return context && context.packageMeta && this.renderContent(context.packageMeta);
const { packageMeta, packageName } = context;
if (!packageMeta) {
return null;
}
return this.renderContent(packageMeta, packageName);
}}
</DetailContextConsumer>
);
}
public renderPackageList = (packages: {}, isVersion: boolean = false, timeMap: Record<string, {}> = {}): ReactElement<HTMLDivElement> => {
public renderPackageList = (packages: {}, timeMap: Record<string, {}>, packageName): ReactElement<HTMLDivElement> => {
return (
<List>
<List dense={true}>
{Object.keys(packages)
.reverse()
.map(version => (
<ListItem className="version-item" key={version}>
<Link component={RouterLink} to={`/-/web/detail/${packageName}/v/${version}`}>
<ListItemText>{version}</ListItemText>
</Link>
<Spacer />
{isVersion && <ListItemText>{timeMap[version] ? `${formatDateDistance(timeMap[version])} ago` : NOT_AVAILABLE}</ListItemText>}
{isVersion === false && <ListItemText>{packages[version]}</ListItemText>}
<ListItemText>{timeMap[version] ? `${formatDateDistance(timeMap[version])} ago` : NOT_AVAILABLE}</ListItemText>
</ListItem>
))}
</List>
);
};
public renderContent(packageMeta): ReactElement<HTMLDivElement> {
public renderTagList = (packages: {}): ReactElement<HTMLDivElement> => {
return (
<List dense={true}>
{Object.keys(packages)
.reverse()
.map(tag => (
<ListItem className="version-item" key={tag}>
<ListItemText>{tag}</ListItemText>
<Spacer />
<ListItemText>{packages[tag]}</ListItemText>
</ListItem>
))}
</List>
);
};
public renderContent(packageMeta, packageName): ReactElement<HTMLDivElement> {
const { versions = {}, time: timeMap = {}, [DIST_TAGS]: distTags = {} } = packageMeta;
return (
<>
{distTags && (
<>
<Heading variant="subheading">{'Current Tags'}</Heading>
{this.renderPackageList(distTags, false, timeMap)}
<Heading variant="subtitle1">{LABEL_CURRENT_TAGS}</Heading>
{this.renderTagList(distTags)}
</>
)}
{versions && (
<>
<Heading variant="subheading">{'Version History'}</Heading>
{this.renderPackageList(versions, true, timeMap)}
<Heading variant="subtitle1">{LABEL_VERSION_HISTORY}</Heading>
{this.renderPackageList(versions, timeMap, packageName)}
</>
)}
</>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,27 @@
import React, { FC, ReactElement } from 'react';
import Grid from '@material-ui/core/Grid';
import DetailContainer from '../../components/DetailContainer';
import DetailSidebar from '../../components/DetailSidebar';
function renderDetail(): ReactElement<HTMLElement> {
return <DetailContainer />;
}
function renderSidebar(): ReactElement<HTMLElement> {
return <DetailSidebar />;
}
const Layout: FC<{}> = () => {
return (
<Grid className={'container content'} container={true} data-testid="version-layout" spacing={0}>
<Grid item={true} xs={8}>
{renderDetail()}
</Grid>
<Grid item={true} xs={4}>
{renderSidebar()}
</Grid>
</Grid>
);
};
export { Layout };

View File

@ -0,0 +1,100 @@
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
import vueMetadata from '../../../test/fixtures/metadata/vue.json';
import Version from './Version';
import { waitForElement } from '@testing-library/dom';
import ErrorBoundary from '../../App/AppError';
// :-) we mock this otherways fails on render, some weird issue on material-ui
jest.mock('@material-ui/core/Avatar');
// eslint-disable-next-line react/display-name
jest.mock('../../components/NotFound', () => () => <div>{'Not found'}</div>);
describe('test Version page', () => {
jest.setTimeout(40000000);
beforeAll(() => {
// FIXME: a better way to mock this
// @ts-ignore
global.window.VERDACCIO_API_URL = 'http://test';
});
afterEach(() => {
cleanup();
});
beforeEach(() => {
jest.resetAllMocks();
// @ts-ignore
fetch.resetMocks();
});
test('should render the version page', async () => {
const readmeText = 'test';
// @ts-ignore
fetch.mockResponses(
[[JSON.stringify(vueMetadata)], { status: 200, headers: { 'content-type': 'application/json' } }],
[[`<p align="center">${readmeText}</p>`], { status: 200, headers: { 'content-type': 'text/html' } }]
);
const { getByTestId, getByText } = render(
<ErrorBoundary>
<MemoryRouter>
<Version match={{ params: { ['package']: 'vue' } }}></Version>
</MemoryRouter>
</ErrorBoundary>
);
// first it display loading
const hasLoading = getByTestId('loading');
expect(hasLoading).toBeTruthy();
// we wait fetch response (mocked above)
await waitForElement(() => getByTestId('version-layout'));
// check whether readme was loaded
const hasReadme = getByText(readmeText);
expect(hasReadme).toBeTruthy();
});
test('should render 404 page if the resources are not found', async () => {
// @ts-ignore
fetch.mockResponses(
[[JSON.stringify({})], { status: 404, headers: { 'content-type': 'application/json' } }],
[[``], { status: 404, headers: { 'content-type': 'text/html' } }]
);
const { getByTestId, getByText } = render(
<ErrorBoundary>
<MemoryRouter>
<Version match={{ params: { ['package']: 'vue' } }}></Version>
</MemoryRouter>
</ErrorBoundary>
);
// first it display loading
const hasLoading = getByTestId('loading');
expect(hasLoading).toBeTruthy();
// we wait fetch response (mocked above)
await waitForElement(() => getByText('Not found'));
// check whether readme was loaded
const hasReadme = getByText('Not found');
expect(hasReadme).toBeTruthy();
});
// Wanna contribute? Here we some scenarios we need to test
test.todo('should test click on tabs');
test.todo('should check what is rendered int he sidebar is correct');
test.todo('should test click back home on 404');
test.todo('should test click on elements in the sidebar');
test.todo('should test other not consider scenarios');
});

View File

@ -0,0 +1,98 @@
import React, { useEffect, useState } from 'react';
import { callDetailPage, callReadme } from '../../utils/calls';
import { buildScopePackage } from '../../utils/package';
import Loading from '../../components/Loading/Loading';
import NotFound from '../../components/NotFound';
import { Layout } from './Layout';
import { DetailContextProvider } from './context';
import { StateInterface } from './types';
export function getRouterPackageName(params): string {
const packageName = params.package;
const { scope } = params;
if (scope) {
return buildScopePackage(scope, packageName);
}
return packageName;
}
function fillTitle(text) {
return `Verdaccio - ${text}`;
}
function isVersionValid(packageMeta, packageVersion): boolean {
const hasVersion = typeof packageVersion !== 'undefined';
if (!hasVersion) {
// if is undefined, that means versions does not exist, we continue
return true;
}
const hasMatchVersion = Object.keys(packageMeta.versions).includes(packageVersion);
return hasMatchVersion;
}
const Version = ({ match: { params } }) => {
const pkgName = getRouterPackageName(params);
const [readMe, setReadme] = useState();
const [packageName, setPackageName] = useState(pkgName);
// eslint-disable-next-line no-unused-vars
const [packageVersion, setPackageVersion] = useState(params.version);
const [packageMeta, setPackageMeta] = useState();
const [isLoading, setIsLoading] = useState(true);
const [notFound, setNotFound] = useState(false);
useEffect(() => {
(async () => {
try {
const packageMeta = (await callDetailPage(packageName, packageVersion)) as Partial<StateInterface>;
const readMe = (await callReadme(packageName, packageVersion)) as Partial<StateInterface>;
if (isVersionValid(packageMeta, packageVersion)) {
setReadme(readMe);
setPackageMeta(packageMeta);
setIsLoading(false);
} else {
setIsLoading(false);
setNotFound(true);
}
} catch (error) {
setNotFound(true);
setIsLoading(false);
}
})();
}, [packageName, packageVersion]);
useEffect(() => {
if (!packageVersion) {
document.title = fillTitle(packageName);
} else {
document.title = fillTitle(`${packageName}@${packageVersion}`);
}
}, [packageName, packageVersion]);
useEffect(() => {
const pkgName = getRouterPackageName(params);
setPackageName(pkgName);
setPackageVersion(params.version);
}, [params, setPackageName, setPackageVersion]);
const isNotFound = notFound || typeof packageMeta === 'undefined' || typeof packageName === 'undefined' || typeof readMe === 'undefined';
const renderContent = (): React.ReactElement<HTMLElement> => {
if (isLoading) {
return <Loading />;
} else if (isNotFound) {
return <NotFound />;
} else {
return <Layout />;
}
};
return (
<DetailContextProvider value={{ packageMeta, packageVersion, readMe, packageName, enableLoading: setIsLoading }}>{renderContent()}</DetailContextProvider>
);
};
export default Version;

View File

@ -0,0 +1,7 @@
import React, { Consumer, Provider } from 'react';
import { DetailContextProps, VersionPageConsumerProps } from './types';
export const DetailContext = React.createContext<Partial<DetailContextProps>>({});
export const DetailContextProvider: Provider<Partial<VersionPageConsumerProps>> = DetailContext.Provider;
export const DetailContextConsumer: Consumer<Partial<VersionPageConsumerProps>> = DetailContext.Consumer;

View File

@ -0,0 +1,3 @@
export { DetailContextProps, VersionPageConsumerProps } from './types';
export { DetailContext, DetailContextConsumer, DetailContextProvider } from './context';
export { default } from './Version';

View File

@ -0,0 +1,30 @@
import { PackageMetaInterface } from '../../../types/packageMeta';
export interface DetailContextProps {
packageMeta: PackageMetaInterface;
packageVersion?: string;
readMe: string;
packageName: string;
enableLoading: () => void;
}
export interface VersionPageConsumerProps {
packageMeta: PackageMetaInterface;
readMe: string;
packageName: string;
packageVersion?: string;
// FIXME: looking for the appropiated type here
enableLoading: any;
}
export interface PropsInterface {
match: boolean;
}
export interface StateInterface {
readMe: string;
packageName: string;
packageMeta?: PackageMetaInterface;
isLoading: boolean;
notFound: boolean;
}

View File

@ -1,160 +0,0 @@
import React, { Component, ReactElement, Consumer, Provider } from 'react';
import Grid from '@material-ui/core/Grid';
import Loading from '../../components/Loading/Loading';
import DetailContainer from '../../components/DetailContainer/DetailContainer';
import DetailSidebar from '../../components/DetailSidebar/DetailSidebar';
import { callDetailPage } from '../../utils/calls';
import { getRouterPackageName } from '../../utils/package';
import NotFound from '../../components/NotFound';
import { PackageMetaInterface } from '../../../types/packageMeta';
export interface DetailContextProps {
packageMeta: PackageMetaInterface;
readMe: string;
packageName: string;
enableLoading: () => void;
}
export const DetailContext = React.createContext<Partial<DetailContextProps>>({});
export interface VersionPageConsumerProps {
packageMeta: PackageMetaInterface;
readMe: string;
packageName: string;
enableLoading: () => void;
}
export const DetailContextProvider: Provider<Partial<VersionPageConsumerProps>> = DetailContext.Provider;
export const DetailContextConsumer: Consumer<Partial<VersionPageConsumerProps>> = DetailContext.Consumer;
interface PropsInterface {
match: boolean;
}
interface StateInterface {
readMe: string;
packageName: string;
packageMeta: PackageMetaInterface | null;
isLoading: boolean;
notFound: boolean;
}
class VersionPage extends Component<PropsInterface, Partial<StateInterface>> {
constructor(props) {
super(props);
this.state = {
readMe: '',
packageName: getRouterPackageName(props.match),
packageMeta: null,
isLoading: true,
notFound: false,
};
}
public static getDerivedStateFromProps(nextProps, prevState): { packageName?: string; isLoading: boolean; notFound?: boolean } | null {
const { match } = nextProps;
const packageName = getRouterPackageName(match);
if (packageName !== prevState.packageName) {
try {
return {
packageName,
isLoading: false,
};
} catch (err) {
return {
notFound: true,
isLoading: false,
};
}
} else {
return null;
}
}
public async componentDidMount(): Promise<void> {
await this.loadPackageInfo();
}
/* eslint no-unused-vars: 0 */
public async componentDidUpdate(nextProps, prevState: StateInterface): Promise<void> {
const { packageName } = this.state;
if (packageName !== prevState.packageName) {
const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
this.setState({
readMe,
packageMeta,
packageName,
notFound: false,
isLoading: false,
});
}
}
public render(): ReactElement<HTMLElement> {
const { isLoading, packageMeta, readMe, packageName } = this.state;
if (isLoading) {
return <Loading />;
} else if (!packageMeta) {
return <NotFound />;
} else {
return (
<DetailContextProvider value={{ packageMeta, readMe, packageName, enableLoading: this.enableLoading }}>
<Grid className={'container content'} container={true} spacing={0}>
<Grid item={true} xs={8}>
{this.renderDetail()}
</Grid>
<Grid item={true} xs={4}>
{this.renderSidebar()}
</Grid>
</Grid>
</DetailContextProvider>
);
}
}
public async loadPackageInfo(): Promise<void> {
const { packageName } = this.state;
// FIXME: use utility
document.title = `Verdaccio - ${packageName}`;
this.setState({
readMe: '',
});
try {
const { readMe, packageMeta } = (await callDetailPage(packageName)) as Partial<StateInterface>;
this.setState({
readMe,
packageMeta,
packageName,
notFound: false,
isLoading: false,
});
} catch (err) {
this.setState({
notFound: true,
packageName,
isLoading: false,
});
}
}
public enableLoading = () => {
this.setState({
isLoading: true,
});
};
public renderDetail(): ReactElement<HTMLElement> {
return <DetailContainer />;
}
public renderSidebar(): ReactElement<HTMLElement> {
return <DetailSidebar />;
}
}
export default VersionPage;

View File

@ -1 +0,0 @@
export { default, DetailContextProps } from './Version';

View File

@ -13,7 +13,7 @@ const history = createBrowserHistory({
});
const NotFound = asyncComponent(() => import('./components/NotFound'));
const VersionPackage = asyncComponent(() => import('./pages/version/Version'));
const VersionPackage = asyncComponent(() => import('./pages/Version'));
const HomePage = asyncComponent(() => import('./pages/home'));
interface RouterAppProps {
@ -31,6 +31,8 @@ class RouterApp extends Component<RouterAppProps> {
<Route exact={true} path={'/'} render={this.renderHomePage} />
<Route exact={true} path={'/-/web/detail/@:scope/:package'} render={this.renderVersionPage} />
<Route exact={true} path={'/-/web/detail/:package'} render={this.renderVersionPage} />
<Route exact={true} path={'/-/web/detail/:package/v/:version'} render={this.renderVersionPage} />
<Route exact={true} path={'/-/web/detail/@:scope/:package/v/:version'} render={this.renderVersionPage} />
<Route component={NotFound} />
</Switch>
</>

View File

@ -1,14 +1,18 @@
import API from './api';
import { PackageMetaInterface } from 'types/packageMeta';
export interface DetailPage {
readMe: string | {};
packageMeta: PackageMetaInterface | {};
export async function callReadme(packageName, packageVersion?: string): Promise<string | {}> {
return await API.request<string | {}>(`package/readme/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
}
export async function callDetailPage(packageName): Promise<DetailPage> {
const readMe = await API.request<string | {}>(`package/readme/${packageName}`, 'GET');
const packageMeta = await API.request<PackageMetaInterface | {}>(`sidebar/${packageName}`, 'GET');
export async function callDetailPage(packageName: string, packageVersion?: string): Promise<PackageMetaInterface | {}> {
const packageMeta = await API.request<PackageMetaInterface | {}>(`sidebar/${packageName}${packageVersion ? `?v=${packageVersion}` : ''}`, 'GET');
return { readMe, packageMeta };
return packageMeta;
}
export function callSearch(value: string, signal: any) {
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#Browser_compatibility
// FUTURE: signal is not well supported for IE and Samsung Browser
return API.request(`search/${encodeURIComponent(value)}`, 'GET', { signal, headers: {} });
}

View File

@ -56,16 +56,10 @@ export function formatDateDistance(lastUpdate): string {
return distanceInWordsToNow(new Date(lastUpdate));
}
export function getRouterPackageName(match): string {
const packageName = match.params.package;
const scope = match.params.scope;
if (scope) {
export function buildScopePackage(scope: string, packageName: string) {
return `@${scope}/${packageName}`;
}
return packageName;
}
/**
* For <LastSync /> component
* @param {array} uplinks

24204
test/fixtures/metadata/vue.json vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,9 @@ new WebpackDevServer(compiler, {
contentBase: `${env.DIST_PATH}`,
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
historyApiFallback: {
disableDotRule: true,
},
quiet: true,
noInfo: false,
stats: {

View File

@ -7,8 +7,7 @@ module.exports = {
output: {
path: `${env.APP_ROOT}/static/`,
filename: '[name].[hash].js',
// FIXME: do we need this?
publicPath: 'ToReplaceByVerdaccio/-/static',
publicPath: '/-/static',
},
resolve: {

View File

@ -9,15 +9,18 @@
"allowSyntheticDefaultImports": true,
"jsx": "react",
"allowJs": true,
"resolveJsonModule": true,
"checkJs": false,
"esModuleInterop": true,
"baseUrl": ".",
"baseUrl": "."
},
"include": [
"src",
"types/*.d.ts", "scripts/lib", "node_modules/config"
"types/*.d.ts",
"scripts/lib",
"node_modules/config"
],
"exclude": [
"node_modules",
"node_modules"
]
}

6377
yarn.lock

File diff suppressed because it is too large Load Diff