Compare commits

..

4 Commits

Author SHA1 Message Date
Priscila Oliveira
8c9076d0a2 chore: update emotion dependencies 2019-11-16 00:28:36 +01:00
Priscila Oliveira
ea19a2bb47 Merge branch 'master' into refactor/migrate_autocomplete_to_mui 2019-11-15 23:20:30 +01:00
Priscila Oliveira
d9f463688d Merge branch 'master' into refactor/migrate_autocomplete_to_mui 2019-11-13 15:09:22 +01:00
Priscila Oliveira
571d9c3fa7 refactor: converting autoComplete to Mui's autocomplete 2019-11-10 16:31:29 +01:00
117 changed files with 2010 additions and 3452 deletions

View File

@@ -1,8 +1,3 @@
{ {
"presets": [["@verdaccio"]], "presets": [["@verdaccio"]]
"plugins": [
"emotion",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator"
]
} }

View File

@@ -1,2 +1 @@
save-prefix "" save-prefix ""
registry "https://registry.verdaccio.org"

View File

@@ -2,20 +2,6 @@
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. 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.7](https://github.com/verdaccio/ui/compare/v0.3.6...v0.3.7) (2019-11-24)
### Features
* Added Theme and migrate to emotion@10.x 🚀 ([#286](https://github.com/verdaccio/ui/issues/286)) ([111f0c5](https://github.com/verdaccio/ui/commit/111f0c50e5053202ca55fe4f3f28dd30e4932240))
### Bug Fixes
* **#300:** correctly reference registry url from options ([ee74474](https://github.com/verdaccio/ui/commit/ee74474811eb609072e1678bcb90db33756dcf38)), closes [#300](https://github.com/verdaccio/ui/issues/300)
* restore lint-staged@8.2.1 ([dbaa0c4](https://github.com/verdaccio/ui/commit/dbaa0c43b8104b350e4907387f89d4e9e719741f))
* update snapshots ([fd306de](https://github.com/verdaccio/ui/commit/fd306def9535d9168dc79ab020ec288a4d5df1a8))
### [0.3.6](https://github.com/verdaccio/ui/compare/v0.3.5...v0.3.6) (2019-11-08) ### [0.3.6](https://github.com/verdaccio/ui/compare/v0.3.5...v0.3.6) (2019-11-08)
### [0.3.5](https://github.com/verdaccio/ui/compare/v0.3.4...v0.3.5) (2019-11-07) ### [0.3.5](https://github.com/verdaccio/ui/compare/v0.3.4...v0.3.5) (2019-11-07)

View File

@@ -1,6 +1,6 @@
{ {
"name": "@verdaccio/ui-theme", "name": "@verdaccio/ui-theme",
"version": "0.3.7", "version": "0.3.6",
"description": "Verdaccio User Interface", "description": "Verdaccio User Interface",
"author": { "author": {
"name": "Verdaccio Core Team", "name": "Verdaccio Core Team",
@@ -13,12 +13,8 @@
"homepage": "https://verdaccio.org", "homepage": "https://verdaccio.org",
"main": "index.js", "main": "index.js",
"devDependencies": { "devDependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "7.7.4",
"@babel/plugin-proposal-optional-chaining": "7.7.4",
"@commitlint/cli": "8.2.0", "@commitlint/cli": "8.2.0",
"@commitlint/config-conventional": "8.2.0", "@commitlint/config-conventional": "8.2.0",
"@emotion/core": "10.0.22",
"@emotion/styled": "10.0.23",
"@material-ui/core": "4.6.1", "@material-ui/core": "4.6.1",
"@material-ui/icons": "4.5.1", "@material-ui/icons": "4.5.1",
"@octokit/rest": "16.35.0", "@octokit/rest": "16.35.0",
@@ -27,20 +23,20 @@
"@types/enzyme": "3.10.3", "@types/enzyme": "3.10.3",
"@types/jest": "24.0.23", "@types/jest": "24.0.23",
"@types/js-base64": "2.3.1", "@types/js-base64": "2.3.1",
"@types/lodash": "4.14.149", "@types/lodash": "4.14.147",
"@types/node": "12.12.11", "@types/node": "12.12.7",
"@types/react": "16.9.11", "@types/react": "16.9.11",
"@types/react-autosuggest": "9.3.13", "@types/react-autosuggest": "9.3.13",
"@types/react-dom": "16.9.4", "@types/react-dom": "16.9.4",
"@types/react-router-dom": "5.1.2", "@types/react-router-dom": "5.1.2",
"@types/request": "2.48.3", "@types/request": "2.48.3",
"@types/validator": "12.0.0", "@types/validator": "10.11.3",
"@types/webpack-env": "1.14.1", "@types/webpack-env": "1.14.1",
"@typescript-eslint/parser": "2.8.0", "@typescript-eslint/parser": "2.7.0",
"@verdaccio/babel-preset": "8.4.2", "@verdaccio/babel-preset": "8.2.0",
"@verdaccio/commons-api": "8.4.2", "@verdaccio/commons-api": "8.3.0",
"@verdaccio/eslint-config": "8.4.2", "@verdaccio/eslint-config": "8.2.0",
"@verdaccio/types": "8.4.2", "@verdaccio/types": "8.3.0",
"autosuggest-highlight": "3.1.1", "autosuggest-highlight": "3.1.1",
"babel-loader": "8.0.6", "babel-loader": "8.0.6",
"bundlesize": "0.18.0", "bundlesize": "0.18.0",
@@ -49,27 +45,26 @@
"concurrently": "5.0.0", "concurrently": "5.0.0",
"cross-env": "6.0.3", "cross-env": "6.0.3",
"css-loader": "3.2.0", "css-loader": "3.2.0",
"date-fns": "2.8.1", "date-fns": "2.7.0",
"detect-secrets": "1.0.5", "detect-secrets": "1.0.5",
"emotion": "10.0.23", "emotion": "10.0.23",
"emotion-theming": "10.0.19",
"enzyme": "3.10.0", "enzyme": "3.10.0",
"enzyme-adapter-react-16": "1.15.1", "enzyme-adapter-react-16": "1.15.1",
"enzyme-to-json": "3.4.3", "enzyme-to-json": "3.4.3",
"eslint": "6.7.0", "eslint": "6.6.0",
"eslint-plugin-codeceptjs": "1.2.0", "eslint-plugin-codeceptjs": "1.1.0",
"eslint-plugin-import": "2.18.2", "eslint-plugin-import": "2.18.2",
"eslint-plugin-jsx-a11y": "6.2.3", "eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.1", "eslint-plugin-prettier": "3.1.1",
"eslint-plugin-react": "7.16.0", "eslint-plugin-react": "7.16.0",
"eslint-plugin-react-hooks": "2.3.0", "eslint-plugin-react-hooks": "2.3.0",
"eslint-plugin-verdaccio": "8.4.2", "eslint-plugin-verdaccio": "8.2.0",
"file-loader": "4.3.0", "file-loader": "4.2.0",
"friendly-errors-webpack-plugin": "1.7.0", "friendly-errors-webpack-plugin": "1.7.0",
"get-stdin": "7.0.0", "get-stdin": "7.0.0",
"github-markdown-css": "3.0.1", "github-markdown-css": "3.0.1",
"html-webpack-plugin": "3.2.0", "html-webpack-plugin": "3.2.0",
"husky": "3.1.0", "husky": "3.0.9",
"identity-obj-proxy": "3.0.0", "identity-obj-proxy": "3.0.0",
"in-publish": "2.0.0", "in-publish": "2.0.0",
"jest": "24.9.0", "jest": "24.9.0",
@@ -95,28 +90,28 @@
"react": "16.12.0", "react": "16.12.0",
"react-autosuggest": "9.4.3", "react-autosuggest": "9.4.3",
"react-dom": "16.12.0", "react-dom": "16.12.0",
"react-hot-loader": "4.12.18", "react-hot-loader": "4.12.17",
"react-router-dom": "5.1.2", "react-router-dom": "5.1.2",
"request": "2.88.0", "request": "2.88.0",
"resolve-url-loader": "3.1.1", "resolve-url-loader": "3.1.1",
"rimraf": "3.0.0", "rimraf": "3.0.0",
"source-map-loader": "0.2.4", "source-map-loader": "0.2.4",
"standard-version": "7.0.1", "standard-version": "7.0.0",
"style-loader": "1.0.0", "style-loader": "1.0.0",
"stylelint": "12.0.0", "stylelint": "11.1.1",
"stylelint-config-recommended": "3.0.0", "stylelint-config-recommended": "3.0.0",
"stylelint-config-styled-components": "0.1.1", "stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.8.0", "stylelint-processor-styled-components": "1.8.0",
"stylelint-webpack-plugin": "1.1.0", "stylelint-webpack-plugin": "1.0.4",
"supertest": "4.0.2", "supertest": "4.0.2",
"typeface-roboto": "0.0.75", "typeface-roboto": "0.0.75",
"typescript": "3.7.2", "typescript": "3.7.2",
"uglifyjs-webpack-plugin": "2.2.0", "uglifyjs-webpack-plugin": "2.2.0",
"url-loader": "2.3.0", "url-loader": "2.2.0",
"validator": "12.1.0", "validator": "12.0.0",
"verdaccio": "4.3.5", "verdaccio": "4.3.4",
"verdaccio-auth-memory": "8.4.2", "verdaccio-auth-memory": "8.3.0",
"verdaccio-memory": "8.4.2", "verdaccio-memory": "8.3.0",
"wait-on": "3.3.0", "wait-on": "3.3.0",
"webpack": "4.41.2", "webpack": "4.41.2",
"webpack-bundle-analyzer": "3.6.0", "webpack-bundle-analyzer": "3.6.0",
@@ -188,11 +183,13 @@
}, },
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "lint-staged --relative", "pre-commit": "lint-staged",
"commit-msg": "commitlint -e $GIT_PARAMS" "commit-msg": "commitlint -e $GIT_PARAMS"
} }
}, },
"lint-staged": { "lint-staged": {
"relative": true,
"linters": {
"*.{js,tsx,ts}": [ "*.{js,tsx,ts}": [
"eslint . --ext .js,.ts,.tsx", "eslint . --ext .js,.ts,.tsx",
"prettier --write" "prettier --write"
@@ -202,6 +199,10 @@
"git add" "git add"
] ]
}, },
"ignore": [
"*.json"
]
},
"license": "MIT", "license": "MIT",
"commitlint": { "commitlint": {
"extends": [ "extends": [
@@ -213,5 +214,9 @@
"url": "https://opencollective.com/verdaccio", "url": "https://opencollective.com/verdaccio",
"logo": "https://opencollective.com/verdaccio/logo.txt" "logo": "https://opencollective.com/verdaccio/logo.txt"
}, },
"dependencies": {} "dependencies": {
"@emotion/core": "10.0.22",
"@emotion/styled": "10.0.23",
"@material-ui/lab": "4.0.0-alpha.31"
}
} }

View File

@@ -1,11 +1,11 @@
import React from 'react'; import React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import { render, waitForElement, fireEvent } from '../utils/test-react-testing-library';
import storage from '../utils/storage'; import storage from '../utils/storage';
// eslint-disable-next-line jest/no-mocks-import
import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__/token'; import { generateTokenWithTimeRange } from '../../jest/unit/components/__mocks__/token';
import App from './App'; import App from './App';
import { AppProps } from './AppContext';
jest.mock('../utils/storage', () => { jest.mock('../utils/storage', () => {
class LocalStorageMock { class LocalStorageMock {
@@ -30,75 +30,66 @@ jest.mock('../utils/storage', () => {
}); });
jest.mock('../utils/api', () => ({ jest.mock('../utils/api', () => ({
// eslint-disable-next-line jest/no-mocks-import
request: require('../../jest/unit/components/__mocks__/api').default.request, request: require('../../jest/unit/components/__mocks__/api').default.request,
})); }));
/* eslint-disable react/jsx-no-bind*/ describe('App', () => {
describe('<App />', () => { let wrapper: ReactWrapper<{}, AppProps, App>;
test('should display the Loading component at the beginning ', () => {
const { container, queryByTestId } = render(<App />);
expect(container.firstChild).toMatchSnapshot(); beforeEach(() => {
expect(queryByTestId('loading')).toBeTruthy(); wrapper = mount(<App />);
}); });
test('should display the Header component ', async () => { test('toggleLoginModal: should toggle the value in state', () => {
const { container, queryByTestId } = render(<App />); const { handleToggleLoginModal } = wrapper.instance();
expect(wrapper.state().showLoginModal).toBeFalsy();
expect(container.firstChild).toMatchSnapshot(); handleToggleLoginModal();
expect(queryByTestId('loading')).toBeTruthy(); expect(wrapper.state('showLoginModal')).toBeTruthy();
expect(wrapper.state('error')).toEqual(undefined);
// wait for the Header component appearance and return the element
const headerElement = await waitForElement(() => queryByTestId('header'));
expect(headerElement).toBeTruthy();
});
test('handleLogout - logouts the user and clear localstorage', async () => {
storage.setItem('username', 'verdaccio');
storage.setItem('token', generateTokenWithTimeRange(24));
const { queryByTestId } = render(<App />);
// wait for the Account's circle element component appearance and return the element
const accountCircleElement = await waitForElement(() => queryByTestId('header--menu-accountcircle'));
expect(accountCircleElement).toBeTruthy();
if (accountCircleElement) {
fireEvent.click(accountCircleElement);
// wait for the Button's logout element component appearance and return the element
const buttonLogoutElement = await waitForElement(() => queryByTestId('header--button-logout'));
expect(buttonLogoutElement).toBeTruthy();
if (buttonLogoutElement) {
fireEvent.click(buttonLogoutElement);
expect(queryByTestId('greetings-label')).toBeFalsy();
}
}
}); });
test('isUserAlreadyLoggedIn: token already available in storage', async () => { test('isUserAlreadyLoggedIn: token already available in storage', async () => {
storage.setItem('username', 'verdaccio'); storage.setItem('username', 'verdaccio');
storage.setItem('token', generateTokenWithTimeRange(24)); storage.setItem('token', generateTokenWithTimeRange(24));
const { isUserAlreadyLoggedIn } = wrapper.instance();
const { queryByTestId, queryAllByText } = render(<App />); isUserAlreadyLoggedIn();
// wait for the Account's circle element component appearance and return the element expect(wrapper.state('user').username).toEqual('verdaccio');
const accountCircleElement = await waitForElement(() => queryByTestId('header--menu-accountcircle')); });
expect(accountCircleElement).toBeTruthy();
if (accountCircleElement) { test('handleLogout - logouts the user and clear localstorage', async () => {
fireEvent.click(accountCircleElement); const { handleLogout } = wrapper.instance();
storage.setItem('username', 'verdaccio');
storage.setItem('token', 'xxxx.TOKEN.xxxx');
// wait for the Greeting's label element component appearance and return the element await handleLogout();
const greetingsLabelElement = await waitForElement(() => queryByTestId('greetings-label')); expect(wrapper.state('user')).toEqual({});
expect(greetingsLabelElement).toBeTruthy(); expect(wrapper.state('isUserLoggedIn')).toBeFalsy();
});
if (greetingsLabelElement) { test('handleDoLogin - login the user successfully', async () => {
expect(queryAllByText('verdaccio')).toBeTruthy(); const { handleDoLogin } = wrapper.instance();
} await handleDoLogin('sam', '1234');
} const result = {
username: 'sam',
};
expect(wrapper.state('isUserLoggedIn')).toBeTruthy();
expect(wrapper.state('showLoginModal')).toBeFalsy();
expect(storage.getItem('username')).toEqual('sam');
expect(storage.getItem('token')).toEqual('TEST_TOKEN');
expect(wrapper.state('user')).toEqual(result);
});
test('handleDoLogin - authentication failure', async () => {
const { handleDoLogin } = wrapper.instance();
await handleDoLogin('sam', '12345');
const result = {
description: 'bad username/password, access denied',
title: 'Unable to login',
type: 'error',
};
expect(wrapper.state('user')).toEqual({});
expect(wrapper.state('error')).toEqual(result);
}); });
}); });

View File

@@ -1,106 +1,188 @@
import React, { useState, useEffect } from 'react'; import React, { Component, ReactElement } from 'react';
import styled from '@emotion/styled';
import isNil from 'lodash/isNil'; import isNil from 'lodash/isNil';
import { Router } from 'react-router-dom';
import storage from '../utils/storage'; import storage from '../utils/storage';
import { isTokenExpire } from '../utils/login'; import { makeLogin, isTokenExpire } from '../utils/login';
import API from '../utils/api';
import Header from '../components/Header';
import Footer from '../components/Footer';
import Box from '../muiComponents/Box';
import Loading from '../components/Loading'; import Loading from '../components/Loading';
import LoginModal from '../components/Login';
import Header from '../components/Header';
import { Container, Content } from '../components/Layout';
import API from '../utils/api';
import Footer from '../components/Footer';
import StyleBaseline from '../design-tokens/StyleBaseline'; import StyleBaseline from '../design-tokens/StyleBaseline';
import { breakpoints } from '../utils/styles/media';
import AppContextProvider from './AppContextProvider'; import AppRoute from './AppRoute';
import AppRoute, { history } from './AppRoute'; import { AppProps, AppContextProvider } from './AppContext';
const StyledBoxContent = styled(Box)({ export default class App extends Component<{}, AppProps> {
padding: 15, public state: AppProps = {
[`@media screen and (min-width: ${breakpoints.container}px)`]: { logoUrl: window.VERDACCIO_LOGO,
maxWidth: breakpoints.container, user: {},
width: '100%', scope: window.VERDACCIO_SCOPE || '',
marginLeft: 'auto', showLoginModal: false,
marginRight: 'auto', isUserLoggedIn: false,
}, packages: [],
}); isLoading: true,
/* eslint-disable react/jsx-max-depth */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable react/jsx-no-bind */
/* eslint-disable react-hooks/exhaustive-deps */
const App: React.FC = () => {
const [user, setUser] = useState();
const [packages, setPackages] = useState([]);
const [isLoading, setIsLoading] = useState(true);
/**
* Logouts user
* Required by: <Header />
*/
const logout = () => {
storage.removeItem('username');
storage.removeItem('token');
setUser(undefined);
}; };
const checkUserAlreadyLoggedIn = () => { public componentDidMount(): void {
// checks for token validity this.isUserAlreadyLoggedIn();
const token = storage.getItem('token'); this.loadOnHandler();
const username = storage.getItem('username');
if (isTokenExpire(token) || isNil(username)) {
logout();
return;
} }
setUser({ username }); // eslint-disable-next-line no-unused-vars
public componentDidUpdate(_: AppProps, prevState: AppProps): void {
const { isUserLoggedIn } = this.state;
if (prevState.isUserLoggedIn !== isUserLoggedIn) {
this.loadOnHandler();
}
}
public render(): React.ReactElement<HTMLDivElement> {
const { isLoading, isUserLoggedIn, packages, logoUrl, user, scope } = this.state;
const context = { isUserLoggedIn, packages, logoUrl, user, scope };
return (
<>
<StyleBaseline />
<Container isLoading={isLoading}>
{isLoading ? <Loading /> : <AppContextProvider value={context}>{this.renderContent()}</AppContextProvider>}
{this.renderLoginModal()}
</Container>
</>
);
}
public isUserAlreadyLoggedIn = () => {
// checks for token validity
const token = storage.getItem('token');
const username: string = storage.getItem('username') as string;
if (isTokenExpire(token) || isNil(username)) {
this.handleLogout();
} else {
this.setState({
user: { username },
isUserLoggedIn: true,
});
}
}; };
const loadOnHandler = async () => { public loadOnHandler = async () => {
try { try {
const packages = await API.request('packages', 'GET'); const packages = await API.request<any[]>('packages', 'GET');
// FIXME add correct type for package // @ts-ignore: FIX THIS TYPE: Type 'any[]' is not assignable to type '[]'
setPackages(packages as never[]); this.setState({
packages,
isLoading: false,
});
} catch (error) { } catch (error) {
// FIXME: add dialog // FIXME: add dialog
console.error({ console.error({
title: 'Warning', title: 'Warning',
message: `Unable to load package list: ${error.message}`, message: `Unable to load package list: ${error.message}`,
}); });
this.setLoading(false);
} }
setIsLoading(false);
}; };
useEffect(() => { public setLoading = (isLoading: boolean) =>
checkUserAlreadyLoggedIn(); this.setState({
loadOnHandler(); isLoading,
}, []); });
/**
* Toggles the login modal
* Required by: <LoginModal /> <Header />
*/
public handleToggleLoginModal = () => {
this.setState(prevState => ({
showLoginModal: !prevState.showLoginModal,
}));
};
/**
* handles login
* Required by: <Header />
*/
public handleDoLogin = async (usernameValue: string, passwordValue: string) => {
const { username, token, error } = await makeLogin(usernameValue, passwordValue);
if (username && token) {
storage.setItem('username', username);
storage.setItem('token', token);
this.setLoggedUser(username);
}
if (error) {
this.setState({
user: {},
error,
});
}
};
public setLoggedUser = (username: string) => {
this.setState({
user: {
username,
},
isUserLoggedIn: true, // close login modal after successful login
showLoginModal: false, // set isUserLoggedIn to true
});
};
/**
* Logouts user
* Required by: <Header />
*/
public handleLogout = () => {
storage.removeItem('username');
storage.removeItem('token');
this.setState({
user: {},
isUserLoggedIn: false,
});
};
public renderLoginModal = (): ReactElement<HTMLElement> => {
const { error, showLoginModal } = this.state;
return (
<LoginModal
error={error}
onCancel={this.handleToggleLoginModal}
onSubmit={this.handleDoLogin}
visibility={showLoginModal}
/>
);
};
public renderContent = (): ReactElement<HTMLElement> => {
return ( return (
<> <>
<StyleBaseline /> <Content>
<Box display="flex" flexDirection="column" height="100%"> <AppRoute>{this.renderHeader()}</AppRoute>
{isLoading ? ( </Content>
<Loading />
) : (
<>
<Router history={history}>
<AppContextProvider packages={packages} user={user}>
<Header />
<StyledBoxContent flexGrow={1}>
<AppRoute />
</StyledBoxContent>
</AppContextProvider>
</Router>
<Footer /> <Footer />
</> </>
)}
</Box>
</>
); );
}; };
export default App; public renderHeader = (): ReactElement<HTMLElement> => {
const {
logoUrl,
user: { username },
scope,
} = this.state;
return (
<Header
logo={logoUrl}
onLogout={this.handleLogout}
onToggleLoginModal={this.handleToggleLoginModal}
scope={scope}
username={username}
/>
);
};
}

View File

@@ -1,23 +0,0 @@
import { createContext } from 'react';
import { FormError } from '../components/Login/Login';
export interface AppProps {
error?: FormError;
user?: User;
scope: string;
packages: any[];
}
export interface User {
username: string;
}
export interface AppContextProps extends AppProps {
setUser: (user?: User) => void;
setError: (error?: FormError) => void;
}
const AppContext = createContext<undefined | AppContextProps>(undefined);
export default AppContext;

20
src/App/AppContext.tsx Normal file
View File

@@ -0,0 +1,20 @@
import { createContext } from 'react';
import { FormError } from '../components/Login/Login';
export interface AppProps {
error?: FormError;
logoUrl: string;
user: {
username?: string;
};
scope: string;
showLoginModal: boolean;
isUserLoggedIn: boolean;
packages: [];
isLoading: boolean;
}
export const AppContext = createContext<Partial<AppProps>>({});
export const AppContextProvider = AppContext.Provider;
export const AppContextConsumer = AppContext.Consumer;

View File

@@ -1,61 +0,0 @@
import React, { useState, useEffect } from 'react';
import { FormError } from '../components/Login/Login';
import AppContext, { AppProps, User } from './AppContext';
interface Props {
packages: any[];
user?: User;
}
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable react-hooks/exhaustive-deps */
const AppContextProvider: React.FC<Props> = ({ children, packages, user }) => {
const [state, setState] = useState<AppProps>({
scope: window.VERDACCIO_SCOPE || '',
packages,
user,
});
useEffect(() => {
setState({
...state,
user,
});
}, [user]);
useEffect(() => {
setState({
...state,
packages,
});
}, [packages]);
const setUser = (user?: User) => {
setState({
...state,
user,
});
};
const setError = (error?: FormError) => {
setState({
...state,
error,
});
};
return (
<AppContext.Provider
value={{
...state,
setUser,
setError,
}}>
{children}
</AppContext.Provider>
);
};
export default AppContextProvider;

View File

@@ -4,7 +4,7 @@ import { createBrowserHistory } from 'history';
import Loading from '../components/Loading'; import Loading from '../components/Loading';
import AppContext from './AppContext'; import { AppContext } from './AppContext';
const NotFound = lazy(() => import('../components/NotFound')); const NotFound = lazy(() => import('../components/NotFound'));
const VersionContextProvider = lazy(() => import('../pages/Version/VersionContextProvider')); const VersionContextProvider = lazy(() => import('../pages/Version/VersionContextProvider'));
@@ -19,25 +19,19 @@ enum Route {
PACKAGE_VERSION = '/-/web/detail/:package/v/:version', PACKAGE_VERSION = '/-/web/detail/:package/v/:version',
} }
export const history = createBrowserHistory({ const history = createBrowserHistory({
basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix, basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix,
}); });
/* eslint react/jsx-max-depth: 0 */ /* eslint react/jsx-max-depth: 0 */
const AppRoute: React.FC = () => { const AppRoute: React.FC = ({ children }) => {
const appContext = useContext(AppContext); const appContext = useContext(AppContext);
const { isUserLoggedIn, packages } = appContext;
if (!appContext) {
throw Error('The app Context was not correct used');
}
const { user, packages } = appContext;
const isUserLoggedIn = user && user.username;
return ( return (
<Router history={history}> <Router history={history}>
<Suspense fallback={<Loading />}> <Suspense fallback={<Loading />}>
{children}
<Switch> <Switch>
<ReactRouterDomRoute exact={true} path={Route.ROOT}> <ReactRouterDomRoute exact={true} path={Route.ROOT}>
<HomePage isUserLoggedIn={!!isUserLoggedIn} packages={packages || []} /> <HomePage isUserLoggedIn={!!isUserLoggedIn} packages={packages || []} />

View File

@@ -1,179 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<App /> should display the Header component 1`] = `
.emotion-8 {
-webkit-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
position: absolute;
}
.emotion-2 {
margin: 0 0 30px 0;
border-radius: 25px;
box-shadow: 0 10px 20px 0 rgba(69,58,100,0.2);
background: #f7f8f6;
}
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 90px;
height: 90px;
}
.emotion-6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.emotion-4 {
color: #4b5e40;
}
<div
class="MuiBox-root MuiBox-root-215"
>
<div
class="emotion-8 emotion-9"
data-testid="loading"
>
<div
class="emotion-2 emotion-3"
>
<div
class="emotion-0 emotion-1"
/>
</div>
<div
class="emotion-6 emotion-7"
>
<div
class="MuiCircularProgress-root emotion-4 emotion-5 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate"
role="progressbar"
style="width: 50px; height: 50px;"
>
<svg
class="MuiCircularProgress-svg"
viewBox="22 22 44 44"
>
<circle
class="MuiCircularProgress-circle MuiCircularProgress-circleIndeterminate"
cx="44"
cy="44"
fill="none"
r="20.2"
stroke-width="3.6"
/>
</svg>
</div>
</div>
</div>
</div>
`;
exports[`<App /> should display the Loading component at the beginning 1`] = `
.emotion-8 {
-webkit-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
position: absolute;
}
.emotion-2 {
margin: 0 0 30px 0;
border-radius: 25px;
box-shadow: 0 10px 20px 0 rgba(69,58,100,0.2);
background: #f7f8f6;
}
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 90px;
height: 90px;
}
.emotion-6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.emotion-4 {
color: #4b5e40;
}
<div
class="MuiBox-root MuiBox-root-2"
>
<div
class="emotion-8 emotion-9"
data-testid="loading"
>
<div
class="emotion-2 emotion-3"
>
<div
class="emotion-0 emotion-1"
/>
</div>
<div
class="emotion-6 emotion-7"
>
<div
class="MuiCircularProgress-root emotion-4 emotion-5 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate"
role="progressbar"
style="width: 50px; height: 50px;"
>
<svg
class="MuiCircularProgress-svg"
viewBox="22 22 44 44"
>
<circle
class="MuiCircularProgress-circle MuiCircularProgress-circleIndeterminate"
cx="44"
cy="44"
fill="none"
r="20.2"
stroke-width="3.6"
/>
</svg>
</div>
</div>
</div>
</div>
`;

View File

@@ -1,2 +1 @@
export { default } from './App'; export { default } from './App';
export { default as AppContextProvider } from './AppContextProvider';

View File

@@ -1,9 +1,9 @@
import { css } from '@emotion/core'; import { css } from 'emotion';
import { theme } from '../design-tokens/theme'; import colors from '../utils/styles/colors';
export const alertError = css({ export const alertError = css({
backgroundColor: `${theme.palette.red} !important`, backgroundColor: `${colors.red} !important`,
minWidth: 'inherit !important', minWidth: 'inherit !important',
}); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import api from '../../utils/api'; import api from '../../utils/api';
import { ActionBar } from './ActionBar'; import { ActionBar } from './ActionBar';

View File

@@ -2,6 +2,6 @@
exports[`<ActionBar /> component should render the component in default state 1`] = `""`; 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 MuiList-padding\\"><div class=\\"MuiButtonBase-root MuiListItem-root css-l3mdff-ActionListItem eux6shq0 MuiListItem-gutters MuiListItem-button MuiListItem-alignItemsFlexStart\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><button class=\\"MuiButtonBase-root MuiFab-root css-is03ew-Fab 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>"`; 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-1br2q5z eux6shq0 MuiListItem-gutters MuiListItem-button MuiListItem-alignItemsFlexStart\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><button class=\\"MuiButtonBase-root MuiFab-root css-z6z5me 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>"`;
exports[`<ActionBar /> component when there is a button to open an issue 1`] = `"<ul class=\\"MuiList-root MuiList-padding\\"><div class=\\"MuiButtonBase-root MuiListItem-root css-l3mdff-ActionListItem eux6shq0 MuiListItem-gutters MuiListItem-button MuiListItem-alignItemsFlexStart\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><a href=\\"https://verdaccio.tld/bugs\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root MuiFab-root css-is03ew-Fab eux6shq1 MuiFab-sizeSmall\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><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><span class=\\"MuiTouchRipple-root\\"></span></button></a><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`; exports[`<ActionBar /> component when there is a button to open an issue 1`] = `"<ul class=\\"MuiList-root MuiList-padding\\"><div class=\\"MuiButtonBase-root MuiListItem-root css-1br2q5z eux6shq0 MuiListItem-gutters MuiListItem-button MuiListItem-alignItemsFlexStart\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><a href=\\"https://verdaccio.tld/bugs\\" target=\\"_blank\\"><button class=\\"MuiButtonBase-root MuiFab-root css-z6z5me eux6shq1 MuiFab-sizeSmall\\" tabindex=\\"0\\" type=\\"button\\"><span class=\\"MuiFab-label\\"><svg class=\\"MuiSvgIcon-root\\" focusable=\\"false\\" viewBox=\\"0 0 24 24\\" aria-hidden=\\"true\\" role=\\"presentation\\"><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><span class=\\"MuiTouchRipple-root\\"></span></button></a><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@@ -1,8 +1,8 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import colors from '../../utils/styles/colors';
import ListItem from '../../muiComponents/ListItem'; import ListItem from '../../muiComponents/ListItem';
import FloatingActionButton from '../../muiComponents/FloatingActionButton'; import FloatingActionButton from '../../muiComponents/FloatingActionButton';
import { Theme } from '../../design-tokens/theme';
export const ActionListItem = styled(ListItem)({ export const ActionListItem = styled(ListItem)({
paddingTop: 0, paddingTop: 0,
@@ -10,8 +10,8 @@ export const ActionListItem = styled(ListItem)({
paddingRight: 0, paddingRight: 0,
}); });
export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>(props => ({ export const Fab = styled(FloatingActionButton)({
backgroundColor: props.theme && props.theme.palette.primary.main, backgroundColor: colors.primary,
color: props.theme && props.theme.palette.white, color: colors.white,
marginRight: '10px', marginRight: '10px',
})); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import { DetailContext } from '../../pages/Version'; import { DetailContext } from '../../pages/Version';
import Authors from './Author'; import Authors from './Author';

View File

@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Author /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-1na337r-StyledText e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1k45khb-AuthorListItem 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 MuiAvatar-circle\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div></a><div class=\\"MuiListItemText-root css-1cnlq5d-AuthorListItemText 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 in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-b8upko e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-zw46c6 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 MuiAvatar-circle\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div></a><div class=\\"MuiListItemText-root css-fipixf 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 MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-1na337r-StyledText e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1k45khb-AuthorListItem e1xuehjw1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div><div class=\\"MuiListItemText-root css-1cnlq5d-AuthorListItemText 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 MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-b8upko e1xuehjw0 MuiTypography-subtitle1\\">Author</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-zw46c6 e1xuehjw1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle\\"><img alt=\\"verdaccio user\\" src=\\"https://www.gravatar.com/avatar/000000\\" class=\\"MuiAvatar-img\\"></div><div class=\\"MuiListItemText-root css-fipixf e1xuehjw2\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">verdaccio user</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@@ -1,5 +1,4 @@
import React, { KeyboardEvent } from 'react'; import React, { KeyboardEvent } from 'react';
import styled from '@emotion/styled';
import Autosuggest, { SuggestionSelectedEventData, InputProps, ChangeEvent } from 'react-autosuggest'; import Autosuggest, { SuggestionSelectedEventData, InputProps, ChangeEvent } from 'react-autosuggest';
import match from 'autosuggest-highlight/match'; import match from 'autosuggest-highlight/match';
import parse from 'autosuggest-highlight/parse'; import parse from 'autosuggest-highlight/parse';
@@ -9,20 +8,13 @@ import MenuItem from '../../muiComponents/MenuItem';
import { Wrapper, InputField, SuggestionContainer } from './styles'; import { Wrapper, InputField, SuggestionContainer } from './styles';
const StyledAnchor = styled('a')<{ fw: number }>(props => ({
fontWeight: props.fw,
}));
const StyledMenuItem = styled(MenuItem)({
cursor: 'pointer',
});
interface Props { interface Props {
suggestions: unknown[]; suggestions: unknown[];
suggestionsLoading?: boolean; suggestionsLoading?: boolean;
suggestionsLoaded?: boolean; suggestionsLoaded?: boolean;
suggestionsError?: boolean; suggestionsError?: boolean;
apiLoading?: boolean; apiLoading?: boolean;
color?: string;
value?: string; value?: string;
placeholder?: string; placeholder?: string;
startAdornment?: JSX.Element; startAdornment?: JSX.Element;
@@ -61,18 +53,23 @@ const renderSuggestion = (suggestion, { query, isHighlighted }): JSX.Element =>
const matches = match(suggestion.name, query); const matches = match(suggestion.name, query);
const parts = parse(suggestion.name, matches); const parts = parse(suggestion.name, matches);
return ( return (
<StyledMenuItem component="div" selected={isHighlighted}> <MenuItem component="div" selected={isHighlighted}>
<div> <div>
{parts.map((part, index) => { {parts.map((part, index) => {
const fw = part.highlight ? fontWeight.semiBold : fontWeight.light; const fw = part.highlight ? fontWeight.semiBold : fontWeight.light;
return ( return (
<StyledAnchor fw={fw} key={String(index)}> <a
className={css`
font-weight: ${fw};
`}
href={suggestion.link}
key={String(index)}>
{part.text} {part.text}
</StyledAnchor> </a>
); );
})} })}
</div> </div>
</StyledMenuItem> </MenuItem>
); );
}; };
@@ -99,6 +96,7 @@ const AutoComplete = ({
value = '', value = '',
placeholder = '', placeholder = '',
disableUnderline = false, disableUnderline = false,
color,
onClick, onClick,
onKeyDown, onKeyDown,
onBlur, onBlur,
@@ -122,6 +120,7 @@ const AutoComplete = ({
// @ts-ignore // @ts-ignore
startAdornment, startAdornment,
disableUnderline, disableUnderline,
color,
onKeyDown, onKeyDown,
onBlur, onBlur,
}; };
@@ -140,12 +139,7 @@ const AutoComplete = ({
return ( return (
<Wrapper> <Wrapper>
<Autosuggest <Autosuggest {...autosuggestProps} inputProps={inputProps} onSuggestionSelected={onClick} renderSuggestionsContainer={renderSuggestionsContainer} />
{...autosuggestProps}
inputProps={inputProps}
onSuggestionSelected={onClick}
renderSuggestionsContainer={renderSuggestionsContainer}
/>
</Wrapper> </Wrapper>
); );
}; };

View File

@@ -1,44 +1,61 @@
import React from 'react'; import React from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { css } from '@emotion/core';
import TextField from '../../muiComponents/TextField'; import TextField from '../../muiComponents/TextField';
import Paper from '../../muiComponents/Paper'; import Paper from '../../muiComponents/Paper';
import { Theme } from '../../design-tokens/theme';
export interface InputFieldProps { export interface InputFieldProps {
color: string; color: string;
} }
export const Wrapper = styled('div')({ export const Wrapper = styled('div')({
'&&': {
width: '100%', width: '100%',
height: '32px', height: '32px',
position: 'relative', position: 'relative',
zIndex: 1, zIndex: 1,
},
}); });
export const StyledTextField = styled(TextField)<{ theme?: Theme }>(props => ({
'& .MuiInputBase-root': {
':before': {
content: "''",
border: 'none',
},
':after': {
borderColor: props.theme && props.theme.palette.white,
},
':hover:before': {
content: 'none',
},
},
'& .MuiInputBase-input': {
color: props.theme && props.theme.palette.white,
},
}));
/* eslint-disable verdaccio/jsx-spread */ /* eslint-disable verdaccio/jsx-spread */
// @ts-ignore types of color are incompatible export const InputField: React.FC<InputFieldProps> = ({ color, ...others }) => (
export const InputField: React.FC<InputFieldProps> = ({ ...others }) => <StyledTextField {...others} />; <TextField
{...others}
classes={{
// @ts-ignore
input: css`
&& {
${color &&
css`
color: ${color};
`};
}
`,
root: css`
&& {
&:before {
content: '';
border: none;
}
&:after {
${color &&
css`
border-color: ${color};
`};
}
&:hover:before {
content: none;
}
}
`,
}}
/>
);
export const SuggestionContainer = styled(Paper)({ export const SuggestionContainer = styled(Paper)({
'&&': {
maxHeight: '500px', maxHeight: '500px',
overflowY: 'auto', overflowY: 'auto',
},
}); });

View File

@@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import { ReactWrapper } from 'enzyme'; import { mount, ReactWrapper } from 'enzyme';
import { copyToClipBoardUtility } from '../../utils/cli-utils'; import { copyToClipBoardUtility } from '../../utils/cli-utils';
import { mount } from '../../utils/test-enzyme';
import CopyToClipBoard from './CopyToClipBoard'; import CopyToClipBoard from './CopyToClipBoard';
import { CopyIcon } from './styles'; import { CopyIcon } from './styles';
@@ -17,7 +16,7 @@ describe('<CopyToClipBoard /> component', () => {
wrapper = mount(<CopyToClipBoard text={copyText} />); wrapper = mount(<CopyToClipBoard text={copyText} />);
}); });
test('should load the component in default state', () => { test('render the component', () => {
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
}); });

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<CopyToClipBoard /> component should load the component in default state 1`] = `"<div class=\\"css-1in239f-ClipBoardCopy eb8w2fo0\\"><span class=\\"css-7gar9h-ClipBoardCopyText eb8w2fo1\\">copy text</span><button class=\\"MuiButtonBase-root MuiIconButton-root css-1fs86cq-CopyIcon 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>"`; exports[`<CopyToClipBoard /> component render the component 1`] = `"<div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-lh0wgu 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

@@ -3,18 +3,22 @@ import styled from '@emotion/styled';
import IconButton from '../../muiComponents/IconButton'; import IconButton from '../../muiComponents/IconButton';
export const ClipBoardCopy = styled('div')({ export const ClipBoardCopy = styled('div')({
'&&': {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-between', justifyContent: 'space-between',
},
}); });
export const ClipBoardCopyText = styled('span')({ export const ClipBoardCopyText = styled('span')({
'&&': {
display: 'inline-block', display: 'inline-block',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
overflow: 'hidden', overflow: 'hidden',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
height: '21px', height: '21px',
fontSize: '1rem', fontSize: '1rem',
},
}); });
export const CopyIcon = styled(IconButton)({}); export const CopyIcon = styled(IconButton)({});

View File

@@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { render } from '@testing-library/react';
import { HashRouter } from 'react-router-dom'; import { HashRouter } from 'react-router-dom';
import { DetailContextProvider } from '../../pages/Version'; import { DetailContextProvider } from '../../pages/Version';
import { render } from '../../utils/test-react-testing-library';
import Dependencies from './Dependencies'; import Dependencies from './Dependencies';

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { render } from '@testing-library/react';
import { render } from '../../utils/test-react-testing-library';
import DetailContainer from './DetailContainer'; import DetailContainer from './DetailContainer';

View File

@@ -1,15 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`DetailContainer renders correctly 1`] = ` exports[`DetailContainer renders correctly 1`] = `
.emotion-0 {
margin-bottom: 16px;
}
<div <div
class="MuiBox-root MuiBox-root-2" class="MuiBox-root MuiBox-root-2"
> >
<div <div
class="MuiTabs-root emotion-0 emotion-1" class="MuiTabs-root css-1qm1lh emotion-0"
> >
<div <div
class="MuiTabs-scroller MuiTabs-fixed" class="MuiTabs-scroller MuiTabs-fixed"

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import { DetailContextProvider } from '../../pages/Version'; import { DetailContextProvider } from '../../pages/Version';
import Developers, { DevelopersType } from './Developers'; import Developers, { DevelopersType } from './Developers';

View File

@@ -1,57 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`test Developers should render the component for contributors with items 1`] = ` exports[`test Developers should render the component for contributors with items 1`] = `
.emotion-0 {
font-weight: 700;
margin-bottom: 10px;
text-transform: capitalize;
}
.emotion-12 {
margin: 10px 0 10px 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.emotion-12 > * {
margin: 5px;
}
.emotion-8 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
<Developers <Developers
type="contributors" type="contributors"
> >
<StyledText <Styled(Component)
variant="subtitle1" variant="subtitle1"
> >
<ForwardRef(Text) <ForwardRef(Text)
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
variant="subtitle1" variant="subtitle1"
> >
<WithStyles(ForwardRef(Typography)) <WithStyles(ForwardRef(Typography))
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
variant="subtitle1" variant="subtitle1"
> >
<ForwardRef(Typography) <ForwardRef(Typography)
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
classes={ classes={
Object { Object {
"alignCenter": "MuiTypography-alignCenter", "alignCenter": "MuiTypography-alignCenter",
@@ -89,23 +54,23 @@ exports[`test Developers should render the component for contributors with items
variant="subtitle1" variant="subtitle1"
> >
<h6 <h6
className="MuiTypography-root emotion-0 emotion-1 MuiTypography-subtitle1" className="MuiTypography-root css-48zeoi emotion-0 MuiTypography-subtitle1"
> >
contributors contributors
</h6> </h6>
</ForwardRef(Typography)> </ForwardRef(Typography)>
</WithStyles(ForwardRef(Typography))> </WithStyles(ForwardRef(Typography))>
</ForwardRef(Text)> </ForwardRef(Text)>
</StyledText> </Styled(Component)>
<Content> <Styled(div)>
<div <div
className="emotion-12 emotion-13" className="css-mkcn9c emotion-6"
> >
<Details <Styled(span)
key="dave.methvin@gmail.com" key="dave.methvin@gmail.com"
> >
<span <span
className="emotion-8 emotion-9" className="css-dvxtzn emotion-4"
> >
<AvatarTooltip <AvatarTooltip
email="dave.methvin@gmail.com" email="dave.methvin@gmail.com"
@@ -199,12 +164,12 @@ exports[`test Developers should render the component for contributors with items
</ForwardRef(ToolTip)> </ForwardRef(ToolTip)>
</AvatarTooltip> </AvatarTooltip>
</span> </span>
</Details> </Styled(span)>
<Details <Styled(span)
key="m.goleb@gmail.com" key="m.goleb@gmail.com"
> >
<span <span
className="emotion-8 emotion-9" className="css-dvxtzn emotion-4"
> >
<AvatarTooltip <AvatarTooltip
email="m.goleb@gmail.com" email="m.goleb@gmail.com"
@@ -298,64 +263,29 @@ exports[`test Developers should render the component for contributors with items
</ForwardRef(ToolTip)> </ForwardRef(ToolTip)>
</AvatarTooltip> </AvatarTooltip>
</span> </span>
</Details> </Styled(span)>
</div> </div>
</Content> </Styled(div)>
</Developers> </Developers>
`; `;
exports[`test Developers should render the component for maintainers with items 1`] = ` exports[`test Developers should render the component for maintainers with items 1`] = `
.emotion-0 {
font-weight: 700;
margin-bottom: 10px;
text-transform: capitalize;
}
.emotion-12 {
margin: 10px 0 10px 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.emotion-12 > * {
margin: 5px;
}
.emotion-8 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
<Developers <Developers
type="maintainers" type="maintainers"
> >
<StyledText <Styled(Component)
variant="subtitle1" variant="subtitle1"
> >
<ForwardRef(Text) <ForwardRef(Text)
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
variant="subtitle1" variant="subtitle1"
> >
<WithStyles(ForwardRef(Typography)) <WithStyles(ForwardRef(Typography))
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
variant="subtitle1" variant="subtitle1"
> >
<ForwardRef(Typography) <ForwardRef(Typography)
className="emotion-0 emotion-1" className="css-48zeoi emotion-0"
classes={ classes={
Object { Object {
"alignCenter": "MuiTypography-alignCenter", "alignCenter": "MuiTypography-alignCenter",
@@ -393,23 +323,23 @@ exports[`test Developers should render the component for maintainers with items
variant="subtitle1" variant="subtitle1"
> >
<h6 <h6
className="MuiTypography-root emotion-0 emotion-1 MuiTypography-subtitle1" className="MuiTypography-root css-48zeoi emotion-0 MuiTypography-subtitle1"
> >
maintainers maintainers
</h6> </h6>
</ForwardRef(Typography)> </ForwardRef(Typography)>
</WithStyles(ForwardRef(Typography))> </WithStyles(ForwardRef(Typography))>
</ForwardRef(Text)> </ForwardRef(Text)>
</StyledText> </Styled(Component)>
<Content> <Styled(div)>
<div <div
className="emotion-12 emotion-13" className="css-mkcn9c emotion-6"
> >
<Details <Styled(span)
key="dave.methvin@gmail.com" key="dave.methvin@gmail.com"
> >
<span <span
className="emotion-8 emotion-9" className="css-dvxtzn emotion-4"
> >
<AvatarTooltip <AvatarTooltip
email="dave.methvin@gmail.com" email="dave.methvin@gmail.com"
@@ -503,12 +433,12 @@ exports[`test Developers should render the component for maintainers with items
</ForwardRef(ToolTip)> </ForwardRef(ToolTip)>
</AvatarTooltip> </AvatarTooltip>
</span> </span>
</Details> </Styled(span)>
<Details <Styled(span)
key="m.goleb@gmail.com" key="m.goleb@gmail.com"
> >
<span <span
className="emotion-8 emotion-9" className="css-dvxtzn emotion-4"
> >
<AvatarTooltip <AvatarTooltip
email="m.goleb@gmail.com" email="m.goleb@gmail.com"
@@ -602,9 +532,9 @@ exports[`test Developers should render the component for maintainers with items
</ForwardRef(ToolTip)> </ForwardRef(ToolTip)>
</AvatarTooltip> </AvatarTooltip>
</span> </span>
</Details> </Styled(span)>
</div> </div>
</Content> </Styled(div)>
</Developers> </Developers>
`; `;

View File

@@ -1,9 +1,9 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes'; import { fontWeight } from '../../utils/styles/sizes';
import Text from '../../muiComponents/Text'; import Text from '../../muiComponents/Text';
import FloatingActionButton from '../../muiComponents/FloatingActionButton'; import FloatingActionButton from '../../muiComponents/FloatingActionButton';
import { Theme } from '../../design-tokens/theme';
export const Details = styled('span')({ export const Details = styled('span')({
display: 'flex', display: 'flex',
@@ -26,7 +26,7 @@ export const StyledText = styled(Text)({
textTransform: 'capitalize', textTransform: 'capitalize',
}); });
export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>(props => ({ export const Fab = styled(FloatingActionButton)({
backgroundColor: props.theme && props.theme.palette.primary.main, backgroundColor: colors.primary,
color: props.theme && props.theme.palette.white, color: colors.white,
})); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import { DetailContext } from '../../pages/Version'; import { DetailContext } from '../../pages/Version';
import Dist from './Dist'; import Dist from './Dist';

View File

@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Dist /> component should render the component in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-1na337r-StyledText estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1mms18p-DistListItem estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-e2le7v-DistChips estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-e2le7v-DistChips 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 in default state 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-b8upko estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1huthg8 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-42zb18 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 MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-1na337r-StyledText estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1mms18p-DistListItem estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-e2le7v-DistChips estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-e2le7v-DistChips estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-e2le7v-DistChips 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 object 1`] = `"<ul class=\\"MuiList-root MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-b8upko estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1huthg8 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-42zb18 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 MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-1na337r-StyledText estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1mms18p-DistListItem estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-e2le7v-DistChips estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-e2le7v-DistChips estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-e2le7v-DistChips 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 MuiList-padding MuiList-subheader\\"><h6 class=\\"MuiTypography-root css-b8upko estxrtg0 MuiTypography-subtitle1\\">Latest Distribution</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-1huthg8 estxrtg1 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>file count</b>: 7</span></div><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>size</b>: 10.00 Bytes</span></div><div class=\\"MuiChip-root css-42zb18 estxrtg2\\"><span class=\\"MuiChip-label\\"><b>license</b>: MIT</span></div><span class=\\"MuiTouchRipple-root\\"></span></div></ul>"`;

View File

@@ -1,6 +1,6 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { Theme } from '../../design-tokens/theme'; import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes'; import { fontWeight } from '../../utils/styles/sizes';
import ListItem from '../../muiComponents/ListItem'; import ListItem from '../../muiComponents/ListItem';
import Text from '../../muiComponents/Text'; import Text from '../../muiComponents/Text';
@@ -18,11 +18,11 @@ export const DistListItem = styled(ListItem)({
}); });
export const DistChips = styled(Chip)({ export const DistChips = styled(Chip)({
marginRight: 5, marginRight: '5px',
textTransform: 'capitalize', textTransform: 'capitalize',
}); });
export const DownloadButton = styled(FloatingActionButton)<{ theme?: Theme }>(props => ({ export const DownloadButton = styled(FloatingActionButton)({
backgroundColor: props.theme && props.theme.palette.primary.main, backgroundColor: colors.primary,
color: props.theme && props.theme.palette.white, color: colors.white,
})); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import { DetailContext } from '../../pages/Version'; import { DetailContext } from '../../pages/Version';
import { PackageMetaInterface } from '../../../types/packageMeta'; import { PackageMetaInterface } from '../../../types/packageMeta';

View File

@@ -13,7 +13,7 @@ import node from './img/node.png';
const Engine: React.FC = () => { const Engine: React.FC = () => {
const { packageMeta } = useContext(DetailContext); const { packageMeta } = useContext(DetailContext);
const engines = packageMeta?.latest?.engines; const engines = packageMeta && packageMeta.latest && packageMeta.latest.engines;
if (!engines || (!engines.node && !engines.npm)) { if (!engines || (!engines.node && !engines.npm)) {
return null; return null;

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
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-1na337r-StyledText et66bt70 MuiTypography-subtitle1\\">node JS</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-18b06t0-EngineListItem et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle 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-1na337r-StyledText et66bt70 MuiTypography-subtitle1\\">NPM version</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-18b06t0-EngineListItem et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle 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>"`; 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-b8upko et66bt70 MuiTypography-subtitle1\\">node JS</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-131yq1t et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle 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-b8upko et66bt70 MuiTypography-subtitle1\\">NPM version</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-131yq1t et66bt71 MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle 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,20 +1,21 @@
import React from 'react'; import React from 'react';
import { mount, ReactWrapper } from 'enzyme';
import { render } from '../../utils/test-react-testing-library';
import Footer from './Footer'; import Footer from './Footer';
describe('<Footer /> component', () => { jest.mock('../../../package.json', () => ({
beforeAll(() => { version: '4.0.0-alpha.3',
window.VERDACCIO_VERSION = 'v.1.0.0'; }));
});
afterAll(() => { describe('<Footer /> component', () => {
let wrapper: ReactWrapper;
beforeEach(() => {
window.VERDACCIO_VERSION = 'v.1.0.0';
wrapper = mount(<Footer />);
delete window.VERDACCIO_VERSION; delete window.VERDACCIO_VERSION;
}); });
test('should load the initial state of Footer component', () => { test('should load the initial state of Footer component', () => {
const { container } = render(<Footer />); expect(wrapper.html()).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
}); });
}); });

View File

@@ -1,274 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Footer /> component should load the initial state of Footer component 1`] = ` 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-151fgib ek145dl0\\"><title>Earth</title><use xlink:href=\\"[object Object]#earth\\"></use></svg><span class=\\"css-8631ip ezbsl486\\"><svg class=\\"ezbsl488 css-1ah96gu ek145dl0\\"><title>Spain</title><use xlink:href=\\"[object Object]#spain\\"></use></svg><svg class=\\"ezbsl488 css-1ah96gu ek145dl0\\"><title>Nicaragua</title><use xlink:href=\\"[object Object]#nicaragua\\"></use></svg><svg class=\\"ezbsl488 css-1ah96gu ek145dl0\\"><title>India</title><use xlink:href=\\"[object Object]#india\\"></use></svg><svg class=\\"ezbsl488 css-1ah96gu ek145dl0\\"><title>Brazil</title><use xlink:href=\\"[object Object]#brazil\\"></use></svg><svg class=\\"ezbsl488 css-1ah96gu ek145dl0\\"><title>China</title><use xlink:href=\\"[object Object]#china\\"></use></svg><svg class=\\"ezbsl488 css-1ah96gu 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-ommwhu ek145dl1\\" name=\\"verdaccio\\" title=\\"Verdaccio\\"><img alt=\\"Verdaccio\\" src=\\"[object Object]\\" class=\\"css-1ncdhax ek145dl2\\"></span>/ v.1.0.0</div></div></div>"`;
.emotion-38 {
background: #f9f9f9;
border-top: 1px solid #e3e3e3;
color: #999999;
font-size: 14px;
padding: 20px;
}
.emotion-36 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: end;
-webkit-justify-content: flex-end;
-ms-flex-pack: end;
justify-content: flex-end;
width: 100%;
}
@media (min-width:768px) {
.emotion-36 {
min-width: 400px;
max-width: 800px;
margin: auto;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
}
@media (min-width:1024px) {
.emotion-36 {
max-width: 1240px;
}
}
.emotion-27 {
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: none;
}
@media (min-width:768px) {
.emotion-27 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
}
.emotion-0 {
color: #e25555;
padding: 0 5px;
}
.emotion-25 {
position: relative;
height: 18px;
}
.emotion-25:hover .emotion-24 {
visibility: visible;
}
.emotion-3 {
box-sizing: initial;
display: inline-block;
cursor: default;
width: 18px;
height: 18px;
padding: 0 10px;
}
.emotion-23 {
position: absolute;
background: #d3dddd;
padding: 1px 4px;
border-radius: 3px;
height: 20px;
display: -webkit-inline-box;
display: -webkit-inline-flex;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
visibility: hidden;
top: -2px;
}
.emotion-23:before {
content: '';
position: absolute;
top: 29%;
left: -4px;
margin-left: -5px;
border: 5px solid;
border-color: #d3dddd transparent transparent transparent;
-webkit-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.emotion-6 {
box-sizing: initial;
display: inline-block;
cursor: default;
width: 18px;
height: 18px;
padding: 0 5px;
}
.emotion-34 {
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: none;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
@media (min-width:768px) {
.emotion-34 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
}
.emotion-32 {
box-sizing: initial;
display: inline-block;
cursor: pointer;
width: 18px;
height: 18px;
padding: 0 5px;
}
.emotion-29 {
width: 100%;
height: auto;
}
<div
class="emotion-38 emotion-39"
>
<div
class="emotion-36 emotion-37"
>
<div
class="emotion-27 emotion-28"
>
Made with
<span
class="emotion-0 emotion-1"
>
♥
</span>
on
<span
class="emotion-25 emotion-26"
>
<svg
class="emotion-2 emotion-3 emotion-4"
>
<title>
Earth
</title>
<use
xlink:href="[object Object]#earth"
/>
</svg>
<span
class="emotion-23 emotion-24"
>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
Spain
</title>
<use
xlink:href="[object Object]#spain"
/>
</svg>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
Nicaragua
</title>
<use
xlink:href="[object Object]#nicaragua"
/>
</svg>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
India
</title>
<use
xlink:href="[object Object]#india"
/>
</svg>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
Brazil
</title>
<use
xlink:href="[object Object]#brazil"
/>
</svg>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
China
</title>
<use
xlink:href="[object Object]#china"
/>
</svg>
<svg
class="emotion-5 emotion-6 emotion-4"
>
<title>
Austria
</title>
<use
xlink:href="[object Object]#austria"
/>
</svg>
</span>
</span>
</div>
<div
class="emotion-34 emotion-35"
>
Powered by
<span
class="emotion-5 emotion-32 emotion-33"
title="Verdaccio"
>
<img
alt="Verdaccio"
class="emotion-29 emotion-30"
src="[object Object]"
/>
</span>
/ v.1.0.0
</div>
</div>
</div>
`;

View File

@@ -1,88 +1,111 @@
import { css } from '@emotion/core';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { breakpoints } from '../../utils/styles/media'; import mq from '../../utils/styles/media';
import Icon from '../Icon/Icon'; import Icon from '../Icon/Icon';
import { Theme } from '../../design-tokens/theme'; import colors from '../../utils/styles/colors';
export const Wrapper = styled('div')<{ theme?: Theme }>(props => ({ export const Wrapper = styled('div')({
background: props.theme && props.theme.palette.snow, '&&': {
borderTop: `1px solid ${props.theme && props.theme.palette.greyGainsboro}`, background: colors.snow,
color: props.theme && props.theme.palette.nobel01, borderTop: `1px solid ${colors.greyGainsboro}`,
color: colors.nobel01,
fontSize: '14px', fontSize: '14px',
padding: '20px', padding: '20px',
}));
export const Inner = styled('div')({
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
width: '100%',
[`@media (min-width: ${breakpoints.medium}px)`]: {
minWidth: 400,
maxWidth: 800,
margin: 'auto',
justifyContent: 'space-between',
},
[`@media (min-width: ${breakpoints.large}px)`]: {
maxWidth: 1240,
}, },
}); });
export const Left = styled('div')({ export const Inner = styled('div')`
alignItems: 'center', && {
display: 'none', display: flex;
[`@media (min-width: ${breakpoints.medium}px)`]: { align-items: center;
display: 'flex', justify-content: flex-end;
}, width: 100%;
}); ${() => {
return mq.medium(css`
min-width: 400px;
max-width: 800px;
margin: auto;
justify-content: space-between;
`);
}};
${() => {
return mq.large(css`
max-width: 1240px;
`);
}};
}
`;
export const Left = styled('div')`
&& {
align-items: center;
display: none;
${() => {
return mq.medium(css`
display: flex;
`);
}};
}
`;
export const Right = styled(Left)({ export const Right = styled(Left)({
'&&': {
display: 'flex', display: 'flex',
},
});
export const ToolTip = styled('span')({
'&&': {
position: 'relative',
height: '18px',
},
}); });
export const Earth = styled(Icon)({ export const Earth = styled(Icon)({
'&&': {
padding: '0 10px', padding: '0 10px',
});
export const Flags = styled('span')<{ theme?: Theme }>(props => ({
position: 'absolute',
background: props.theme && props.theme.palette.greyAthens,
padding: '1px 4px',
borderRadius: 3,
height: 20,
display: 'inline-flex',
alignItems: 'center',
visibility: 'hidden',
top: -2,
':before': {
content: "''",
position: 'absolute',
top: '29%',
left: -4,
marginLeft: -5,
border: '5px solid',
borderColor: `${props.theme && props.theme.palette.greyAthens} transparent transparent transparent`,
transform: 'rotate(90deg)',
},
}));
export const ToolTip = styled('span')({
position: 'relative',
height: '18px',
':hover': {
[`${Flags}`]: {
visibility: 'visible',
},
}, },
}); });
export const Love = styled('span')<{ theme?: Theme }>(props => ({ export const Flags = styled('span')`
color: props.theme && props.theme.palette.love, && {
position: absolute;
background: ${colors.greyAthens};
padding: 1px 4px;
border-radius: 3px;
height: 20px;
display: inline-flex;
align-items: center;
visibility: hidden;
top: -2px;
:before {
content: '';
position: absolute;
top: 29%;
left: -4px;
margin-left: -5px;
border: 5px solid;
border-color: ${colors.greyAthens} transparent transparent transparent;
transform: rotate(90deg);
}
${/* sc-selector */ ToolTip}:hover & {
visibility: visible;
}
}
`;
export const Love = styled('span')({
'&&': {
color: colors.love,
padding: '0 5px', padding: '0 5px',
})); },
});
export const Flag = styled(Icon)({ export const Flag = styled(Icon)({
'&&': {
padding: '0 5px', padding: '0 5px',
},
}); });
export const Logo = Flag; export const Logo = Flag;

View File

@@ -1,16 +1,15 @@
import React from 'react'; import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom'; import { BrowserRouter as Router } from 'react-router-dom';
import { render, fireEvent, waitForElementToBeRemoved, waitForElement } from '@testing-library/react';
import { render, fireEvent, waitForElement, waitForElementToBeRemoved } from '../../utils/test-react-testing-library';
import { AppContextProvider } from '../../App';
import Header from './Header'; import Header from './Header';
const props = { const headerProps = {
user: {
username: 'verddacio-user', username: 'verddacio-user',
}, scope: 'test scope',
packages: [], withoutSearch: true,
handleToggleLoginModal: jest.fn(),
handleLogout: jest.fn(),
}; };
/* eslint-disable react/jsx-no-bind*/ /* eslint-disable react/jsx-no-bind*/
@@ -18,71 +17,82 @@ describe('<Header /> component with logged in state', () => {
test('should load the component in logged out state', () => { test('should load the component in logged out state', () => {
const { container, queryByTestId, getByText } = render( const { container, queryByTestId, getByText } = render(
<Router> <Router>
<AppContextProvider packages={props.packages}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
/>
</Router> </Router>
); );
expect(container.firstChild).toMatchSnapshot(); expect(container.firstChild).toMatchSnapshot();
expect(queryByTestId('header--menu-accountcircle')).toBeNull(); expect(queryByTestId('header--menu-acountcircle')).toBeNull();
expect(getByText('Login')).toBeTruthy(); expect(getByText('Login')).toBeTruthy();
}); });
test('should load the component in logged in state', () => { test('should load the component in logged in state', () => {
const { container, getByTestId, queryByText } = render( const { container, getByTestId, queryByText } = render(
<Router> <Router>
<AppContextProvider packages={props.packages} user={props.user}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
username={headerProps.username}
/>
</Router> </Router>
); );
expect(container.firstChild).toMatchSnapshot(); expect(container.firstChild).toMatchSnapshot();
expect(getByTestId('header--menu-accountcircle')).toBeTruthy(); expect(getByTestId('header--menu-acountcircle')).toBeTruthy();
expect(queryByText('Login')).toBeNull(); expect(queryByText('Login')).toBeNull();
}); });
test('should open login dialog', async () => { test('should open login dialog', async () => {
const { getByText, getByTestId } = render( const { getByText } = render(
<Router> <Router>
<AppContextProvider packages={props.packages}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
/>
</Router> </Router>
); );
const loginBtn = getByText('Login'); const loginBtn = getByText('Login');
fireEvent.click(loginBtn); fireEvent.click(loginBtn);
// wait for login modal appearance and return the element expect(headerProps.handleToggleLoginModal).toHaveBeenCalled();
const registrationInfoModal = await waitForElement(() => getByTestId('login--form-container'));
expect(registrationInfoModal).toBeTruthy();
}); });
test('should logout the user', async () => { test('should logout the user', async () => {
const { getByText, getByTestId } = render( const { getByText, getByTestId } = render(
<Router> <Router>
<AppContextProvider packages={props.packages} user={props.user}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
username={headerProps.username}
/>
</Router> </Router>
); );
const headerMenuAccountCircle = getByTestId('header--menu-accountcircle'); const headerMenuAccountCircle = getByTestId('header--menu-acountcircle');
fireEvent.click(headerMenuAccountCircle); fireEvent.click(headerMenuAccountCircle);
// wait for button Logout's appearance and return the element // wait for button Logout's appearance and return the element
const logoutBtn = await waitForElement(() => getByText('Logout')); const logoutBtn = await waitForElement(() => getByText('Logout'));
fireEvent.click(logoutBtn); fireEvent.click(logoutBtn);
expect(getByText('Login')).toBeTruthy(); expect(headerProps.handleLogout).toHaveBeenCalled();
}); });
test("The question icon should open a new tab of verdaccio's website - installation doc", () => { test("The question icon should open a new tab of verdaccio's website - installation doc", async () => {
const { getByTestId } = render( const { getByTestId } = render(
<Router> <Router>
<AppContextProvider packages={props.packages} user={props.user}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
username={headerProps.username}
/>
</Router> </Router>
); );
@@ -93,9 +103,12 @@ describe('<Header /> component with logged in state', () => {
test('should open the registrationInfo modal when clicking on the info icon', async () => { test('should open the registrationInfo modal when clicking on the info icon', async () => {
const { getByTestId } = render( const { getByTestId } = render(
<Router> <Router>
<AppContextProvider packages={props.packages} user={props.user}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
username={headerProps.username}
/>
</Router> </Router>
); );
@@ -110,9 +123,12 @@ describe('<Header /> component with logged in state', () => {
test('should close the registrationInfo modal when clicking on the button close', async () => { test('should close the registrationInfo modal when clicking on the button close', async () => {
const { getByTestId, getByText, queryByTestId } = render( const { getByTestId, getByText, queryByTestId } = render(
<Router> <Router>
<AppContextProvider packages={props.packages} user={props.user}> <Header
<Header /> onLogout={headerProps.handleLogout}
</AppContextProvider> onToggleLoginModal={headerProps.handleToggleLoginModal}
scope={headerProps.scope}
username={headerProps.username}
/>
</Router> </Router>
); );
@@ -127,6 +143,6 @@ describe('<Header /> component with logged in state', () => {
queryByTestId('registryInfo--dialog') queryByTestId('registryInfo--dialog')
); );
expect(hasRegistrationInfoModalBeenRemoved).toBeTruthy(); expect(hasRegistrationInfoModalBeenRemoved).toBeTruthy();
});
test.todo('autocompletion should display suggestions according to the type value'); test.todo('autocompletion should display suggestions according to the type value');
}); });
});

View File

@@ -1,12 +1,8 @@
import React, { useState, useContext } from 'react'; import React, { useState } from 'react';
import storage from '../../utils/storage';
import { getRegistryURL } from '../../utils/url';
import { makeLogin } from '../../utils/login';
import Button from '../../muiComponents/Button';
import AppContext from '../../App/AppContext';
import LoginModal from '../Login';
import Search from '../Search'; import Search from '../Search';
import { getRegistryURL } from '../../utils/url';
import Button from '../../muiComponents/Button';
import { NavBar, InnerNavBar, MobileNavBar, InnerMobileNavBar } from './styles'; import { NavBar, InnerNavBar, MobileNavBar, InnerMobileNavBar } from './styles';
import HeaderLeft from './HeaderLeft'; import HeaderLeft from './HeaderLeft';
@@ -14,66 +10,31 @@ import HeaderRight from './HeaderRight';
import HeaderInfoDialog from './HeaderInfoDialog'; import HeaderInfoDialog from './HeaderInfoDialog';
interface Props { interface Props {
logo?: string;
username?: string;
onLogout: () => void;
onToggleLoginModal: () => void;
scope: string;
withoutSearch?: boolean; withoutSearch?: boolean;
} }
/* eslint-disable react/jsx-max-depth */ /* eslint-disable react/jsx-max-depth */
/* eslint-disable react/jsx-no-bind*/ /* eslint-disable react/jsx-no-bind*/
/* eslint-disable @typescript-eslint/explicit-function-return-type */ const Header: React.FC<Props> = ({ logo, withoutSearch, username, onLogout, onToggleLoginModal, scope }) => {
const Header: React.FC<Props> = ({ withoutSearch }) => {
const appContext = useContext(AppContext);
const [isInfoDialogOpen, setOpenInfoDialog] = useState(); const [isInfoDialogOpen, setOpenInfoDialog] = useState();
const [showMobileNavBar, setShowMobileNavBar] = useState(); const [showMobileNavBar, setShowMobileNavBar] = useState();
const [showLoginModal, setShowLoginModal] = useState(false);
if (!appContext) {
throw Error('The app Context was not correct used');
}
const { user, scope, error, setUser, setError } = appContext;
const logo = window.VERDACCIO_LOGO;
/**
* handles login
* Required by: <Header />
*/
const handleDoLogin = async (usernameValue: string, passwordValue: string) => {
const { username, token, error } = await makeLogin(usernameValue, passwordValue);
if (username && token) {
storage.setItem('username', username);
storage.setItem('token', token);
setUser({ username });
setShowLoginModal(false);
}
if (error) {
setUser(undefined);
setError(error);
}
};
/**
* Logouts user
* Required by: <Header />
*/
const handleLogout = () => {
storage.removeItem('username');
storage.removeItem('token');
setUser(undefined);
};
return ( return (
<> <>
<NavBar data-testid="header" position="static"> <NavBar position="static">
<InnerNavBar> <InnerNavBar>
<HeaderLeft logo={logo} /> <HeaderLeft logo={logo} />
<HeaderRight <HeaderRight
onLogout={handleLogout} onLogout={onLogout}
onOpenRegistryInfoDialog={() => setOpenInfoDialog(true)} onOpenRegistryInfoDialog={() => setOpenInfoDialog(true)}
onToggleLogin={() => setShowLoginModal(!showLoginModal)} onToggleLogin={onToggleLoginModal}
onToggleMobileNav={() => setShowMobileNavBar(!showMobileNavBar)} onToggleMobileNav={() => setShowMobileNavBar(!showMobileNavBar)}
username={user && user.username} username={username}
withoutSearch={withoutSearch} withoutSearch={withoutSearch}
/> />
</InnerNavBar> </InnerNavBar>
@@ -94,12 +55,6 @@ const Header: React.FC<Props> = ({ withoutSearch }) => {
</Button> </Button>
</MobileNavBar> </MobileNavBar>
)} )}
<LoginModal
error={error}
onCancel={() => setShowLoginModal(false)}
onSubmit={handleDoLogin}
visibility={showLoginModal}
/>
</> </>
); );
}; };

View File

@@ -11,7 +11,7 @@ interface Props {
const HeaderGreetings: React.FC<Props> = ({ username }) => ( const HeaderGreetings: React.FC<Props> = ({ username }) => (
<> <>
<Greetings>{'Hi,'}</Greetings> <Greetings>{'Hi,'}</Greetings>
<Label capitalize={true} data-testid="greetings-label" text={username} weight="bold" /> <Label capitalize={true} text={username} weight="bold" />
</> </>
); );

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import styled from '@emotion/styled'; import { css } from 'emotion';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Search from '../Search/'; import Search from '../Search/';
@@ -12,15 +12,15 @@ interface Props {
logo?: string; logo?: string;
} }
const StyledLink = styled(Link)({
marginRight: '1em',
});
const HeaderLeft: React.FC<Props> = ({ withoutSearch = false, logo }) => ( const HeaderLeft: React.FC<Props> = ({ withoutSearch = false, logo }) => (
<LeftSide> <LeftSide>
<StyledLink to={'/'}> <Link
className={css`
margin-right: 1em;
`}
to={'/'}>
<HeaderLogo logo={logo} /> <HeaderLogo logo={logo} />
</StyledLink> </Link>
{!withoutSearch && ( {!withoutSearch && (
<SearchWrapper> <SearchWrapper>
<Search /> <Search />

View File

@@ -28,7 +28,7 @@ const HeaderMenu: React.FC<Props> = ({
<> <>
<IconButton <IconButton
color="inherit" color="inherit"
data-testid="header--menu-accountcircle" data-testid="header--menu-acountcircle"
id="header--button-account" id="header--button-account"
onClick={onLoggedInMenu}> onClick={onLoggedInMenu}>
<AccountCircle /> <AccountCircle />
@@ -48,7 +48,7 @@ const HeaderMenu: React.FC<Props> = ({
<MenuItem disabled={true}> <MenuItem disabled={true}>
<HeaderGreetings username={username} /> <HeaderGreetings username={username} />
</MenuItem> </MenuItem>
<MenuItem button={true} data-testid="header--button-logout" id="header--button-logout" onClick={onLogout}> <MenuItem button={true} id="header--button-logout" onClick={onLogout}>
{'Logout'} {'Logout'}
</MenuItem> </MenuItem>
</Menu> </Menu>

View File

@@ -53,7 +53,7 @@ const HeaderRight: React.FC<Props> = ({
}; };
return ( return (
<RightSide data-testid="header-right"> <RightSide>
{!withoutSearch && ( {!withoutSearch && (
<HeaderToolTip onClick={onToggleMobileNav} title={'Search packages'} tooltipIconType={'search'} /> <HeaderToolTip onClick={onToggleMobileNav} title={'Search packages'} tooltipIconType={'search'} />
)} )}

View File

@@ -1,167 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Header /> component with logged in state should load the component in logged in state 1`] = ` exports[`<Header /> component with logged in state should load the component in logged in state 1`] = `
.emotion-24 {
background-color: #4b5e40;
min-height: 60px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
@media (min-width:768px) {
.emotion-24 .emotion-13 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.emotion-24 .emotion-17 {
display: none;
}
.emotion-24 .e1jf5lit4 {
display: none;
}
}
@media (min-width:1024px) {
.emotion-24 .emotion-23 {
padding: 0 20px;
}
@media (min-width:1275px) {
.emotion-24 .emotion-23 {
max-width: 1240px;
width: 100%;
margin: 0 auto;
}
}
}
.emotion-22 {
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 0 15px;
}
.emotion-14 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
.emotion-2 {
margin-right: 1em;
}
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 40px;
height: 40px;
}
.emotion-12 {
display: none;
max-width: 393px;
width: 100%;
}
.emotion-10 {
width: 100%;
height: 32px;
position: relative;
z-index: 1;
}
.emotion-6 .MuiInputBase-root:before {
content: '';
border: none;
}
.emotion-6 .MuiInputBase-root:after {
border-color: #fff;
}
.emotion-6 .MuiInputBase-root:hover:before {
content: none;
}
.emotion-6 .MuiInputBase-input {
color: #fff;
}
.emotion-4 {
color: #fff;
}
.emotion-8 {
max-height: 500px;
overflow-y: auto;
}
.emotion-20 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
}
.emotion-16 {
display: block;
}
.emotion-18 {
color: #fff;
}
<header <header
class="MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic emotion-24 emotion-25 MuiAppBar-colorPrimary" class="MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic css-rfunvc emotion-9 MuiAppBar-colorPrimary"
data-testid="header"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-22 emotion-23 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-1bjere7 emotion-8 MuiToolbar-gutters"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-14 emotion-15 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-i5xjw9 emotion-4 MuiToolbar-gutters"
> >
<a <a
class="emotion-2 emotion-3" class="css-1dk30lc"
href="/" href="/"
> >
<div <div
class="emotion-0 emotion-1" class="css-1sifsqk emotion-0"
/> />
</a> </a>
<div <div
class="emotion-12 emotion-13" class="css-12prohx emotion-3"
> >
<div <div
class="emotion-10 emotion-11" class="css-1crzyyo emotion-2"
> >
<div <div
aria-expanded="false" aria-expanded="false"
@@ -173,13 +34,13 @@ exports[`<Header /> component with logged in state should load the component in
<div <div
aria-autocomplete="list" aria-autocomplete="list"
aria-controls="react-autowhatever-1" aria-controls="react-autowhatever-1"
class="MuiFormControl-root MuiTextField-root react-autosuggest__input emotion-6 emotion-7 MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root react-autosuggest__input MuiFormControl-fullWidth"
> >
<div <div
class="MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart" class="MuiInputBase-root MuiInput-root css-n9ojyg MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart"
> >
<div <div
class="MuiInputAdornment-root emotion-4 emotion-5 MuiInputAdornment-positionStart" class="MuiInputAdornment-root css-fvu7gn MuiInputAdornment-positionStart"
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
@@ -196,7 +57,7 @@ exports[`<Header /> component with logged in state should load the component in
<input <input
aria-invalid="false" aria-invalid="false"
autocomplete="off" autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart" class="MuiInputBase-input MuiInput-input css-hodoyq MuiInputBase-inputAdornedStart"
placeholder="Search Packages" placeholder="Search Packages"
type="text" type="text"
value="" value=""
@@ -204,7 +65,7 @@ exports[`<Header /> component with logged in state should load the component in
</div> </div>
</div> </div>
<div <div
class="MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container emotion-8 emotion-9" class="MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container css-cfo6a emotion-1"
id="react-autowhatever-1" id="react-autowhatever-1"
role="listbox" role="listbox"
/> />
@@ -213,11 +74,10 @@ exports[`<Header /> component with logged in state should load the component in
</div> </div>
</div> </div>
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-20 emotion-21 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-1qii1b7 emotion-7 MuiToolbar-gutters"
data-testid="header-right"
> >
<button <button
class="MuiButtonBase-root MuiIconButton-root emotion-16 emotion-17 MuiIconButton-colorInherit" class="MuiButtonBase-root MuiIconButton-root css-13o7eu2 emotion-5 MuiIconButton-colorInherit"
tabindex="0" tabindex="0"
type="button" type="button"
> >
@@ -241,7 +101,7 @@ exports[`<Header /> component with logged in state should load the component in
/> />
</button> </button>
<a <a
class="emotion-18 emotion-19" class="css-kbn7if emotion-6"
data-testid="header--tooltip-documentation" data-testid="header--tooltip-documentation"
href="https://verdaccio.org/docs/en/installation" href="https://verdaccio.org/docs/en/installation"
rel="noopener noreferrer" rel="noopener noreferrer"
@@ -304,7 +164,7 @@ exports[`<Header /> component with logged in state should load the component in
</button> </button>
<button <button
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit" class="MuiButtonBase-root MuiIconButton-root MuiIconButton-colorInherit"
data-testid="header--menu-accountcircle" data-testid="header--menu-acountcircle"
id="header--button-account" id="header--button-account"
tabindex="0" tabindex="0"
type="button" type="button"
@@ -334,167 +194,28 @@ exports[`<Header /> component with logged in state should load the component in
`; `;
exports[`<Header /> component with logged in state should load the component in logged out state 1`] = ` exports[`<Header /> component with logged in state should load the component in logged out state 1`] = `
.emotion-24 {
background-color: #4b5e40;
min-height: 60px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
@media (min-width:768px) {
.emotion-24 .emotion-13 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.emotion-24 .emotion-17 {
display: none;
}
.emotion-24 .e1jf5lit4 {
display: none;
}
}
@media (min-width:1024px) {
.emotion-24 .emotion-23 {
padding: 0 20px;
}
@media (min-width:1275px) {
.emotion-24 .emotion-23 {
max-width: 1240px;
width: 100%;
margin: 0 auto;
}
}
}
.emotion-22 {
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 0 15px;
}
.emotion-14 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
.emotion-2 {
margin-right: 1em;
}
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 40px;
height: 40px;
}
.emotion-12 {
display: none;
max-width: 393px;
width: 100%;
}
.emotion-10 {
width: 100%;
height: 32px;
position: relative;
z-index: 1;
}
.emotion-6 .MuiInputBase-root:before {
content: '';
border: none;
}
.emotion-6 .MuiInputBase-root:after {
border-color: #fff;
}
.emotion-6 .MuiInputBase-root:hover:before {
content: none;
}
.emotion-6 .MuiInputBase-input {
color: #fff;
}
.emotion-4 {
color: #fff;
}
.emotion-8 {
max-height: 500px;
overflow-y: auto;
}
.emotion-20 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 0;
}
.emotion-16 {
display: block;
}
.emotion-18 {
color: #fff;
}
<header <header
class="MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic emotion-24 emotion-25 MuiAppBar-colorPrimary" class="MuiPaper-root MuiPaper-elevation4 MuiAppBar-root MuiAppBar-positionStatic css-rfunvc emotion-9 MuiAppBar-colorPrimary"
data-testid="header"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-22 emotion-23 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-1bjere7 emotion-8 MuiToolbar-gutters"
> >
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-14 emotion-15 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-i5xjw9 emotion-4 MuiToolbar-gutters"
> >
<a <a
class="emotion-2 emotion-3" class="css-1dk30lc"
href="/" href="/"
> >
<div <div
class="emotion-0 emotion-1" class="css-1sifsqk emotion-0"
/> />
</a> </a>
<div <div
class="emotion-12 emotion-13" class="css-12prohx emotion-3"
> >
<div <div
class="emotion-10 emotion-11" class="css-1crzyyo emotion-2"
> >
<div <div
aria-expanded="false" aria-expanded="false"
@@ -506,13 +227,13 @@ exports[`<Header /> component with logged in state should load the component in
<div <div
aria-autocomplete="list" aria-autocomplete="list"
aria-controls="react-autowhatever-1" aria-controls="react-autowhatever-1"
class="MuiFormControl-root MuiTextField-root react-autosuggest__input emotion-6 emotion-7 MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root react-autosuggest__input MuiFormControl-fullWidth"
> >
<div <div
class="MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart" class="MuiInputBase-root MuiInput-root css-n9ojyg MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart"
> >
<div <div
class="MuiInputAdornment-root emotion-4 emotion-5 MuiInputAdornment-positionStart" class="MuiInputAdornment-root css-fvu7gn MuiInputAdornment-positionStart"
> >
<svg <svg
aria-hidden="true" aria-hidden="true"
@@ -529,7 +250,7 @@ exports[`<Header /> component with logged in state should load the component in
<input <input
aria-invalid="false" aria-invalid="false"
autocomplete="off" autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart" class="MuiInputBase-input MuiInput-input css-hodoyq MuiInputBase-inputAdornedStart"
placeholder="Search Packages" placeholder="Search Packages"
type="text" type="text"
value="" value=""
@@ -537,7 +258,7 @@ exports[`<Header /> component with logged in state should load the component in
</div> </div>
</div> </div>
<div <div
class="MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container emotion-8 emotion-9" class="MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container css-cfo6a emotion-1"
id="react-autowhatever-1" id="react-autowhatever-1"
role="listbox" role="listbox"
/> />
@@ -546,11 +267,10 @@ exports[`<Header /> component with logged in state should load the component in
</div> </div>
</div> </div>
<div <div
class="MuiToolbar-root MuiToolbar-regular emotion-20 emotion-21 MuiToolbar-gutters" class="MuiToolbar-root MuiToolbar-regular css-1qii1b7 emotion-7 MuiToolbar-gutters"
data-testid="header-right"
> >
<button <button
class="MuiButtonBase-root MuiIconButton-root emotion-16 emotion-17 MuiIconButton-colorInherit" class="MuiButtonBase-root MuiIconButton-root css-13o7eu2 emotion-5 MuiIconButton-colorInherit"
tabindex="0" tabindex="0"
type="button" type="button"
> >
@@ -574,7 +294,7 @@ exports[`<Header /> component with logged in state should load the component in
/> />
</button> </button>
<a <a
class="emotion-18 emotion-19" class="css-kbn7if emotion-6"
data-testid="header--tooltip-documentation" data-testid="header--tooltip-documentation"
href="https://verdaccio.org/docs/en/installation" href="https://verdaccio.org/docs/en/installation"
rel="noopener noreferrer" rel="noopener noreferrer"

View File

@@ -1,8 +1,8 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { css } from '@emotion/core'; import { css } from '@emotion/core';
import { Theme } from '../../design-tokens/theme'; import colors from '../../utils/styles/colors';
import { breakpoints } from '../../utils/styles/media'; import mq from '../../utils/styles/media';
import IconButton from '../../muiComponents/IconButton'; import IconButton from '../../muiComponents/IconButton';
import AppBar from '../../muiComponents/AppBar'; import AppBar from '../../muiComponents/AppBar';
import Toolbar from '../../muiComponents/Toolbar'; import Toolbar from '../../muiComponents/Toolbar';
@@ -27,39 +27,41 @@ export const LeftSide = styled(RightSide)({
flex: 1, flex: 1,
}); });
export const MobileNavBar = styled('div')<{ theme?: Theme }>(props => ({ export const MobileNavBar = styled('div')({
alignItems: 'center', alignItems: 'center',
display: 'flex', display: 'flex',
borderBottom: `1px solid ${props.theme && props.theme.palette.greyLight}`, borderBottom: `1px solid ${colors.greyLight}`,
padding: '8px', padding: '8px',
position: 'relative', position: 'relative',
})); });
export const InnerMobileNavBar = styled('div')<{ theme?: Theme }>(props => ({ export const InnerMobileNavBar = styled('div')({
borderRadius: '4px', borderRadius: '4px',
backgroundColor: props.theme && props.theme.palette.greyLight, backgroundColor: colors.greyLight,
color: props.theme && props.theme.palette.white, color: colors.white,
width: '100%', width: '100%',
padding: '0 5px', padding: '0 5px',
margin: '0 10px 0 0', margin: '0 10px 0 0',
})); });
export const IconSearchButton = styled(IconButton)({ export const IconSearchButton = styled(IconButton)({
display: 'block', display: 'block',
}); });
export const SearchWrapper = styled('div')({ export const SearchWrapper = styled('div')({
display: 'none', // display: 'none',
maxWidth: '393px', maxWidth: '393px',
width: '100%', width: '100%',
}); });
export const NavBar = styled(AppBar)<{ theme?: Theme }>(props => ({ export const NavBar = styled(AppBar)`
backgroundColor: props.theme && props.theme.palette.primary.main, && {
minHeight: 60, background-color: ${colors.primary};
display: 'flex', min-height: 60px;
justifyContent: 'center', display: flex;
[`@media (min-width: ${breakpoints.medium}px)`]: css` justify-content: center;
${() =>
mq.medium(css`
${SearchWrapper} { ${SearchWrapper} {
display: flex; display: flex;
} }
@@ -69,21 +71,24 @@ export const NavBar = styled(AppBar)<{ theme?: Theme }>(props => ({
${MobileNavBar} { ${MobileNavBar} {
display: none; display: none;
} }
`, `)};
[`@media (min-width: ${breakpoints.large}px)`]: css` ${() =>
mq.large(css`
${InnerNavBar} { ${InnerNavBar} {
padding: 0 20px; padding: 0 20px;
} }
`, `)};
[`@media (min-width: ${breakpoints.xlarge}px)`]: css` ${() =>
mq.xlarge(css`
${InnerNavBar} { ${InnerNavBar} {
max-width: 1240px; max-width: 1240px;
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
} }
`, `)};
})); }
`;
export const StyledLink = styled(Link)<{ theme?: Theme }>(props => ({ export const StyledLink = styled(Link)({
color: props.theme && props.theme.palette.white, color: 'white',
})); });

View File

@@ -1,12 +1,11 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { render } from '../../utils/test-react-testing-library';
import Help from './Help'; import Help from './Help';
describe('<Help /> component', () => { describe('<Help /> component', () => {
test('should load the component in default state', () => { test('should render the component in default state', () => {
const { container } = render(<Help />); const wrapper = mount(<Help />);
expect(container.firstChild).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
}); });
}); });

View File

@@ -1,159 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Help /> component should load the component in default state 1`] = ` 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><h6 class=\\"MuiTypography-root css-zg2fwz e1wgaou61 MuiTypography-h6 MuiTypography-colorTextSecondary MuiTypography-gutterBottom\\">To publish your first package just:</h6><p class=\\"MuiTypography-root MuiTypography-body1\\">1. Login</p><div class=\\"css-1mta3t8 eb8w2fo0\\"><span class=\\"css-lh0wgu 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-lh0wgu 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-textSizeSmall MuiButton-sizeSmall\\" tabindex=\\"0\\" aria-disabled=\\"false\\" href=\\"https://verdaccio.org/docs/en/installation\\"><span class=\\"MuiButton-label\\">Learn More</span><span class=\\"MuiTouchRipple-root\\"></span></a></div></div>"`;
.emotion-14 {
width: 600px;
margin: auto;
}
.emotion-0 {
margin-bottom: 20px;
}
.emotion-6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.emotion-2 {
display: inline-block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
height: 21px;
font-size: 1rem;
}
<div
class="MuiPaper-root MuiPaper-elevation1 MuiCard-root emotion-14 emotion-15 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>
<h6
class="MuiTypography-root emotion-0 emotion-1 MuiTypography-h6 MuiTypography-colorTextSecondary MuiTypography-gutterBottom"
>
To publish your first package just:
</h6>
<p
class="MuiTypography-root MuiTypography-body1"
>
1. Login
</p>
<div
class="emotion-6 emotion-7"
>
<span
class="emotion-2 emotion-3"
>
npm adduser --registry http://localhost
</span>
<button
class="MuiButtonBase-root MuiIconButton-root emotion-4 emotion-5"
tabindex="0"
title="Copy to Clipboard"
type="button"
>
<span
class="MuiIconButton-label"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<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"
/>
</svg>
</span>
<span
class="MuiTouchRipple-root"
/>
</button>
</div>
<p
class="MuiTypography-root MuiTypography-body1"
>
2. Publish
</p>
<div
class="emotion-6 emotion-7"
>
<span
class="emotion-2 emotion-3"
>
npm publish --registry http://localhost
</span>
<button
class="MuiButtonBase-root MuiIconButton-root emotion-4 emotion-5"
tabindex="0"
title="Copy to Clipboard"
type="button"
>
<span
class="MuiIconButton-label"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root"
focusable="false"
role="presentation"
viewBox="0 0 24 24"
>
<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"
/>
</svg>
</span>
<span
class="MuiTouchRipple-root"
/>
</button>
</div>
<p
class="MuiTypography-root MuiTypography-body2"
>
3. Refresh this page.
</p>
</div>
<div
class="MuiCardActions-root MuiCardActions-spacing"
>
<a
aria-disabled="false"
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-textSizeSmall MuiButton-sizeSmall"
href="https://verdaccio.org/docs/en/installation"
tabindex="0"
>
<span
class="MuiButton-label"
>
Learn More
</span>
<span
class="MuiTouchRipple-root"
/>
</a>
</div>
</div>
`;

View File

@@ -4,10 +4,14 @@ import { default as Typography } from '../../muiComponents/Heading';
import Card from '../../muiComponents/Card'; import Card from '../../muiComponents/Card';
export const CardStyled = styled(Card)({ export const CardStyled = styled(Card)({
width: 600, '&&': {
width: '600px',
margin: 'auto', margin: 'auto',
},
}); });
export const HelpTitle = styled(Typography)({ export const HelpTitle = styled(Typography)({
marginBottom: 20, '&&': {
marginBottom: '20px',
},
}); });

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme';
import { render } from '../../utils/test-react-testing-library';
import Icon from './Icon'; import Icon from './Icon';
@@ -9,7 +8,7 @@ describe('<Icon /> component', () => {
name: 'austria', name: 'austria',
}; };
test('should render the component in default state', () => { test('should render the component in default state', () => {
const { container } = render(<Icon name={props.name} />); const wrapper = shallow(<Icon name={props.name} />);
expect(container.firstChild).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
}); });
}); });

View File

@@ -63,11 +63,10 @@ export interface Props {
modifiers?: null | undefined; modifiers?: null | undefined;
} }
/* eslint-disable verdaccio/jsx-spread */
const Icon: React.FC<Props> = ({ className, name, size = 'sm', img = false, pointer = false, ...props }) => { const Icon: React.FC<Props> = ({ className, name, size = 'sm', img = false, pointer = false, ...props }) => {
const title = capitalize(name.toString()); const title = capitalize(name.toString());
return img ? ( return img ? (
<ImgWrapper className={className} pointer={pointer} size={size} title={title} {...props}> <ImgWrapper className={className} name={name} pointer={pointer} size={size} title={title} {...props}>
<Img alt={title} src={Icons[name]} /> <Img alt={title} src={Icons[name]} />
</ImgWrapper> </ImgWrapper>
) : ( ) : (

View File

@@ -1,22 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Icon /> component should render the component in default state 1`] = ` exports[`<Icon /> component should render the component in default state 1`] = `"<svg class=\\"css-j2zgvv ek145dl0\\"><title>Austria</title><use xlink:href=\\"[object Object]#austria\\"></use></svg>"`;
.emotion-0 {
box-sizing: initial;
display: inline-block;
cursor: default;
width: 14px;
height: 16px;
}
<svg
class="emotion-0 emotion-1"
>
<title>
Austria
</title>
<use
xlink:href="[object Object]#austria"
/>
</svg>
`;

View File

@@ -1,42 +1,45 @@
import { css } from '@emotion/core';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { Breakpoint } from '@material-ui/core/styles/createBreakpoints'; import { Breakpoint } from '@material-ui/core/styles/createBreakpoints';
import { DetailedHTMLProps, HTMLAttributes } from 'react';
const getSize = (size: Breakpoint): { width: number; height: number } => { const getSize = (size: Breakpoint): string => {
switch (size) { switch (size) {
case 'md': case 'md':
return { return `
width: 18, width: 18px;
height: 18, height: 18px;
}; `;
default: default:
return { return `
width: 14, width: 14px;
height: 16, height: 16px;
}; `;
} }
}; };
interface CommonStyleProps { const commonStyle = ({ size = 'sm' as Breakpoint, pointer, modifiers = null }) => css`
size: Breakpoint; && {
pointer?: boolean; display: inline-block;
cursor: ${pointer ? 'pointer' : 'Developers'};
${getSize(size)};
${modifiers && modifiers};
} }
const commonStyle = ({ size = 'sm', pointer }: CommonStyleProps): object => ({ `;
display: 'inline-block',
cursor: pointer ? 'pointer' : 'default',
...getSize(size),
});
export const Svg = styled('svg')<CommonStyleProps>(props => ({ export const Svg = styled('svg')`
boxSizing: 'initial', ${commonStyle};
...commonStyle(props), box-sizing: initial;
})); `;
export const ImgWrapper = styled('span')<CommonStyleProps>(props => ({ export const ImgWrapper = styled('span')`
boxSizing: 'initial', ${commonStyle};
...commonStyle(props), box-sizing: initial;
})); `;
export const Img = styled('img')({ export const Img = styled('img')({
'&&': {
width: '100%', width: '100%',
height: 'auto', height: 'auto',
},
}); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { render } from '@testing-library/react';
import { render } from '../../utils/test-react-testing-library';
import { DetailContext, DetailContextProps } from '../../pages/Version'; import { DetailContext, DetailContextProps } from '../../pages/Version';
import data from './__partials__/data.json'; import data from './__partials__/data.json';

View File

@@ -1,71 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Install /> renders correctly 1`] = ` exports[`<Install /> renders correctly 1`] = `
.emotion-0 {
font-weight: 700;
text-transform: capitalize;
}
.emotion-12 {
padding: 0;
}
.emotion-12:hover {
background-color: transparent;
}
.emotion-2 {
border-radius: 0px;
padding: 0;
}
.emotion-10 {
padding: 0 10px;
margin: 0;
}
.emotion-8 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
.emotion-4 {
display: inline-block;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
height: 21px;
font-size: 1rem;
}
<ul <ul
class="MuiList-root MuiList-padding MuiList-subheader" class="MuiList-root MuiList-padding MuiList-subheader"
data-testid="installList" data-testid="installList"
> >
<h6 <h6
class="MuiTypography-root emotion-0 emotion-1 MuiTypography-subtitle1" class="MuiTypography-root css-b8upko emotion-0 MuiTypography-subtitle1"
> >
Installation Installation
</h6> </h6>
<div <div
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root MuiListItem-root emotion-12 emotion-13 MuiListItem-gutters MuiListItem-button" class="MuiButtonBase-root MuiListItem-root css-zw46c6 emotion-6 MuiListItem-gutters MuiListItem-button"
data-testid="installListItem-npm" data-testid="installListItem-npm"
role="button" role="button"
tabindex="0" tabindex="0"
> >
<div <div
class="MuiAvatar-root MuiAvatar-circle emotion-2 emotion-3" class="MuiAvatar-root MuiAvatar-circle css-19top7x emotion-1"
> >
<img <img
alt="npm" alt="npm"
@@ -74,21 +27,21 @@ exports[`<Install /> renders correctly 1`] = `
/> />
</div> </div>
<div <div
class="MuiListItemText-root emotion-10 emotion-11 MuiListItemText-multiline" class="MuiListItemText-root css-fipixf emotion-5 MuiListItemText-multiline"
> >
<span <span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1" class="MuiTypography-root MuiListItemText-primary MuiTypography-body1"
> >
<div <div
class="emotion-8 emotion-9" class="css-1mta3t8 emotion-4"
> >
<span <span
class="emotion-4 emotion-5" class="css-lh0wgu emotion-2"
> >
npm install foo npm install foo
</span> </span>
<button <button
class="MuiButtonBase-root MuiIconButton-root emotion-6 emotion-7" class="MuiButtonBase-root MuiIconButton-root css-0 emotion-3"
tabindex="0" tabindex="0"
title="Copy to Clipboard" title="Copy to Clipboard"
type="button" type="button"
@@ -126,13 +79,13 @@ exports[`<Install /> renders correctly 1`] = `
</div> </div>
<div <div
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root MuiListItem-root emotion-12 emotion-13 MuiListItem-gutters MuiListItem-button" class="MuiButtonBase-root MuiListItem-root css-zw46c6 emotion-6 MuiListItem-gutters MuiListItem-button"
data-testid="installListItem-yarn" data-testid="installListItem-yarn"
role="button" role="button"
tabindex="0" tabindex="0"
> >
<div <div
class="MuiAvatar-root MuiAvatar-circle emotion-2 emotion-3" class="MuiAvatar-root MuiAvatar-circle css-19top7x emotion-1"
> >
<img <img
alt="yarn" alt="yarn"
@@ -141,21 +94,21 @@ exports[`<Install /> renders correctly 1`] = `
/> />
</div> </div>
<div <div
class="MuiListItemText-root emotion-10 emotion-11 MuiListItemText-multiline" class="MuiListItemText-root css-fipixf emotion-5 MuiListItemText-multiline"
> >
<span <span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1" class="MuiTypography-root MuiListItemText-primary MuiTypography-body1"
> >
<div <div
class="emotion-8 emotion-9" class="css-1mta3t8 emotion-4"
> >
<span <span
class="emotion-4 emotion-5" class="css-lh0wgu emotion-2"
> >
yarn add foo yarn add foo
</span> </span>
<button <button
class="MuiButtonBase-root MuiIconButton-root emotion-6 emotion-7" class="MuiButtonBase-root MuiIconButton-root css-0 emotion-3"
tabindex="0" tabindex="0"
title="Copy to Clipboard" title="Copy to Clipboard"
type="button" type="button"
@@ -193,13 +146,13 @@ exports[`<Install /> renders correctly 1`] = `
</div> </div>
<div <div
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root MuiListItem-root emotion-12 emotion-13 MuiListItem-gutters MuiListItem-button" class="MuiButtonBase-root MuiListItem-root css-zw46c6 emotion-6 MuiListItem-gutters MuiListItem-button"
data-testid="installListItem-pnpm" data-testid="installListItem-pnpm"
role="button" role="button"
tabindex="0" tabindex="0"
> >
<div <div
class="MuiAvatar-root MuiAvatar-circle emotion-2 emotion-3" class="MuiAvatar-root MuiAvatar-circle css-19top7x emotion-1"
> >
<img <img
alt="pnpm" alt="pnpm"
@@ -208,21 +161,21 @@ exports[`<Install /> renders correctly 1`] = `
/> />
</div> </div>
<div <div
class="MuiListItemText-root emotion-10 emotion-11 MuiListItemText-multiline" class="MuiListItemText-root css-fipixf emotion-5 MuiListItemText-multiline"
> >
<span <span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1" class="MuiTypography-root MuiListItemText-primary MuiTypography-body1"
> >
<div <div
class="emotion-8 emotion-9" class="css-1mta3t8 emotion-4"
> >
<span <span
class="emotion-4 emotion-5" class="css-lh0wgu emotion-2"
> >
pnpm install foo pnpm install foo
</span> </span>
<button <button
class="MuiButtonBase-root MuiIconButton-root emotion-6 emotion-7" class="MuiButtonBase-root MuiIconButton-root css-0 emotion-3"
tabindex="0" tabindex="0"
title="Copy to Clipboard" title="Copy to Clipboard"
type="button" type="button"

View File

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

View File

@@ -7,17 +7,19 @@ interface Props {
text: string; text: string;
capitalize?: boolean; capitalize?: boolean;
weight?: string; weight?: string;
modifiers?: null | undefined;
} }
interface WrapperProps { interface WrapperProps {
capitalize: boolean; capitalize: boolean;
weight: string; weight: string;
modifiers?: null;
} }
const Wrapper = styled('div')`
const Wrapper = styled('div')<WrapperProps>(props => ({ font-weight: ${({ weight }: WrapperProps) => fontWeight[weight]};
fontWeight: fontWeight[props.weight], text-transform: ${({ capitalize }: WrapperProps) => (capitalize ? 'capitalize' : 'none')};
textTransform: props.capitalize ? 'capitalize' : 'none', ${({ modifiers }: WrapperProps) => modifiers};
})); `;
const Label: React.FC<Props> = ({ text = '', capitalize = false, weight = 'regular', ...props }) => { const Label: React.FC<Props> = ({ text = '', capitalize = false, weight = 'regular', ...props }) => {
return ( return (

View File

@@ -1,14 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Label /> component should render the component in default state 1`] = ` exports[`<Label /> component should render the component in default state 1`] = `"<div class=\\"css-1xfhjjm esyufg60\\">test</div>"`;
.emotion-0 {
font-weight: 400;
text-transform: none;
}
<div
class="emotion-0 emotion-1"
>
test
</div>
`;

View File

@@ -1,29 +1,33 @@
import styled from '@emotion/styled';
import { css } from '@emotion/core'; import { css } from '@emotion/core';
import styled from '@emotion/styled';
import { Theme } from '../../design-tokens/theme'; import colors from '../../utils/styles/colors';
export const Content = styled('div')<{ theme?: Theme }>(props => ({ export const Content = styled('div')({
backgroundColor: props.theme && props.theme.palette.white, '&&': {
backgroundColor: colors.white,
flex: 1, flex: 1,
display: 'flex', display: 'flex',
position: 'relative', position: 'relative',
flexDirection: 'column', flexDirection: 'column',
})); },
});
interface ContainerProps { interface ContainerProps {
isLoading: boolean; isLoading: boolean;
} }
export const Container = styled('div')<ContainerProps>(props => ({ export const Container = styled('div')`
display: 'flex', && {
flexDirection: 'column', display: flex;
minHeight: '100vh', flex-direction: column;
overflow: 'hidden', min-height: 100vh;
...(props.isLoading && overflow: hidden;
${({ isLoading }: ContainerProps) =>
isLoading &&
css` css`
${Content} { ${Content} {
background-color: #f5f6f8; background-color: #f5f6f8;
} }
`), `}
})); `;

View File

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

View File

@@ -1,86 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Loading /> component should render the component in default state 1`] = ` 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>"`;
.emotion-8 {
-webkit-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
position: absolute;
}
.emotion-2 {
margin: 0 0 30px 0;
border-radius: 25px;
box-shadow: 0 10px 20px 0 rgba(69,58,100,0.2);
background: #f7f8f6;
}
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 90px;
height: 90px;
}
.emotion-6 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.emotion-4 {
color: #4b5e40;
}
<div
class="emotion-8 emotion-9"
data-testid="loading"
>
<div
class="emotion-2 emotion-3"
>
<div
class="emotion-0 emotion-1"
/>
</div>
<div
class="emotion-6 emotion-7"
>
<div
class="MuiCircularProgress-root emotion-4 emotion-5 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate"
role="progressbar"
style="width: 50px; height: 50px;"
>
<svg
class="MuiCircularProgress-svg"
viewBox="22 22 44 44"
>
<circle
class="MuiCircularProgress-circle MuiCircularProgress-circleIndeterminate"
cx="44"
cy="44"
fill="none"
r="20.2"
stroke-width="3.6"
/>
</svg>
</div>
</div>
</div>
`;

View File

@@ -1,15 +1,19 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export const Wrapper = styled('div')({ export const Wrapper = styled('div')`
transform: 'translate(-50%, -50%)', && {
top: '50%', transform: translate(-50%, -50%);
left: '50%', top: 50%;
position: 'absolute', left: 50%;
}); position: absolute;
}
`;
export const Badge = styled('div')({ export const Badge = styled('div')`
margin: '0 0 30px 0', && {
borderRadius: 25, margin: 0 0 30px 0;
boxShadow: '0 10px 20px 0 rgba(69, 58, 100, 0.2)', border-radius: 25px;
background: '#f7f8f6', box-shadow: 0 10px 20px 0 rgba(69, 58, 100, 0.2);
}); background: #f7f8f6;
}
`;

View File

@@ -3,8 +3,7 @@
*/ */
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import LoginModal from './Login'; import LoginModal from './Login';
@@ -67,7 +66,7 @@ describe('<LoginModal />', () => {
onCancel: () => {}, onCancel: () => {},
onSubmit: () => {}, onSubmit: () => {},
}; };
const wrapper = mount(<LoginModal {...props} />); const wrapper = mount<LoginModal>(<LoginModal {...props} />);
const { setCredentials } = wrapper.instance(); const { setCredentials } = wrapper.instance();
expect(setCredentials('username', eventUsername)).toBeUndefined(); expect(setCredentials('username', eventUsername)).toBeUndefined();
@@ -84,7 +83,7 @@ describe('<LoginModal />', () => {
onSubmit: jest.fn(), onSubmit: jest.fn(),
}; };
const wrapper = mount(<LoginModal {...props} />); const wrapper = mount<LoginModal>(<LoginModal {...props} />);
const instance = wrapper.instance(); const instance = wrapper.instance();
instance.submitCredentials = jest.fn(); instance.submitCredentials = jest.fn();
@@ -109,7 +108,7 @@ describe('<LoginModal />', () => {
onSubmit: jest.fn(), onSubmit: jest.fn(),
}; };
const wrapper = mount(<LoginModal {...props} />); const wrapper = mount<LoginModal>(<LoginModal {...props} />);
const { setCredentials, submitCredentials } = wrapper.instance(); const { setCredentials, submitCredentials } = wrapper.instance();
expect(setCredentials('username', eventUsername)).toBeUndefined(); expect(setCredentials('username', eventUsername)).toBeUndefined();
expect(wrapper.state('form').username.value).toEqual('xyz'); expect(wrapper.state('form').username.value).toEqual('xyz');

View File

@@ -1,5 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import ErrorIcon from '@material-ui/icons/Error'; import ErrorIcon from '@material-ui/icons/Error';
import { css } from 'emotion';
import Button from '../../muiComponents/Button'; import Button from '../../muiComponents/Button';
import Dialog from '../../muiComponents/Dialog'; import Dialog from '../../muiComponents/Dialog';
@@ -66,13 +67,7 @@ export default class LoginModal extends Component<Partial<LoginModalProps>, Logi
public render(): JSX.Element { public render(): JSX.Element {
const { visibility = true, onCancel = () => null, error } = this.props as LoginModalProps; const { visibility = true, onCancel = () => null, error } = this.props as LoginModalProps;
return ( return (
<Dialog <Dialog fullWidth={true} id={'login--form-container'} maxWidth={'xs'} onClose={onCancel} open={visibility}>
data-testid={'login--form-container'}
fullWidth={true}
id={'login--form-container'}
maxWidth={'xs'}
onClose={onCancel}
open={visibility}>
<form noValidate={true} onSubmit={this.handleValidateCredentials}> <form noValidate={true} onSubmit={this.handleValidateCredentials}>
<DialogTitle>{'Login'}</DialogTitle> <DialogTitle>{'Login'}</DialogTitle>
<DialogContent> <DialogContent>
@@ -210,9 +205,9 @@ export default class LoginModal extends Component<Partial<LoginModalProps>, Logi
} = this.state; } = this.state;
return ( return (
<FormControl <FormControl
// className={css` className={css`
// margin-top: 8px; margin-top: 8px;
// `} `}
error={!password.value && !password.pristine} error={!password.value && !password.pristine}
fullWidth={true} fullWidth={true}
required={password.required}> required={password.required}>

View File

@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<LoginModal /> should load the component in default state 1`] = `"<div role=\\"presentation\\" class=\\"MuiDialog-root\\" data-testid=\\"login--form-container\\" 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=\\"none presentation\\" 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\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input\\" value=\\"\\"></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=\\"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\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" class=\\"MuiInputBase-input MuiInput-input\\" 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 MuiButton-colorInherit Mui-disabled 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 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=\\"none presentation\\" 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\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input\\" 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\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" class=\\"MuiInputBase-input MuiInput-input\\" 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 MuiButton-colorInherit Mui-disabled 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=\\"presentation\\" class=\\"MuiDialog-root\\" data-testid=\\"login--form-container\\" 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=\\"none presentation\\" 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-xlgaf-loginError MuiTypography-body2\\" role=\\"alert\\"><div class=\\"MuiSnackbarContent-message\\"><div class=\\"css-vvv32-loginErrorMsg\\" id=\\"client-snackbar\\"><svg class=\\"MuiSvgIcon-root css-tkvt8h-loginIcon\\" 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\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input\\" value=\\"\\"></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=\\"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\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" class=\\"MuiInputBase-input MuiInput-input\\" 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 MuiButton-colorInherit Mui-disabled 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=\\"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=\\"none presentation\\" 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=\\"alert\\"><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\\" id=\\"login--form-username\\" placeholder=\\"Your username\\" required=\\"\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input\\" 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\\" id=\\"login--form-password\\" placeholder=\\"Your strong password\\" required=\\"\\" type=\\"password\\" class=\\"MuiInputBase-input MuiInput-input\\" 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 MuiButton-colorInherit Mui-disabled 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,13 +1,13 @@
import { css } from 'emotion'; import { css } from 'emotion';
import { theme } from '../../design-tokens/theme'; import colors from '../../utils/styles/colors';
export const loginDialog = css({ export const loginDialog = css({
minWidth: '300px', minWidth: '300px',
}); });
export const loginError = css({ export const loginError = css({
backgroundColor: `${theme.palette.red} !important`, backgroundColor: `${colors.red} !important`,
minWidth: 'inherit !important', minWidth: 'inherit !important',
marginBottom: '10px !important', marginBottom: '10px !important',
}); });

View File

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

View File

@@ -12,18 +12,19 @@ interface Props {
size?: Size; size?: Size;
} }
const StyledLogo = styled('div')<Props>(props => ({ const StyledLogo = styled('div')<Props>`
display: 'inline-block', && {
verticalAlign: 'middle', display: inline-block;
boxSizing: 'border-box', vertical-align: middle;
backgroundPosition: 'center', box-sizing: border-box;
backgroundSize: 'contain', background-position: center;
backgroundImage: `url(${logo})`, background-size: contain;
backgroundRepeat: ' no-repeat', background-image: url(${logo});
width: props.size, background-repeat: no-repeat;
height: props.size, width: ${({ size }) => size};
})); height: ${({ size }) => size};
}
`;
const Logo: React.FC<Props> = ({ size = Size.Small }) => { const Logo: React.FC<Props> = ({ size = Size.Small }) => {
return <StyledLogo size={size} />; return <StyledLogo size={size} />;
}; };

View File

@@ -1,19 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Logo /> component should render the component in default state 1`] = ` exports[`<Logo /> component should render the component in default state 1`] = `"<div class=\\"css-1sifsqk em793ed0\\"></div>"`;
.emotion-0 {
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
background-position: center;
background-size: contain;
background-image: url([object Object]);
background-repeat: no-repeat;
width: 40px;
height: 40px;
}
<div
class="emotion-0 emotion-1"
/>
`;

View File

@@ -1,16 +1,25 @@
import React from 'react'; import React from 'react';
import { shallow, mount } from 'enzyme';
import { render } from '../../utils/test-react-testing-library';
import NoItems from './NoItems'; import NoItems from './NoItems';
console.error = jest.fn();
describe('<NoItem /> component', () => { describe('<NoItem /> component', () => {
const props = { const props = {
text: 'test', text: 'test',
}; };
test('should load the component in default state', () => { test('should load the component in default state', () => {
const { container } = render(<NoItems text={props.text} />); const wrapper = shallow(<NoItems text={props.text} />);
expect(container.firstChild).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
});
test('should set html from props', () => {
const props = {
text: 'This is a test string',
};
const wrapper = mount(<NoItems text={props.text} />);
expect(wrapper.html()).toMatchSnapshot();
}); });
}); });

View File

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

View File

@@ -5,8 +5,8 @@ import { useHistory } from 'react-router-dom';
import Box from '../../muiComponents/Box'; import Box from '../../muiComponents/Box';
import Button from '../../muiComponents/Button'; import Button from '../../muiComponents/Button';
import Heading from '../../muiComponents/Heading'; import Heading from '../../muiComponents/Heading';
import colors from '../../utils/styles/colors';
import { spacings } from '../../utils/styles/spacings'; import { spacings } from '../../utils/styles/spacings';
import { Theme } from '../../design-tokens/theme';
import PackageImg from './img/package.svg'; import PackageImg from './img/package.svg';
@@ -19,10 +19,10 @@ const EmptyPackage = styled('img')({
margin: '0 auto', margin: '0 auto',
}); });
const StyledHeading = styled(Heading)<{ theme?: Theme }>(props => ({ const StyledHeading = styled(Heading)({
color: props.theme && props.theme.palette.primary.main, color: colors.primary,
marginBottom: spacings.sm, marginBottom: spacings.sm,
})); });
const NotFound: React.FC = () => { const NotFound: React.FC = () => {
const history = useHistory(); const history = useHistory();

View File

@@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom'; import { BrowserRouter as Router } from 'react-router-dom';
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent } from '../../utils/test-react-testing-library';
import NotFound, { GO_TO_HOME_PAGE } from './NotFound'; import NotFound, { GO_TO_HOME_PAGE } from './NotFound';

View File

@@ -1,27 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<NotFound /> component should load the component in default state 1`] = ` exports[`<NotFound /> component should load the component in default state 1`] = `
.emotion-0 {
width: 150px;
margin: 0 auto;
}
.emotion-2 {
color: #4b5e40;
margin-bottom: 16px;
}
<div <div
class="MuiBox-root MuiBox-root-2" class="MuiBox-root MuiBox-root-2"
data-testid="404" data-testid="404"
> >
<img <img
alt="404 - Page not found" alt="404 - Page not found"
class="emotion-0 emotion-1" class="css-17y48z2 emotion-0"
src="[object Object]" src="[object Object]"
/> />
<h4 <h4
class="MuiTypography-root not-found-text emotion-2 emotion-3 MuiTypography-h4" class="MuiTypography-root not-found-text css-7pe7kh emotion-1 MuiTypography-h4"
> >
Sorry, we couldn't find it... Sorry, we couldn't find it...
</h4> </h4>

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme';
import { shallow } from '../../utils/test-enzyme';
import Tag from '../Tag'; import Tag from '../Tag';
import Package from './Package'; import Package from './Package';

View File

@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
import { breakpoints } from '../../utils/styles/media'; import { breakpoints } from '../../utils/styles/media';
import Ico from '../Icon'; import Ico from '../Icon';
import Label from '../Label'; import Label from '../Label';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes'; import { fontWeight } from '../../utils/styles/sizes';
import { default as MuiIconButton } from '../../muiComponents/IconButton'; import { default as MuiIconButton } from '../../muiComponents/IconButton';
import { default as Photo } from '../../muiComponents/Avatar'; import { default as Photo } from '../../muiComponents/Avatar';
@@ -11,115 +12,147 @@ import List from '../../muiComponents/List';
import { default as Typography } from '../../muiComponents/Heading'; import { default as Typography } from '../../muiComponents/Heading';
import Grid from '../../muiComponents/Grid'; import Grid from '../../muiComponents/Grid';
import ListItemText from '../../muiComponents/ListItemText'; import ListItemText from '../../muiComponents/ListItemText';
import { Theme } from '../../design-tokens/theme';
export const OverviewItem = styled('span')<{ theme?: Theme }>(props => ({ export const OverviewItem = styled('span')`
display: 'flex', && {
alignItems: 'center', display: flex;
margin: '0 0 0 16px', align-items: center;
color: props.theme && props.theme.palette.greyLight2, margin: 0 0 0 16px;
fontSize: 12, color: ${colors.greyLight2};
[`@media (max-width: ${breakpoints.medium}px)`]: { font-size: 12px;
':nth-of-type(3)': { @media (max-width: ${breakpoints.medium}px) {
display: 'none', &:nth-child(3) {
}, display: none;
}, }
[`@media (max-width: ${breakpoints.small}px)`]: { }
':nth-of-type(4)': { @media (max-width: ${breakpoints.small}px) {
display: 'none', &:nth-child(4) {
}, display: none;
}, }
})); }
}
`;
export const Icon = styled(Ico)<{ theme?: Theme }>(props => ({ export const Icon = styled(Ico)({
'&&': {
margin: '2px 10px 0 0', margin: '2px 10px 0 0',
fill: props.theme && props.theme.palette.greyLight2, fill: colors.greyLight2,
})); },
});
export const Published = styled('span')<{ theme?: Theme }>(props => ({ export const Published = styled('span')({
color: props.theme && props.theme.palette.greyLight2, '&&': {
color: colors.greyLight2,
margin: '0 5px 0 0', margin: '0 5px 0 0',
})); },
});
export const Text = styled(Label)<{ theme?: Theme }>(props => ({ export const Text = styled(Label)({
'&&': {
fontSize: '12px', fontSize: '12px',
fontWeight: fontWeight.semiBold, fontWeight: fontWeight.semiBold,
color: props.theme && props.theme.palette.greyLight2, color: colors.greyLight2,
})); },
});
export const Details = styled('span')({ export const Details = styled('span')({
'&&': {
marginLeft: '5px', marginLeft: '5px',
lineHeight: 1.5, lineHeight: 1.5,
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
},
}); });
export const Author = styled('div')({ export const Author = styled('div')({
'&&': {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
},
}); });
export const Avatar = styled(Photo)({ export const Avatar = styled(Photo)({
'&&': {
width: '20px', width: '20px',
height: '20px', height: '20px',
},
}); });
export const WrapperLink = styled(Link)({ export const WrapperLink = styled(Link)({
'&&': {
textDecoration: 'none', textDecoration: 'none',
},
}); });
export const PackageTitle = styled('span')<{ theme?: Theme }>(props => ({ export const PackageTitle = styled('span')`
fontWeight: 600, && {
fontSize: 20, font-weight: 600;
display: 'block', font-size: 20px;
marginBottom: 12, display: block;
color: props.theme && props.theme.palette.eclipse, margin-bottom: 12px;
cursor: 'pointer', color: ${colors.eclipse};
':hover': { cursor: pointer;
color: props.theme && props.theme.palette.black,
}, &:hover {
[`@media (max-width: ${breakpoints.small}px)`]: { color: ${colors.black};
fontSize: 14, }
marginBottom: 8,
}, @media (max-width: ${breakpoints.small}px) {
})); font-size: 14px;
margin-bottom: 8px;
}
}
`;
export const GridRightAligned = styled(Grid)({ export const GridRightAligned = styled(Grid)({
'&&': {
textAlign: 'right', textAlign: 'right',
},
}); });
export const PackageList = styled(List)<{ theme?: Theme }>(props => ({ export const PackageList = styled(List)({
'&&': {
padding: '12px 0 12px 0', padding: '12px 0 12px 0',
':hover': {
backgroundColor: props.theme && props.theme.palette.greyLight3, '&:hover': {
backgroundColor: colors.greyLight3,
}, },
'> :last-child': { '> :last-child': {
paddingTop: 0, paddingTop: 0,
}, },
})); },
});
export const IconButton = styled(MuiIconButton)({ export const IconButton = styled(MuiIconButton)({
padding: 6, '&&': {
padding: '6px',
svg: { svg: {
fontSize: 16, fontSize: '16px',
},
}, },
}); });
export const TagContainer = styled('span')({ export const TagContainer = styled('span')`
marginTop: 8, && {
marginBottom: 12, margin-top: 8px;
display: 'block', margin-bottom: 12px;
[`@media (max-width: ${breakpoints.medium}px)`]: { display: block;
display: 'none', @media (max-width: ${breakpoints.medium}px) {
}, display: none;
}); }
}
`;
export const PackageListItemText = styled(ListItemText)({ export const PackageListItemText = styled(ListItemText)({
'&&': {
paddingRight: 0, paddingRight: 0,
},
}); });
export const Description = styled(Typography)<{ theme?: Theme }>(props => ({ export const Description = styled(Typography)({
color: props.theme && props.theme.palette.greyDark2, color: colors.greyDark2,
fontSize: '14px', fontSize: '14px',
paddingRight: 0, paddingRight: 0,
})); });

View File

@@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { mount } from '../../utils/test-enzyme';
import Help from '../Help'; import Help from '../Help';
import { PackageList } from './PackageList'; import { PackageList } from './PackageList';

View File

@@ -1,4 +1,4 @@
import { css } from 'emotion'; import { css } from '@emotion/core';
import { fontWeight, fontSize } from '../../utils/styles/sizes'; import { fontWeight, fontSize } from '../../utils/styles/sizes';

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import Readme from './Readme'; import Readme from './Readme';

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { render, cleanup, fireEvent } from '@testing-library/react';
import { render, cleanup, fireEvent } from '../../utils/test-react-testing-library';
import RegistryInfoContent from './RegistryInfoContent'; import RegistryInfoContent from './RegistryInfoContent';

View File

@@ -47,13 +47,7 @@ const RegistryInfoContent: React.FC<Props> = props => {
return ( return (
<> <>
<Tabs <Tabs data-testid={'tabs-el'} indicatorColor="primary" onChange={handleChange} textColor="primary" value={tabPosition} variant="fullWidth">
data-testid={'tabs-el'}
indicatorColor="primary"
onChange={handleChange}
textColor="primary"
value={tabPosition}
variant="fullWidth">
<Tab data-testid={'npm-tab'} label={NODE_MANAGER.npm} /> <Tab data-testid={'npm-tab'} label={NODE_MANAGER.npm} />
<Tab data-testid={'pnpm-tab'} label={NODE_MANAGER.pnpm} /> <Tab data-testid={'pnpm-tab'} label={NODE_MANAGER.pnpm} />
<Tab data-testid={'yarn-tab'} label={NODE_MANAGER.yarn} /> <Tab data-testid={'yarn-tab'} label={NODE_MANAGER.yarn} />
@@ -70,10 +64,10 @@ const RegistryInfoContent: React.FC<Props> = props => {
return ( return (
<CommandContainer> <CommandContainer>
<Typography <Typography
// className={css` className={css`
// padding: 0; padding: 0;
// min-height: 170; min-height: 170;
// `} `}
component="div"> component="div">
{children} {children}
</Typography> </Typography>

View File

@@ -1,5 +1,7 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export const CommandContainer = styled('div')({ export const CommandContainer = styled('div')({
paddingTop: 20, '&&': {
paddingTop: '20px',
},
}); });

View File

@@ -1,15 +1,15 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import colors from '../../utils/styles/colors';
import { fontSize } from '../../utils/styles/sizes'; import { fontSize } from '../../utils/styles/sizes';
import DialogTitle from '../../muiComponents/DialogTitle'; import DialogTitle from '../../muiComponents/DialogTitle';
import DialogContent from '../../muiComponents/DialogContent'; import DialogContent from '../../muiComponents/DialogContent';
import { Theme } from '../../design-tokens/theme';
export const Title = styled(DialogTitle)<{ theme?: Theme }>(props => ({ export const Title = styled(DialogTitle)({
backgroundColor: props.theme && props.theme.palette.primary.main, backgroundColor: colors.primary,
color: props.theme && props.theme.palette.white, color: colors.white,
fontSize: fontSize.lg, fontSize: fontSize.lg,
})); });
export const Content = styled(DialogContent)({ export const Content = styled(DialogContent)({
padding: '0 24px', padding: '0 24px',

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import Repository from './Repository'; import Repository from './Repository';

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
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-1na337r-StyledText e1wmjxnh0 MuiTypography-subtitle1\\">Repository</h6><div class=\\"MuiButtonBase-root MuiListItem-root css-719o4l-RepositoryListItem e1wmjxnh4 MuiListItem-dense MuiListItem-gutters MuiListItem-button\\" tabindex=\\"0\\" role=\\"button\\" aria-disabled=\\"false\\"><div class=\\"MuiAvatar-root MuiAvatar-circle MuiAvatar-colorDefault\\"></div><div class=\\"MuiListItemText-root css-1lp4n02-RepositoryListItemText e1wmjxnh5 MuiListItemText-dense\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body2\\"><div class=\\"css-1in239f-ClipBoardCopy eb8w2fo0\\"><span class=\\"css-7gar9h-ClipBoardCopyText eb8w2fo1\\"><a href=\\"git+https://github.com/verdaccio/ui.git\\" target=\\"_blank\\" class=\\"css-6tc7qn-GithubLink e1wmjxnh2\\">git+https://github.com/verdaccio/ui.git</a></span><button class=\\"MuiButtonBase-root MuiIconButton-root css-1fs86cq-CopyIcon 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>"`; 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-b8upko 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-circle 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-lh0wgu 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

@@ -1,12 +1,12 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import Github from '../../icons/GitHub'; import Github from '../../icons/GitHub';
import colors from '../../utils/styles/colors';
import { fontWeight } from '../../utils/styles/sizes'; import { fontWeight } from '../../utils/styles/sizes';
import Text from '../../muiComponents/Text'; import Text from '../../muiComponents/Text';
import ListItem from '../../muiComponents/ListItem'; import ListItem from '../../muiComponents/ListItem';
import ListItemText from '../../muiComponents/ListItemText'; import ListItemText from '../../muiComponents/ListItemText';
import Grid from '../../muiComponents/Grid'; import Grid from '../../muiComponents/Grid';
import { Theme } from '../../design-tokens/theme';
export const StyledText = styled(Text)({ export const StyledText = styled(Text)({
fontWeight: fontWeight.bold, fontWeight: fontWeight.bold,
@@ -17,24 +17,32 @@ export const GridRepo = styled(Grid)({
alignItems: 'center', alignItems: 'center',
}); });
export const GithubLink = styled('a')<{ theme?: Theme }>(props => ({ export const GithubLink = styled('a')({
color: props.theme && props.theme.palette.primary.main, '&&': {
})); color: colors.primary,
},
});
export const GithubLogo = styled(Github)<{ theme?: Theme }>(props => ({ export const GithubLogo = styled(Github)({
fontSize: 40, '&&': {
color: props.theme && props.theme.palette.primary.main, fontSize: '40px',
backgroundColor: props.theme && props.theme.palette.greySuperLight, color: colors.primary,
})); backgroundColor: colors.greySuperLight,
},
});
export const RepositoryListItem = styled(ListItem)({ export const RepositoryListItem = styled(ListItem)({
'&&': {
padding: 0, padding: 0,
':hover': { },
'&&:hover': {
backgroundColor: 'transparent', backgroundColor: 'transparent',
}, },
}); });
export const RepositoryListItemText = styled(ListItemText)({ export const RepositoryListItemText = styled(ListItemText)({
'&&': {
padding: '0 10px', padding: '0 10px',
margin: 0, margin: 0,
},
}); });

View File

@@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import { mount, shallow } from 'enzyme';
import { BrowserRouter } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { mount, shallow } from '../../utils/test-enzyme';
import Search from './Search'; import Search from './Search';
const SEARCH_FILE_PATH = './Search'; const SEARCH_FILE_PATH = './Search';

View File

@@ -1,32 +1,8 @@
import React, { KeyboardEvent, Component, ReactElement } from 'react'; import React from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { SuggestionSelectedEventData, ChangeEvent } from 'react-autosuggest';
import styled from '@emotion/styled';
import { default as IconSearch } from '@material-ui/icons/Search';
import debounce from 'lodash/debounce'; import debounce from 'lodash/debounce';
import InputAdornment from '../../muiComponents/InputAdornment'; import AutoComplete from '../../muiComponents/AutoComplete';
import AutoComplete from '../AutoComplete';
import { callSearch } from '../../utils/calls'; import { callSearch } from '../../utils/calls';
import { Theme } from '../../design-tokens/theme';
export interface State {
search: string;
suggestions: unknown[];
loading: boolean;
loaded: boolean;
error: boolean;
}
export type cancelAllSearchRequests = () => void;
export type handlePackagesClearRequested = () => void;
export type handleSearch = (event: React.FormEvent<HTMLInputElement>, { newValue, method }: ChangeEvent) => void;
export type handleClickSearch = (
event: KeyboardEvent<HTMLInputElement>,
{ suggestionValue, method }: { suggestionValue: object[]; method: string }
) => void;
export type handleFetchPackages = ({ value: string }) => Promise<void>;
export type onBlur = (event: React.FormEvent<HTMLInputElement>) => void;
const CONSTANTS = { const CONSTANTS = {
API_DELAY: 300, API_DELAY: 300,
@@ -34,168 +10,71 @@ const CONSTANTS = {
ABORT_ERROR: 'AbortError', ABORT_ERROR: 'AbortError',
}; };
const StyledInputAdornment = styled(InputAdornment)<{ theme?: Theme }>(props => ({ /* eslint-disable @typescript-eslint/explicit-function-return-type */
color: props.theme && props.theme.palette.white, const Search: React.FC = () => {
})); const [suggestions, setSuggestions] = React.useState([]);
const [isLoading, setIsLoading] = React.useState();
const [hasBeenLoaded, setHasBeenLoaded] = React.useState();
const [error, setError] = React.useState();
export class Search extends Component<RouteComponentProps<{}>, State> { const handleFetchPackages = debounce(async (value: string) => {
constructor(props: RouteComponentProps<{}>) {
super(props);
this.state = {
search: '',
suggestions: [],
// loading: A boolean value to indicate that request is in pending state.
loading: false,
// loaded: A boolean value to indicate that result has been loaded.
loaded: false,
// error: A boolean value to indicate API error.
error: false,
};
this.requestList = [];
}
public render(): ReactElement<HTMLElement> {
const { suggestions, search, loaded, loading, error } = this.state;
return (
<AutoComplete
onBlur={this.handleOnBlur}
onChange={this.handleSearch}
onCleanSuggestions={this.handlePackagesClearRequested}
onClick={this.handleClickSearch}
onSuggestionsFetch={debounce(this.handleFetchPackages, CONSTANTS.API_DELAY)}
placeholder={CONSTANTS.PLACEHOLDER_TEXT}
startAdornment={this.getAdorment()}
suggestions={suggestions}
suggestionsError={error}
suggestionsLoaded={loaded}
suggestionsLoading={loading}
value={search}
/>
);
}
/**
* Cancel all the requests which are in pending state.
*/
private cancelAllSearchRequests: cancelAllSearchRequests = () => {
this.requestList.forEach(request => request.abort());
this.requestList = [];
};
/**
* Cancel all the request from list and make request list empty.
*/
private handlePackagesClearRequested: handlePackagesClearRequested = () => {
this.setState({
suggestions: [],
});
};
/**
* onChange method for the input element.
*/
private handleSearch: handleSearch = (event, { newValue, method }) => {
// stops event bubbling
event.stopPropagation();
if (method === 'type') {
const value = newValue.trim();
this.setState(
{
search: value,
loading: true,
loaded: false,
error: false,
},
() => {
/**
* A use case where User keeps adding and removing value in input field,
* so we cancel all the existing requests when input is empty.
*/
if (value.length === 0) {
this.cancelAllSearchRequests();
}
}
);
}
};
/**
* When an user select any package by clicking or pressing return key.
*/
private handleClickSearch = (
event: React.FormEvent<HTMLInputElement>,
{ suggestionValue, method }: SuggestionSelectedEventData<unknown>
): void | undefined => {
const { history } = this.props;
// stops event bubbling
event.stopPropagation();
switch (method) {
case 'click':
case 'enter':
this.setState({ search: '' });
history.push(`/-/web/detail/${suggestionValue}`);
break;
}
};
/**
* Fetch packages from API.
* For AbortController see: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
*/
private handleFetchPackages: handleFetchPackages = async ({ value }) => {
try { try {
const controller = new window.AbortController(); const controller = new window.AbortController();
const signal = controller.signal; const signal = controller.signal;
// Keep track of search requests. // Keep track of search requests.
this.requestList.push(controller); // this.requestList.push(controller);
const suggestions = await callSearch(value, signal); const suggestions = await callSearch(value, signal);
setSuggestions(
// @ts-ignore // @ts-ignore
this.setState({ suggestions.map(suggestion => ({
suggestions, ...suggestion,
loaded: true, id: suggestion._id,
}); label: suggestion.name,
}))
);
setHasBeenLoaded(true);
} catch (error) { } catch (error) {
/** /**
* AbortError is not the API error. * AbortError is not the API error.
* It means browser has cancelled the API request. * It means browser has cancelled the API request.
*/ */
if (error.name === CONSTANTS.ABORT_ERROR) { if (error.name === CONSTANTS.ABORT_ERROR) {
this.setState({ error: false, loaded: false }); setError(false);
setHasBeenLoaded(false);
} else { } else {
this.setState({ error: true, loaded: false }); setError(true);
setHasBeenLoaded(false);
} }
} finally { } finally {
this.setState({ loading: false }); setIsLoading(false);
} }
}; }, CONSTANTS.API_DELAY);
private requestList: AbortController[]; const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
public getAdorment(): JSX.Element {
return (
<StyledInputAdornment position={'start'}>
<IconSearch />
</StyledInputAdornment>
);
}
/**
* As user focuses out from input, we cancel all the request from requestList
* and set the API state parameters to default boolean values.
*/
private handleOnBlur: onBlur = event => {
// stops event bubbling // stops event bubbling
event.stopPropagation(); event.stopPropagation();
this.setState( setIsLoading(true);
{ setHasBeenLoaded(false);
loaded: false, setError(undefined);
loading: false, handleFetchPackages(event.target.value);
error: false, };
},
() => this.cancelAllSearchRequests() return (
<AutoComplete
// onBlur={this.handleOnBlur}
onChange={handleChange}
// onCleanSuggestions={this.handlePackagesClearRequested}
// onClick={this.handleClickSearch}
// onSuggestionsFetch={debounce(this.handleFetchPackages, CONSTANTS.API_DELAY)}
options={suggestions}
placeholder={CONSTANTS.PLACEHOLDER_TEXT}
// startAdornment={this.getAdorment()}
// suggestionsError={error}
// suggestionsLoaded={loaded}
// suggestionsLoading={loading}
// value={search}
/>
); );
}; };
}
export default withRouter(Search); export default Search;

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Search /> component test should load the component in default state 1`] = `"<div class=\\"css-pnwf4z-Wrapper 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 css-ae5nkp-StyledTextField e1rflf271 MuiFormControl-fullWidth\\" aria-autocomplete=\\"list\\" aria-controls=\\"react-autowhatever-1\\"><div class=\\"MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart\\"><div class=\\"MuiInputAdornment-root css-1wub48n-StyledInputAdornment e1n3ivvz0 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\\" placeholder=\\"Search Packages\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart\\" value=\\"\\"></div></div><div class=\\"MuiPaper-root MuiPaper-elevation1 react-autosuggest__suggestions-container css-kc7cda-SuggestionContainer e1rflf272\\" 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-fvu7gn 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\\" placeholder=\\"Search Packages\\" type=\\"text\\" class=\\"MuiInputBase-input MuiInput-input css-hodoyq MuiInputBase-inputAdornedStart\\" 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,13 +1,12 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme';
import { mount } from '../../utils/test-enzyme';
import Spinner from './Spinner'; import Spinner from './Spinner';
import { Circular, Wrapper } from './styles'; import { Circular, Wrapper } from './styles';
describe('<Spinner /> component', () => { describe('<Spinner /> component', () => {
test('should render the component in default state', () => { test('should render the component in default state', () => {
const wrapper = mount(<Spinner />); const wrapper = shallow(<Spinner />);
const wrapperComponent = wrapper.find(Wrapper); const wrapperComponent = wrapper.find(Wrapper);
const circular = wrapper.find(Circular); const circular = wrapper.find(Circular);
@@ -16,7 +15,7 @@ describe('<Spinner /> component', () => {
}); });
test('should render the component in custom state', () => { test('should render the component in custom state', () => {
const wrapper = mount(<Spinner centered={true} size={10} />); const wrapper = shallow(<Spinner centered={true} size={10} />);
const wrapperComponent = wrapper.find(Wrapper); const wrapperComponent = wrapper.find(Wrapper);
const circular = wrapper.find(Circular); const circular = wrapper.find(Circular);

View File

@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Spinner /> component should render the component in custom state 1`] = `"<div class=\\"css-1ju0ex2-Wrapper e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root css-evyw70-Circular e1ag4h8b1 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate\\" style=\\"width: 10px; height: 10px;\\" 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>"`; exports[`<Spinner /> component should render the component in custom state 1`] = `"<div class=\\"css-zo92co e1ag4h8b0\\"><div class=\\"MuiCircularProgress-root css-15gl0ho e1ag4h8b1 MuiCircularProgress-colorPrimary MuiCircularProgress-indeterminate\\" style=\\"width:10px;height:10px\\" 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,24 +1,31 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { css } from '@emotion/core';
import colors from '../../utils/styles/colors';
import CircularProgress from '../../muiComponents/CircularProgress'; import CircularProgress from '../../muiComponents/CircularProgress';
import { Theme } from '../../design-tokens/theme';
interface WrapperProps { interface WrapperProps {
centered: boolean; centered: boolean;
} }
export const Wrapper = styled('div')<WrapperProps>(props => ({ export const Wrapper = styled('div')`
display: 'flex', && {
alignItems: 'center', display: flex;
justifyContent: 'center', align-items: center;
...(props.centered && { justify-content: center;
position: 'absolute', ${(props: WrapperProps) =>
top: '50%', props.centered &&
left: '50%', css`
transform: 'translate(-50%, -50%)', position: absolute;
}), top: 50%;
})); left: 50%;
transform: translate(-50%, -50%);
`};
}
`;
export const Circular = styled(CircularProgress)<{ theme?: Theme }>(props => ({ export const Circular = styled(CircularProgress)({
color: props.theme && props.theme.palette.primary.main, '&&': {
})); color: colors.primary,
},
});

View File

@@ -1,16 +1,15 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme';
import { render } from '../../utils/test-react-testing-library';
import Tag from './Tag'; import Tag from './Tag';
describe('<Tag /> component', () => { describe('<Tag /> component', () => {
test('should load the component in default state', () => { test('should render the component in default state', () => {
const { container } = render( const wrapper = shallow(
<Tag> <Tag>
<span>{'I am a child'}</span> <span>{'I am a child'}</span>
</Tag> </Tag>
); );
expect(container.firstChild).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();
}); });
}); });

View File

@@ -1,21 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<Tag /> component should load the component in default state 1`] = ` exports[`<Tag /> component should render the component in default state 1`] = `"<span class=\\"css-le0azu e1q9boj50\\"><span>I am a child</span></span>"`;
.emotion-0 {
vertical-align: middle;
line-height: 22px;
border-radius: 2px;
color: #485a3e;
background-color: #f3f4f2;
padding: 0.22rem 0.4rem;
margin: 8px 8px 0 0;
}
<span
class="emotion-0 emotion-1"
>
<span>
I am a child
</span>
</span>
`;

View File

@@ -1,6 +1,7 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
export const Wrapper = styled('span')({ export const Wrapper = styled('span')({
'&&': {
verticalAlign: 'middle', verticalAlign: 'middle',
lineHeight: '22px', lineHeight: '22px',
borderRadius: '2px', borderRadius: '2px',
@@ -8,4 +9,5 @@ export const Wrapper = styled('span')({
backgroundColor: '#f3f4f2', backgroundColor: '#f3f4f2',
padding: '0.22rem 0.4rem', padding: '0.22rem 0.4rem',
margin: '8px 8px 0 0', margin: '8px 8px 0 0',
},
}); });

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { shallow, mount } from 'enzyme';
import { mount, shallow } from '../../utils/test-enzyme';
import { DetailContext } from '../../pages/Version'; import { DetailContext } from '../../pages/Version';
import UpLinks from './UpLinks'; import UpLinks from './UpLinks';

View File

@@ -2,4 +2,4 @@
exports[`<UpLinks /> component should render the component when there is no uplink 1`] = `"<h6 class=\\"MuiTypography-root MuiTypography-subtitle1 MuiTypography-gutterBottom\\">verdaccio has no uplinks.</h6>"`; exports[`<UpLinks /> component should render the component when there is no uplink 1`] = `"<h6 class=\\"MuiTypography-root MuiTypography-subtitle1 MuiTypography-gutterBottom\\">verdaccio has no uplinks.</h6>"`;
exports[`<UpLinks /> component should render the component with uplinks 1`] = `"<h6 class=\\"MuiTypography-root css-5wp24z-StyledText e14i1sy10 MuiTypography-subtitle1\\">Uplinks</h6><ul class=\\"MuiList-root MuiList-padding\\"><li class=\\"MuiListItem-root MuiListItem-gutters\\"><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">npmjs</span></div><div class=\\"css-t1rp47-Spacer e14i1sy11\\"></div><div class=\\"MuiListItemText-root css-1pxn9ma-ListItemText e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">over 1 year ago</span></div></li></ul>"`; exports[`<UpLinks /> component should render the component with uplinks 1`] = `"<h6 class=\\"MuiTypography-root css-1vg6q84 e14i1sy10 MuiTypography-subtitle1\\">Uplinks</h6><ul class=\\"MuiList-root MuiList-padding\\"><li class=\\"MuiListItem-root MuiListItem-gutters\\"><div class=\\"MuiListItemText-root css-o655gb e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">npmjs</span></div><div class=\\"css-1l1cv61 e14i1sy11\\"></div><div class=\\"MuiListItemText-root css-o655gb e14i1sy12\\"><span class=\\"MuiTypography-root MuiListItemText-primary MuiTypography-body1\\">over 1 year ago</span></div></li></ul>"`;

View File

@@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { mount } from 'enzyme';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { render, cleanup } from '@testing-library/react';
import { render, cleanup } from '../../utils/test-react-testing-library';
import { mount } from '../../utils/test-enzyme';
import { DetailContext, DetailContextProps } from '../../pages/Version'; import { DetailContext, DetailContextProps } from '../../pages/Version';
import Versions, { LABEL_CURRENT_TAGS, LABEL_VERSION_HISTORY } from './Versions'; import Versions, { LABEL_CURRENT_TAGS, LABEL_VERSION_HISTORY } from './Versions';

View File

@@ -16,11 +16,6 @@ const resetStyles = makeStyles(() => ({
'html, body, #root': { 'html, body, #root': {
height: '100%', height: '100%',
}, },
ul: {
margin: 0,
padding: 0,
listStyle: 'none',
},
'.container': { '.container': {
padding: 15, padding: 15,
flex: 1, flex: 1,

View File

@@ -1,13 +0,0 @@
import React from 'react';
import { ThemeProvider as MuiThemeProvider } from '@material-ui/core/styles';
import { ThemeProvider as EmotionThemeProvider } from 'emotion-theming';
import theme from './theme';
const ThemeProvider: React.FC = ({ children }) => (
<EmotionThemeProvider theme={theme}>
<MuiThemeProvider theme={theme}>{children}</MuiThemeProvider>
</EmotionThemeProvider>
);
export default ThemeProvider;

Some files were not shown because too many files have changed in this diff Show More