'use strict';

const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
const modifyPackages = blueprintHelpers.modifyPackages;

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const fixture = require('../helpers/fixture');
const fs = require('fs-extra');

describe('Blueprint: initializer-test', function() {
  setupTestHooks(this);

  describe('in app', function() {
    beforeEach(function() {
      return emberNew();
    });

    describe('with ember-cli-qunit@4.1.0', function() {
      beforeEach(function() {
        generateFakePackageManifest('ember-cli-qunit', '4.1.0');
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('tests/unit/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/default.js')
          );
        });
      });
    });

    describe('with ember-cli-qunit@4.2.0', function() {
      beforeEach(function() {
        generateFakePackageManifest('ember-cli-qunit', '4.2.0');
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('tests/unit/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/rfc232.js')
          );
        });
      });
    });

    describe('with ember-cli-mocha', function() {
      beforeEach(function() {
        modifyPackages([
          { name: 'ember-cli-qunit', delete: true },
          { name: 'ember-cli-mocha', dev: true },
        ]);
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('tests/unit/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/mocha.js')
          );
        });
      });
    });
  });

  describe('in addon', function() {
    beforeEach(function() {
      return emberNew({ target: 'addon' });
    });

    it('initializer-test foo', function() {
      return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
        expect(_file('tests/unit/initializers/foo-test.js')).to.equal(
          fixture('initializer-test/dummy.js')
        );
      });
    });
  });

  describe('in app – module unification', function() {
    beforeEach(function() {
      return emberNew().then(() => fs.ensureDirSync('src'));
    });

    describe('with ember-cli-qunit@4.1.0', function() {
      beforeEach(function() {
        generateFakePackageManifest('ember-cli-qunit', '4.1.0');
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('src/init/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/module-unification/default.js')
          );
        });
      });
    });

    describe('with ember-cli-qunit@4.2.0', function() {
      beforeEach(function() {
        generateFakePackageManifest('ember-cli-qunit', '4.2.0');
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('src/init/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/module-unification/rfc232.js')
          );
        });
      });
    });

    describe('with ember-cli-mocha', function() {
      beforeEach(function() {
        modifyPackages([
          { name: 'ember-cli-qunit', delete: true },
          { name: 'ember-cli-mocha', dev: true },
        ]);
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('src/init/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/module-unification/mocha.js')
          );
        });
      });
    });
  });

  describe('in addon - module unification', function() {
    beforeEach(function() {
      return emberNew({ target: 'addon' }).then(() => fs.ensureDirSync('src'));
    });

    describe('with ember-cli-qunit@4.1.0', function() {
      beforeEach(function() {
        generateFakePackageManifest('ember-cli-qunit', '4.1.0');
      });

      it('initializer-test foo', function() {
        return emberGenerateDestroy(['initializer-test', 'foo'], _file => {
          expect(_file('src/init/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/module-unification/dummy.js')
          );
        });
      });

      it('initializer-test foo --dummy', function() {
        return emberGenerateDestroy(['initializer-test', 'foo', '--dummy'], _file => {
          expect(_file('tests/dummy/src/init/initializers/foo-test.js')).to.equal(
            fixture('initializer-test/module-unification/dummy.js')
          );
        });
      });
    });
  });
});

@@ -2288,24 +2288,188 @@
 );%0A    %7D);%0A%0A
+    describe('with ember-cli-qunit@4.1.0', function() %7B%0A      beforeEach(function() %7B%0A        generateFakePackageManifest('ember-cli-qunit', '4.1.0');%0A      %7D);%0A%0A  
     it('init
@@ -2492,32 +2492,34 @@
 ', function() %7B%0A
+  
       return emb
@@ -2576,32 +2576,34 @@
 le =%3E %7B%0A        
+ 
+ 
 expect(_file('te
@@ -2651,32 +2651,34 @@
 qual(%0A          
+  
 fixture('initial
@@ -2698,32 +2698,46 @@
 my.js')%0A        
+  );%0A        %7D
 );%0A      %7D);%0A   

Make initializer-test blueprint test explicit about QUnit version