 shouldSinon = require 'should-sinon'
 Utils = require '../../lib/utils/index'
 
+# Preparation function for simulating
+# a text selection.
+selectDummyElement = (innerText = 'dummy data') ->
+  text             = document.createElement 'div'
+  text.innerHTML   = innerText
+  selection        = window.getSelection()
+  range            = document.createRange()
+
+  document.body.appendChild text
+
+  range.selectNodeContents text
+  selection.removeAllRanges()
+  selection.addRange range
+
+  return text
 
 describe 'Utils', ->
   beforeEach ->

    Utils.formatIndefiniteArticle('car').should.equal 'a car'
    Utils.formatIndefiniteArticle('apple').should.equal 'an apple'

  it 'should throw error on missing api key on shorten url', ->
    @faulty = ->
      Utils.shortenUrl 'https://koding.com', (->)

    @faulty().should.throw

  # it 'should create external link', ->
  #   appendChildSpy = sinon.spy document.body.appendChild
  #   removeChildSpy = sinon.spy document.body.removeChild
  #   Utils.createExternalLink 'http://koding.com'
  #   appendChildSpy.should.be.calledOnce
  #   removeChildSpy.should.be.calledOnce

  it 'should check if touch device', ->
    Utils.isTouchDevice().should.equal no


  it 'exists', ->
    Utils.should.exist

  it 'should extend', ->
    target = {}
    firstSource = { a: 1, b: 2 }
    secondSource = { c: 3, d: 4 }

    extended = Utils.extend target, firstSource, secondSource

    expected = { a: 1, b: 2, c: 3, d: 4 }

    extended.should.deepEqual expected

  it 'should show an element', ->
    @el.classList = 'hidden'
