|
38 | 38 | </cosmoz-omnitable-column>
|
39 | 39 | <cosmoz-omnitable-column name="columnWithoutSortOn" value-path="valuePath">
|
40 | 40 | </cosmoz-omnitable-column>
|
| 41 | + <cosmoz-omnitable-column name="columnWithFilter" value-path="valuePath"> |
| 42 | + </cosmoz-omnitable-column> |
41 | 43 | </cosmoz-omnitable>
|
42 | 44 | </template>
|
43 | 45 | </test-fixture>
|
|
58 | 60 | <script type="module">
|
59 | 61 | import { setupOmnitableFixture } from './helpers/utils';
|
60 | 62 | import { generateTableDemoData } from '../demo/table-demo-helper';
|
| 63 | + import { flush } from '@polymer/polymer/lib/utils/flush'; |
61 | 64 |
|
62 | 65 | sinon.assert.expose(chai.assert, { prefix: '' });
|
63 | 66 |
|
|
89 | 92 | });
|
90 | 93 |
|
91 | 94 | test('sets column groupOn property to valuePath when group-on attribute is missing', () => {
|
92 |
| - const column = omnitable.columns.find(col => { |
93 |
| - return col.name === 'columnWithoutGroupOn'; |
94 |
| - }); |
95 |
| - |
| 95 | + const column = omnitable.columns.find(col => col.name === 'columnWithoutGroupOn'); |
96 | 96 | assert.equal(column.groupOn, 'valuePath');
|
97 | 97 | });
|
98 | 98 |
|
99 | 99 | test('sets column groupOn property to group-on attribute', () => {
|
100 |
| - const column = omnitable.columns.find(col => { |
101 |
| - return col.name === 'columnWithGroupOn'; |
102 |
| - }); |
103 |
| - |
| 100 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
104 | 101 | assert.equal(column.groupOn, 'groupOnValuePath');
|
105 | 102 | });
|
106 | 103 |
|
107 | 104 | test('sets column sortOn property to valuePath when sort-on attribute is missing', () => {
|
108 |
| - const column = omnitable.columns.find(col => { |
109 |
| - return col.name === 'columnWithoutSortOn'; |
110 |
| - }); |
111 |
| - |
| 105 | + const column = omnitable.columns.find(col => col.name === 'columnWithoutSortOn'); |
112 | 106 | assert.equal(column.sortOn, 'valuePath');
|
113 | 107 | });
|
114 | 108 | test('sets column sortOn property to sort-on attribute', () => {
|
115 |
| - const column = omnitable.columns.find(col => { |
116 |
| - return col.name === 'columnWithSortOn'; |
117 |
| - }); |
118 |
| - |
| 109 | + const column = omnitable.columns.find(col => col.name === 'columnWithSortOn'); |
119 | 110 | assert.equal(column.sortOn, 'sortOnValuePath');
|
120 | 111 | });
|
121 | 112 |
|
| 113 | + test('changing inputValue updates filter eventually', () => { |
| 114 | + const column = omnitable.columns.find(col => col.name === 'columnWithFilter'); |
| 115 | + assert.isNull(column.filter); |
| 116 | + assert.isNull(column.inputValue); |
| 117 | + column.inputValue = 'test'; |
| 118 | + flush(); |
| 119 | + assert.equal(column.filter, 'test'); |
| 120 | + }); |
| 121 | + |
| 122 | + test('changing inputValue to empty updates filter instantly', () => { |
| 123 | + const column = omnitable.columns.find(col => col.name === 'columnWithFilter'); |
| 124 | + assert.isNull(column.filter); |
| 125 | + assert.isNull(column.inputValue); |
| 126 | + column.inputValue = ''; |
| 127 | + assert.equal(column.filter, ''); |
| 128 | + }); |
| 129 | + |
122 | 130 | test('_serializeFilter returns filter', () => {
|
123 |
| - const column = omnitable.columns.find(col => { |
124 |
| - return col.name === 'columnWithGroupOn'; |
125 |
| - }), |
| 131 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'), |
126 | 132 | filter = { key: 'value' };
|
127 | 133 | assert.deepEqual(column._serializeFilter(filter), filter);
|
128 | 134 | });
|
129 | 135 |
|
130 | 136 | test('_serializeFilter uses default filter', () => {
|
131 |
| - const column = omnitable.columns.find(col => { |
132 |
| - return col.name === 'columnWithGroupOn'; |
133 |
| - }); |
| 137 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
134 | 138 | assert.isNull(column.filter);
|
135 | 139 | column.filter = { key: 'value' };
|
136 | 140 | assert.deepEqual(column._serializeFilter(), column.filter);
|
137 | 141 | });
|
138 | 142 |
|
139 | 143 | test('_serializeFilter handles null filter', () => {
|
140 |
| - const column = omnitable.columns.find(col => { |
141 |
| - return col.name === 'columnWithGroupOn'; |
142 |
| - }); |
| 144 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
143 | 145 | assert.isNull(column.filter);
|
144 | 146 | assert.isNull(column._serializeFilter());
|
145 | 147 | });
|
146 | 148 |
|
147 | 149 | test('_deserializeFilter returns object', () => {
|
148 |
| - const column = omnitable.columns.find(col => { |
149 |
| - return col.name === 'columnWithGroupOn'; |
150 |
| - }); |
| 150 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
151 | 151 | assert.deepEqual(column._deserializeFilter({ key: 'value' }), { key: 'value' });
|
152 | 152 | });
|
153 | 153 |
|
154 | 154 | test('_deserializeFilter handles null', () => {
|
155 |
| - const column = omnitable.columns.find(col => { |
156 |
| - return col.name === 'columnWithGroupOn'; |
157 |
| - }); |
| 155 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
158 | 156 | assert.isNull(column._deserializeFilter());
|
159 | 157 | });
|
160 | 158 |
|
161 | 159 | test('resetFilter resets filter to null', () => {
|
162 |
| - const column = omnitable.columns.find(col => { |
163 |
| - return col.name === 'columnWithGroupOn'; |
164 |
| - }); |
| 160 | + const column = omnitable.columns.find(col => col.name === 'columnWithGroupOn'); |
165 | 161 | column.filter = { key: 'value' };
|
166 | 162 | column.resetFilter();
|
167 | 163 | assert.isNull(column.filter);
|
|
0 commit comments