return getJSON('/api/qualityprofiles/projects', data).catch(throwGlobalError);
}
-export function getProfileInheritance(profileKey: string): Promise<any> {
+export function getProfileInheritance(
+ profileKey: string
+): Promise<{
+ ancestors: T.ProfileInheritanceDetails[];
+ children: T.ProfileInheritanceDetails[];
+ profile: T.ProfileInheritanceDetails;
+}> {
return getJSON('/api/qualityprofiles/inheritance', { profileKey }).catch(throwGlobalError);
}
}>;
}
+ export interface ProfileInheritanceDetails {
+ activeRuleCount: number;
+ isBuiltIn: boolean;
+ key: string;
+ name: string;
+ overridingRuleCount?: number;
+ }
+
export interface ProjectLink {
id: string;
name?: string;
updateProfiles: () => Promise<void>;
}
-interface ProfileInheritanceDetails {
- activeRuleCount: number;
- isBuiltIn: boolean;
- key: string;
- language: string;
- name: string;
- overridingRuleCount?: number;
-}
-
interface State {
- ancestors?: Array<ProfileInheritanceDetails>;
- children?: Array<ProfileInheritanceDetails>;
+ ancestors?: T.ProfileInheritanceDetails[];
+ children?: T.ProfileInheritanceDetails[];
formOpen: boolean;
loading: boolean;
- profile?: ProfileInheritanceDetails;
+ profile?: T.ProfileInheritanceDetails;
}
export default class ProfileInheritance extends React.PureComponent<Props, State> {
r => {
if (this.mounted) {
const { ancestors, children } = r;
+ ancestors.reverse();
+
this.setState({
children,
- ancestors: ancestors.reverse(),
+ ancestors,
profile: r.profile,
loading: false
});
language={profile.language}
organization={this.props.organization}
profile={this.state.profile}
- type="current"
/>
)}
extendsBuiltIn?: boolean;
language: string;
organization: string | null;
- profile: {
- activeRuleCount: number;
- isBuiltIn: boolean;
- key: string;
- language: string;
- name: string;
- overridingRuleCount?: number;
- };
- type: string;
+ profile: T.ProfileInheritanceDetails;
+ type?: string;
}
-export default function ProfileInheritanceBox({ type, displayLink = true, ...props }: Props) {
- const { profile, className, extendsBuiltIn } = props;
- const offset = 25 * props.depth;
+export default function ProfileInheritanceBox(props: Props) {
+ const {
+ className,
+ depth,
+ extendsBuiltIn,
+ language,
+ organization,
+ profile,
+ displayLink = true,
+ type = 'current'
+ } = props;
+ const offset = 25 * depth;
return (
<tr className={className} data-test={`quality-profiles__inheritance-${type}`}>
{displayLink ? (
<ProfileLink
className="text-middle"
- language={props.language}
+ language={language}
name={profile.name}
- organization={props.organization}>
+ organization={organization}>
{profile.name}
</ProfileLink>
) : (
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { shallow } from 'enzyme';
+import * as React from 'react';
+import { mockQualityProfileInheritance } from '../../../../helpers/testMocks';
+import ProfileInheritanceBox from '../ProfileInheritanceBox';
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot();
+ expect(
+ shallowRender({
+ depth: 3,
+ displayLink: true,
+ profile: mockQualityProfileInheritance({ isBuiltIn: true })
+ })
+ ).toMatchSnapshot();
+ expect(shallowRender({ extendsBuiltIn: true })).toMatchSnapshot();
+ expect(
+ shallowRender({ profile: mockQualityProfileInheritance({ overridingRuleCount: 10 }) })
+ ).toMatchSnapshot();
+});
+
+function shallowRender(props = {}) {
+ return shallow(
+ <ProfileInheritanceBox
+ depth={1}
+ language="foo"
+ organization={null}
+ profile={mockQualityProfileInheritance()}
+ {...props}
+ />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<tr
+ data-test="quality-profiles__inheritance-current"
+>
+ <td>
+ <div
+ style={
+ Object {
+ "paddingLeft": 25,
+ }
+ }
+ >
+ <ProfileLink
+ className="text-middle"
+ language="foo"
+ name="Foo"
+ organization={null}
+ >
+ Foo
+ </ProfileLink>
+ </div>
+ </td>
+ <td>
+ quality_profile.x_active_rules.4
+ </td>
+ <td>
+ <p>
+ quality_profiles.x_overridden_rules.0
+ </p>
+ </td>
+</tr>
+`;
+
+exports[`should render correctly 2`] = `
+<tr
+ data-test="quality-profiles__inheritance-current"
+>
+ <td>
+ <div
+ style={
+ Object {
+ "paddingLeft": 75,
+ }
+ }
+ >
+ <ProfileLink
+ className="text-middle"
+ language="foo"
+ name="Foo"
+ organization={null}
+ >
+ Foo
+ </ProfileLink>
+ <BuiltInQualityProfileBadge
+ className="spacer-left"
+ />
+ </div>
+ </td>
+ <td>
+ quality_profile.x_active_rules.4
+ </td>
+ <td>
+ <p>
+ quality_profiles.x_overridden_rules.0
+ </p>
+ </td>
+</tr>
+`;
+
+exports[`should render correctly 3`] = `
+<tr
+ data-test="quality-profiles__inheritance-current"
+>
+ <td>
+ <div
+ style={
+ Object {
+ "paddingLeft": 25,
+ }
+ }
+ >
+ <ProfileLink
+ className="text-middle"
+ language="foo"
+ name="Foo"
+ organization={null}
+ >
+ Foo
+ </ProfileLink>
+ <HelpTooltip
+ className="spacer-left"
+ overlay="quality_profiles.extends_built_in"
+ />
+ </div>
+ </td>
+ <td>
+ quality_profile.x_active_rules.4
+ </td>
+ <td>
+ <p>
+ quality_profiles.x_overridden_rules.0
+ </p>
+ </td>
+</tr>
+`;
+
+exports[`should render correctly 4`] = `
+<tr
+ data-test="quality-profiles__inheritance-current"
+>
+ <td>
+ <div
+ style={
+ Object {
+ "paddingLeft": 25,
+ }
+ }
+ >
+ <ProfileLink
+ className="text-middle"
+ language="foo"
+ name="Foo"
+ organization={null}
+ >
+ Foo
+ </ProfileLink>
+ </div>
+ </td>
+ <td>
+ quality_profile.x_active_rules.4
+ </td>
+ <td>
+ <p>
+ quality_profiles.x_overridden_rules.10
+ </p>
+ </td>
+</tr>
+`;
};
}
+export function mockQualityProfileInheritance(
+ overrides: Partial<T.ProfileInheritanceDetails> = {}
+): T.ProfileInheritanceDetails {
+ return {
+ activeRuleCount: 4,
+ isBuiltIn: false,
+ key: 'foo',
+ name: 'Foo',
+ overridingRuleCount: 0,
+ ...overrides
+ };
+}
+
export function mockQualityGateProjectStatus(
overrides: Partial<T.QualityGateProjectStatus> = {}
): T.QualityGateProjectStatus {