Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


# End of https://www.gitignore.io/api/node
61 changes: 61 additions & 0 deletions app/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

require('./scss/reset.scss');
require('./scss/main.scss');

const angular = require('angular');
const cowsay = require('cowsay-browser');

const cowsayApp = angular.module('cowsayApp', []);

cowsayApp.controller('CowsayController', ['$log', CowsayController]);

function CowsayController($log) {
$log.debug('CowsayController');

this.title = 'Welcome to Cowville';
this.history = [];

cowsay.list((err, cowfiles) => {
this.cowfiles = cowfiles;
this.current = this.cowfiles[0];
});

this.update = function(input) {
$log.debug('cowsayCtrl.update');
return cowsay.say({ text: input || 'moo', f: this.current });
};

this.speak = function(input) {
$log.debug('cowsayCtrl.speak');
this.spoken = this.update(input);
this.history.push(this.spoken);
};

this.undo = function() {
$log.debug('cowsayCtrl.undo');
this.history.pop();
this.spoken = this.history.pop();
};
}

cowsayApp.controller('NavController', ['$log', NavController]);

function NavController($log) {
$log.debug('NavController');

this.routes = [
{
name: 'home',
url: '/home'
},
{
name: 'cow creator',
url: '/cowcreator'
},
{
name: 'account',
url: '/myaccount'
}
];
}
52 changes: 52 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html ng-app="cowsayApp">
<head>
<title>Cowsville!</title>
</head>
<body>
<header>
<nav ng-controller="NavController as navCtrl">
<ul>
<li ng-repeat="route in navCtrl.routes">
<a href="{{ route.url }}">{{ route.name }}</a>
</li>
</ul>
</nav>
</header>

<main>
<section
class="container"
ng-controller="CowsayController as cowsayCtrl"
ng-init="cowsayCtrl.current = 'moose'">
<h2>{{ cowsayCtrl.title }}</h2>

<pre class="cow">
{{ cowsayCtrl.update(cowsayCtrl.text) }}
</pre>

<form
ng-submit="cowsayCtrl.speak(cowsayCtrl.text)"
name="cowsayForm"
no validate>
<select ng-model="cowsayCtrl.current">
<option ng-repeat="cowfile in cowsayCtrl.cowfiles" value="{{ cowfile }}">
{{ cowfile }}
</option>
</select>

<input type="text" ng-model="cowsayCtrl.text" required>
<button type="submit">Speak!</button>

<div ng-show="cowsayCtrl.spoken" class="history">
<!-- watch vid about ng-show!!!!!!! -->
<pre class="cow">
{{cowsayCtrl.spoken}}
</pre>
<button type="button" ng-click="cowsayCtrl.undo()">Undo!</button>
</div>
</form>
</section>
</main>
</body>
</html>
Empty file added app/scss/main.scss
Empty file.
Empty file added app/scss/reset.scss
Empty file.
26 changes: 26 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const webpackConfig = require('./webpack.config.js');
webpackConfig.entry = {};

module.exports = function(config) {
config.set({
webpack: webpackConfig,
basePath: '',
frameworks: ['jasmine'],
files: [
'test/**/*-test.js'
],
exclude: [
],
preprocessors: {
'test/**/*-test.js': ['webpack']
},
reporters: ['mocha'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
});
};
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "22-testing_controllers",
"version": "1.0.0",
"description": "![cf](https://i.imgur.com/7v5ASc8.png) Lab 22 - Testing Angular Controllers\r ======",
"main": "index.js",
"scripts": {
"build": "./node_modules/webpack/bin/webpack.js",
"watch": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot",
"test": "./node_modules/karma/bin/karma start",
"test-watch": "./node_modules/karma/bin/karma start --single-run"
},
"repository": {
"type": "git",
"url": "git+https://github.com/noahgribbin/22-testing_controllers.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/noahgribbin/22-testing_controllers/issues"
},
"homepage": "https://github.com/noahgribbin/22-testing_controllers#readme",
"dependencies": {
"angular": "^1.6.3",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"cowsay-browser": "^1.1.8",
"css-loader": "^0.27.3",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.28.0",
"node-sass": "^4.5.1",
"sass-loader": "^6.0.3",
"style-loader": "^0.16.0",
"webpack": "^1.14.0"
},
"devDependencies": {
"angular-mocks": "^1.6.3",
"jasmine-core": "^2.5.2",
"karma": "^1.5.0",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.3",
"karma-phantomjs-launcher": "^1.0.4",
"karma-webpack": "^2.0.3",
"webpack-dev-server": "^1.16.2"
}
}
58 changes: 58 additions & 0 deletions test/cowsay-ctrl-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

require('./lib/test-setup.js');

const angular = require('angular');
const cowsay = require('cowsay-browser');

describe('Cowsay Controller', function() {
beforeEach(() => {
angular.mock.module('cowsayApp');
angular.mock.inject($controller => {
this.cowsayCtrl = new $controller('CowsayController');
});
});

describe('starting properties', () => {
it('title should be "Welcome to Cowville"', () => {
expect(this.cowsayCtrl.title).toBe('Welcome to Cowville');
});
it('history should be an empty array', () => {
expect(Array.isArray(this.cowsayCtrl.history)).toBe(true);
});
it('cowfiles should be populated', () => {
cowsay.list((err, list) => {
expect(this.cowsayCtrl.cowfiles).toEqual(list);
});
});
it('current should be the first cowfile in the array', () => {
cowsay.list((err, list) => {
expect(this.cowsayCtrl.current).toEqual(list[0]);
});
});
});
describe('#update', () => {
it('should return a cow that says "testing"', () => {
let expected = cowsay.say({text:'testing', f: this.cowsayCtrl.current});
let result = this.cowsayCtrl.update('testing');
expect(result).toEqual(expected);
});
});
describe('#speak', () => {
it('should expect spoken and history to equal a cowsay "testing"', () => {
let expected = cowsay.say({text:'testing', f: this.cowsayCtrl.current});
this.cowsayCtrl.speak('testing');
expect(this.cowsayCtrl.spoken).toEqual(expected);
expect(this.cowsayCtrl.history[0]).toEqual(expected);
});
});
describe('#undo', () => {
it('should pop off the second "speak" call, and return the first call', () => {
let expected = cowsay.say({text:'testing', f: this.cowsayCtrl.current});
this.cowsayCtrl.speak('testing');
this.cowsayCtrl.speak('testing to be popped off');
this.cowsayCtrl.undo();
expect(this.cowsayCtrl.spoken).toEqual(expected);
});
});
});
4 changes: 4 additions & 0 deletions test/lib/test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

require('../../app/entry.js');
require('angular-mocks');
35 changes: 35 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const HTMLPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
entry: `${__dirname}/app/entry.js`,
output: {
filename: 'bundle.js',
path: 'build'
},
plugins: [
new HTMLPlugin({
template: `${__dirname}/app/index.html`
}),
new ExtractTextPlugin('bundle.css')
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.(eot|woff|ttft|svg).*/,
loader: 'url?limit=10000&name=fonts/[hash].[ext]'
}
]
}
};