Commit 1f566339 authored by Jozef Bátrna's avatar Jozef Bátrna
Browse files

added hierarchy tests for tags, fixed errors with tags (bundling duplicate...

added hierarchy tests for tags, fixed errors with tags (bundling duplicate tags, nodes dont have vis.tags yet)
parent 81c5ef8c
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ export function filterTagsByNodeId(tags, id) {
 * @param {number} groupNodeId
 */
function createTag(tags, objects, assignedObjectsIds, tagId, name, color, type, groupNodeId) {
  if (tags.find(t => t.name === name)) {
  if (type != 'bundle' && tags.find(t => t.name === name)) {
    throw Error('Tag with the same name already exists'); // FIXME: custom
  }

@@ -232,10 +232,11 @@ export function updateTags(tags, objects, arrIds, action, groupNode, color) {
      // if adding additional nodes to bundle, only update the tag, do not create new one
    } else if (action === 'bundle' && tag.groupNodeId === groupNode.id) {
      arrIds.forEach(id => {
        let obj = objects.find(o => o.id === id);

        obj.vis.tags.push(id);
        if (!tag.assignedObjectsIds.includes(id)) {
          //let obj = objects.find(o => o.id === id)
          //obj.vis.tags.push(id)  // FIXME: dataset doesn't have vis.tags
          tag.assignedObjectsIds.push(id);
        }
      });
      tag.name = groupNode.label;
      return;
+254 −50
Original line number Diff line number Diff line
/* eslint-disable prettier/prettier */
import { mutations, updateTags } from '@/store/modules/data/tags.js'
import { mutations, updateTags } from '@/store/modules/data/tags.js';

describe('store/data/tags/TAG_NODES', () => {
  it('adds 1 tag to 1 regular node', () => {
@@ -7,7 +7,7 @@ describe('store/data/tags/TAG_NODES', () => {
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'regular', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [0],
        id: 0,
@@ -29,18 +29,18 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    mutations.TAG_NODES(state, payload)
    expect(state).toEqual(expectedState)
  })
    mutations.TAG_NODES(state, payload);
    expect(state).toEqual(expectedState);
  });

  it('adds 1 tag without specified tag name to 1 regular node', () => {
    const nodes = [
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'regular', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [1],
        id: 0,
@@ -62,12 +62,12 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    mutations.TAG_NODES(state, payload)
    mutations.TAG_NODES(state, payload);

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  // still manual, other types are only assigned through AGGREGATE_NODES
  // so it has to be tested in data store
@@ -76,7 +76,7 @@ describe('store/data/tags/TAG_NODES', () => {
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'group', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [1],
        id: 0,
@@ -98,19 +98,19 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    mutations.TAG_NODES(state, payload)
    mutations.TAG_NODES(state, payload);

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  it('adds second tag to multiple regular nodes', () => {
    const nodes = [
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'group', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [0, 2],
        id: 1,
@@ -156,12 +156,12 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    mutations.TAG_NODES(state, payload)
    mutations.TAG_NODES(state, payload);

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  // should throw
  it('try to add the tag with the same name to node which already has it', () => {
@@ -169,7 +169,7 @@ describe('store/data/tags/TAG_NODES', () => {
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'group', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [0],
        id: 0,
@@ -205,14 +205,14 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    expect(() => {
      mutations.TAG_NODES(state, payload)
    }).toThrow()
      mutations.TAG_NODES(state, payload);
    }).toThrow();

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  // should pass - we can have a selection "classmates" and "murderers"
  it('try to add the tag to the same array of assigned nodes', () => {
@@ -220,7 +220,7 @@ describe('store/data/tags/TAG_NODES', () => {
      { id: 0, type: 'regular', vis: { tags: [] } },
      { id: 1, type: 'group', vis: { tags: [] } },
      { id: 2, type: 'regular', vis: { tags: [] } }
    ]
    ];
    const payload = {
        arr: [0, 1, 2],
        id: 1,
@@ -266,13 +266,13 @@ describe('store/data/tags/TAG_NODES', () => {
          }
        ],
        nodes: nodes
      }
      };

    mutations.TAG_NODES(state, payload)
    mutations.TAG_NODES(state, payload);

    expect(state).toEqual(expectedState)
  })
})
    expect(state).toEqual(expectedState);
  });
});

describe('store/data/tags/updateTags', () => {
  it('simulate grouping by updating tag on grouped nodes', () => {
@@ -284,7 +284,7 @@ describe('store/data/tags/updateTags', () => {
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode
      ]
      ];

    const state = {
        tags: []
@@ -302,12 +302,12 @@ describe('store/data/tags/updateTags', () => {
            type: 'group'
          }
        ]
      }
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000')
    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000');

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  // TODO should it also update the tag name to group label? (it does now)
  // assign tag to nodes which already have it, but didnt have group node
@@ -320,7 +320,7 @@ describe('store/data/tags/updateTags', () => {
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode
      ]
      ];

    const state = {
        tags: [
@@ -348,14 +348,14 @@ describe('store/data/tags/updateTags', () => {
            type: 'group'
          }
        ]
      }
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000')
    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000');

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  it('update bundled node by adding new nodes to the same tag', () => {
  it('bundle into existing bundle', () => {
    const nodesToGroupIds = [2],
      action = 'bundle',
      groupNode = { id: 3, type: 'bundle', label: 'group label', vis: { tags: [] } },
@@ -364,7 +364,7 @@ describe('store/data/tags/updateTags', () => {
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode
      ]
      ];

    const state = {
        tags: [
@@ -393,12 +393,216 @@ describe('store/data/tags/updateTags', () => {
            type: 'bundle'
          }
        ]
      }
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000')
    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000');

    expect(state).toEqual(expectedState)
  })
    expect(state).toEqual(expectedState);
  });

  // TODO: test hierarchy of grouping--agregation of tags
})
  it('bundle into existing group', () => {
    const nodesToGroupIds = [2],
      action = 'bundle',
      groupNode = { id: 3, type: 'group', label: 'group 0', vis: { tags: [] } },
      stateNodes = [
        { id: 0, type: 'regular', vis: { tags: [] } },
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode
      ];

    const state = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          }
        ]
      },
      expectedState = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1, 2],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          }
        ]
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode, '#000000');

    expect(state).toEqual(expectedState);
  });

  it('group two groups', () => {
    const nodesToGroupIds = [3, 5],
      action = 'group',
      groupNode = { id: 3, type: 'group', label: 'group 0', vis: { tags: [] } },
      groupNode2 = { id: 5, type: 'group', label: 'group 1', vis: { tags: [] } },
      groupNode3 = { id: 6, type: 'group', label: 'group 2', vis: { tags: [] } },
      stateNodes = [
        { id: 0, type: 'regular', vis: { tags: [] } },
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode,
        { id: 4, type: 'regular', vis: { tags: [] } },
        groupNode2,
        groupNode3
      ];

    const state = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          },
          {
            id: 1,
            name: 'group 1',
            groupNodeId: groupNode2.id,
            assignedObjectsIds: [2, 4],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          }
        ]
      },
      expectedState = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          },
          {
            id: 1,
            name: 'group 1',
            groupNodeId: groupNode2.id,
            assignedObjectsIds: [2, 4],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          },
          {
            id: 2,
            name: 'group 2',
            groupNodeId: groupNode3.id,
            assignedObjectsIds: [3, 5],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          }
        ]
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode3, '#000000');

    expect(state).toEqual(expectedState);
  });

  it('alias two aggregations (group and a bundle)', () => {
    const nodesToGroupIds = [3, 5],
      action = 'alias',
      groupNode = { id: 3, type: 'group', label: 'group 0', vis: { tags: [] } },
      groupNode2 = { id: 5, type: 'bundle', label: 'group 1', vis: { tags: [] } },
      groupNode3 = { id: 6, type: 'alias', label: 'group 2', vis: { tags: [] } },
      stateNodes = [
        { id: 0, type: 'regular', vis: { tags: [] } },
        { id: 1, type: 'regular', vis: { tags: [] } },
        { id: 2, type: 'regular', vis: { tags: [] } },
        groupNode,
        { id: 4, type: 'regular', vis: { tags: [] } },
        groupNode2,
        groupNode3
      ];

    const state = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          },
          {
            id: 1,
            name: 'group 1',
            groupNodeId: groupNode2.id,
            assignedObjectsIds: [2, 4],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'bundle'
          }
        ]
      },
      expectedState = {
        tags: [
          {
            id: 0,
            name: 'group 0',
            groupNodeId: groupNode.id,
            assignedObjectsIds: [0, 1],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'group'
          },
          {
            id: 1,
            name: 'group 1',
            groupNodeId: groupNode2.id,
            assignedObjectsIds: [2, 4],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'bundle'
          },
          {
            id: 2,
            name: 'group 2',
            groupNodeId: groupNode3.id,
            assignedObjectsIds: [3, 5],
            isVisualized: true,
            color: '#000000',
            stroke: 'none',
            type: 'alias'
          }
        ]
      };

    updateTags(state.tags, stateNodes, nodesToGroupIds, action, groupNode3, '#000000');

    expect(state).toEqual(expectedState);
  });
});