Skip to content
Permalink
Browse files
test(ConfigFile): group & cleanup tests (#125)
* group tests in describe

* remove unused beforeEach

* reduce variable scope

* Make test titles unique

Co-Authored-By: エリス <erisu@users.noreply.github.com>
  • Loading branch information
raphinesse and erisu committed Dec 20, 2019
1 parent e2a4848 commit fd933231bb87939e37400cbde7d946319c76d5de
Showing 1 changed file with 64 additions and 54 deletions.
@@ -19,73 +19,83 @@ var rewire = require('rewire');
var configFile = rewire('../../src/ConfigChanges/ConfigFile');
var fs = require('fs-extra');
var path = require('path');
var projectDir = path.join('project_dir', 'app', 'src', 'main');

describe('ConfigFile tests', function () {
beforeEach(function () {
spyOn(configFile, 'isBinaryPlist').and.callThrough();
describe('instance methods', () => {
describe('save', () => {
it('calls fs.writeFileSync', function () {
spyOn(fs, 'writeFileSync');
configFile.prototype.save();
expect(fs.writeFileSync).toHaveBeenCalled();
});
});
});

it('ConfigFile_save/ConfigFile.prototype.save', function () {
spyOn(fs, 'writeFileSync');
configFile.prototype.save();
expect(fs.writeFileSync).toHaveBeenCalled();
});
describe('static methods', () => {
describe('isBinaryPlist', () => {
it('should return false if not binary', function () {
spyOn(fs, 'readFileSync').and.returnValue('not bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(false);
});

it('isBinaryPlist should return false if not binary', function () {
spyOn(fs, 'readFileSync').and.returnValue('not bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(false);
});
it('isBinaryPlist should return true if binary', function () {
spyOn(fs, 'readFileSync').and.returnValue('bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(true);
});
it('should return true if binary', function () {
spyOn(fs, 'readFileSync').and.returnValue('bplist');
expect(configFile.isBinaryPlist('someFile')).toBe(true);
});
});

it('getIOSProjectname should throw error', function () {
expect(function () { configFile.getIOSProjectname('some/project/name'); }).toThrow();
});
describe('getIOSProjectname', () => {
it('should throw error', function () {
expect(function () { configFile.getIOSProjectname('some/project/name'); }).toThrow();
});
});

it('resolveConfigFilePath should return file path', function () {
var filePath = path.join('project_dir', 'file');
expect(configFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
});
describe('resolveConfigFilePath', () => {
const projectDir = path.join('project_dir', 'app', 'src', 'main');

it('resolveConfigFilePath should return file path', function () {
var androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
});
it('should return file path', function () {
var filePath = path.join('project_dir', 'file');
expect(configFile.resolveConfigFilePath('project_dir', 'platform', 'file')).toBe(filePath);
});

it('resolveConfigFilePath should return file path', function () {
var configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
});
it('should return AndroidManifest.xml file path', function () {
var androidManifestPath = path.join(projectDir, 'AndroidManifest.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'AndroidManifest.xml')).toBe(androidManifestPath);
});

it('resolveConfigFilePath should return file path', function () {
var stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
});
it('should return android config.xml file path', function () {
var configPath = path.join(projectDir, 'res', 'xml', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'config.xml')).toBe(configPath);
});

it('resolveConfigFilePath should return file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('iospath');
var configPath = path.join('project_dir', 'iospath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
});
it('should return android strings.xml file path', function () {
var stringsPath = path.join(projectDir, 'res', 'values', 'strings.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', 'strings.xml')).toBe(stringsPath);
});

it('resolveConfigFilePath should return file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('osxpath');
var configPath = path.join('project_dir', 'osxpath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'osx', 'config.xml')).toBe(configPath);
});
it('should return ios config.xml file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('iospath');
var configPath = path.join('project_dir', 'iospath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'ios', 'config.xml')).toBe(configPath);
});

it('resolveConfigFilePath should return file path', function () {
var file = path.join('res', 'xml');
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});
it('should return osx config.xml file path', function () {
spyOn(configFile, 'getIOSProjectname').and.returnValue('osxpath');
var configPath = path.join('project_dir', 'osxpath', 'config.xml');
expect(configFile.resolveConfigFilePath('project_dir', 'osx', 'config.xml')).toBe(configPath);
});

it('should return android resource file path when path is normalized', function () {
var file = path.join('res', 'xml');
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});

it('resolveConfigFilePath should return file path', function () {
var file = 'res/xml';
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
it('should return android resource file path when path is not normalized', function () {
var file = 'res/xml';
var configPath = path.join('project_dir', 'app', 'src', 'main', file, 'xml');
expect(configFile.resolveConfigFilePath('project_dir', 'android', file)).toBe(configPath);
});
});
});
});

0 comments on commit fd93323

Please sign in to comment.