{"size": 1816, "ext": "js", "max_stars_repo_path": "test/spec/xml/edit.js", "max_stars_repo_name": "davcs86/pfdn-moddle", "max_stars_repo_stars_event_min_datetime": "2018-01-23T00:26:58.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-23T00:38:03.000Z", "max_issues_repo_path": "test/spec/xml/edit.js", "max_issues_repo_name": "davcs86/pfdn-moddle", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/spec/xml/edit.js", "max_forks_repo_name": "davcs86/pfdn-moddle", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8947368421, "max_line_length": 121, "alphanum_fraction": 0.5886563877}
'use strict';

var XMLHelper = require('../../xml-helper'),
    Helper = require('../../helper');

var toXML = XMLHelper.toXML;


describe('bpmn-moddle - edit', function() {

  var moddle = Helper.createModdle();

  function fromFile(file, done) {
    XMLHelper.fromFile(moddle, file, done);
  }


  describe('save after change', function() {

    it('should serialize changed name', function(done) {

      // given
      fromFile('test/fixtures/bpmn/simple.bpmn', function(err, result) {

        if (err) {
          return done(err);
        }

        result.rootElements[0].name = 'OTHER PROCESS';

        // when
        toXML(result, { format: true }, function(err, xml) {
          expect(xml).to.contain('name="OTHER PROCESS"');

          done(err);
        });
      });

    });

  });


  describe('dataObjectRef', function() {

    it('should update', function(done) {

      fromFile('test/fixtures/bpmn/data-object-reference.bpmn', function(err, result) {

        // given
        var process = result.rootElements[0],
            dataObjectReference = process.flowElements[0];

        // when
        // creating new data object
        var dataObject_2 = moddle.create('bpmn:DataObject', { id: 'dataObject_2' });

        // adding data object to its parent (makes sure it is contained in the XML)
        process.flowElements.push(dataObject_2);

        // set reference to the new data object
        dataObjectReference.dataObjectRef = dataObject_2;

        toXML(result, { format: true }, function(err, xml) {

          // then
          expect(xml).to.contain('<bpmn:dataObject id="dataObject_2" />');
          expect(xml).to.contain('<bpmn:dataObjectReference id="DataObjectReference_1" dataObjectRef="dataObject_2" />');

          done(err);
        });

      });
    });
  });
});