/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    mockInjector = require('../../../mock_injector'),
    generateFileConfigHelper = require('../../../../ci/worker/generate_file_config' +
        '_helper.js');

exports.setUp = function (done) {
    done();
};

exports.tearDown = function (done) {
    mockInjector.restoreAll();
    done();
};

exports['Load the template.'] = function (test) {
    generateFileConfigHelper._loadFileConfigHelperTmpl(function (err, tmpl) {
        test.ifError(err);
        test.ok(tmpl);
        test.done();
    });
};

exports['Write test file.'] = function (test) {
    var dest = testResource.resolveWorkFile('work_file_config_helper_test.js');
    generateFileConfigHelper._writeTestFile(dest, {
        modulePath: 'foo',
        moduleName: 'foo'
    }, function (err) {
        test.ifError(err);
        test.done();
    });
};

exports['Load the test template.'] = function (test) {
    generateFileConfigHelper._loadFileConfigHelperTestTmpl(function (err, tmpl) {
        test.ifError(err);
        test.ok(tmpl);
        test.done();
    });
};

exports['Name a helper function.'] = function (test) {
    var name = generateFileConfigHelper._name('js/do_something.js.hbs');
    test.equal(name, 'doSomethingJs');
    test.done();
};

exports['Should ignore.'] = function (test) {
    test.ok(generateFileConfigHelper._shouldIgnore('foo/bar/.DS_Store'));
    test.ok(generateFileConfigHelper._shouldIgnore('foo/.svn/do.txt'));
    test.ok(generateFileConfigHelper._shouldIgnore('foo/_doc/abc.txt'));
    test.ifError(generateFileConfigHelper._shouldIgnore('foo/bar/baz.txt'));
    test.done();
};

exports['Generate file config' +
    ' helper.'] = function (test) {
    generateFileConfigHelper({
        tmplDir: testResource.resolveMockFile('mock_tmpl'),
        dest: testResource.resolveWorkFile('work_file_config' +
            '_helper.js')
    }, function (err) {
        test.ifError(err);
        test.done();
    });
};