<commit_before>SVGDocument = require '../src/svg-document'

Node = require '../src/node'
Path = require '../src/path'
SelectionModel = require '../src/selection-model'
ObjectEditor = require '../src/object-editor'

describe 'ObjectEditor', ->
  [canvas, svgDocument, model, editor, path] = []
  beforeEach ->
    canvas = document.createElement('canvas')
    jasmine.attachToDOM(canvas)
    svgDocument = new SVGDocument(canvas)
    model = svgDocument.getSelectionModel()

    editor = new ObjectEditor(svgDocument)
    path = new Path(svgDocument)
    path.addNode(new Node([50, 50], [-10, 0], [10, 0]))
    path.close()

  it 'ignores selection model when not active', ->
    expect(editor.isActive()).toBe false
    expect(editor.getActiveObject()).toBe null
    model.setSelected(path)
    expect(editor.isActive()).toBe false
    expect(editor.getActiveObject()).toBe null

  describe "when the ObjectEditor is active", ->
    beforeEach ->
      editor.activate()
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe null

    it 'activates the editor associated with the selected object', ->
      model.setSelected(path)
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe path
      expect(canvas.querySelector('svg circle.node-editor-node')).toShow()

      model.clearSelected()
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe null
      expect(canvas.querySelector('svg circle.node-editor-node')).toHide()
<commit_msg>Spec to ensure the object editor uses selected on activate<commit_after>SVGDocument = require '../src/svg-document'

Node = require '../src/node'
Path = require '../src/path'
SelectionModel = require '../src/selection-model'
ObjectEditor = require '../src/object-editor'

describe 'ObjectEditor', ->
  [canvas, svgDocument, model, editor, path] = []
  beforeEach ->
    canvas = document.createElement('canvas')
    jasmine.attachToDOM(canvas)
    svgDocument = new SVGDocument(canvas)
    model = svgDocument.getSelectionModel()

    editor = new ObjectEditor(svgDocument)
    path = new Path(svgDocument)
    path.addNode(new Node([50, 50], [-10, 0], [10, 0]))
    path.close()

  it 'ignores selection model when not active', ->
    expect(editor.isActive()).toBe false
    expect(editor.getActiveObject()).toBe null
    model.setSelected(path)
    expect(editor.isActive()).toBe false
    expect(editor.getActiveObject()).toBe null

  describe "when there are selected objects before the editor becomes active", ->
    beforeEach ->
      model.setSelected(path)
      model.setSelectedNode(path.getNodes()[0])

    it 'activates the editor associated with the selected object', ->
      editor.activate()
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe path.getNodes()[0]

  describe "when the ObjectEditor is active", ->
    beforeEach ->
      editor.activate()
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe null

    it 'activates the editor associated with the selected object', ->
      model.setSelected(path)
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe path
      expect(canvas.querySelector('svg circle.node-editor-node')).toShow()

      model.clearSelected()
      expect(editor.isActive()).toBe true
      expect(editor.getActiveObject()).toBe null
      expect(canvas.querySelector('svg circle.node-editor-node')).toHide()

{'fraction_non_alphanumeric': 0.1347254004576659, 'fraction_numerical': 0.006292906178489702, 'mean_word_length': 3.7065948855989235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6320241', 'n_tokens_mistral': 979, 'n_tokens_neox': 954, 'n_words': 229}