123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import modelingModule from 'lib/features/modeling';
- describe('features/modeling - create label', function() {
- beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
- var rootShape, parentShape, childShape, childShape2, connection;
- beforeEach(inject(function(elementFactory, canvas) {
- rootShape = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(rootShape);
- parentShape = elementFactory.createShape({
- id: 'parent',
- x: 100, y: 100, width: 300, height: 300
- });
- canvas.addShape(parentShape, rootShape);
- childShape = elementFactory.createShape({
- id: 'child',
- x: 100, y: 100, width: 100, height: 100
- });
- canvas.addShape(childShape, parentShape);
- childShape2 = elementFactory.createShape({
- id: 'child2',
- x: 300, y: 100, width: 100, height: 100
- });
- canvas.addShape(childShape2, parentShape);
- connection = elementFactory.createConnection({
- id: 'connection',
- waypoints: [ { x: 150, y: 150 }, { x: 350, y: 150 } ],
- source: childShape,
- target: childShape2
- });
- canvas.addConnection(connection, parentShape);
- }));
- describe('on shapes', function() {
- var newLabel;
- beforeEach(inject(function(modeling) {
- // add new shape
- newLabel = modeling.createLabel(childShape, { x: 160, y: 250 });
- }));
- it('should return label', inject(function() {
- // when
- // label added
- // then
- expect(newLabel).to.exist;
- expect(newLabel.parent).to.equal(parentShape);
- }));
- it('should render label', inject(function(elementRegistry) {
- // when
- // label added
- // then
- expect(elementRegistry.getGraphics(newLabel)).to.exist;
- }));
- it('should maintain shape relationship', inject(function() {
- // when
- // label added
- // then
- expect(newLabel.labelTarget).to.equal(childShape);
- expect(childShape.label).to.equal(newLabel);
- }));
- it('should undo', inject(function(commandStack, elementRegistry) {
- // given
- // shape added
- // when
- commandStack.undo();
- // then
- expect(newLabel.parent).to.be.null;
- expect(newLabel.labelTarget).to.be.null;
- expect(childShape.label).not.to.exist;
- expect(elementRegistry.getGraphics(newLabel)).to.be.undefined;
- }));
- });
- describe('on connections', function() {
- var newLabel;
- beforeEach(inject(function(modeling) {
- // add new shape
- newLabel = modeling.createLabel(connection, { x: 160, y: 250 });
- }));
- it('should return label', inject(function() {
- // when
- // label added
- // then
- expect(newLabel).to.exist;
- }));
- it('should render label', inject(function(elementRegistry) {
- // when
- // label added
- // then
- expect(elementRegistry.getGraphics(newLabel)).to.exist;
- }));
- it('should maintain shape relationship', inject(function() {
- // when
- // label added
- // then
- expect(newLabel.labelTarget).to.equal(connection);
- expect(connection.label).to.equal(newLabel);
- }));
- it('should undo', inject(function(commandStack, elementRegistry) {
- // given
- // shape added
- // when
- commandStack.undo();
- // then
- expect(newLabel.parent).to.be.null;
- expect(newLabel.labelTarget).to.be.null;
- expect(connection.label).not.to.exist;
- expect(elementRegistry.getGraphics(newLabel)).to.be.undefined;
- }));
- });
- });
|