<commit_before>'use babel'

/* @flow */

/* eslint-disable prefer-const */

import { Range, Point } from 'atom'
import Editor from '../lib/editor'
import { it, wait, getMessage, generateEvent } from './helpers'

describe('Editor', function() {
  let editor
  let message
  let textEditor

  beforeEach(function() {
    message = getMessage()
    message.range = [[2, 0], [2, 1]]
    message.filePath = __filename
    waitsForPromise(function() {
      return atom.workspace.open(__filename).then(function() {
        textEditor = atom.workspace.getActiveTextEditor()
        editor = new Editor(textEditor, true)
      })
    })
  })
  afterEach(function() {
    editor.dispose()
    atom.workspace.destroyActivePaneItem()
  })

  describe('apply', function() {
    it('applies the messages to the editor', function() {
      expect(textEditor.getMarkerCount()).toBe(0)
      editor.apply([message], [])
      expect(textEditor.getMarkerCount()).toBe(1)
      editor.apply([], [message])
      expect(textEditor.getMarkerCount()).toBe(0)
    })
    it('makes sure that the message is updated if text is manipulated', function() {
      expect(textEditor.getMarkerCount()).toBe(0)
      editor.apply([message], [])
      expect(textEditor.getMarkerCount()).toBe(1)
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 1 } })
      textEditor.getBuffer().insert([2, 0], 'Hello')
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 6 } })
      editor.apply([], [message])
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 6 } })
      expect(textEditor.getMarkerCount()).toBe(0)
    })
  })
  describe('Response to config', function() {
    it('responds to `tooltipFollows` config', async function() {
      const position = [2, 1]
      const editorElement = atom.views.getView(textEditor)
      editor.apply([
        getMessage('Error', __filename, Range.fromObject([position, [Infinity, Infinity]]))
      ], [])

      atom.config.set('linter-ui-default.tooltipFollows', 'Keyboard')
      expect(editor.bubble).toBe(null)
      textEditor.setCursorBufferPosition(position)
      await wait(60)
      expect(editor.bubble).not.toBe(null)
      expect(typeof editor.bubble.destroy).toBe('function')

      atom.config.set('linter-ui-default.tooltipFollows', 'Mouse')
      expect(editor.bubble).toBe(null)
      const event = generateEvent(editorElement, 'mousemove')
      Object.defineProperty(event, 'target', { value: editorElement })
      editorElement.dispatchEvent(event)
      spyOn(textEditor, 'bufferPositionForScreenPosition').andCallFake(function() {
        return Point.fromObject(position)
      })
      await wait(200)
      expect(editor.bubble).not.toBe(null)
      expect(typeof editor.bubble.destroy).toBe('function')
    })<commit_msg>:bug: Fix the specs to pass with new behavior<commit_after>'use babel'

/* @flow */

/* eslint-disable prefer-const */

import { Range, Point } from 'atom'
import Editor from '../lib/editor'
import { it, wait, getMessage, generateEvent } from './helpers'

describe('Editor', function() {
  let editor
  let message
  let textEditor

  beforeEach(function() {
    message = getMessage()
    message.range = [[2, 0], [2, 1]]
    message.filePath = __filename
    waitsForPromise(function() {
      return atom.workspace.open(__filename).then(function() {
        textEditor = atom.workspace.getActiveTextEditor()
        editor = new Editor(textEditor, true)
      })
    })
  })
  afterEach(function() {
    editor.dispose()
    atom.workspace.destroyActivePaneItem()
  })

  describe('apply', function() {
    it('applies the messages to the editor', function() {
      expect(textEditor.getMarkerCount()).toBe(0)
      editor.apply([message], [])
      expect(textEditor.getMarkerCount()).toBe(1)
      editor.apply([], [message])
      expect(textEditor.getMarkerCount()).toBe(0)
    })
    it('makes sure that the message is updated if text is manipulated', function() {
      expect(textEditor.getMarkerCount()).toBe(0)
      editor.apply([message], [])
      expect(textEditor.getMarkerCount()).toBe(1)
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 1 } })
      textEditor.getBuffer().insert([2, 0], 'Hello')
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 6 } })
      editor.apply([], [message])
      expect(Range.fromObject(message.range)).toEqual({ start: { row: 2, column: 0 }, end: { row: 2, column: 6 } })
      expect(textEditor.getMarkerCount()).toBe(0)
    })
  })
  describe('Response to config', function() {
    it('responds to `tooltipFollows` config', async function() {
      const position = [2, 1]
      const editorElement = atom.views.getView(textEditor)
      editor.apply([
        getMessage('Error', __filename, Range.fromObject([position, [Infinity, Infinity]]))
      ], [])

      atom.config.set('linter-ui-default.tooltipFollows', 'Keyboard')
      expect(editor.bubble).toBe(null)
      textEditor.setCursorBufferPosition(position)
      await wait(60)
      expect(editor.bubble).not.toBe(null)
      expect(typeof editor.bubble.destroy).toBe('function')

      const pixelPosition = { top: 0, left: 0 }
      atom.config.set('linter-ui-default.tooltipFollows', 'Mouse')
      expect(editor.bubble).toBe(null)
      const event = generateEvent(editorElement, 'mousemove')
      Object.defineProperty(event, 'target', { value: editorElement })
      editorElement.dispatchEvent(event)
      spyOn(textEditor, 'bufferPositionForScreenPosition').andCallFake(function() {
        return Point.fromObject(position)
      })
      spyOn(textEditor, 'pixelPositionForScreenPosition').andCallFake(function() {
        return pixelPosition
      })
      spyOn(editorElement.component, 'pixelPositionForMouseEvent').andCallFake(function() {
        return pixelPosition
      })
      await wait(200)
      expect(editor.bubble).not.toBe(null)
      expect(typeof editor.bubble.destroy).toBe('function')
    })
{'fraction_non_alphanumeric': 0.15194574519618925, 'fraction_numerical': 0.010334248344905539, 'mean_word_length': 3.551065393093314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2805895', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1834, 'n_words': 368}