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,6 +1,6 @@
import React from 'react';
import { translate } from 'react-i18next';
import { Checkbox } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { Checkbox } from "@scm-manager/ui-components";
type Props = {
t: (p: string) => string;
@@ -17,8 +17,8 @@ class PermissionCheckbox extends React.Component<Props> {
<Checkbox
key={this.props.name}
name={this.props.name}
helpText={t('verbs.repository.' + this.props.name + '.description')}
label={t('verbs.repository.' + this.props.name + '.displayName')}
helpText={t("verbs.repository." + this.props.name + ".description")}
label={t("verbs.repository." + this.props.name + ".displayName")}
checked={this.props.checked}
onChange={this.props.onChange}
disabled={this.props.disabled}
@@ -27,4 +27,4 @@ class PermissionCheckbox extends React.Component<Props> {
}
}
export default translate('plugins')(PermissionCheckbox);
export default translate("plugins")(PermissionCheckbox);

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { translate } from 'react-i18next';
import { Select } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { Select } from "@scm-manager/ui-components";
type Props = {
t: (p: string) => string;
@@ -20,19 +20,19 @@ class RoleSelector extends React.Component<Props> {
handleRoleChange,
loading,
label,
helpText,
helpText
} = this.props;
if (!availableRoles) return null;
const options = role
? this.createSelectOptions(availableRoles)
: ['', ...this.createSelectOptions(availableRoles)];
: ["", ...this.createSelectOptions(availableRoles)];
return (
<Select
onChange={handleRoleChange}
value={role ? role : ''}
value={role ? role : ""}
options={options}
loading={loading}
label={label}
@@ -45,10 +45,10 @@ class RoleSelector extends React.Component<Props> {
return roles.map(role => {
return {
label: role,
value: role,
value: role
};
});
}
}
export default translate('repos')(RoleSelector);
export default translate("repos")(RoleSelector);

View File

@@ -1,76 +1,75 @@
import React from 'react';
import { shallow, mount } from '@scm-manager/ui-tests/enzyme-router';
import '@scm-manager/ui-tests/enzyme';
import '@scm-manager/ui-tests/i18n';
import DeletePermissionButton from './DeletePermissionButton';
import React from "react";
import { shallow, mount } from "@scm-manager/ui-tests/enzyme-router";
import "@scm-manager/ui-tests/enzyme";
import "@scm-manager/ui-tests/i18n";
import DeletePermissionButton from "./DeletePermissionButton";
import { confirmAlert } from '@scm-manager/ui-components';
jest.mock('@scm-manager/ui-components', () => ({
import { confirmAlert } from "@scm-manager/ui-components";
jest.mock("@scm-manager/ui-components", () => ({
confirmAlert: jest.fn(),
DeleteButton: require.requireActual('@scm-manager/ui-components')
.DeleteButton,
DeleteButton: require.requireActual("@scm-manager/ui-components").DeleteButton
}));
describe('DeletePermissionButton', () => {
it('should render nothing, if the delete link is missing', () => {
describe("DeletePermissionButton", () => {
it("should render nothing, if the delete link is missing", () => {
const permission = {
_links: {},
_links: {}
};
const navLink = shallow(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
/>
);
expect(navLink.text()).toBe('');
expect(navLink.text()).toBe("");
});
it('should render the delete icon', () => {
it("should render the delete icon", () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
href: "/permission"
}
}
};
const deleteIcon = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
/>
);
expect(deleteIcon.html()).not.toBe('');
expect(deleteIcon.html()).not.toBe("");
});
it('should open the confirm dialog on button click', () => {
it("should open the confirm dialog on button click", () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
href: "/permission"
}
}
};
const button = mount(
<DeletePermissionButton
permission={permission}
deletePermission={() => {}}
/>,
/>
);
button.find('.fa-trash').simulate('click');
button.find(".fa-trash").simulate("click");
expect(confirmAlert.mock.calls.length).toBe(1);
});
it('should call the delete permission function with delete url', () => {
it("should call the delete permission function with delete url", () => {
const permission = {
_links: {
delete: {
href: '/permission',
},
},
href: "/permission"
}
}
};
let calledUrl = null;
@@ -83,10 +82,10 @@ describe('DeletePermissionButton', () => {
permission={permission}
confirmDialog={false}
deletePermission={capture}
/>,
/>
);
button.find('.fa-trash').simulate('click');
button.find(".fa-trash").simulate("click");
expect(calledUrl).toBe('/permission');
expect(calledUrl).toBe("/permission");
});
});

View File

@@ -1,7 +1,7 @@
import React from 'react';
import { translate } from 'react-i18next';
import { Permission } from '@scm-manager/ui-types';
import { confirmAlert } from '@scm-manager/ui-components';
import React from "react";
import { translate } from "react-i18next";
import { Permission } from "@scm-manager/ui-types";
import { confirmAlert } from "@scm-manager/ui-components";
type Props = {
permission: Permission;
@@ -12,39 +12,39 @@ type Props = {
deletePermission: (
permission: Permission,
namespace: string,
repoName: string,
repoName: string
) => void;
loading: boolean;
};
class DeletePermissionButton extends React.Component<Props> {
static defaultProps = {
confirmDialog: true,
confirmDialog: true
};
deletePermission = () => {
this.props.deletePermission(
this.props.permission,
this.props.namespace,
this.props.repoName,
this.props.repoName
);
};
confirmDelete = () => {
const { t } = this.props;
confirmAlert({
title: t('permission.delete-permission-button.confirm-alert.title'),
message: t('permission.delete-permission-button.confirm-alert.message'),
title: t("permission.delete-permission-button.confirm-alert.title"),
message: t("permission.delete-permission-button.confirm-alert.message"),
buttons: [
{
label: t('permission.delete-permission-button.confirm-alert.submit'),
onClick: () => this.deletePermission(),
label: t("permission.delete-permission-button.confirm-alert.submit"),
onClick: () => this.deletePermission()
},
{
label: t('permission.delete-permission-button.confirm-alert.cancel'),
onClick: () => null,
},
],
label: t("permission.delete-permission-button.confirm-alert.cancel"),
onClick: () => null
}
]
});
};
@@ -69,4 +69,4 @@ class DeletePermissionButton extends React.Component<Props> {
}
}
export default translate('repos')(DeletePermissionButton);
export default translate("repos")(DeletePermissionButton);

View File

@@ -1,69 +1,69 @@
import * as validator from './permissionValidation';
import * as validator from "./permissionValidation";
describe('permission validation', () => {
it('should return true if permission is valid and does not exist', () => {
describe("permission validation", () => {
it("should return true if permission is valid and does not exist", () => {
const permissions = [];
const name = 'PermissionName';
const name = "PermissionName";
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions),
validator.isPermissionValid(name, groupPermission, permissions)
).toBe(true);
});
it('should return true if permission is valid and does not exists with same group permission', () => {
it("should return true if permission is valid and does not exists with same group permission", () => {
const permissions = [
{
name: 'PermissionName',
name: "PermissionName",
groupPermission: true,
type: 'READ',
type: "READ",
_links: {},
verbs: [],
},
verbs: []
}
];
const name = 'PermissionName';
const name = "PermissionName";
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions),
validator.isPermissionValid(name, groupPermission, permissions)
).toBe(true);
});
it('should return false if permission is valid but exists', () => {
it("should return false if permission is valid but exists", () => {
const permissions = [
{
name: 'PermissionName',
name: "PermissionName",
groupPermission: false,
type: 'READ',
type: "READ",
_links: {},
verbs: [],
},
verbs: []
}
];
const name = 'PermissionName';
const name = "PermissionName";
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions),
validator.isPermissionValid(name, groupPermission, permissions)
).toBe(false);
});
it('should return false if permission does not exist but is invalid', () => {
it("should return false if permission does not exist but is invalid", () => {
const permissions = [];
const name = '@PermissionName';
const name = "@PermissionName";
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions),
validator.isPermissionValid(name, groupPermission, permissions)
).toBe(false);
});
it('should return false if permission is not valid and does not exist', () => {
it("should return false if permission is not valid and does not exist", () => {
const permissions = [];
const name = '@PermissionName';
const name = "@PermissionName";
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions),
validator.isPermissionValid(name, groupPermission, permissions)
).toBe(false);
});
});

View File

@@ -1,5 +1,5 @@
import { validation } from '@scm-manager/ui-components';
import { PermissionCollection } from '@scm-manager/ui-types';
import { validation } from "@scm-manager/ui-components";
import { PermissionCollection } from "@scm-manager/ui-types";
const isNameValid = validation.isNameValid;
@@ -8,7 +8,7 @@ export { isNameValid };
export const isPermissionValid = (
name: string,
groupPermission: boolean,
permissions: PermissionCollection,
permissions: PermissionCollection
) => {
return (
isNameValid(name) &&
@@ -19,7 +19,7 @@ export const isPermissionValid = (
const currentPermissionIncludeName = (
name: string,
groupPermission: boolean,
permissions: PermissionCollection,
permissions: PermissionCollection
) => {
for (let i = 0; i < permissions.length; i++) {
if (