|
7 | 7 |
|
8 | 8 | import { Storage } from '@kbn/kibana-utils-plugin/public'; |
9 | 9 | import { |
10 | | - PAGE_FILTER_STORAGE_KEY, |
| 10 | + GET_PAGE_FILTER_STORAGE_KEY, |
11 | 11 | migrateAlertPageControlsTo816, |
12 | 12 | } from './migrate_alert_page_controls'; |
| 13 | +import type { StartPlugins } from '../../../types'; |
13 | 14 |
|
14 | 15 | const OLD_FORMAT = { |
15 | 16 | viewMode: 'view', |
@@ -216,40 +217,94 @@ const NEW_FORMAT = { |
216 | 217 | }; |
217 | 218 | const storage = new Storage(localStorage); |
218 | 219 |
|
| 220 | +const mockPlugins = { |
| 221 | + spaces: { |
| 222 | + getActiveSpace: jest.fn().mockResolvedValue({ id: 'default' }), |
| 223 | + }, |
| 224 | +} as unknown as StartPlugins; |
| 225 | + |
219 | 226 | describe('migrateAlertPageControlsTo816', () => { |
220 | 227 | beforeEach(() => { |
221 | 228 | storage.clear(); |
222 | 229 | }); |
223 | | - it('should migrate the old format to the new format', () => { |
224 | | - storage.set(PAGE_FILTER_STORAGE_KEY, OLD_FORMAT); |
225 | | - migrateAlertPageControlsTo816(storage); |
226 | | - const migrated = storage.get(PAGE_FILTER_STORAGE_KEY); |
227 | | - expect(migrated).toMatchObject(NEW_FORMAT); |
228 | | - }); |
| 230 | + describe('Default space', () => { |
| 231 | + beforeEach(() => { |
| 232 | + if (mockPlugins.spaces?.getActiveSpace) { |
| 233 | + mockPlugins.spaces.getActiveSpace = jest.fn().mockResolvedValue({ id: 'default' }); |
| 234 | + } |
| 235 | + }); |
| 236 | + it('should migrate the old format to the new format', async () => { |
| 237 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(), OLD_FORMAT); |
| 238 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 239 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY()); |
| 240 | + expect(migrated).toMatchObject(NEW_FORMAT); |
| 241 | + }); |
229 | 242 |
|
230 | | - it('should be a no-op if the new format already exists', () => { |
231 | | - storage.set(PAGE_FILTER_STORAGE_KEY, NEW_FORMAT); |
232 | | - migrateAlertPageControlsTo816(storage); |
233 | | - const migrated = storage.get(PAGE_FILTER_STORAGE_KEY); |
234 | | - expect(migrated).toMatchObject(NEW_FORMAT); |
235 | | - }); |
| 243 | + it('should be a no-op if the new format already exists', async () => { |
| 244 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(), NEW_FORMAT); |
| 245 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 246 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY()); |
| 247 | + expect(migrated).toMatchObject(NEW_FORMAT); |
| 248 | + }); |
236 | 249 |
|
237 | | - it('should be a no-op if no value is present in localstorage for page filters ', () => { |
238 | | - migrateAlertPageControlsTo816(storage); |
239 | | - const migrated = storage.get(PAGE_FILTER_STORAGE_KEY); |
240 | | - expect(migrated).toBeNull(); |
| 250 | + it('should be a no-op if no value is present in localstorage for page filters ', async () => { |
| 251 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 252 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY()); |
| 253 | + expect(migrated).toBeNull(); |
| 254 | + }); |
| 255 | + |
| 256 | + it('should convert custom old format correctly', async () => { |
| 257 | + const MODIFIED_OLD_FORMAT = structuredClone(OLD_FORMAT); |
| 258 | + MODIFIED_OLD_FORMAT.panels['0'].explicitInput.hideExists = true; |
| 259 | + MODIFIED_OLD_FORMAT.chainingSystem = 'NONE'; |
| 260 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(), MODIFIED_OLD_FORMAT); |
| 261 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 262 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY()); |
| 263 | + const EXPECTED_NEW_FORMAT = structuredClone(NEW_FORMAT); |
| 264 | + EXPECTED_NEW_FORMAT.initialChildControlState['0'].hideExists = true; |
| 265 | + EXPECTED_NEW_FORMAT.chainingSystem = 'NONE'; |
| 266 | + expect(migrated).toMatchObject(EXPECTED_NEW_FORMAT); |
| 267 | + }); |
241 | 268 | }); |
242 | 269 |
|
243 | | - it('should convert custom old format correctly', () => { |
244 | | - const MODIFIED_OLD_FORMAT = structuredClone(OLD_FORMAT); |
245 | | - MODIFIED_OLD_FORMAT.panels['0'].explicitInput.hideExists = true; |
246 | | - MODIFIED_OLD_FORMAT.chainingSystem = 'NONE'; |
247 | | - storage.set(PAGE_FILTER_STORAGE_KEY, MODIFIED_OLD_FORMAT); |
248 | | - migrateAlertPageControlsTo816(storage); |
249 | | - const migrated = storage.get(PAGE_FILTER_STORAGE_KEY); |
250 | | - const EXPECTED_NEW_FORMAT = structuredClone(NEW_FORMAT); |
251 | | - EXPECTED_NEW_FORMAT.initialChildControlState['0'].hideExists = true; |
252 | | - EXPECTED_NEW_FORMAT.chainingSystem = 'NONE'; |
253 | | - expect(migrated).toMatchObject(EXPECTED_NEW_FORMAT); |
| 270 | + describe('Non Default space', () => { |
| 271 | + const nonDefaultSpaceId = 'space1'; |
| 272 | + beforeEach(() => { |
| 273 | + if (mockPlugins.spaces?.getActiveSpace) { |
| 274 | + mockPlugins.spaces.getActiveSpace = jest.fn().mockResolvedValue({ id: nonDefaultSpaceId }); |
| 275 | + } |
| 276 | + }); |
| 277 | + it('should migrate the old format to the new format', async () => { |
| 278 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId), OLD_FORMAT); |
| 279 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 280 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId)); |
| 281 | + expect(migrated).toMatchObject(NEW_FORMAT); |
| 282 | + }); |
| 283 | + |
| 284 | + it('should be a no-op if the new format already exists', async () => { |
| 285 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId), NEW_FORMAT); |
| 286 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 287 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId)); |
| 288 | + expect(migrated).toMatchObject(NEW_FORMAT); |
| 289 | + }); |
| 290 | + |
| 291 | + it('should be a no-op if no value is present in localstorage for page filters ', async () => { |
| 292 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 293 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId)); |
| 294 | + expect(migrated).toBeNull(); |
| 295 | + }); |
| 296 | + |
| 297 | + it('should convert custom old format correctly', async () => { |
| 298 | + const MODIFIED_OLD_FORMAT = structuredClone(OLD_FORMAT); |
| 299 | + MODIFIED_OLD_FORMAT.panels['0'].explicitInput.hideExists = true; |
| 300 | + MODIFIED_OLD_FORMAT.chainingSystem = 'NONE'; |
| 301 | + storage.set(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId), MODIFIED_OLD_FORMAT); |
| 302 | + await migrateAlertPageControlsTo816(storage, mockPlugins); |
| 303 | + const migrated = storage.get(GET_PAGE_FILTER_STORAGE_KEY(nonDefaultSpaceId)); |
| 304 | + const EXPECTED_NEW_FORMAT = structuredClone(NEW_FORMAT); |
| 305 | + EXPECTED_NEW_FORMAT.initialChildControlState['0'].hideExists = true; |
| 306 | + EXPECTED_NEW_FORMAT.chainingSystem = 'NONE'; |
| 307 | + expect(migrated).toMatchObject(EXPECTED_NEW_FORMAT); |
| 308 | + }); |
254 | 309 | }); |
255 | 310 | }); |
0 commit comments