import { RuleDescriptionSections } from '../../apps/coding-rules/rule';
import {
mockCurrentUser,
+ mockPaging,
mockQualityProfile,
mockRuleDetails,
mockRuleRepository,
} from '../../helpers/testMocks';
-import { RuleRepository } from '../../types/coding-rules';
+import { RuleRepository, SearchRulesResponse } from '../../types/coding-rules';
import { RawIssuesResponse } from '../../types/issues';
import { SearchRulesQuery } from '../../types/rules';
import { Rule, RuleActivation, RuleDetails, RulesUpdateRequest } from '../../types/types';
ps,
available_since,
rule_key,
- }: SearchRulesQuery) => {
+ }: SearchRulesQuery): Promise<SearchRulesResponse> => {
const countFacet = (facets || '').split(',').map((facet: keyof Rule) => {
const facetCount = countBy(
this.rules.map((r) => r[FACET_RULE_MAP[facet] || facet] as string)
}
const responseRules = filteredRules.slice((currentP - 1) * currentPs, currentP * currentPs);
return this.reply({
- total: filteredRules.length,
- p: currentP,
- ps: currentPs,
rules: responseRules,
facets: countFacet,
+ paging: mockPaging({
+ total: filteredRules.length,
+ pageIndex: currentP,
+ pageSize: currentPs,
+ }),
});
};
ps?: number;
q?: string;
selected?: string;
- }): Promise<Paging & { users: UserGroupMember[] }> => {
+ }): Promise<{ paging: Paging; users: UserGroupMember[] }> => {
return this.reply({
- ...this.paging,
users: this.users
.filter((u) => u.name.includes(data.q ?? ''))
.filter((u) => {
return true;
}
}),
+ paging: { ...this.paging },
});
};
mockRule,
mockRuleDetails,
} from '../../helpers/testMocks';
+import { SearchRulesResponse } from '../../types/coding-rules';
import {
ASSIGNEE_ME,
IssueActions,
return this.reply(issue.snippets);
};
- handleSearchRules = (req: SearchRulesQuery) => {
+ handleSearchRules = (req: SearchRulesQuery): Promise<SearchRulesResponse> => {
const rules = this.rulesList.filter((rule) => {
const query = req.q?.toLowerCase() || '';
const nameMatches = rule.name.toLowerCase().includes(query);
return isTypeRight && (nameMatches || keyMatches);
});
return this.reply({
- p: 1,
- ps: 30,
rules,
- total: rules.length,
+ paging: mockPaging({
+ total: rules.length,
+ pageIndex: 1,
+ pageSize: 30,
+ }),
});
};
*/
import { cloneDeep } from 'lodash';
import { RequestData } from '../../helpers/request';
-import { mockCompareResult, mockQualityProfile, mockRuleDetails } from '../../helpers/testMocks';
+import {
+ mockCompareResult,
+ mockPaging,
+ mockQualityProfile,
+ mockRuleDetails,
+} from '../../helpers/testMocks';
import { SearchRulesResponse } from '../../types/coding-rules';
import { Dict, Paging, ProfileInheritanceDetails, RuleDetails } from '../../types/types';
import {
+ CompareResponse,
+ Profile,
+ ProfileProject,
+ SearchQualityProfilesParameters,
+ SearchQualityProfilesResponse,
activateRule,
changeProfileParent,
compareProfiles,
- CompareResponse,
copyProfile,
createQualityProfile,
getImporters,
getProfileInheritance,
getProfileProjects,
- Profile,
- ProfileProject,
searchQualityProfiles,
- SearchQualityProfilesParameters,
- SearchQualityProfilesResponse,
} from '../quality-profiles';
import { getRuleDetails, searchRules } from '../rules';
comparisonResult: CompareResponse = mockCompareResult();
searchRulesResponse: SearchRulesResponse = {
- p: 0,
- ps: 500,
- total: 0,
rules: [],
+ paging: mockPaging(),
};
constructor() {
resetSearchRulesResponse() {
this.searchRulesResponse = {
- p: 0,
- ps: 500,
- total: 0,
rules: [],
+ paging: {
+ pageIndex: 1,
+ pageSize: 500,
+ total: 0,
+ },
};
}
import { Exporter, ProfileChangelogEvent } from '../apps/quality-profiles/types';
import { csvEscape } from '../helpers/csv';
import { throwGlobalError } from '../helpers/error';
-import { getJSON, post, postJSON, RequestData } from '../helpers/request';
+import { RequestData, getJSON, post, postJSON } from '../helpers/request';
import { Dict, Paging, ProfileInheritanceDetails, UserSelected } from '../types/types';
export interface ProfileActions {
return getJSON('/api/qualityprofiles/exporters').then((r) => r.exporters);
}
+export interface ChangelogResponse {
+ events: ProfileChangelogEvent[];
+ paging: Paging;
+}
+
export function getProfileChangelog(
since: any,
to: any,
{ language, name: qualityProfile }: Profile,
page?: number
-): Promise<{
- events: ProfileChangelogEvent[];
- p: number;
- ps: number;
- total: number;
-}> {
+): Promise<ChangelogResponse> {
return getJSON('/api/qualityprofiles/changelog', {
since,
to,
ps?: number;
q?: string;
selected?: string;
-}): Promise<
- Paging & {
- users: UserGroupMember[];
- }
-> {
+}): Promise<{
+ paging: Paging;
+ users: UserGroupMember[];
+}> {
return getJSON('/api/user_groups/users', data).catch(throwGlobalError);
}
qprofile: profileKey,
statuses: 'DEPRECATED',
};
- return searchRules(data).then((r) => r.total);
+ return searchRules(data).then((r) => r.paging.total);
}
getDeprecatedRulesCount(profile: { key: string }) {
import { screen } from '@testing-library/react';
import * as React from 'react';
import { searchRules } from '../../../../../../../api/rules';
-import { mockLanguage, mockQualityProfile } from '../../../../../../../helpers/testMocks';
+import {
+ mockLanguage,
+ mockPaging,
+ mockQualityProfile,
+} from '../../../../../../../helpers/testMocks';
import { renderComponent } from '../../../../../../../helpers/testReactTestingUtils';
import { SearchRulesResponse } from '../../../../../../../types/coding-rules';
import { Dict } from '../../../../../../../types/types';
ts: 10,
css: 0,
};
- jest.mocked(searchRules).mockImplementation(({ qprofile }: { qprofile: string }) => {
- return Promise.resolve({ total: totals[qprofile] } as SearchRulesResponse);
- });
+ jest
+ .mocked(searchRules)
+ .mockImplementation(({ qprofile }: { qprofile: string }): Promise<SearchRulesResponse> => {
+ return Promise.resolve({
+ rules: [],
+ paging: mockPaging({
+ total: totals[qprofile],
+ }),
+ });
+ });
renderMetaQualityprofiles();
makeFetchRequest = (query?: RawQuery) =>
searchRules({ ...this.getSearchParameters(), ...query }).then(
- ({ actives: rawActives, facets: rawFacets, p, ps, rules, total }) => {
+ ({ actives: rawActives, facets: rawFacets, rules, paging }) => {
const actives = rawActives && parseActives(rawActives);
const facets = rawFacets && parseFacets(rawFacets);
- const paging = { pageIndex: p, pageSize: ps, total };
return { actives, facets, paging, rules };
}
);
jest.mock('../../../../components/common/ScreenPositionHelper');
jest.mock('../../../../api/rules', () => {
- const { mockRule } = jest.requireActual('../../../../helpers/testMocks');
+ const { mockRule, mockPaging } = jest.requireActual('../../../../helpers/testMocks');
return {
getRulesApp: jest.fn().mockResolvedValue({ canWrite: true, repositories: [] }),
searchRules: jest.fn().mockResolvedValue({
rawActives: [],
facets: [],
rawFacets: [],
- p: 0,
- ps: 100,
rules: [mockRule(), mockRule()],
- total: 0,
+ paging: mockPaging({
+ total: 0,
+ pageIndex: 1,
+ pageSize: 100,
+ }),
}),
};
});
<PageActions
paging={
{
- "pageIndex": 0,
+ "pageIndex": 1,
"pageSize": 100,
"total": 0,
}
import { find, without } from 'lodash';
import * as React from 'react';
import { addUserToGroup, getUsersInGroup, removeUserFromGroup } from '../../../api/user_groups';
-import { ResetButtonLink } from '../../../components/controls/buttons';
import Modal from '../../../components/controls/Modal';
import SelectList, {
SelectListFilter,
SelectListSearchParams,
} from '../../../components/controls/SelectList';
+import { ResetButtonLink } from '../../../components/controls/buttons';
import { translate } from '../../../helpers/l10n';
import { Group, UserSelected } from '../../../types/types';
lastSearchParams: searchParams,
loading: false,
users,
- usersTotalCount: data.total,
+ usersTotalCount: data.paging.total,
selectedUsers,
};
});
import { DeferredSpinner } from 'design-system/lib';
import * as React from 'react';
import { getUsersInGroup } from '../../../api/user_groups';
-import { ResetButtonLink } from '../../../components/controls/buttons';
import ListFooter from '../../../components/controls/ListFooter';
import Modal from '../../../components/controls/Modal';
import SearchBox from '../../../components/controls/SearchBox';
import { SelectListFilter } from '../../../components/controls/SelectList';
+import { ResetButtonLink } from '../../../components/controls/buttons';
import { translate } from '../../../helpers/l10n';
import { Group, UserGroupMember } from '../../../types/types';
} else {
setUsers(data.users);
}
- setTotal(data.total);
+ setTotal(data.paging.total);
setLoading(false);
})();
}, [query, page]);
: ISSUE_TYPES.filter((type) => type !== IssueType.SecurityHotspot).join(),
s: 'name',
include_external: true,
- }).then((response) => ({
- paging: { pageIndex: response.p, pageSize: response.ps, total: response.total },
- results: response.rules,
+ }).then(({ rules, paging }) => ({
+ results: rules,
+ paging,
}));
};
import selectEvent from 'react-select-event';
import { byRole } from 'testing-library-selector';
import QualityProfilesServiceMock from '../../../api/mocks/QualityProfilesServiceMock';
-import { mockRule } from '../../../helpers/testMocks';
+import { mockPaging, mockRule } from '../../../helpers/testMocks';
import { renderAppRoutes } from '../../../helpers/testReactTestingUtils';
import routes from '../routes';
serviceMock.setAdmin();
serviceMock.setRulesSearchResponse({
rules: [mockRule({ name: 'Recently Added Rule' })],
- total: 20,
+ paging: mockPaging({
+ total: 20,
+ }),
});
renderQualityProfiles();
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import { getProfileChangelog } from '../../../api/quality-profiles';
+import { ChangelogResponse, getProfileChangelog } from '../../../api/quality-profiles';
import { Location, Router, withRouter } from '../../../components/hoc/withRouter';
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
import { parseDate, toISO8601WithOffsetString } from '../../../helpers/dates';
} = this.props;
getProfileChangelog(query.since, query.to, profile)
- .then((r: any) => {
+ .then((r: ChangelogResponse) => {
if (this.mounted) {
this.setState({
events: r.events,
- total: r.total,
- page: r.p,
+ total: r.paging.total,
+ page: r.paging.pageIndex,
loading: false,
});
}
} = this.props;
getProfileChangelog(query.since, query.to, profile, this.state.page + 1)
- .then((r: any) => {
+ .then((r: ChangelogResponse) => {
if (this.mounted && this.state.events) {
this.setState(({ events = [] }) => ({
events: [...events, ...r.events],
- total: r.total,
- page: r.p,
+ total: r.paging.total,
+ page: r.paging.pageIndex,
loading: false,
}));
}
import { shallow } from 'enzyme';
import * as React from 'react';
import { getProfileChangelog } from '../../../../api/quality-profiles';
-import { mockLocation, mockQualityProfile, mockRouter } from '../../../../helpers/testMocks';
+import {
+ mockLocation,
+ mockPaging,
+ mockQualityProfile,
+ mockRouter,
+} from '../../../../helpers/testMocks';
import { mockEvent, waitAndUpdate } from '../../../../helpers/testUtils';
import { ChangelogContainer } from '../ChangelogContainer';
beforeEach(() => jest.clearAllMocks());
jest.mock('../../../../api/quality-profiles', () => {
- const { mockQualityProfileChangelogEvent } = jest.requireActual('../../../../helpers/testMocks');
+ const { mockQualityProfileChangelogEvent, mockPaging } = jest.requireActual(
+ '../../../../helpers/testMocks'
+ );
return {
getProfileChangelog: jest.fn().mockResolvedValue({
events: [
mockQualityProfileChangelogEvent(),
mockQualityProfileChangelogEvent(),
],
- total: 6,
- p: 1,
+ paging: mockPaging({
+ total: 6,
+ pageIndex: 1,
+ }),
}),
};
});
it('should render correctly without events', async () => {
- (getProfileChangelog as jest.Mock).mockResolvedValueOnce({ events: [] });
+ (getProfileChangelog as jest.Mock).mockResolvedValueOnce({
+ events: [],
+ paging: mockPaging({ total: 0 }),
+ });
const wrapper = shallowRender();
await waitAndUpdate(wrapper);
expect(wrapper).toMatchSnapshot();
import { getQualityProfile } from '../../../api/quality-profiles';
import { searchRules, takeFacet } from '../../../api/rules';
import Link from '../../../components/common/Link';
-import { Button } from '../../../components/controls/buttons';
import Tooltip from '../../../components/controls/Tooltip';
+import { Button } from '../../../components/controls/buttons';
import { translate } from '../../../helpers/l10n';
import { getRulesUrl } from '../../../helpers/urls';
import { Dict } from '../../../types/types';
if (this.mounted) {
const [allRules, activatedRules, showProfile] = responses;
this.setState({
- activatedTotal: activatedRules.total,
+ activatedTotal: activatedRules.paging.total,
allByType: keyBy<ByType>(takeFacet(allRules, 'types'), 'val'),
activatedByType: keyBy<ByType>(takeFacet(activatedRules, 'types'), 'val'),
compareToSonarWay: showProfile && showProfile.compareToSonarWay,
- total: allRules.total,
+ total: allRules.paging.total,
});
}
}
import { shallow } from 'enzyme';
import * as React from 'react';
import { getQualityProfile } from '../../../../api/quality-profiles';
-import { mockQualityProfile } from '../../../../helpers/testMocks';
+import { mockPaging, mockQualityProfile } from '../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../helpers/testUtils';
import ProfileRules from '../ProfileRules';
const EDITABLE_PROFILE = { ...PROFILE, actions: { edit: true } };
const apiResponseAll = {
- total: 253,
facets: [
{
property: 'types',
],
},
],
+ paging: mockPaging({
+ total: 253,
+ }),
};
const apiResponseActive = {
- total: 68,
facets: [
{
property: 'types',
],
},
],
+ paging: mockPaging({
+ total: 68,
+ }),
};
jest.mock('../../../../api/rules', () => ({
it('should render the quality profiles rules with sonarway comparison', async () => {
const wrapper = shallow(<ProfileRules profile={PROFILE} />);
- const instance = wrapper.instance() as any;
+ const instance = wrapper.instance() as ProfileRules;
instance.mounted = true;
instance.loadRules();
await waitAndUpdate(wrapper);
};
searchRules(data).then(
- ({ actives, rules, total }) => {
+ ({ actives, rules, paging: { total } }) => {
if (this.mounted) {
this.setState({
latestRules: sortBy(parseRules(rules, actives), 'langName'),
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { Dict, Rule, RuleActivation } from './types';
+import { Dict, Paging, Rule, RuleActivation } from './types';
export interface RuleRepository {
key: string;
export interface SearchRulesResponse {
actives?: Dict<RuleActivation[]>;
facets?: { property: string; values: { count: number; val: string }[] }[];
- p: number;
- ps: number;
rules: Rule[];
- total: number;
+ paging: Paging;
}