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

moduleForComponent('ember-youtube', 'Integration | Component | ember youtube', {
	integration: true
});

test('it renders', function (assert) {
	assert.expect(2);
	// Set any properties with this.set('myProperty', 'value');
	// Handle any actions with this.on('myAction', function(val) { ... });" + EOL + EOL +

	this.render(hbs`{{ember-youtube}}`);

	assert.equal(this.$().text().trim(), '', 'starts empty');

	// Template block usage:" + EOL +
	this.render(hbs`
		{{#ember-youtube}}
			template block text
		{{/ember-youtube}}
	`);
	assert.equal(this.$('.EmberYoutube-yield').text().trim(), 'template block text', 'yield is wrapped in an extra <div>');
});

test('it can show and remove controls', function (assert) {
	assert.expect(3);
	this.set('controls', true);
	this.render(hbs`{{ember-youtube showControls=controls}}`);
	assert.ok(this.$('.EmberYoutube-controls button').length);
	assert.equal(this.$('.EmberYoutube-controls button').eq(0).text().trim(), 'Play');
	this.set('controls', false);
	assert.notOk(this.$('.EmberYoutube-controls button').length);
});

test('it can show and hide progress', function (assert) {
	assert.expect(2);
	this.set('progress', false);
	this.render(hbs`{{ember-youtube showProgress=progress}}`);
	assert.equal(this.$('.EmberYoutube-progress').length, 0, 'Progress is hidden by default');
	this.set('progress', true);
	assert.equal(this.$('.EmberYoutube-progress').length, 1, 'Progress can be shown');
});

test('it has an iframe', function (assert) {
	const done = assert.async();
	this.set('youtubeVideoId', 'fZ7MhTRmJ60');
	this.render(hbs`{{ember-youtube ytid=youtubeVideoId}}`);
	// It takes some time before the youtube api is loaded,
	// how do we avoid the timeout?
	Ember.run.later(this, function () {
		assert.ok(this.$('iframe').length);
		done();
	}, 1000);
});

@@ -1,12 +1,15 @@
+// 
 import Ember
@@ -77,16 +77,60 @@
 qunit';%0A
+import wait from 'ember-test-helpers/wait';%0A
 import h
@@ -286,549 +286,1016 @@
 'it 
-renders', function (assert) %7B%0A%09assert.expect(2);%0A%09// Set any properties with this.set('myProperty', 'value');%0A%09// Handle any actions with this.on('myAction', function(val) %7B ... %7D);%22 + EOL + EOL +%0A%0A%09this.render(hbs%60%7B%7Bember-youtube%7D%7D%60);%0A%0A%09assert.equal(this.$().text().trim(), '', 'starts empty');%0A%0A%09// Template block usage:%22 + EOL +%0A%09this.render(hbs%60%0A%09%09%7B%7B#ember-youtube%7D%7D%0A%09%09%09template block text%0A%09%09%7B%7B/ember-youtube%7D%7D%0A%09%60);%0A%09assert.equal(this.$('.EmberYoutube-yield').text().trim(), 'template block t
+loads the youtubeapi and create an iframe', function (assert) %7B%0A%09this.set('youTubeId', 'w311Hd4K_Fk');%0A%09this.render(hbs%60%7B%7Bember-youtube ytid=youTubeId%7D%7D%60);%0A%09return wait().then(() =%3E %7B%0A%09%09return wait().then(() =%3E %7B%0A%09%09%09// it needs a double wait for whatever reason%0A%09%09%09assert.ok(this.$('iframe').length, 'has iframe');%0A%09%09%7D);%0A%09%7D);%0A%7D);%0A%0A// Todo: create a promise so we can assert autoplay is working%0A// test('it can autoplay', function (assert) %7B%0A// %09this.set('youTubeId', 'w311Hd4K_Fk');%0A// %09this.set('myPlayerVars', %7Bautoplay: 1%7D);%0A// %09this.render(hbs%60%7B%7Bember-youtube ytid=youTubeId showControls=true playerVars=myPlayerVars%7D%7D%60);%0A// %09// console.log(this.$('.EmberYoutube-controls button').eq(0).text());%0A// %09return wait().then(() =%3E %7B%0A// %09%09// it needs a double wait for whatever reason%0A// %09%09return wait().then(() =%3E %7B%0A// %09%09%09assert.ok(this.$('iframe').length, 'has iframe');%0A// %09%09%09// var btnText = this.$('.EmberYoutube-controls button').eq(0).text();%0A// %09%09%09// assert.equal(btnT
 ext
-'
 , '
-yield is wrapped in an extra %3Cdiv%3E');%0A
+pause');%0A// %09%09%7D);%0A// %09%7D);%0A// 
 %7D);%0A
@@ -2085,372 +2085,4 @@
 %7D);%0A
-%0Atest('it has an iframe', function (assert) %7B%0A%09const done = assert.async();%0A%09this.set('youtubeVideoId', 'fZ7MhTRmJ60');%0A%09this.render(hbs%60%7B%7Bember-youtube ytid=youtubeVideoId%7D%7D%60);%0A%09// It takes some time before the youtube api is loaded,%0A%09// how do we avoid the timeout?%0A%09Ember.run.later(this, function () %7B%0A%09%09assert.ok(this.$('iframe').length);%0A%09%09done();%0A%09%7D, 1000);%0A%7D);%0A

Fix async tests