/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    path = require('path'),
    fs = require('fs'),
    linkThemeFiles = require('../../../../task/worker/link_theme_files.js');

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

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


exports['Link theme image files.'] = function (test) {
    var destDir = testResource.resolveWorkFile('work_link_images');
    testResource.prepareCleanWorkDir(destDir, function () {
        linkThemeFiles({
            srcDir: path.resolve(__dirname, '../../../../clientside/src/img_themes'),
            destDir: destDir,
            settingFile: testResource.resolveMockFile('mock-style-theme-setting.json')
        }, function (err) {
            test.ifError(err);
            test.done();
        });
    });
};

exports['Get theme names.'] = function (test) {
    test.ok(linkThemeFiles._getThemeName({fooBar: 'baz'}, 'fooBar'));
    test.ok(linkThemeFiles._getThemeName({fooBar: 'baz'}, 'foo_bar'));
    test.ok(linkThemeFiles._getThemeName({'foo*': 'baz'}, 'foo'));
    test.done();
};

exports['Find theme files.'] = function (test) {
    var workDir = testResource.resolveWorkFile('work_find_theme_files_dir');
    testResource.prepareCleanWorkDir(workDir, function () {
        linkThemeFiles._findThemeFileFromDir(workDir, 'a', function (err) {
            fs.writeFile(workDir + '/theme-a.txt', 'foo', function () {
                linkThemeFiles._findThemeFileFromDir(workDir, 'a', function (err, filenames) {
                    test.ifError(err);
                    test.ok(filenames);
                    test.done();
                });
            });
        });
    });
};