|
1 | 1 | import dh from '@deephaven/jsapi-shim'; |
2 | 2 | import type IrisGridModel from './IrisGridModel'; |
3 | | -import type IrisGridProxyModel from './IrisGridProxyModel'; |
| 3 | +import IrisGridProxyModel from './IrisGridProxyModel'; |
4 | 4 | import IrisGridTestUtils from './IrisGridTestUtils'; |
| 5 | +import { type PartitionConfig } from './PartitionedGridModel'; |
5 | 6 |
|
6 | 7 | const irisGridTestUtils = new IrisGridTestUtils(dh); |
7 | 8 |
|
@@ -136,6 +137,77 @@ describe('IrisGridProxyModel', () => { |
136 | 137 | expect(testUnderlyingSetter).toHaveBeenCalledTimes(1); |
137 | 138 | }); |
138 | 139 |
|
| 140 | + describe('set partitionConfig', () => { |
| 141 | + const mockPartitionedTable = { |
| 142 | + getMergedTable: jest.fn(() => |
| 143 | + Promise.resolve(irisGridTestUtils.makeTable()) |
| 144 | + ), |
| 145 | + getKeyTable: jest.fn(() => |
| 146 | + Promise.resolve(irisGridTestUtils.makeTable()) |
| 147 | + ), |
| 148 | + getKeys: jest.fn(() => Promise.resolve([])), |
| 149 | + getTable: jest.fn(() => Promise.resolve(irisGridTestUtils.makeTable())), |
| 150 | + keyColumns: [], |
| 151 | + columns: [], |
| 152 | + close: jest.fn(), |
| 153 | + addEventListener: jest.fn(), |
| 154 | + removeEventListener: jest.fn(), |
| 155 | + }; |
| 156 | + |
| 157 | + let setNextModelSpy: jest.SpyInstance; |
| 158 | + |
| 159 | + beforeEach(() => { |
| 160 | + setNextModelSpy = jest |
| 161 | + .spyOn(IrisGridProxyModel.prototype, 'setNextModel') |
| 162 | + .mockImplementation(() => null); |
| 163 | + }); |
| 164 | + |
| 165 | + afterEach(() => { |
| 166 | + setNextModelSpy.mockRestore(); |
| 167 | + }); |
| 168 | + |
| 169 | + function makePartitionedModel() { |
| 170 | + return irisGridTestUtils.makeModel( |
| 171 | + mockPartitionedTable as unknown as Parameters< |
| 172 | + typeof irisGridTestUtils.makeModel |
| 173 | + >[0] |
| 174 | + ); |
| 175 | + } |
| 176 | + |
| 177 | + it('does not swap model when the same config reference is set again', () => { |
| 178 | + const model = makePartitionedModel(); |
| 179 | + const config: PartitionConfig = { mode: 'partition', partitions: ['a'] }; |
| 180 | + model.partitionConfig = config; |
| 181 | + setNextModelSpy.mockClear(); |
| 182 | + model.partitionConfig = config; |
| 183 | + expect(setNextModelSpy).not.toHaveBeenCalled(); |
| 184 | + }); |
| 185 | + |
| 186 | + it('does not swap model when a structurally equal config is set', () => { |
| 187 | + const model = makePartitionedModel(); |
| 188 | + model.partitionConfig = { mode: 'partition', partitions: ['a'] }; |
| 189 | + setNextModelSpy.mockClear(); |
| 190 | + model.partitionConfig = { mode: 'partition', partitions: ['a'] }; |
| 191 | + expect(setNextModelSpy).not.toHaveBeenCalled(); |
| 192 | + }); |
| 193 | + |
| 194 | + it('swaps model when mode changes', () => { |
| 195 | + const model = makePartitionedModel(); |
| 196 | + model.partitionConfig = { mode: 'partition', partitions: ['a'] }; |
| 197 | + setNextModelSpy.mockClear(); |
| 198 | + model.partitionConfig = { mode: 'merged', partitions: ['a'] }; |
| 199 | + expect(setNextModelSpy).toHaveBeenCalled(); |
| 200 | + }); |
| 201 | + |
| 202 | + it('swaps model when partition values change', () => { |
| 203 | + const model = makePartitionedModel(); |
| 204 | + model.partitionConfig = { mode: 'partition', partitions: ['a'] }; |
| 205 | + setNextModelSpy.mockClear(); |
| 206 | + model.partitionConfig = { mode: 'partition', partitions: ['b'] }; |
| 207 | + expect(setNextModelSpy).toHaveBeenCalled(); |
| 208 | + }); |
| 209 | + }); |
| 210 | + |
139 | 211 | // Functions must be set on prototype |
140 | 212 | test('Proxies functions when necessary', () => { |
141 | 213 | const testFn = jest.fn(); |
|
0 commit comments