import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('read-more', 'Integration | Component | read more', {
  integration: true
});

test('should have correct state classes', function(assert) {
  assert.expect(2);

  this.render(hbs`{{read-more}}`);
  assert.equal(this.$(':first-child').hasClass('is-closed'), true, 'it has label is-closed');

  this.render(hbs`{{read-more isOpen=true}}`);
  assert.equal(this.$(':first-child').hasClass('is-open'), true, 'it has label is-open');
});

test('should toggle link text on click', function(assert) {
  assert.expect(2);

  this.render(hbs`{{read-more}}`);

  // click the toggle link
  this.$('a').click();
  assert.equal(this.$('a').text().trim(), 'Close', 'link text is "Close"');

  // click the toggle link
  this.$('a').click();
  assert.equal(this.$('a').text().trim(), 'Read more', 'link text is "Read more"');
});

test('should trigger onOpen action', function(assert) {
  assert.expect(1);

  // test double for the external action
  this.set('externalAction', () => {
    assert.ok('onOpen triggered');
  });

  this.render(hbs`{{read-more onOpen=(action externalAction)}}`);

  // click the toggle link
  this.$('a').click();
});

test('should trigger onClose action', function(assert) {
  assert.expect(1);

  // test double for the external action
  this.set('externalAction', () => {
    assert.ok('onClose triggered');
  });

  this.render(hbs`{{read-more isOpen=true onClose=(action externalAction)}}`);

  // click the toggle link
  this.$('a').click();
});

@@ -216,16 +216,20 @@
 ave 
+the 
 correct 
 stat
@@ -228,21 +228,26 @@
 ect 
-state classes
+class when is open
 ', f
@@ -314,22 +314,126 @@
 ead-more
+ isOpen=true
 %7D%7D%60);%0A
+  assert.equal(this.$(':first-child').hasClass('is-open'), true, 'it has class %60is-open%60');%0A
   assert
@@ -489,38 +489,146 @@
 '), 
-tru
+fals
 e, 'it 
-has label is-
+doesn%5C't have class %60is-open%60');%0A%7D);%0A%0Atest('should have the correct class when is 
 closed'
+, function(assert) %7B%0A  assert.expect(2
 );%0A%0A
@@ -656,35 +656,36 @@
 ead-more isOpen=
-tru
+fals
 e%7D%7D%60);%0A  assert.
@@ -725,32 +725,137 @@
 lass('is-open'),
+ false, 'it doesn%5C't have class %60is-open%60');%0A  assert.equal(this.$(':first-child').hasClass('is-closed'),
  true, 'it has l
@@ -857,21 +857,23 @@
 has 
+c
 la
-bel 
+ss %60
 is-open
+%60
 ');%0A
@@ -897,25 +897,33 @@
  toggle 
-link text
+%60isOpen%60 property
  on clic
@@ -958,32 +958,62 @@
 ert.expect(2);%0A%0A
+  this.set('isOpen', false);%0A%0A
   this.render(hb
@@ -1025,16 +1025,30 @@
 ead-more
+ isOpen=isOpen
 %7D%7D%60);%0A%0A 
@@ -1120,60 +1120,48 @@
 his.
-$('a').text().trim(), 'Close', 'link text is %22Close%22
+get('isOpen'), true, '%60isOpen%60 is %60true%60
 ');%0A
@@ -1235,66 +1235,403 @@
 his.
-$('a').text().trim(), 'Read more', 'link text is %22Read mor
+get('isOpen'), false, '%60isOpen%60 is %60false%60');%0A%7D);%0A%0Atest('should have correct toggle text', function(assert) %7B%0A  assert.expect(2);%0A%0A  this.set('isOpen', false);%0A%0A  this.render(hbs%60%7B%7Bread-more isOpen=isOpen%7D%7D%60);%0A%0A  assert.equal(this.$('a').text().trim(), 'Read more', 'link text is %22Read more%22');%0A%0A  this.set('isOpen', true);%0A%0A  assert.equal(this.$('a').text().trim(), 'Close', 'link text is %22Clos
 e%22')
@@ -1658,22 +1658,24 @@
 trigger 
+%60
 onOpen
+%60
  action'
@@ -1979,23 +1979,25 @@
 trigger 
+%60
 onClose
+%60
  action'

Add and fix some tests