Skip to content

Commit

Permalink
fix(RHICOMPL-1005): Address issues with more spaces in filter labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bastilian committed Oct 7, 2020
1 parent dbbb71d commit 9ec2bbe
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const FILTER_CONFIGURATION = [
},
{
type: conditionalFilterType.checkbox,
label: 'Compliance score',
label: 'Systems meeting compliance',
filterString: (value) => {
const scoreRange = value.split('-');
return `compliance_score >= ${scoreRange[0]} and compliance_score <= ${scoreRange[1]}`;
Expand Down Expand Up @@ -59,16 +59,16 @@ describe('buildFilterString', () => {
expect(filterBuilder.buildFilterString(testExampleState)).toMatchSnapshot();
});

it('returns a filter for complianceStates', () => {
it('returns a filter for compliant', () => {
const testExampleState = {
compliant: [ true ]
};
expect(filterBuilder.buildFilterString(testExampleState)).toMatchSnapshot();
});

it('returns a filter for complianceStates', () => {
it('returns a filter for scores', () => {
const testExampleState = {
compliancescore: [ '0-49', '50-69' ]
systemsmeetingcompliance: [ '0-49', '50-69' ]
};
expect(filterBuilder.buildFilterString(testExampleState)).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FilterBuilder from './FilterBuilder';
import ChipBuilder from './ChipBuilder';

export const stringToId = (string) => (
string.replace(' ', '').toLowerCase()
string.split(' ').join('').toLowerCase()
);

class FilterConfigBuilder {
Expand Down Expand Up @@ -103,7 +103,7 @@ class FilterConfigBuilder {
initialDefaultState = (defaultStates = {}) => {
let initialState = {};
this.config.forEach((filter) => {
const filterStateName = filter.label.replace(' ', '').toLowerCase();
const filterStateName = stringToId(filter.label);
initialState[filterStateName] =
defaultStates[filterStateName] || this.defaultValueForFilter(filter);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import buildFilterConfig from './FilterBuilderConfigBuilder';
import FilterConfigBuilder from './FilterConfigBuilder';
import { conditionalFilterType } from '@redhat-cloud-services/frontend-components';

describe('FilterConfigBuilder', () => {
const config = buildFilterConfig({ selectedFilter: true, showPassFailFilter: true, policies: [] });
const config = [
{
type: conditionalFilterType.checkbox,
label: 'Filter with multiple spaces',
items: [
{ label: 'Show ', value: 'show' }
],
filter: () => ([])
},
...buildFilterConfig({ selectedFilter: true, showPassFailFilter: true, policies: [] })
];
let builder;

beforeEach(() => {
Expand All @@ -19,6 +30,11 @@ describe('FilterConfigBuilder', () => {

expect(builtConfig).toMatchSnapshot();
});
describe('initialDefaultState', () => {
it('to return a matching category label', () => {
expect(builder.initialDefaultState()).toMatchSnapshot();
});
});

describe('categoryLabelForValue', () => {
it('to return a matching category label', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`buildFilterString filter building returns a base filter for name when searching 1`] = `"name ~ Name"`;

exports[`buildFilterString filter building returns a filter for complianceStates 1`] = `"compliant = true"`;
exports[`buildFilterString filter building returns a filter for compliant 1`] = `"compliant = true"`;

exports[`buildFilterString filter building returns a filter for complianceStates 2`] = `"compliance_score >= 0 and compliance_score <= 49 or compliance_score >= 50 and compliance_score <= 69"`;
exports[`buildFilterString filter building returns a filter for scores 1`] = `"compliance_score >= 0 and compliance_score <= 49 or compliance_score >= 50 and compliance_score <= 69"`;

exports[`buildFilterString returns a filterstring 1`] = `"name ~ Name and compliant = true and compliance_score >= 0 and compliance_score <= 49 or compliance_score >= 50 and compliance_score <= 69"`;
exports[`buildFilterString returns a filterstring 1`] = `"name ~ Name and compliant = true"`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ exports[`FilterConfigBuilder categoryLabelForValue to return a matching category

exports[`FilterConfigBuilder categoryLabelForValue to return a matching category label 3`] = `"Search term"`;

exports[`FilterConfigBuilder initialDefaultState to return a matching category label 1`] = `
Object {
"filterwithmultiplespaces": Array [],
"name": "",
"passed": undefined,
"selected": Array [],
"severity": Array [],
}
`;

exports[`FilterConfigBuilder labelForValue to return a matching label 1`] = `"true"`;

exports[`FilterConfigBuilder labelForValue to return a matching label 2`] = `"0-49"`;
Expand All @@ -17,6 +27,21 @@ Object {
"compliancescore": Array [],
"compliant": Array [],
"items": Array [
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Show ",
"value": "show",
},
],
"onChange": [Function],
"value": undefined,
},
"id": "filterwithmultiplespaces",
"label": "Filter with multiple spaces",
"type": "checkbox",
},
Object {
"filterValues": Object {
"onChange": [Function],
Expand Down

0 comments on commit 9ec2bbe

Please sign in to comment.