|
1 | 1 | import Neo4j, * as Neo4jMock from 'neo4j-driver';
|
2 |
| -import Neovis, { NEOVIS_DEFAULT_CONFIG, NEOVIS_ADVANCED_CONFIG, migrateFromOldConfig } from '../src/neovis'; |
| 2 | +import Neovis, { NEOVIS_DEFAULT_CONFIG, NEOVIS_ADVANCED_CONFIG, migrateFromOldConfig } from '../src/neovis'; |
3 | 3 | import { NeoVisEvents } from '../src/events';
|
4 | 4 | import * as testUtils from './testUtils';
|
5 | 5 |
|
@@ -357,6 +357,84 @@ describe('Neovis', () => {
|
357 | 357 | expect(neovis._data.nodes.get(1)).toHaveProperty('font', undefined);
|
358 | 358 | });
|
359 | 359 | });
|
| 360 | + describe('neovis non flat config test', () => { |
| 361 | + const imageUrl = 'https://visjs.org/images/visjs_logo.png'; |
| 362 | + const fontSize = 28; |
| 363 | + const fontColor = '#00FF00'; |
| 364 | + let config = { |
| 365 | + container_id: container_id, |
| 366 | + non_flat: true, |
| 367 | + labels: { |
| 368 | + [label1]: { |
| 369 | + 'static': { |
| 370 | + image: imageUrl, |
| 371 | + font: { |
| 372 | + 'size': fontSize, |
| 373 | + 'color': fontColor, |
| 374 | + } |
| 375 | + } |
| 376 | + } |
| 377 | + }, |
| 378 | + initial_cypher: initial_cypher |
| 379 | + }; |
| 380 | + beforeEach(() => { |
| 381 | + neovis = new Neovis(config); |
| 382 | + }); |
| 383 | + |
| 384 | + it('image field in config should reflect in node data', async () => { |
| 385 | + const node1 = testUtils.makeNode([label1]); |
| 386 | + testUtils.mockFullRunSubscribe({ |
| 387 | + [initial_cypher]: { |
| 388 | + default: [testUtils.makeRecord([node1])] |
| 389 | + } |
| 390 | + }); |
| 391 | + |
| 392 | + neovis.render(); |
| 393 | + await testUtils.neovisRenderDonePromise(neovis); |
| 394 | + expect(neovis._data.nodes.get(1)).toHaveProperty('image', imageUrl); |
| 395 | + }); |
| 396 | + |
| 397 | + it('image field for type not specified in config should not reflect in node data', async () => { |
| 398 | + const node1 = testUtils.makeNode([label2]); |
| 399 | + testUtils.mockFullRunSubscribe({ |
| 400 | + [initial_cypher]: { |
| 401 | + default: [testUtils.makeRecord([node1])] |
| 402 | + } |
| 403 | + }); |
| 404 | + |
| 405 | + neovis.render(); |
| 406 | + await testUtils.neovisRenderDonePromise(neovis); |
| 407 | + expect(neovis._data.nodes.get(1)).toHaveProperty('image', undefined); |
| 408 | + }); |
| 409 | + |
| 410 | + it('font field in config should reflect in node data', async () => { |
| 411 | + const node1 = testUtils.makeNode([label1]); |
| 412 | + testUtils.mockFullRunSubscribe({ |
| 413 | + [initial_cypher]: { |
| 414 | + default: [testUtils.makeRecord([node1])] |
| 415 | + } |
| 416 | + }); |
| 417 | + |
| 418 | + neovis.render(); |
| 419 | + await testUtils.neovisRenderDonePromise(neovis); |
| 420 | + expect(neovis._data.nodes.get(1).font).toBeDefined(); |
| 421 | + expect(neovis._data.nodes.get(1).font.size).toBe(fontSize); |
| 422 | + expect(neovis._data.nodes.get(1).font.color).toBe(fontColor); |
| 423 | + }); |
| 424 | + |
| 425 | + it('font field for type not specified in config should not reflect in node data', async () => { |
| 426 | + const node1 = testUtils.makeNode([label2]); |
| 427 | + testUtils.mockFullRunSubscribe({ |
| 428 | + [initial_cypher]: { |
| 429 | + default: [testUtils.makeRecord([node1])] |
| 430 | + } |
| 431 | + }); |
| 432 | + |
| 433 | + neovis.render(); |
| 434 | + await testUtils.neovisRenderDonePromise(neovis); |
| 435 | + expect(neovis._data.nodes.get(1)).toHaveProperty('font', undefined); |
| 436 | + }); |
| 437 | + }); |
360 | 438 |
|
361 | 439 | // TODO: After upgrading to merge config, type casting is failing due to not able to detect target type. A proper way
|
362 | 440 | // either let the user to define type casting or do it automaticlly need to be implemented.
|
@@ -472,7 +550,7 @@ describe('Neovis', () => {
|
472 | 550 | [label1]: {
|
473 | 551 | [NEOVIS_ADVANCED_CONFIG]: {
|
474 | 552 | 'function': {
|
475 |
| - 'label': () => {return intProperityValue;} |
| 553 | + 'label': () => intProperityValue |
476 | 554 | }
|
477 | 555 | }
|
478 | 556 | }
|
|
0 commit comments