From: Grégoire Aubert Date: Fri, 1 Dec 2017 14:44:27 +0000 (+0100) Subject: SONAR-10074 Use new QP actions 'delete' and 'associateProjects' X-Git-Tag: 7.0-RC1~206 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08be68fda3cfd859ab412bfa634409d211f79927;p=sonarqube.git SONAR-10074 Use new QP actions 'delete' and 'associateProjects' --- diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java index 88b009687b0..0541b1bd794 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java @@ -48,7 +48,19 @@ public class QualityProfilePage { public QualityProfilePage shouldAllowToChangeProjects() { Selenide.$(".js-change-projects").shouldBe(Condition.visible).click(); - Selenide.$("#profile-projects .select-list-list").shouldBe(Condition.visible); + Selenide.$("#profile-projects .select-list-list-container").shouldBe(Condition.visible); + return this; + } + + public QualityProfilePage shouldNotAllowToChangeProjects() { + Selenide.$(".js-change-projects").shouldNot(Condition.exist); + return this; + } + + public QualityProfilePage shouldNotAllowToEdit() { + Selenide.$("button.dropdown-toggle").should(Condition.exist).click(); + Selenide.$("#quality-profile-rename").shouldNot(Condition.exist); + Selenide.$("#quality-profile-activate-more-rules").shouldNot(Condition.exist); return this; } } diff --git a/server/sonar-web/src/main/js/api/quality-profiles.ts b/server/sonar-web/src/main/js/api/quality-profiles.ts index 77bc1868809..5488682fa16 100644 --- a/server/sonar-web/src/main/js/api/quality-profiles.ts +++ b/server/sonar-web/src/main/js/api/quality-profiles.ts @@ -30,7 +30,9 @@ import { Paging } from '../app/types'; import throwGlobalError from '../app/utils/throwGlobalError'; export interface ProfileActions { + associateProjects?: boolean; copy?: boolean; + delete?: boolean; edit?: boolean; setAsDefault?: boolean; } @@ -104,7 +106,7 @@ export function restoreQualityProfile(data: RequestData): Promise { } export function getProfileProjects(data: RequestData): Promise { - return getJSON('/api/qualityprofiles/projects', data); + return getJSON('/api/qualityprofiles/projects', data).catch(throwGlobalError); } export function getProfileInheritance(profileKey: string): Promise { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/BuiltInQualityProfileBadge.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/BuiltInQualityProfileBadge.tsx index f7e7d5f2679..9cda74cbfe1 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/BuiltInQualityProfileBadge.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/BuiltInQualityProfileBadge.tsx @@ -41,5 +41,11 @@ export default function BuiltInQualityProfileBadge({ className, tooltip = true } ); - return tooltip ? {badge} : badge; + return tooltip ? ( + + {badge} + + ) : ( + badge + ); } diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.tsx index 0a2aff5cffb..0ed58dbb34c 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.tsx @@ -137,15 +137,10 @@ export default class ProfileActions extends React.PureComponent { this.props.organization ); - const canActivateRules = actions.edit && !profile.isBuiltIn; - const canRename = actions.edit && !profile.isBuiltIn; - const canSetAsDefault = actions.setAsDefault && !profile.isDefault; - const canDelete = actions.edit && !profile.isDefault && !profile.isBuiltIn; - return ( - {canActivateRules && ( - + {actions.edit && ( + {translate('quality_profiles.activate_more_rules')} )} @@ -171,13 +166,13 @@ export default class ProfileActions extends React.PureComponent { )} - {canRename && ( + {actions.edit && ( {translate('rename')} )} - {canSetAsDefault && ( + {actions.setAsDefault && ( @@ -185,9 +180,9 @@ export default class ProfileActions extends React.PureComponent { )} - {canDelete && } + {actions.delete && } - {canDelete && ( + {actions.delete && ( { ).toMatchSnapshot(); }); -it('renders with permission to edit', () => { +it('renders with permission to edit only', () => { expect( shallow( { ) diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/ProfileActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/ProfileActions-test.tsx.snap index ba760e5cb62..7e53929904b 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/ProfileActions-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/ProfileActions-test.tsx.snap @@ -3,6 +3,7 @@ exports[`renders with all permissions 1`] = ` quality_profiles.activate_more_rules @@ -83,9 +84,10 @@ exports[`renders with no permissions 1`] = ` `; -exports[`renders with permission to edit 1`] = ` +exports[`renders with permission to edit only 1`] = ` quality_profiles.activate_more_rules @@ -117,13 +119,5 @@ exports[`renders with permission to edit 1`] = ` > rename - - - delete - `; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx index 9b1acd46c8e..66476d8c966 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx @@ -69,15 +69,18 @@ export default class ProfileProjects extends React.PureComponent { } const data = { key: this.props.profile.key }; - getProfileProjects(data).then((r: any) => { - if (this.mounted) { - this.setState({ - projects: r.results, - more: r.more, - loading: false - }); - } - }); + getProfileProjects(data).then( + (r: any) => { + if (this.mounted) { + this.setState({ + projects: r.results, + more: r.more, + loading: false + }); + } + }, + () => {} + ); } handleChangeClick = (event: React.SyntheticEvent) => { @@ -91,6 +94,10 @@ export default class ProfileProjects extends React.PureComponent { }; renderDefault() { + if (this.state.loading) { + return ; + } + return (
{translate('default')} @@ -100,6 +107,10 @@ export default class ProfileProjects extends React.PureComponent { } renderProjects() { + if (this.state.loading) { + return ; + } + const { projects } = this.state; if (projects == null) { @@ -130,8 +141,7 @@ export default class ProfileProjects extends React.PureComponent { return (
{profile.actions && - profile.actions.edit && - !profile.isDefault && ( + profile.actions.associateProjects && (