expect(utils.parseSorting('-size')).toEqual({ sortDesc: true, sortValue: 'size' });
});
});
-
-describe('cumulativeMapFacetValues', () => {
- it('should correctly cumulate facets', () => {
- expect(
- utils.cumulativeMapFacetValues([
- { val: '1', count: 50 },
- { val: '2', count: 1 },
- { val: '3', count: 6 },
- { val: '4', count: 2 },
- { val: '5', count: 0 }
- ])
- // eslint-disable-next-line
- ).toEqual({ '1': 50, '2': 9, '3': 8, '4': 2, '5': 0 });
- });
- it('should correctly cumulate facets with NO_DATA items', () => {
- const expectedResult = {
- '80.0-*': 59,
- '70.0-80.0': 26,
- '50.0-70.0': 15,
- '30.0-50.0': 11,
- '*-30.0': 7,
- NO_DATA: 5
- };
- expect(
- utils.cumulativeMapFacetValues([
- { val: '80.0-*', count: 59 },
- { val: '70.0-80.0', count: 11 },
- { val: '50.0-70.0', count: 4 },
- { val: '30.0-50.0', count: 4 },
- { val: '*-30.0', count: 7 },
- { val: 'NO_DATA', count: 5 }
- ])
- ).toEqual(expectedResult);
- expect(
- utils.cumulativeMapFacetValues([
- { val: 'NO_DATA', count: 5 },
- { val: '80.0-*', count: 59 },
- { val: '70.0-80.0', count: 11 },
- { val: '50.0-70.0', count: 4 },
- { val: '30.0-50.0', count: 4 },
- { val: '*-30.0', count: 7 }
- ])
- ).toEqual(expectedResult);
- expect(
- utils.cumulativeMapFacetValues([
- { val: '80.0-*', count: 59 },
- { val: '70.0-80.0', count: 11 },
- { val: '50.0-70.0', count: 4 },
- { val: 'NO_DATA', count: 5 },
- { val: '30.0-50.0', count: 4 },
- { val: '*-30.0', count: 7 }
- ])
- ).toEqual(expectedResult);
- });
-});
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { sumBy, uniq } from 'lodash';
+import { uniq } from 'lodash';
import { Query, convertToFilter } from './query';
import { translate } from '../../helpers/l10n';
import { RequestData } from '../../helpers/request';
'tags'
];
-const CUMULATIVE_FACETS = [
- 'reliability',
- 'new_reliability',
- 'security',
- 'new_security',
- 'maintainability',
- 'new_maintainability',
- 'coverage',
- 'new_coverage',
- 'duplications',
- 'new_duplications',
- 'size',
- 'new_lines'
-];
-
const REVERSED_FACETS = ['coverage', 'new_coverage'];
export function localizeSorting(sort?: string): string {
return map;
}
-export function cumulativeMapFacetValues(values: Array<{ val: string; count: number }>) {
- const noDataVal = values.find(value => value.val === 'NO_DATA');
- const filteredValues = noDataVal ? values.filter(value => value.val !== 'NO_DATA') : values;
-
- let sum = sumBy(filteredValues, value => value.count);
- const map: { [value: string]: number } = {};
- filteredValues.forEach((value, index) => {
- map[value.val] = index > 0 && index < values.length - 1 ? sum : value.count;
- sum -= value.count;
- });
-
- if (noDataVal) {
- map[noDataVal.val] = noDataVal.count;
- }
- return map;
-}
-
function getFacetsMap(facets: Facet[]) {
const map: { [property: string]: { [value: string]: number } } = {};
facets.forEach(facet => {
if (REVERSED_FACETS.includes(property)) {
values.reverse();
}
- map[property] = CUMULATIVE_FACETS.includes(property)
- ? cumulativeMapFacetValues(values)
- : mapFacetValues(values);
+ map[property] = mapFacetValues(values);
});
return map;
}
export function getCoverageRatingLabel(rating: number): string {
checkNumberRating(rating);
- const mapping = ['≥ 80%', '< 80%', '< 70%', '< 50%', '< 30%'];
+ const mapping = ['≥ 80%', '70% - 80%', '50% - 70%', '30% - 50%', '< 30%'];
return mapping[rating - 1];
}
export function getDuplicationsRatingLabel(rating: number): string {
checkNumberRating(rating);
- const mapping = ['< 3%', '≥ 3%', '> 5%', '> 10%', '> 20%'];
+ const mapping = ['< 3%', '3% - 5%', '5% - 10%', '10% - 20%', '> 20%'];
return mapping[rating - 1];
}
export function getSizeRatingLabel(rating: number): string {
checkNumberRating(rating);
- const mapping = ['< 1k', '≥ 1k', '> 10k', '> 100k', '> 500k'];
+ const mapping = ['< 1k', '1k - 10k', '10k - 100k', '100k - 500k', '> 500k'];
return mapping[rating - 1];
}
ProjectsPage page = tester.openBrowser().openProjects();
page.getFacetByProperty("duplications")
.shouldHaveValue("1", "1")
- .shouldHaveValue("2", "1")
- .shouldHaveValue("3", "1")
- .shouldHaveValue("4", "1")
+ .shouldHaveValue("2", "0")
+ .shouldHaveValue("3", "0")
+ .shouldHaveValue("4", "0")
.shouldHaveValue("5", "1")
.shouldHaveValue("6", "0");
}