
import Ember from 'ember';

import { module, test } from 'qunit';

import d3 from 'd3';

module('Unit | Extensions', {
  beforeEach() {
    this.rect = d3.select('#ember-testing')
      .append('svg')
      .append('rect');
  },

  afterEach() {
    this.rect.remove();
    this.rect = null;
  }
});

test('d3.selection.prototype#style string setter', function (assert) {
  let expected = 'rgb(0, 0, 0)';
  let actual = this.rect
    .style('fill', expected)
    .style('fill');

  assert.equal(actual, expected);
});

test('d3.selection.prototype#style hash setter', function (assert) {
  let expected = 'rgb(0, 0, 0)';
  let actual = this.rect
    .style({ fill: expected })
    .style('fill');

  assert.equal(actual, expected);
});

test('d3.selection.prototype#style set url as string', function (assert) {
  let expected = `url(${location.pathname}${location.search}#target)`;
  let actual = this.rect
    .style('fill', 'url(#target)')
    .style('fill');

  assert.equal(actual, expected);
});

test('d3.selection.prototype#style set url as hash', function (assert) {
  let expected = `url(${location.pathname}${location.search}#target)`;
  let actual = this.rect
    .style({ 'fill': 'url(#target)' })
    .style('fill');

  assert.equal(actual, expected);
});

test('d3.transition.prototype#style string setter', function (assert) {
  return new Ember.RSVP.Promise(resolve => {
    let expected = 'rgb(255, 255, 255)';

    this.rect
      .style('fill', 'rgb(0, 0, 0)')
      .transition()
      .style('fill', expected)
      .each('end', function () {
        let actual = d3.select(this).style('fill');

        assert.equal(actual, expected);

        resolve();
      });
  });
});

test('d3.transition.prototype#style hash setter', function (assert) {
  return new Ember.RSVP.Promise(resolve => {
    let expected = 'rgb(255, 255, 255)';

    this.rect
      .style({ fill: 'rgb(0, 0, 0)' })
      .transition()
      .style({ fill: expected })
      .each('end', function () {
        let actual = d3.select(this).style('fill');

        assert.equal(actual, expected);

        resolve();
      });
  });
});

test('d3.selection.prototype#attr string setter', function (assert) {
  let expected = 'classy';
  let actual = this.rect
    .attr('class', expected)
    .attr('class');

  assert.equal(actual, expected);
});

test('d3.selection.prototype#attr hash setter', function (assert) {
  let expected = 'classy';
  let actual = this.rect
    .attr({ 'class': expected })
    .attr('class');

  assert.equal(actual, expected);
});

@@ -299,444 +299,8 @@
 );%0A%0A
-test('d3.selection.prototype#style string setter', function (assert) %7B%0A  let expected = 'rgb(0, 0, 0)';%0A  let actual = this.rect%0A    .style('fill', expected)%0A    .style('fill');%0A%0A  assert.equal(actual, expected);%0A%7D);%0A%0Atest('d3.selection.prototype#style hash setter', function (assert) %7B%0A  let expected = 'rgb(0, 0, 0)';%0A  let actual = this.rect%0A    .style(%7B fill: expected %7D)%0A    .style('fill');%0A%0A  assert.equal(actual, expected);%0A%7D);%0A%0A
 test
@@ -966,34 +966,20 @@
 cted = '
-rgb(255, 255, 255)
+20px
 ';%0A%0A    
@@ -1006,29 +1006,24 @@
 le('
-fill', 'rgb(0, 0, 0)'
+stroke-width', 0
 )%0A  
@@ -1054,20 +1054,28 @@
 .style('
-fill
+stroke-width
 ', expec
@@ -1148,36 +1148,44 @@
 ct(this).style('
-fill
+stroke-width
 ');%0A%0A        ass
@@ -1393,26 +1393,12 @@
  = '
-rgb(255, 255, 255)
+20px
 ';%0A%0A
@@ -1430,28 +1430,25 @@
 e(%7B 
-fill: 'rgb(0, 0, 0)'
+'stroke-width': 0
  %7D)%0A
@@ -1482,20 +1482,30 @@
 style(%7B 
-fill
+'stroke-width'
 : expect
@@ -1583,28 +1583,36 @@
 his).style('
-fill
+stroke-width
 ');%0A%0A       

fix test for phantom