'use strict'

let describe = global.describe
let it = global.it

var assert = require('assert')
let parseCss = require('../src/cssParser').parseCss
var state = require('../src/state')

describe('css parser', function() {
  before(function() {
    this.timeout(5000)
    global.window = {
      document: {
        createElementNS: function() {
          return {}
        },
      },
    }
    global.navigator = {}
    let jsPDF = require('jspdf')
    require('../src/main')
    state.setupState(new jsPDF())
  })

  after(function() {
    state.resetState()
  })

  it('normal styles', function() {
    global.window = {
      getComputedStyle: function() {
        return {
          fontFamily: 'Times',
          borderColor: 'rgba(0, 0, 0, 0)',
          fontStyle: 'italic',
          fontWeight: 'bold',
          backgroundColor: 'rgba(240, 255, 255, 1)',
          color: 'rgb(50, 50, 50)',
          textAlign: 'center',
          verticalAlign: 'top',
          fontSize: '16px',
          padding: '5px',
          borderTopWidth: '2px',
        }
      },
    }

    let pxScaleFactor = 96 / 72
    let styles = parseCss({}, 1)
    assert(styles, 'Should have result')
    assert(!styles.lineColor, 'Transparent color')
    assert(styles.fillColor, 'Parse color')
    assert(styles.halign === 'center', 'Horizontal align')
    assert(styles.valign === 'top', 'String value')
    assert.equal(styles.cellPadding.top, 5 / pxScaleFactor, 'Cell padding')
    assert.equal(styles.lineWidth, 2 / pxScaleFactor, 'Line width')

    delete global.window
  })

  it('minimal styles', function() {
    global.window = {
      getComputedStyle: function() {
        return {
          backgroundColor: 'transparent',
          textAlign: '',
          verticalAlign: '',
          padding: '',
          fontStyle: 'normal',
          fontWeight: 'normal',
          fontSize: '',
          borderWidth: '',
          display: 'none',
        }
      },
    }

    let styles = parseCss({}, 1)
    assert(styles, 'Should have result')
    assert(!styles.fillColor, 'Transparent')
    assert(!styles.halign, 'Empty string halign')
    assert(!styles.valign, 'Empty tring valign')
    assert(!styles.cellPadding, 'Empty string padding')
    assert(!styles.fontStyle, 'No font style')
    assert(!styles.fontSize, 'No font size')

    delete global.window
  })
})

@@ -1002,16 +1002,112 @@
  padding
+Top: '5px',%0A          paddingLeft: '5px',%0A          paddingRight: '5px',%0A          paddingBottom
 : '5px',
@@ -1099,32 +1099,32 @@
 gBottom: '5px',%0A
-
           border
@@ -1223,32 +1223,56 @@
 parseCss(%7B%7D, 1)%0A
+    console.log(styles)%0A
     assert(style
@@ -1645,16 +1645,83 @@
  width')
+%0A    assert(styles.fontSize === 16 / pxScaleFactor, 'No font size')
 %0A%0A    de
@@ -1889,19 +1889,24 @@
 r: '
-transparent
+rgba(0, 0, 0, 0)
 ',%0A 
@@ -1918,32 +1918,40 @@
     textAlign: '
+baseline
 ',%0A          ver
@@ -1963,16 +1963,21 @@
 Align: '
+start
 ',%0A     
@@ -1988,19 +1988,118 @@
  padding
-: '
+Top: '0px',%0A          paddingLeft: '0px',%0A          paddingRight: '0px',%0A          paddingBottom: '0px
 ',%0A     
@@ -2160,32 +2160,8 @@
 l',%0A
-          fontSize: '',%0A
     
@@ -2180,16 +2180,19 @@
 Width: '
+0px
 ',%0A     
@@ -2487,16 +2487,20 @@
 lPadding
+.top
 , 'Empty
@@ -2567,53 +2567,8 @@
 le')
-%0A    assert(!styles.fontSize, 'No font size')
 %0A%0A  

Fix cssParser tests