*/
import { shallow } from 'enzyme';
import * as React from 'react';
+import { searchQualityProfiles } from '../../../../api/quality-profiles';
import { getRulesApp } from '../../../../api/rules';
import ScreenPositionHelper from '../../../../components/common/ScreenPositionHelper';
-import { mockCurrentUser, mockLocation, mockRouter, mockRule } from '../../../../helpers/testMocks';
+import {
+ mockCurrentUser,
+ mockLocation,
+ mockQualityProfile,
+ mockRouter,
+ mockRule
+} from '../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import { App } from '../App';
const wrapper = shallowRender({
currentUser: mockCurrentUser()
});
- expect(wrapper.instance().renderBulkButton()).toBeNull();
+ expect(wrapper.instance().renderBulkButton()).toMatchSnapshot();
});
it('should be null when the user does not have the sufficient permission', () => {
- (getRulesApp as jest.Mock).mockReturnValue({ canWrite: false, repositories: [] });
+ (getRulesApp as jest.Mock).mockReturnValueOnce({ canWrite: false, repositories: [] });
+
+ const wrapper = shallowRender();
+ expect(wrapper.instance().renderBulkButton()).toMatchSnapshot();
+ });
+ it('should show bulk change button when user has global admin rights on quality profiles', async () => {
+ (getRulesApp as jest.Mock).mockReturnValueOnce({ canWrite: true, repositories: [] });
const wrapper = shallowRender();
- expect(wrapper.instance().renderBulkButton()).toBeNull();
+ await waitAndUpdate(wrapper);
+
+ expect(wrapper.instance().renderBulkButton()).toMatchSnapshot();
});
- it('should show bulk change button when everything is fine', async () => {
- (getRulesApp as jest.Mock).mockReturnValue({ canWrite: true, repositories: [] });
+ it('should show bulk change button when user has edit rights on specific quality profile', async () => {
+ (getRulesApp as jest.Mock).mockReturnValueOnce({ canWrite: false, repositories: [] });
+ (searchQualityProfiles as jest.Mock).mockReturnValueOnce({
+ profiles: [mockQualityProfile({ key: 'foo', actions: { edit: true } }), mockQualityProfile()]
+ });
+
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`renderBulkButton should show bulk change button when everything is fine 1`] = `
+exports[`renderBulkButton should be null when the user does not have the sufficient permission 1`] = `<div />`;
+
+exports[`renderBulkButton should be null when the user is not logged in 1`] = `<div />`;
+
+exports[`renderBulkButton should show bulk change button when user has edit rights on specific quality profile 1`] = `
+<BulkChange
+ languages={
+ Object {
+ "js": Object {
+ "key": "js",
+ "name": "JavaScript",
+ },
+ }
+ }
+ query={
+ Object {
+ "activation": undefined,
+ "activationSeverities": Array [],
+ "availableSince": undefined,
+ "compareToProfile": undefined,
+ "cwe": Array [],
+ "inheritance": undefined,
+ "languages": Array [],
+ "owaspTop10": Array [],
+ "profile": undefined,
+ "repositories": Array [],
+ "ruleKey": undefined,
+ "sansTop25": Array [],
+ "searchQuery": undefined,
+ "severities": Array [],
+ "sonarsourceSecurity": Array [],
+ "statuses": Array [],
+ "tags": Array [],
+ "template": undefined,
+ "types": Array [],
+ }
+ }
+ referencedProfiles={
+ Object {
+ "foo": Object {
+ "actions": Object {
+ "edit": true,
+ },
+ "activeDeprecatedRuleCount": 2,
+ "activeRuleCount": 10,
+ "childrenCount": 0,
+ "depth": 1,
+ "isBuiltIn": false,
+ "isDefault": false,
+ "isInherited": false,
+ "key": "foo",
+ "language": "js",
+ "languageName": "JavaScript",
+ "name": "name",
+ "projectCount": 3,
+ },
+ "key": Object {
+ "activeDeprecatedRuleCount": 2,
+ "activeRuleCount": 10,
+ "childrenCount": 0,
+ "depth": 1,
+ "isBuiltIn": false,
+ "isDefault": false,
+ "isInherited": false,
+ "key": "key",
+ "language": "js",
+ "languageName": "JavaScript",
+ "name": "name",
+ "projectCount": 3,
+ },
+ }
+ }
+ total={0}
+/>
+`;
+
+exports[`renderBulkButton should show bulk change button when user has global admin rights on quality profiles 1`] = `
<BulkChange
languages={
Object {
<div
className="display-flex-space-between"
>
+ <div />
<PageActions
loading={true}
onReload={[Function]}