diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..6738afc --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +/node_modules + +*.md + +npm-debug.log diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..2b88e95 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,22 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ], + # "no-unused-vars": [2, {"vars": "local", "args": "after-used"}] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4785718 --- /dev/null +++ b/.gitignore @@ -0,0 +1,132 @@ + +# Created by https://www.gitignore.io/api/node,osx,windows,linux + +### Linux ### +*~ + +#Build (webpack) +build/ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### 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 + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/node,osx,windows,linux diff --git a/app/entry.js b/app/entry.js new file mode 100644 index 0000000..8788ca7 --- /dev/null +++ b/app/entry.js @@ -0,0 +1,62 @@ +'use strict'; + +require('./scss/core.scss'); + +const angular = require('angular'); +const cowsay = require('cowsay-browser'); + +const mooMooApp = angular.module('mooMooApp', []); + +mooMooApp.controller('CowsayController', ['$log', CowsayController]); + +function CowsayController($log) { + $log.debug('CowsayController'); + + this.title = 'Cow Creator'; + this.history = []; + + cowsay.list((err, cowfiles) => { + this.cowfiles = cowfiles; + this.current = cowfiles[0]; + }); + + this.update = function(input) { + $log.debug('cowsayCtrl.update'); + return cowsay.say({ text: input || 'cowcontrol.io', f: this.current }); + }; + + this.speak = function(input) { + $log.debug('cowsayCtrl.update'); + + 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() || ''; + }; +} + +mooMooApp.controller('NavController', ['$log', NavController]); + +function NavController($log) { + $log.debug('NavController'); + + this.routes = [ + { + name: 'Home', + url: '/home' + }, + { + name: 'Cow Creator', + url: '/cow-creator' + }, + { + name: 'Account', + url: '/account' + } + ]; +} diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..7a6f645 --- /dev/null +++ b/app/index.html @@ -0,0 +1,70 @@ + + + + + MooMoo Tests + + +
+
+ +

cowcontrol.io

+
+ +
+ +
+ +
+

{{ cowsayCtrl.title }}

+

make it, view it, and undo it!

+
+ +
+        {{ cowsayCtrl.update(cowsayCtrl.text) }}
+      
+ +
+

Select a cowfile

+ +

What does it say?

+ +

View it!

+ +
+ +
+ +
+
+

View it!

+

check out the cow you just made!

+
+
+          {{ cowsayCtrl.spoken }}
+        
+
+ +
+
+ +
+ + + + diff --git a/app/scss/_base.scss b/app/scss/_base.scss new file mode 100644 index 0000000..1a3cc38 --- /dev/null +++ b/app/scss/_base.scss @@ -0,0 +1,15 @@ +//:::: Base Styles ::::// +$font-color: #484848; + +p { + font-family: muli; + color: $font-color; +} + +body { + width: 900px; + height: 100%; + background-color: $site-primary; + margin: auto; + outline: 1px solid black; +} diff --git a/app/scss/_footer.scss b/app/scss/_footer.scss new file mode 100644 index 0000000..c9136fa --- /dev/null +++ b/app/scss/_footer.scss @@ -0,0 +1,14 @@ +//:::: footer ::::// + +footer { + height: 90px; + background-color: $footer-bg; + position: relative; + + p { + display: inline-block; + position: absolute; + top: 70%; + left: 89%; + } +} diff --git a/app/scss/_main.scss b/app/scss/_main.scss new file mode 100644 index 0000000..3e1ca6c --- /dev/null +++ b/app/scss/_main.scss @@ -0,0 +1,74 @@ +//:::: content styles ::::// + +.cow-header { + display: block; + width: 100%; + margin: 3% 0 0 17%; + + h2 { + font-size: 20px; + color: #484848; + font-family: sans-serif; + display: inline; + + } + p { + display: inline; + padding: 0 0 0 10px; + } +} + +.cow { + width: 40%; + display: inline-block; + margin: 2% 0 0 18%; + outline: 1px black solid; + font-size: 25px; + color: $font-color; +} + +.opts-container { + margin: auto 20px auto 20px; + width: 20%; + display: inline-block; + + p { + font-size: 18px; + margin-bottom: 10px; + } + + select{ + display: block; + width: 100%; + height: 25px; + margin-bottom: 35px; + border-radiu: 5px; + border: 2px solid black; + } + input { + display: block; + width: 100%; + height: 18px; + margin-bottom: 35px; + border-radius: 5px; + border: 2px solid black; + } + button { + width: 100%; + height: 25px; + display: block; + margin-bottom: 35px; + border-radius: 5px; + border: 2px solid black; + background-color: #4a4a4a; + color: #b0b0b0; + } +} + +.thinline { + display: block; + height: 1px; + width: 75%; + margin: 20px auto 20px auto; + border-top: 1px solid +} diff --git a/app/scss/_nav.scss b/app/scss/_nav.scss new file mode 100644 index 0000000..3767876 --- /dev/null +++ b/app/scss/_nav.scss @@ -0,0 +1,52 @@ +//:::: nav & header styles ::::// + +header { + background-color: $nav-bg; + width: 100%; + height: 8%; + color: $header-color; +} + +.logo-container { + display: inline-block; + margin: 2% 0% 3% 3%; + position: relative; + + h1 { + display: inline-block; + font-size: 22px; + position: absolute; + top: 10px; + left: 50px; + } + + #logo { + display: inline-block; + position: absolute; + } +} + +.nav-bar { + display: inline-block; + margin: 0% 0% 3% 50%; + + ul { + display: inline; + + li { + display: inline; + padding: 0px 10px 0px 10px; + + a { + font-size: 20px; + } + } + } +} + +.nav-link { + font-size: 20px; + text-decoration: none; + color: $header-color; + font-family: sans-serif; +} diff --git a/app/scss/_reset.scss b/app/scss/_reset.scss new file mode 100644 index 0000000..ed11813 --- /dev/null +++ b/app/scss/_reset.scss @@ -0,0 +1,48 @@ +/* http://meyerweb.com/eric/tools/css/reset/ + v2.0 | 20110126 + License: none (public domain) +*/ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +} diff --git a/app/scss/_vars.scss b/app/scss/_vars.scss new file mode 100644 index 0000000..ad5b097 --- /dev/null +++ b/app/scss/_vars.scss @@ -0,0 +1,5 @@ +$site-primary: #d8d8d8; +$nav-bg: #4a4a4a; +$font-color: #484848; +$header-color: #949494; +$footer-bg: #9b9b9b; diff --git a/app/scss/core.scss b/app/scss/core.scss new file mode 100644 index 0000000..b342318 --- /dev/null +++ b/app/scss/core.scss @@ -0,0 +1,6 @@ +@import 'vars'; +@import 'reset'; +@import 'base'; +@import 'main'; +@import 'nav'; +@import 'footer'; diff --git a/assets/moo-moo-logo.png b/assets/moo-moo-logo.png new file mode 100644 index 0000000..837e40f Binary files /dev/null and b/assets/moo-moo-logo.png differ diff --git a/assets/muli-font.ttf b/assets/muli-font.ttf new file mode 100644 index 0000000..1dfd643 Binary files /dev/null and b/assets/muli-font.ttf differ diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..d4c983d --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,27 @@ + +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 + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..c126618 --- /dev/null +++ b/package.json @@ -0,0 +1,48 @@ +{ + "name": "22-testing_controllers", + "version": "1.0.0", + "description": "![cf](https://i.imgur.com/7v5ASc8.png) Lab 22 - Testing Angular Controllers ======", + "main": "karma.conf.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 --single", + "test-watch": "./node_modules/karma/bin/karma start", + "lint": "./node_modules/eslint/bin/eslint.js ./*" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/npisciotti1/22-testing_controllers.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/npisciotti1/22-testing_controllers/issues" + }, + "homepage": "https://github.com/npisciotti1/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" + } +} diff --git a/test/cow-controller-test.js b/test/cow-controller-test.js new file mode 100644 index 0000000..aa1ccd7 --- /dev/null +++ b/test/cow-controller-test.js @@ -0,0 +1,60 @@ +'use strict'; + +require('./lib/test-setup.js'); + +const angular = require('angular'); +const cowsay = require('cowsay-browser'); + +describe('Cowsay Controller', function() { + beforeEach( () => { + angular.mock.module('mooMooApp'); + angular.mock.inject($controller => { + this.cowsayCtrl = new $controller('CowsayController'); + this.navCtrl = new $controller('NavController'); + }); + }); + + describe('initial properties', () => { + it('title should be cowcreator.io', () => { + expect(this.cowsayCtrl.title).toBe('Cow Creator'); + }); + + it('history property should be an empty array', () => { + expect(Array.isArray(this.cowsayCtrl.history)).toBe(true); + }); + + it('list of cowfiles should show proper cowfiles', () => { + cowsay.list((err, cowfiles) => { + expect(this.cowsayCtrl.cowfiles).toEqual(cowfiles); + }); + }); + }); + + describe('#update', () => { + it('should return a cow that says testing', () => { + let expected = cowsay.say({ text: 'testing', f: this.cowsayCtrl.current }); + let testResult = this.cowsayCtrl.update('testing'); + expect(testResult).toEqual(expected); + }); + }); + + describe('#speak', () => { + it('should return a cow that says 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.length).toEqual(1); + }); + }); + + describe('#undo', () => { + it('should modify our history array and return a cow that says testing', () => { + let expected = cowsay.say({ text: 'testing', f: this.cowsayCtrl.current }); + this.cowsayCtrl.speak('testing'); + this.cowsayCtrl.speak('test control'); + this.cowsayCtrl.undo(); + expect(this.cowsayCtrl.spoken).toEqual(expected); + expect(this.cowsayCtrl.history.length).toEqual(0); + }); + }); +}); diff --git a/test/lib/test-setup.js b/test/lib/test-setup.js new file mode 100644 index 0000000..4b6e777 --- /dev/null +++ b/test/lib/test-setup.js @@ -0,0 +1,4 @@ +'use strict;' + +require('../../app/entry.js'); +require('angular-mocks'); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..6748bdc --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,36 @@ +'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: /\.scss$/, + loader: 'style!css!sass!' + }, + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel' + }, + { + test: /\.(eot|woff|ttf|svg).*/, + loader: 'url?limit=10000@name=fonts/[hash].[ext]' + } + ] + } +};