apply prettier, removed flow related config and added tsconfig

This commit is contained in:
Sebastian Sdorra
2019-10-20 18:02:52 +02:00
parent 0e017dcadd
commit 490418d06e
231 changed files with 5771 additions and 30386 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { File } from '@scm-manager/ui-types';
import React from "react";
import { File } from "@scm-manager/ui-types";
type Props = {
file: File;
@@ -8,11 +8,11 @@ type Props = {
class FileIcon extends React.Component<Props> {
render() {
const { file } = this.props;
let icon = 'file';
let icon = "file";
if (file.subRepository) {
icon = 'folder-plus';
icon = "folder-plus";
} else if (file.directory) {
icon = 'folder';
icon = "folder";
}
return <i className={`fa fa-${icon}`} />;
}

View File

@@ -1,10 +1,10 @@
import { findParent } from './FileTree';
import { findParent } from "./FileTree";
describe('find parent tests', () => {
it('should return the parent path', () => {
expect(findParent('src/main/js/')).toBe('src/main');
expect(findParent('src/main/js')).toBe('src/main');
expect(findParent('src/main')).toBe('src');
expect(findParent('src')).toBe('');
describe("find parent tests", () => {
it("should return the parent path", () => {
expect(findParent("src/main/js/")).toBe("src/main");
expect(findParent("src/main/js")).toBe("src/main");
expect(findParent("src/main")).toBe("src");
expect(findParent("src")).toBe("");
});
});

View File

@@ -1,22 +1,22 @@
import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { translate } from 'react-i18next';
import styled from 'styled-components';
import { binder } from '@scm-manager/ui-extensions';
import { Repository, File } from '@scm-manager/ui-types';
import React from "react";
import { compose } from "redux";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { translate } from "react-i18next";
import styled from "styled-components";
import { binder } from "@scm-manager/ui-extensions";
import { Repository, File } from "@scm-manager/ui-types";
import {
ErrorNotification,
Loading,
Notification,
} from '@scm-manager/ui-components';
Notification
} from "@scm-manager/ui-components";
import {
getFetchSourcesFailure,
isFetchSourcesPending,
getSources,
} from '../modules/sources';
import FileTreeLeaf from './FileTreeLeaf';
getSources
} from "../modules/sources";
import FileTreeLeaf from "./FileTreeLeaf";
type Props = {
loading: boolean;
@@ -37,15 +37,15 @@ const FixedWidthTh = styled.th`
`;
export function findParent(path: string) {
if (path.endsWith('/')) {
if (path.endsWith("/")) {
path = path.substring(0, path.length - 1);
}
const index = path.lastIndexOf('/');
const index = path.lastIndexOf("/");
if (index > 0) {
return path.substring(0, index);
}
return '';
return "";
}
class FileTree extends React.Component<Props> {
@@ -73,9 +73,9 @@ class FileTree extends React.Component<Props> {
if (path) {
files.push({
name: '..',
name: "..",
path: findParent(path),
directory: true,
directory: true
});
}
@@ -102,9 +102,9 @@ class FileTree extends React.Component<Props> {
if (files && files.length > 0) {
let baseUrlWithRevision = baseUrl;
if (revision) {
baseUrlWithRevision += '/' + encodeURIComponent(revision);
baseUrlWithRevision += "/" + encodeURIComponent(revision);
} else {
baseUrlWithRevision += '/' + encodeURIComponent(tree.revision);
baseUrlWithRevision += "/" + encodeURIComponent(tree.revision);
}
return (
@@ -112,17 +112,17 @@ class FileTree extends React.Component<Props> {
<thead>
<tr>
<FixedWidthTh />
<th>{t('sources.file-tree.name')}</th>
<th>{t("sources.file-tree.name")}</th>
<th className="is-hidden-mobile">
{t('sources.file-tree.length')}
{t("sources.file-tree.length")}
</th>
<th className="is-hidden-mobile">
{t('sources.file-tree.lastModified')}
{t("sources.file-tree.lastModified")}
</th>
<th className="is-hidden-mobile">
{t('sources.file-tree.description')}
{t("sources.file-tree.description")}
</th>
{binder.hasExtension('repos.sources.tree.row.right') && (
{binder.hasExtension("repos.sources.tree.row.right") && (
<th className="is-hidden-mobile" />
)}
</tr>
@@ -139,7 +139,7 @@ class FileTree extends React.Component<Props> {
</table>
);
}
return <Notification type="info">{t('sources.noSources')}</Notification>;
return <Notification type="info">{t("sources.noSources")}</Notification>;
}
}
@@ -155,11 +155,11 @@ const mapStateToProps = (state: any, ownProps: Props) => {
path,
loading,
error,
tree,
tree
};
};
export default compose(
withRouter,
connect(mapStateToProps),
)(translate('repos')(FileTree));
connect(mapStateToProps)
)(translate("repos")(FileTree));

View File

@@ -1,28 +1,28 @@
import { createLink } from './FileTreeLeaf';
import { File } from '@scm-manager/ui-types';
import { createLink } from "./FileTreeLeaf";
import { File } from "@scm-manager/ui-types";
describe('create link tests', () => {
describe("create link tests", () => {
function dir(path: string): File {
return {
name: 'dir',
name: "dir",
path: path,
directory: true,
length: 1,
revision: '1a',
revision: "1a",
_links: {},
_embedded: {
children: [],
},
children: []
}
};
}
it('should create link', () => {
expect(createLink('src', dir('main'))).toBe('src/main/');
expect(createLink('src', dir('/main'))).toBe('src/main/');
expect(createLink('src', dir('/main/'))).toBe('src/main/');
it("should create link", () => {
expect(createLink("src", dir("main"))).toBe("src/main/");
expect(createLink("src", dir("/main"))).toBe("src/main/");
expect(createLink("src", dir("/main/"))).toBe("src/main/");
});
it('should return base url if the directory path is empty', () => {
expect(createLink('src', dir(''))).toBe('src/');
it("should return base url if the directory path is empty", () => {
expect(createLink("src", dir(""))).toBe("src/");
});
});

View File

@@ -1,11 +1,11 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import styled from 'styled-components';
import { binder, ExtensionPoint } from '@scm-manager/ui-extensions';
import { File } from '@scm-manager/ui-types';
import { DateFromNow, FileSize } from '@scm-manager/ui-components';
import FileIcon from './FileIcon';
import * as React from "react";
import { Link } from "react-router-dom";
import classNames from "classnames";
import styled from "styled-components";
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
import { File } from "@scm-manager/ui-types";
import { DateFromNow, FileSize } from "@scm-manager/ui-components";
import FileIcon from "./FileIcon";
type Props = {
file: File;
@@ -20,13 +20,13 @@ export function createLink(base: string, file: File) {
let link = base;
if (file.path) {
let path = file.path;
if (path.startsWith('/')) {
if (path.startsWith("/")) {
path = path.substring(1);
}
link += '/' + path;
link += "/" + path;
}
if (!link.endsWith('/')) {
link += '/';
if (!link.endsWith("/")) {
link += "/";
}
return link;
}
@@ -61,7 +61,7 @@ export default class FileTreeLeaf extends React.Component<Props> {
render() {
const { file } = this.props;
const fileSize = file.directory ? '' : <FileSize bytes={file.length} />;
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
return (
<tr>
@@ -73,16 +73,16 @@ export default class FileTreeLeaf extends React.Component<Props> {
<td className="is-hidden-mobile">
<DateFromNow date={file.lastModified} />
</td>
<MinWidthTd className={classNames('is-word-break', 'is-hidden-mobile')}>
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>
{file.description}
</MinWidthTd>
{binder.hasExtension('repos.sources.tree.row.right') && (
{binder.hasExtension("repos.sources.tree.row.right") && (
<td className="is-hidden-mobile">
{!file.directory && (
<ExtensionPoint
name="repos.sources.tree.row.right"
props={{
file,
file
}}
renderAll={true}
/>

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { translate } from 'react-i18next';
import { File } from '@scm-manager/ui-types';
import { DownloadButton } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { File } from "@scm-manager/ui-types";
import { DownloadButton } from "@scm-manager/ui-components";
type Props = {
t: (p: string) => string;
@@ -15,11 +15,11 @@ class DownloadViewer extends React.Component<Props> {
<div className="has-text-centered">
<DownloadButton
url={file._links.self.href}
displayName={t('sources.content.downloadButton')}
displayName={t("sources.content.downloadButton")}
/>
</div>
);
}
}
export default translate('repos')(DownloadViewer);
export default translate("repos")(DownloadViewer);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { translate } from 'react-i18next';
import { ButtonAddons, Button } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { ButtonAddons, Button } from "@scm-manager/ui-components";
type Props = {
className?: string;
@@ -19,7 +19,7 @@ class FileButtonAddons extends React.Component<Props> {
};
color = (selected: boolean) => {
return selected ? 'link is-selected' : null;
return selected ? "link is-selected" : null;
};
render() {
@@ -27,7 +27,7 @@ class FileButtonAddons extends React.Component<Props> {
return (
<ButtonAddons className={className}>
<div title={t('sources.content.sourcesButton')}>
<div title={t("sources.content.sourcesButton")}>
<Button
action={this.showSources}
className="reduced"
@@ -38,7 +38,7 @@ class FileButtonAddons extends React.Component<Props> {
</span>
</Button>
</div>
<div title={t('sources.content.historyButton')}>
<div title={t("sources.content.historyButton")}>
<Button
action={this.showHistory}
className="reduced"
@@ -54,4 +54,4 @@ class FileButtonAddons extends React.Component<Props> {
}
}
export default translate('repos')(FileButtonAddons);
export default translate("repos")(FileButtonAddons);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { translate } from 'react-i18next';
import { File } from '@scm-manager/ui-types';
import React from "react";
import { translate } from "react-i18next";
import { File } from "@scm-manager/ui-types";
type Props = {
t: (p: string) => string;
@@ -20,4 +20,4 @@ class ImageViewer extends React.Component<Props> {
}
}
export default translate('repos')(ImageViewer);
export default translate("repos")(ImageViewer);

View File

@@ -1,29 +1,29 @@
import fetchMock from 'fetch-mock';
import { getContent, getLanguage } from './SourcecodeViewer';
import fetchMock from "fetch-mock";
import { getContent, getLanguage } from "./SourcecodeViewer";
describe('get content', () => {
const CONTENT_URL = '/repositories/scmadmin/TestRepo/content/testContent';
describe("get content", () => {
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it('should return content', done => {
fetchMock.getOnce('/api/v2' + CONTENT_URL, 'This is a testContent');
it("should return content", done => {
fetchMock.getOnce("/api/v2" + CONTENT_URL, "This is a testContent");
getContent(CONTENT_URL).then(content => {
expect(content).toBe('This is a testContent');
expect(content).toBe("This is a testContent");
done();
});
});
});
describe('get correct language type', () => {
it('should return javascript', () => {
expect(getLanguage('JAVASCRIPT')).toBe('javascript');
describe("get correct language type", () => {
it("should return javascript", () => {
expect(getLanguage("JAVASCRIPT")).toBe("javascript");
});
it('should return nothing for plain text', () => {
expect(getLanguage('')).toBe('');
it("should return nothing for plain text", () => {
expect(getLanguage("")).toBe("");
});
});

View File

@@ -1,8 +1,8 @@
import React from 'react';
import { translate } from 'react-i18next';
import { apiClient, SyntaxHighlighter } from '@scm-manager/ui-components';
import { File } from '@scm-manager/ui-types';
import { ErrorNotification, Loading } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { apiClient, SyntaxHighlighter } from "@scm-manager/ui-components";
import { File } from "@scm-manager/ui-types";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
type Props = {
t: (p: string) => string;
@@ -21,8 +21,8 @@ class SourcecodeViewer extends React.Component<Props, State> {
super(props);
this.state = {
content: '',
loaded: false,
content: "",
loaded: false
};
}
@@ -34,13 +34,13 @@ class SourcecodeViewer extends React.Component<Props, State> {
this.setState({
...this.state,
error: result.error,
loaded: true,
loaded: true
});
} else {
this.setState({
...this.state,
content: result,
loaded: true,
loaded: true
});
}
})
@@ -82,9 +82,9 @@ export function getContent(url: string) {
})
.catch(err => {
return {
error: err,
error: err
};
});
}
export default translate('repos')(SourcecodeViewer);
export default translate("repos")(SourcecodeViewer);

View File

@@ -1,20 +1,20 @@
import React from 'react';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import classNames from 'classnames';
import styled from 'styled-components';
import { ExtensionPoint } from '@scm-manager/ui-extensions';
import { File, Repository } from '@scm-manager/ui-types';
import React from "react";
import { connect } from "react-redux";
import { translate } from "react-i18next";
import classNames from "classnames";
import styled from "styled-components";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import { File, Repository } from "@scm-manager/ui-types";
import {
DateFromNow,
ErrorNotification,
FileSize,
Icon,
} from '@scm-manager/ui-components';
import { getSources } from '../modules/sources';
import FileButtonAddons from '../components/content/FileButtonAddons';
import SourcesView from './SourcesView';
import HistoryView from './HistoryView';
Icon
} from "@scm-manager/ui-components";
import { getSources } from "../modules/sources";
import FileButtonAddons from "../components/content/FileButtonAddons";
import SourcesView from "./SourcesView";
import HistoryView from "./HistoryView";
type Props = {
loading: boolean;
@@ -59,33 +59,33 @@ class Content extends React.Component<Props, State> {
this.state = {
collapsed: true,
showHistory: false,
showHistory: false
};
}
toggleCollapse = () => {
this.setState(prevState => ({
collapsed: !prevState.collapsed,
collapsed: !prevState.collapsed
}));
};
setShowHistoryState(showHistory: boolean) {
this.setState({
...this.state,
showHistory,
showHistory
});
}
handleExtensionError = (error: Error) => {
this.setState({
errorFromExtension: error,
errorFromExtension: error
});
};
showHeader() {
const { file, revision } = this.props;
const { showHistory, collapsed } = this.state;
const icon = collapsed ? 'angle-right' : 'angle-down';
const icon = collapsed ? "angle-right" : "angle-down";
const selector = file._links.history ? (
<RightMarginFileButtonAddons
@@ -99,7 +99,7 @@ class Content extends React.Component<Props, State> {
return (
<span className="has-cursor-pointer">
<VCenteredChild className={classNames('media', 'is-flex')}>
<VCenteredChild className={classNames("media", "is-flex")}>
<div className="media-content" onClick={this.toggleCollapse}>
<RightMarginIcon name={icon} color="inherit" />
<span className="is-word-break">{file.name}</span>
@@ -111,7 +111,7 @@ class Content extends React.Component<Props, State> {
props={{
file,
revision,
handleExtensionError: this.handleExtensionError,
handleExtensionError: this.handleExtensionError
}}
renderAll={true}
/>
@@ -127,7 +127,7 @@ class Content extends React.Component<Props, State> {
const date = <DateFromNow date={file.lastModified} />;
const description = file.description ? (
<p>
{file.description.split('\n').map((item, key) => {
{file.description.split("\n").map((item, key) => {
return (
<span key={key}>
{item}
@@ -137,30 +137,30 @@ class Content extends React.Component<Props, State> {
})}
</p>
) : null;
const fileSize = file.directory ? '' : <FileSize bytes={file.length} />;
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
if (!collapsed) {
return (
<LighterGreyBackgroundPanelBlock className="panel-block">
<LighterGreyBackgroundTable className="table">
<tbody>
<tr>
<td>{t('sources.content.path')}</td>
<td>{t("sources.content.path")}</td>
<td className="is-word-break">{file.path}</td>
</tr>
<tr>
<td>{t('sources.content.branch')}</td>
<td>{t("sources.content.branch")}</td>
<td className="is-word-break">{revision}</td>
</tr>
<tr>
<td>{t('sources.content.size')}</td>
<td>{t("sources.content.size")}</td>
<td>{fileSize}</td>
</tr>
<tr>
<td>{t('sources.content.lastModified')}</td>
<td>{t("sources.content.lastModified")}</td>
<td>{date}</td>
</tr>
<tr>
<td>{t('sources.content.description')}</td>
<td>{t("sources.content.description")}</td>
<td className="is-word-break">{description}</td>
</tr>
<ExtensionPoint
@@ -169,7 +169,7 @@ class Content extends React.Component<Props, State> {
props={{
file,
repository,
revision,
revision
}}
/>
</tbody>
@@ -217,8 +217,8 @@ const mapStateToProps = (state: any, ownProps: Props) => {
const file = getSources(state, repository, revision, path);
return {
file,
file
};
};
export default connect(mapStateToProps)(translate('repos')(Content));
export default connect(mapStateToProps)(translate("repos")(Content));

View File

@@ -1,17 +1,17 @@
import React from 'react';
import React from "react";
import {
File,
Changeset,
Repository,
PagedCollection,
} from '@scm-manager/ui-types';
PagedCollection
} from "@scm-manager/ui-types";
import {
ErrorNotification,
Loading,
StatePaginator,
ChangesetList,
} from '@scm-manager/ui-components';
import { getHistory } from './history';
ChangesetList
} from "@scm-manager/ui-components";
import { getHistory } from "./history";
type Props = {
file: File;
@@ -33,7 +33,7 @@ class HistoryView extends React.Component<Props, State> {
this.state = {
loaded: false,
page: 1,
changesets: [],
changesets: []
};
}
@@ -49,7 +49,7 @@ class HistoryView extends React.Component<Props, State> {
this.setState({
...this.state,
error: result.error,
loaded: true,
loaded: true
});
} else {
this.setState({
@@ -57,7 +57,7 @@ class HistoryView extends React.Component<Props, State> {
loaded: true,
changesets: result.changesets,
pageCollection: result.pageCollection,
page: result.pageCollection.page,
page: result.pageCollection.page
});
}
})
@@ -68,7 +68,7 @@ class HistoryView extends React.Component<Props, State> {
const { file } = this.props;
const internalPage = page - 1;
this.updateHistory(
file._links.history.href + '?page=' + internalPage.toString(),
file._links.history.href + "?page=" + internalPage.toString()
);
}

View File

@@ -1,24 +1,24 @@
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { Branch, Repository } from '@scm-manager/ui-types';
import FileTree from '../components/FileTree';
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { Branch, Repository } from "@scm-manager/ui-types";
import FileTree from "../components/FileTree";
import {
BranchSelector,
Breadcrumb,
ErrorNotification,
Loading,
} from '@scm-manager/ui-components';
import { translate } from 'react-i18next';
Loading
} from "@scm-manager/ui-components";
import { translate } from "react-i18next";
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending,
} from '../../branches/modules/branches';
import { compose } from 'redux';
import Content from './Content';
import { fetchSources, isDirectory } from '../modules/sources';
isFetchBranchesPending
} from "../../branches/modules/branches";
import { compose } from "redux";
import Content from "./Content";
import { fetchSources, isDirectory } from "../modules/sources";
type Props = {
repository: Repository;
@@ -50,7 +50,7 @@ class Sources extends React.Component<Props, State> {
super(props);
this.state = {
selectedBranch: null,
selectedBranch: null
};
}
@@ -60,7 +60,7 @@ class Sources extends React.Component<Props, State> {
repository,
revision,
path,
fetchSources,
fetchSources
} = this.props;
fetchBranches(repository);
@@ -99,7 +99,7 @@ class Sources extends React.Component<Props, State> {
let url;
if (branch) {
this.setState({
selectedBranch: branch,
selectedBranch: branch
});
if (path) {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`;
@@ -108,7 +108,7 @@ class Sources extends React.Component<Props, State> {
}
} else {
this.setState({
selectedBranch: null,
selectedBranch: null
});
url = `${baseUrl}/`;
}
@@ -123,7 +123,7 @@ class Sources extends React.Component<Props, State> {
error,
revision,
path,
currentFileIsDirectory,
currentFileIsDirectory
} = this.props;
if (error) {
@@ -163,7 +163,7 @@ class Sources extends React.Component<Props, State> {
<BranchSelector
branches={branches}
selectedBranch={revision}
label={t('changesets.branchSelectorLabel')}
label={t("changesets.branchSelectorLabel")}
selected={(b: Branch) => {
this.branchSelected(b);
}}
@@ -215,7 +215,7 @@ const mapStateToProps = (state, ownProps) => {
loading,
error,
branches,
currentFileIsDirectory,
currentFileIsDirectory
};
};
@@ -226,15 +226,15 @@ const mapDispatchToProps = dispatch => {
},
fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, revision, path));
},
}
};
};
export default compose(
translate('repos'),
translate("repos"),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps,
),
mapDispatchToProps
)
)(Sources);

View File

@@ -1,12 +1,12 @@
import React from 'react';
import React from "react";
import SourcecodeViewer from '../components/content/SourcecodeViewer';
import ImageViewer from '../components/content/ImageViewer';
import DownloadViewer from '../components/content/DownloadViewer';
import { ExtensionPoint } from '@scm-manager/ui-extensions';
import { getContentType } from './contentType';
import { File, Repository } from '@scm-manager/ui-types';
import { ErrorNotification, Loading } from '@scm-manager/ui-components';
import SourcecodeViewer from "../components/content/SourcecodeViewer";
import ImageViewer from "../components/content/ImageViewer";
import DownloadViewer from "../components/content/DownloadViewer";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import { getContentType } from "./contentType";
import { File, Repository } from "@scm-manager/ui-types";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
type Props = {
repository: Repository;
@@ -27,9 +27,9 @@ class SourcesView extends React.Component<Props, State> {
super(props);
this.state = {
contentType: '',
language: '',
loaded: false,
contentType: "",
language: "",
loaded: false
};
}
@@ -41,14 +41,14 @@ class SourcesView extends React.Component<Props, State> {
this.setState({
...this.state,
error: result.error,
loaded: true,
loaded: true
});
} else {
this.setState({
...this.state,
contentType: result.type,
language: result.language,
loaded: true,
loaded: true
});
}
})
@@ -58,11 +58,11 @@ class SourcesView extends React.Component<Props, State> {
showSources() {
const { file, revision } = this.props;
const { contentType, language } = this.state;
if (contentType.startsWith('image/')) {
if (contentType.startsWith("image/")) {
return <ImageViewer file={file} />;
} else if (language) {
return <SourcecodeViewer file={file} language={language} />;
} else if (contentType.startsWith('text/')) {
} else if (contentType.startsWith("text/")) {
return <SourcecodeViewer file={file} language="none" />;
} else {
return (
@@ -71,7 +71,7 @@ class SourcesView extends React.Component<Props, State> {
props={{
file,
contentType,
revision,
revision
}}
>
<DownloadViewer file={file} />

View File

@@ -1,27 +1,27 @@
import fetchMock from 'fetch-mock';
import { getContentType } from './contentType';
import fetchMock from "fetch-mock";
import { getContentType } from "./contentType";
describe('get content type', () => {
const CONTENT_URL = '/repositories/scmadmin/TestRepo/content/testContent';
describe("get content type", () => {
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it('should return content', done => {
it("should return content", done => {
let headers = {
'Content-Type': 'application/text',
'X-Programming-Language': 'JAVA',
"Content-Type": "application/text",
"X-Programming-Language": "JAVA"
};
fetchMock.head('/api/v2' + CONTENT_URL, {
headers,
fetchMock.head("/api/v2" + CONTENT_URL, {
headers
});
getContentType(CONTENT_URL).then(content => {
expect(content.type).toBe('application/text');
expect(content.language).toBe('JAVA');
expect(content.type).toBe("application/text");
expect(content.language).toBe("JAVA");
done();
});
});

View File

@@ -1,17 +1,17 @@
import { apiClient } from '@scm-manager/ui-components';
import { apiClient } from "@scm-manager/ui-components";
export function getContentType(url: string) {
return apiClient
.head(url)
.then(response => {
return {
type: response.headers.get('Content-Type'),
language: response.headers.get('X-Programming-Language'),
type: response.headers.get("Content-Type"),
language: response.headers.get("X-Programming-Language")
};
})
.catch(err => {
return {
error: err,
error: err
};
});
}

View File

@@ -1,8 +1,8 @@
import fetchMock from 'fetch-mock';
import { getHistory } from './history';
import fetchMock from "fetch-mock";
import { getHistory } from "./history";
describe('get content type', () => {
const FILE_URL = '/repositories/scmadmin/TestRepo/history/file';
describe("get content type", () => {
const FILE_URL = "/repositories/scmadmin/TestRepo/history/file";
afterEach(() => {
fetchMock.reset();
@@ -14,32 +14,32 @@ describe('get content type', () => {
pageTotal: 10,
_links: {
self: {
href: '/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10',
href: "/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10"
},
first: {
href: '/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10',
href: "/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10"
},
next: {
href: '/repositories/scmadmin/TestRepo/history/file?page=1&pageSize=10',
href: "/repositories/scmadmin/TestRepo/history/file?page=1&pageSize=10"
},
last: {
href: '/repositories/scmadmin/TestRepo/history/file?page=9&pageSize=10',
},
href: "/repositories/scmadmin/TestRepo/history/file?page=9&pageSize=10"
}
},
_embedded: {
changesets: [
{
id: '1234',
id: "1234"
},
{
id: '2345',
},
],
},
id: "2345"
}
]
}
};
it('should return history', done => {
fetchMock.get('/api/v2' + FILE_URL, history);
it("should return history", done => {
fetchMock.get("/api/v2" + FILE_URL, history);
getHistory(FILE_URL).then(content => {
expect(content.changesets).toEqual(history._embedded.changesets);

View File

@@ -1,4 +1,4 @@
import { apiClient } from '@scm-manager/ui-components';
import { apiClient } from "@scm-manager/ui-components";
export function getHistory(url: string) {
return apiClient
@@ -11,13 +11,13 @@ export function getHistory(url: string) {
_embedded: result._embedded,
_links: result._links,
page: result.page,
pageTotal: result.pageTotal,
},
pageTotal: result.pageTotal
}
};
})
.catch(err => {
return {
error: err,
error: err
};
});
}

View File

@@ -1,7 +1,7 @@
import { Repository, File } from '@scm-manager/ui-types';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import { Repository, File } from "@scm-manager/ui-types";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
import {
FETCH_SOURCES,
FETCH_SOURCES_FAILURE,
@@ -13,103 +13,103 @@ import {
default as reducer,
getSources,
fetchSourcesSuccess,
isDirectory,
} from './sources';
isDirectory
} from "./sources";
const sourcesUrl =
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/';
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/";
const repository: Repository = {
name: 'core',
namespace: 'scm',
type: 'git',
name: "core",
namespace: "scm",
type: "git",
_links: {
sources: {
href: sourcesUrl,
},
},
href: sourcesUrl
}
}
};
const collection = {
name: 'src',
path: 'src',
name: "src",
path: "src",
directory: true,
description: 'foo',
description: "foo",
length: 176,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/',
},
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/"
}
},
_embedded: {
children: [
{
name: 'src',
path: 'src',
name: "src",
path: "src",
directory: true,
description: '',
description: "",
length: 176,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
lastModified: '',
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "",
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src',
},
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src"
}
},
_embedded: {
children: [],
},
children: []
}
},
{
name: 'package.json',
path: 'package.json',
name: "package.json",
path: "package.json",
directory: false,
description: 'bump version',
description: "bump version",
length: 780,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
lastModified: '2017-07-31T11:17:19Z',
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "2017-07-31T11:17:19Z",
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/content/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json',
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/content/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json"
},
history: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/history/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json',
},
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/history/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json"
}
},
_embedded: {
children: [],
},
},
],
},
children: []
}
}
]
}
};
const noDirectory: File = {
name: 'src',
path: 'src',
name: "src",
path: "src",
directory: true,
length: 176,
revision: 'abc',
revision: "abc",
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src',
},
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src"
}
},
_embedded: {
children: [],
},
children: []
}
};
describe('sources fetch', () => {
describe("sources fetch", () => {
const mockStore = configureMockStore([thunk]);
afterEach(() => {
@@ -117,162 +117,162 @@ describe('sources fetch', () => {
fetchMock.restore();
});
it('should fetch the sources of the repository', () => {
it("should fetch the sources of the repository", () => {
fetchMock.getOnce(sourcesUrl, collection);
const expectedActions = [
{
type: FETCH_SOURCES_PENDING,
itemId: 'scm/core/_/',
itemId: "scm/core/_/"
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: 'scm/core/_/',
payload: collection,
},
itemId: "scm/core/_/",
payload: collection
}
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, '', '')).then(() => {
return store.dispatch(fetchSources(repository, "", "")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it('should fetch the sources of the repository with the given revision and path', () => {
fetchMock.getOnce(sourcesUrl + 'abc/src', collection);
it("should fetch the sources of the repository with the given revision and path", () => {
fetchMock.getOnce(sourcesUrl + "abc/src", collection);
const expectedActions = [
{
type: FETCH_SOURCES_PENDING,
itemId: 'scm/core/abc/src',
itemId: "scm/core/abc/src"
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: 'scm/core/abc/src',
payload: collection,
},
itemId: "scm/core/abc/src",
payload: collection
}
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, 'abc', 'src')).then(() => {
return store.dispatch(fetchSources(repository, "abc", "src")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it('should dispatch FETCH_SOURCES_FAILURE on server error', () => {
it("should dispatch FETCH_SOURCES_FAILURE on server error", () => {
fetchMock.getOnce(sourcesUrl, {
status: 500,
status: 500
});
const store = mockStore({});
return store.dispatch(fetchSources(repository, '', '')).then(() => {
return store.dispatch(fetchSources(repository, "", "")).then(() => {
const actions = store.getActions();
expect(actions[0].type).toBe(FETCH_SOURCES_PENDING);
expect(actions[1].type).toBe(FETCH_SOURCES_FAILURE);
expect(actions[1].itemId).toBe('scm/core/_/');
expect(actions[1].itemId).toBe("scm/core/_/");
expect(actions[1].payload).toBeDefined();
});
});
});
describe('reducer tests', () => {
it('should return unmodified state on unknown action', () => {
describe("reducer tests", () => {
it("should return unmodified state on unknown action", () => {
const state = {};
expect(reducer(state)).toBe(state);
});
it('should store the collection, without revision and path', () => {
it("should store the collection, without revision and path", () => {
const expectedState = {
'scm/core/_/': collection,
"scm/core/_/": collection
};
expect(
reducer({}, fetchSourcesSuccess(repository, '', '', collection)),
reducer({}, fetchSourcesSuccess(repository, "", "", collection))
).toEqual(expectedState);
});
it('should store the collection, with revision and path', () => {
it("should store the collection, with revision and path", () => {
const expectedState = {
'scm/core/abc/src/main': collection,
"scm/core/abc/src/main": collection
};
expect(
reducer(
{},
fetchSourcesSuccess(repository, 'abc', 'src/main', collection),
),
fetchSourcesSuccess(repository, "abc", "src/main", collection)
)
).toEqual(expectedState);
});
});
describe('selector tests', () => {
it('should return false if it is no directory', () => {
describe("selector tests", () => {
it("should return false if it is no directory", () => {
const state = {
sources: {
'scm/core/abc/src/main/package.json': {
noDirectory,
},
},
"scm/core/abc/src/main/package.json": {
noDirectory
}
}
};
expect(
isDirectory(state, repository, 'abc', 'src/main/package.json'),
isDirectory(state, repository, "abc", "src/main/package.json")
).toBeFalsy();
});
it('should return true if it is directory', () => {
it("should return true if it is directory", () => {
const state = {
sources: {
'scm/core/abc/src': noDirectory,
},
"scm/core/abc/src": noDirectory
}
};
expect(isDirectory(state, repository, 'abc', 'src')).toBe(true);
expect(isDirectory(state, repository, "abc", "src")).toBe(true);
});
it('should return null', () => {
expect(getSources({}, repository, '', '')).toBeFalsy();
it("should return null", () => {
expect(getSources({}, repository, "", "")).toBeFalsy();
});
it('should return the source collection without revision and path', () => {
it("should return the source collection without revision and path", () => {
const state = {
sources: {
'scm/core/_/': collection,
},
"scm/core/_/": collection
}
};
expect(getSources(state, repository, '', '')).toBe(collection);
expect(getSources(state, repository, "", "")).toBe(collection);
});
it('should return the source collection with revision and path', () => {
it("should return the source collection with revision and path", () => {
const state = {
sources: {
'scm/core/abc/src/main': collection,
},
"scm/core/abc/src/main": collection
}
};
expect(getSources(state, repository, 'abc', 'src/main')).toBe(collection);
expect(getSources(state, repository, "abc", "src/main")).toBe(collection);
});
it('should return true, when fetch sources is pending', () => {
it("should return true, when fetch sources is pending", () => {
const state = {
pending: {
[FETCH_SOURCES + '/scm/core/_/']: true,
},
[FETCH_SOURCES + "/scm/core/_/"]: true
}
};
expect(isFetchSourcesPending(state, repository, '', '')).toEqual(true);
expect(isFetchSourcesPending(state, repository, "", "")).toEqual(true);
});
it('should return false, when fetch sources is not pending', () => {
expect(isFetchSourcesPending({}, repository, '', '')).toEqual(false);
it("should return false, when fetch sources is not pending", () => {
expect(isFetchSourcesPending({}, repository, "", "")).toEqual(false);
});
const error = new Error('incredible error from hell');
const error = new Error("incredible error from hell");
it('should return error when fetch sources did fail', () => {
it("should return error when fetch sources did fail", () => {
const state = {
failure: {
[FETCH_SOURCES + '/scm/core/_/']: error,
},
[FETCH_SOURCES + "/scm/core/_/"]: error
}
};
expect(getFetchSourcesFailure(state, repository, '', '')).toEqual(error);
expect(getFetchSourcesFailure(state, repository, "", "")).toEqual(error);
});
it('should return undefined when fetch sources did not fail', () => {
expect(getFetchSourcesFailure({}, repository, '', '')).toBe(undefined);
it("should return undefined when fetch sources did not fail", () => {
expect(getFetchSourcesFailure({}, repository, "", "")).toBe(undefined);
});
});

View File

@@ -1,10 +1,10 @@
import * as types from '../../../modules/types';
import { Repository, File, Action } from '@scm-manager/ui-types';
import { apiClient } from '@scm-manager/ui-components';
import { isPending } from '../../../modules/pending';
import { getFailure } from '../../../modules/failure';
import * as types from "../../../modules/types";
import { Repository, File, Action } from "@scm-manager/ui-types";
import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../../modules/pending";
import { getFailure } from "../../../modules/failure";
export const FETCH_SOURCES = 'scm/repos/FETCH_SOURCES';
export const FETCH_SOURCES = "scm/repos/FETCH_SOURCES";
export const FETCH_SOURCES_PENDING = `${FETCH_SOURCES}_${types.PENDING_SUFFIX}`;
export const FETCH_SOURCES_SUCCESS = `${FETCH_SOURCES}_${types.SUCCESS_SUFFIX}`;
export const FETCH_SOURCES_FAILURE = `${FETCH_SOURCES}_${types.FAILURE_SUFFIX}`;
@@ -12,7 +12,7 @@ export const FETCH_SOURCES_FAILURE = `${FETCH_SOURCES}_${types.FAILURE_SUFFIX}`;
export function fetchSources(
repository: Repository,
revision: string,
path: string,
path: string
) {
return function(dispatch: any) {
dispatch(fetchSourcesPending(repository, revision, path));
@@ -35,18 +35,18 @@ function createUrl(repository: Repository, revision: string, path: string) {
}
// TODO handle trailing slash
const pathDefined = path ? path : '';
const pathDefined = path ? path : "";
return `${base}${encodeURIComponent(revision)}/${pathDefined}`;
}
export function fetchSourcesPending(
repository: Repository,
revision: string,
path: string,
path: string
): Action {
return {
type: FETCH_SOURCES_PENDING,
itemId: createItemId(repository, revision, path),
itemId: createItemId(repository, revision, path)
};
}
@@ -54,12 +54,12 @@ export function fetchSourcesSuccess(
repository: Repository,
revision: string,
path: string,
sources: File,
sources: File
) {
return {
type: FETCH_SOURCES_SUCCESS,
payload: sources,
itemId: createItemId(repository, revision, path),
itemId: createItemId(repository, revision, path)
};
}
@@ -67,18 +67,18 @@ export function fetchSourcesFailure(
repository: Repository,
revision: string,
path: string,
error: Error,
error: Error
): Action {
return {
type: FETCH_SOURCES_FAILURE,
payload: error,
itemId: createItemId(repository, revision, path),
itemId: createItemId(repository, revision, path)
};
}
function createItemId(repository: Repository, revision: string, path: string) {
const revPart = revision ? revision : '_';
const pathPart = path ? path : '';
const revPart = revision ? revision : "_";
const pathPart = path ? path : "";
return `${repository.namespace}/${repository.name}/${revPart}/${pathPart}`;
}
@@ -87,13 +87,13 @@ function createItemId(repository: Repository, revision: string, path: string) {
export default function reducer(
state: any = {},
action: Action = {
type: 'UNKNOWN',
},
type: "UNKNOWN"
}
): any {
if (action.itemId && action.type === FETCH_SOURCES_SUCCESS) {
return {
...state,
[action.itemId]: action.payload,
[action.itemId]: action.payload
};
}
return state;
@@ -105,7 +105,7 @@ export function isDirectory(
state: any,
repository: Repository,
revision: string,
path: string,
path: string
): boolean {
const currentFile = getSources(state, repository, revision, path);
if (currentFile && !currentFile.directory) {
@@ -119,7 +119,7 @@ export function getSources(
state: any,
repository: Repository,
revision: string,
path: string,
path: string
): File | null | undefined {
if (state.sources) {
return state.sources[createItemId(repository, revision, path)];
@@ -131,12 +131,12 @@ export function isFetchSourcesPending(
state: any,
repository: Repository,
revision: string,
path: string,
path: string
): boolean {
return isPending(
state,
FETCH_SOURCES,
createItemId(repository, revision, path),
createItemId(repository, revision, path)
);
}
@@ -144,11 +144,11 @@ export function getFetchSourcesFailure(
state: any,
repository: Repository,
revision: string,
path: string,
path: string
): Error | null | undefined {
return getFailure(
state,
FETCH_SOURCES,
createItemId(repository, revision, path),
createItemId(repository, revision, path)
);
}