Skip to content

Commit

Permalink
fix: added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ravidsrk committed Aug 7, 2016
1 parent 955ebb6 commit b7b54fb
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 17 deletions.
92 changes: 80 additions & 12 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
const mkdirp = require('mkdirp');
var yosay = require('yosay');

module.exports = yeoman.Base.extend({
Expand All @@ -11,26 +12,93 @@ module.exports = yeoman.Base.extend({
));

var prompts = [{
type: 'confirm',
name: 'someAnswer',
message: 'Would you like to enable this option?',
default: true
name: 'name',
message: 'What are you calling your app?',
store: true,
default: this.appname,
validate: function (input) {
if (/^([a-zA-Z0-9_]*)$/.test(input)) {
return true;
}
return 'Your application name cannot contain special characters or a blank space, using the default name instead : ' + this.appname;
}
}, {
name: 'package',
message: 'What package will you be publishing the app under?',
validate: function (input) {
if (/^([a-z_]{1}[a-z0-9_]*(\.[a-z_]{1}[a-z0-9_]*)*)$/.test(input)) {
return true;
}
return 'The package name you have provided is not a valid Java package name.';
},
default: 'in.architecture.sample',
store: true
}, {
type: 'list',
name: 'architecture',
message: 'Choose architecture?',
choices: [{
name: 'todo-mvp - Basic Model-View-Presenter architecture.',
value: 'todo-mvp'
}, {
name: 'todo-mvp-loaders - Based on todo-mvp, fetches data using Loaders.',
value: 'todo-mvp-loaders'
}, {
name: 'todo-mvp-databinding - Based on todo-mvp, uses the Data Binding Library.',
value: 'todo-mvp-databinding'
}, {
name: 'todo-mvp-clean - Based on todo-mvp, uses concepts from Clean Architecture.',
value: 'todo-mvp-clean'
}, {
name: 'todo-mvp-dagger - Based on todo-mvp, uses Dagger2 for Dependency Injection',
value: 'todo-mvp-dagger'
}, {
name: 'todo-mvp-contentproviders - Based on todo-mvp-loaders, fetches data using Loaders and uses Content Providers',
value: 'todo-mvp-contentproviders'
}],
default: 'todo-mvp'
}];

return this.prompt(prompts).then(function (props) {
// To access props later use this.props.someAnswer;
this.props = props;
this.props.appPackage = props.package;
this.appName = props.name;
this.appPackage = props.package;
this.androidTargetSdkVersion = props.targetSdk;
this.androidMinSdkVersion = props.minSdk;
}.bind(this));
},

writing: function () {
this.fs.copy(
this.templatePath('dummyfile.txt'),
this.destinationPath('dummyfile.txt')
);
},
var packageDir = this.props.package.replace(/\./g, '/');
mkdirp('app');
mkdirp('app/src/androidTest/java/' + packageDir);
mkdirp('app/src/androidTestMock/java/' + packageDir);
mkdirp('app/src/main/java/' + packageDir);
mkdirp('app/src/mock/java/' + packageDir);
mkdirp('app/src/prod/java/' + packageDir);
mkdirp('app/src/test/java/' + packageDir);

this.directory(this.props.architecture + '/gradle', 'gradle');

this.copy(this.props.architecture + '/gitignore', '.gitignore');
this.copy(this.props.architecture + '/build.gradle', 'build.gradle');
this.copy(this.props.architecture + '/gradle.properties', 'gradle.properties');
this.copy(this.props.architecture + '/gradlew', 'gradlew');
this.copy(this.props.architecture + '/gradlew.bat', 'gradlew.bat');
this.copy(this.props.architecture + '/settings.gradle', 'settings.gradle');
// this.copy(this.props.architecture + '/README.md', 'README.md');
this.copy(this.props.architecture + '/app/gitignore', 'app/.gitignore');
this.copy(this.props.architecture + '/app/proguard-rules.pro', 'app/proguard-rules.pro');

install: function () {
this.installDependencies();
this.template(this.props.architecture + '/app/build.gradle', 'app/build.gradle');
this.template(this.props.architecture + '/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp', 'app/src/androidTest/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/androidTestMock/java/com/example/android/architecture/blueprints/todoapp', 'app/src/commonTest/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/main/java/com/example/android/architecture/blueprints/todoapp', 'app/src/main/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/mock/java/com/example/android/architecture/blueprints/todoapp', 'app/src/commonTest/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/prod/java/com/example/android/architecture/blueprints/todoapp', 'app/src/commonTest/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/test/java/com/example/android/architecture/blueprints/todoapp', 'app/src/test/java/' + packageDir, this, {});
this.template(this.props.architecture + '/app/src/main/AndroidManifest.xml', 'app/src/main/AndroidManifest.xml');
this.template(this.props.architecture + '/app/src/main/res', 'app/src/main/res', this, {});
}
});
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
"yeoman-generator"
],
"dependencies": {
"yeoman-generator": "^0.24.1",
"chalk": "^1.0.0",
"generator-git-init": "^1.1.3",
"glob": "^7.0.5",
"mkdirp": "^0.5.1",
"slug": "^0.9.1",
"yeoman-generator": "^0.24.1",
"yosay": "^1.0.0"
},
"devDependencies": {
Expand Down
37 changes: 33 additions & 4 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,45 @@ var path = require('path');
var assert = require('yeoman-assert');
var helpers = require('yeoman-test');

describe('generator-android-architecture:app', function () {
describe('generator-android-mvp-starter:app', function () {
this.timeout(15000);

before(function () {
return helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({someAnswer: true})
.withPrompts({
name: 'SampleApp',
package: 'com.sample.mvp',
targetSdk: '21',
minSdk: '14'
})
.toPromise();
});

it('creates files', function () {
it('creates project files', function () {
assert.file([
'.gitignore',
'build.gradle',
'gradle.properties',
'gradlew',
'gradlew.bat',
'settings.gradle'
]);
});

it('creates core app files', function () {
assert.file([
'app/.gitignore',
'app/build.gradle',
'app/proguard-rules.pro',
'app/src/main/java/com/sample/mvp/BaseView.java',
'app/src/main/AndroidManifest.xml'
]);
});

it('copies gradle wrapper', function () {
assert.file([
'dummyfile.txt'
'gradle/wrapper/gradle-wrapper.jar',
'gradle/wrapper/gradle-wrapper.properties'
]);
});
});

0 comments on commit b7b54fb

Please sign in to comment.