|
| 1 | +import {applyCustomConfigVisibility} from '../index'; |
| 2 | + |
| 3 | +describe('applyCustomConfigVisibility', () => { |
| 4 | + it('correctly blacklists attributes taking into account exceptions', () => { |
| 5 | + const customConfig = { |
| 6 | + visibility_rules: { |
| 7 | + blacklist: [{type: 'attrName', regex_match: 'color'}], |
| 8 | + whitelist: [{type: 'attrName', regex_match: 'colorscale(?!.title.font.color|.tickcolor)'}], |
| 9 | + order: ['blacklist', 'whitelist'], |
| 10 | + }, |
| 11 | + }; |
| 12 | + |
| 13 | + const expectedResults = [false, true, false, true, false, false]; |
| 14 | + |
| 15 | + [ |
| 16 | + {attr: 'bg_color'}, |
| 17 | + {attr: 'colorscale'}, |
| 18 | + {attr: 'font.color'}, |
| 19 | + {attr: 'somethingElse'}, |
| 20 | + {attr: 'colorscale.title.font.color'}, |
| 21 | + {attr: 'colorscale.tickcolor'}, |
| 22 | + ].forEach((prop, index) => { |
| 23 | + const isVisible = applyCustomConfigVisibility(prop, 'red', customConfig); |
| 24 | + expect(isVisible).toBe(expectedResults[index]); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('correctly whitelists attributes taking into account exceptions', () => { |
| 29 | + const customConfig = { |
| 30 | + visibility_rules: { |
| 31 | + blacklist: [{type: 'attrName', regex_match: 'color(?!scale)'}], |
| 32 | + whitelist: [{type: 'attrName', regex_match: 'colorscale'}], |
| 33 | + order: ['whitelist', 'blacklist'], |
| 34 | + }, |
| 35 | + }; |
| 36 | + |
| 37 | + const expectedResults = [false, true, false, false]; |
| 38 | + |
| 39 | + [ |
| 40 | + {attr: 'bg_color'}, |
| 41 | + {attr: 'colorscale'}, |
| 42 | + {attr: 'font.color'}, |
| 43 | + {attr: 'somethingElse'}, |
| 44 | + ].forEach((prop, index) => { |
| 45 | + const isVisible = applyCustomConfigVisibility(prop, 'red', customConfig); |
| 46 | + expect(isVisible).toBe(expectedResults[index]); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + it('works when just whitelist prop is provided', () => { |
| 51 | + const customConfig = { |
| 52 | + visibility_rules: { |
| 53 | + whitelist: [{type: 'attrName', regex_match: 'colorscale'}], |
| 54 | + }, |
| 55 | + }; |
| 56 | + |
| 57 | + const expectedResults = [false, true, false, false]; |
| 58 | + |
| 59 | + [ |
| 60 | + {attr: 'bg_color'}, |
| 61 | + {attr: 'colorscale'}, |
| 62 | + {attr: 'font.color'}, |
| 63 | + {attr: 'somethingElse'}, |
| 64 | + ].forEach((prop, index) => { |
| 65 | + const isVisible = applyCustomConfigVisibility(prop, 'red', customConfig); |
| 66 | + expect(isVisible).toBe(expectedResults[index]); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + it('works when just blacklist prop is provided', () => { |
| 71 | + const customConfig = { |
| 72 | + visibility_rules: { |
| 73 | + blacklist: [{type: 'attrName', regex_match: 'colorscale'}], |
| 74 | + }, |
| 75 | + }; |
| 76 | + |
| 77 | + const expectedResults = [true, false, true, true]; |
| 78 | + |
| 79 | + [ |
| 80 | + {attr: 'bg_color'}, |
| 81 | + {attr: 'colorscale'}, |
| 82 | + {attr: 'font.color'}, |
| 83 | + {attr: 'somethingElse'}, |
| 84 | + ].forEach((prop, index) => { |
| 85 | + const isVisible = applyCustomConfigVisibility(prop, 'red', customConfig); |
| 86 | + expect(isVisible).toBe(expectedResults[index]); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + it('defaults to [blacklist, whitelist] order when no order prop is provided', () => { |
| 91 | + const customConfig = { |
| 92 | + visibility_rules: { |
| 93 | + whitelist: [{type: 'attrName', regex_match: 'colorscale'}], |
| 94 | + blacklist: [{type: 'attrName', regex_match: 'color'}], |
| 95 | + }, |
| 96 | + }; |
| 97 | + |
| 98 | + const expectedResults = [false, true, false, true]; |
| 99 | + |
| 100 | + [ |
| 101 | + {attr: 'bg_color'}, |
| 102 | + {attr: 'colorscale'}, |
| 103 | + {attr: 'font.color'}, |
| 104 | + {attr: 'somethingElse'}, |
| 105 | + ].forEach((prop, index) => { |
| 106 | + const isVisible = applyCustomConfigVisibility(prop, 'red', customConfig); |
| 107 | + expect(isVisible).toBe(expectedResults[index]); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments