/**
 * This is an example JS Unit test, designed to run safely with Karma, using the QUnit 2.0 API.
 *
 * The main differences with QUnit 2.0 API is that it doesn't expose test/assert/etc as globals.
 * While we are still using QUnit 1.16 we can still use the old API, but for new tests it's probably
 * good form to use the new API to allow us to move to QUnit 2 in future when it is released without
 * major changes to tests.
 */
define([
	'Squire',
	'test-helper',
	'bitbucket/internal/util/ajax'
], function(
	Squire,
	testHelper, // we don't use testHelper, but it decorates Squire with helper methods
	ajax
) {

    'use strict';

	QUnit.module('example');

	/**
	 * A regular simple test case
	 */
	QUnit.test('isPresent', function(assert) {
		assert.ok(ajax);
		assert.ok(ajax.ajax);
		assert.ok(ajax.rest);
	});

	/**
	 * An asynchronous test
	 */
	QUnit.test('async example', function (assert) {
		var done = assert.async();
		setTimeout(function () {
			assert.ok(true);
			done();
		});
	});

	/**
	 * test-helper module contains a few useful methods for common operations and
	 * mocks, for example mock Soy templates:
	 */
	testHelper.setTemplates({
		'stash.some.template': 'template'
	});

	var mockServer = {
		ajax: 'MARKER'
	};

	var injector = new Squire();
	injector.setDefaultDeps(['bitbucket/internal/util/ajax']);
	injector.mock('bitbucket/util/server', mockServer);

	/**
	 * A test with a mock dependency - in this example we're mocking the server module, and verifying
	 * our test is using the mocked server.
	 */
	injector.test('async mock example', function (assert, ajax) {
		assert.equal(ajax.ajax, 'MARKER');
	});

	/**
	 * This is the same as the test above, but demonstrates the use of the QUnit 2 API for async tests,
	 * we use `assert.async` to get a `done` function to call when our async body is done.
	 */
	injector.test('async mock example with async body', function (assert, ajax) {
		var done = assert.async();
		setTimeout(function () {
			assert.equal(ajax.ajax, 'MARKER');
			done();
		}, 100);
	});

});