};
comparisonResult: CompareResponse = mockCompareResult();
+ searchRulesResponse: SearchRulesResponse = {
+ p: 0,
+ ps: 500,
+ total: 0,
+ rules: [],
+ };
constructor() {
this.resetQualityProfile();
this.comparisonResult = mockCompareResult();
}
+ resetSearchRulesResponse() {
+ this.searchRulesResponse = {
+ p: 0,
+ ps: 500,
+ total: 0,
+ rules: [],
+ };
+ }
+
handleGetImporters = () => {
return this.reply([]);
};
};
handleSearchRules = (): Promise<SearchRulesResponse> => {
- return this.reply({
- p: 0,
- ps: 500,
- total: 0,
- rules: [],
- });
+ return this.reply(this.searchRulesResponse);
};
handleSearchQualityProfiles = (
this.isAdmin = true;
}
+ setRulesSearchResponse(overrides: Partial<SearchRulesResponse>) {
+ this.searchRulesResponse = {
+ ...this.searchRulesResponse,
+ ...overrides,
+ };
+ }
+
reset() {
this.isAdmin = false;
this.resetQualityProfile();
this.resetComparisonResult();
+ this.resetSearchRulesResponse();
}
reply<T>(response: T): Promise<T> {
import selectEvent from 'react-select-event';
import { byRole } from 'testing-library-selector';
import QualityProfilesServiceMock from '../../../api/mocks/QualityProfilesServiceMock';
+import { mockRule } from '../../../helpers/testMocks';
import { renderAppRoutes } from '../../../helpers/testReactTestingUtils';
import routes from '../routes';
byRole('heading', {
name: `quality_profiles.x_rules_have_different_configuration.${rulesQuantity}`,
}),
+ newRuleLink: byRole('link', { name: 'Recently Added Rule' }),
+ seeAllNewRulesLink: byRole('link', { name: 'see_all 20 quality_profiles.latest_new_rules' }),
};
it('should list Quality Profiles and filter by language', async () => {
expect(ui.createButton.get(ui.popup.get())).toBeEnabled();
});
+it('should list recently added rules', async () => {
+ serviceMock.setAdmin();
+ serviceMock.setRulesSearchResponse({
+ rules: [mockRule({ name: 'Recently Added Rule' })],
+ total: 20,
+ });
+
+ renderQualityProfiles();
+ expect(await ui.newRuleLink.find()).toBeInTheDocument();
+ expect(ui.seeAllNewRulesLink.get()).toBeInTheDocument();
+});
+
it('should be able to extend Quality Profile', async () => {
// From the list page
const user = userEvent.setup();
}
render() {
- if (!this.state.latestRulesTotal || !this.state.latestRules) {
+ const { latestRulesTotal, latestRules } = this.state;
+
+ if (!latestRulesTotal || !latestRules) {
return null;
}
+ const newRulesTitle = translate('quality_profiles.latest_new_rules');
const newRulesUrl = getRulesUrl({ available_since: this.periodStartDate });
+ const seeAllRulesText = `${translate('see_all')} ${formatMeasure(
+ latestRulesTotal,
+ 'SHORT_INT',
+ null
+ )}`;
return (
<div className="boxed-group boxed-group-inner quality-profiles-evolution-rules">
<div className="clearfix">
- <strong className="pull-left">{translate('quality_profiles.latest_new_rules')}</strong>
+ <strong className="pull-left">{newRulesTitle}</strong>
</div>
<ul>
- {this.state.latestRules.map((rule) => (
+ {latestRules.map((rule) => (
<li className="spacer-top" key={rule.key}>
<div className="text-ellipsis">
<Link className="link-no-underline" to={getRulesUrl({ rule_key: rule.key })}>
</li>
))}
</ul>
- {this.state.latestRulesTotal > RULES_LIMIT && (
+ {latestRulesTotal > RULES_LIMIT && (
<div className="spacer-top">
- <Link className="small" to={newRulesUrl}>
- {translate('see_all')} {formatMeasure(this.state.latestRulesTotal, 'SHORT_INT', null)}
+ <Link
+ className="small"
+ to={newRulesUrl}
+ aria-label={`${seeAllRulesText} ${newRulesTitle}`}
+ >
+ {seeAllRulesText}
</Link>
</div>
)}