Skip to content

Commit

Permalink
Fix indicating YesNo filters (#2686)
Browse files Browse the repository at this point in the history
* #2685 update filters fixtures with new data structure
#2685 fix caption test
#2685 unskip some test
#2615

* #2685 properly show caption for YesNo filter with falsy value

* #2615 fix the rest of skipped filters

* #2685 fix lint error
  • Loading branch information
siemiatj committed Apr 15, 2020
1 parent 91f4975 commit 94efb22
Show file tree
Hide file tree
Showing 4 changed files with 757 additions and 641 deletions.
26 changes: 11 additions & 15 deletions src/__tests__/components/Filters.test.js
Expand Up @@ -29,9 +29,9 @@ const createStore = function(state = {}) {
}

const createInitialProps = function(basicFixtures = filtersFixtures.data1, additionalProps = {}) {
const filterData = additionalProps.filterData
? additionalProps.filterData
: basicFixtures.filterData;
const filterData = additionalProps.filters
? additionalProps.filters
: basicFixtures.filters;
const filtersActive = additionalProps.filtersActive
? additionalProps.filtersActive
: basicFixtures.filtersActive;
Expand Down Expand Up @@ -87,20 +87,16 @@ describe('Filters tests', () => {
});

const store = mockStore(initialState)
const wrapper = mount(
const wrapper = shallow(
<Provider store={store}>
<Filters {...dummyProps} />
</Provider>
);
const html = wrapper.html();

expect(html).toContain('filter-wrapper');
expect(html).toContain('filters-frequent');
expect(html).toContain('btn-filter');
expect(html).toContain('Aufträge');
wrapper.find('.filter-wrapper button[title="Akontozahlung, Completed, Error"]');
});

it.skip('opens dropdown and filter details', () => {
it('opens dropdown and filter details', () => {
const dummyProps = createInitialProps();
const initialState = createStore({
windowHandler: {
Expand Down Expand Up @@ -134,8 +130,8 @@ describe('Filters tests', () => {
// as the widgets need an architecture overhaul, and filters should be moved to redux state
describe('Temporary bloated filter tests', () => {
// https://github.com/metasfresh/me03/issues/3649
it.skip('clears list filters and applies without error', () => {
const dummyProps = createInitialProps(undefined, { filtersActive: filtersFixtures.filtersActive1 });
it('clears list filters and applies without error', () => {
const dummyProps = createInitialProps(undefined, { filtersActive: filtersFixtures.filtersActive2 });
const initialState = createStore({
windowHandler: {
allowShortcut: true,
Expand Down Expand Up @@ -173,12 +169,12 @@ describe('Filters tests', () => {
expect(wrapper.find('.filters-overlay').length).toBe(0);
});

it.skip('supports `false` values for checkbox widgets', () => {
it('supports `false` values for checkbox widgets', () => {
const updateDocListListener = jest.fn();
const dummyProps = createInitialProps(
filtersFixtures.data2,
{
filtersActive: filtersFixtures.filtersActive2,
filtersActive: filtersFixtures.filtersActive3,
updateDocList: updateDocListListener,
}
);
Expand Down Expand Up @@ -236,7 +232,7 @@ describe('Filters tests', () => {
expect(updateDocListListener).toBeCalledWith(filterResult);
});

it.skip('supports filters without parameters', () => {
it('supports filters without parameters', () => {
const updateDocListListener = jest.fn();
const dummyProps = createInitialProps(
filtersFixtures.data3,
Expand Down
5 changes: 5 additions & 0 deletions src/components/filters/Filters.js
Expand Up @@ -210,6 +210,11 @@ class Filters extends PureComponent {
}, '');
break;
case 'YesNo':
if (value === null) {
captionName = '';
itemCaption = '';
}
break;
case 'Switch':
default:
if (!value) {
Expand Down
10 changes: 6 additions & 4 deletions src/components/filters/FiltersItem.js
Expand Up @@ -381,11 +381,13 @@ class FiltersItem extends PureComponent {
);
} else {
// update the active filter with the defaultValue if value from active filter is empty
let activeFilterClone = _.cloneDeep(activeFilter);
const activeFilterClone = _.cloneDeep(activeFilter);
activeFilterClone.parameters.map((afcItem, index) => {
afcItem.value = !afcItem.value
? filter.parameters[index].defaultValue
: afcItem.value;
// YesNo filters (checkboxes) can be either null, true or false
afcItem.value =
!afcItem.value && afcItem.value !== false
? filter.parameters[index].defaultValue
: afcItem.value;
return afcItem;
});

Expand Down

0 comments on commit 94efb22

Please sign in to comment.