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
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "thoughter",
"version": "1.0.0",
"author": "Brian Fiala",
"license": "ISC",
"description": "Definitely not a Twitter clone.",
"main": "src/js/recent-thoughts.js",
"scripts": {
"test": "karma start test.conf.js"
},
"dependencies": {
"fetch-mock": "^5.9.4",
"jquery": "^3.2.0"
},
"devDependencies": {
"chai": "^3.5.0",
"fetch-mock": "^5.9.4",
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-sass": "^1.0.0",
"grunt-karma": "^2.0.0",
"karma": "^1.5.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-mocha": "^1.3.0",
"karma-requirejs": "^1.1.0",
"load-grunt-tasks": "^3.5.2",
"mocha": "^3.2.0",
"requirejs": "^2.3.3"
}
}
22 changes: 22 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>Thoughter</title>

<meta name='viewport' content='width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'>

<link href='style.css' rel='stylesheet'>
</head>
<body>
<header>
<h1>Thoughter</h1>
</header>

<!-- TODO! -->

<script src='/js/vendor/jquery.js'></script>
<script src='/js/app.js'></script>
<script src="js/recent-thoughts.js"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions src/js/new-thought.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(function() {

window.thoughter = window.thoughter || {};

/**
* Creates a new thought with the given text
*
* @param {String} text The text to use for the thought - this is REQUIRED!
* @return {Promise} The resolved promise will have the new thought data object in it
*/
window.thoughter.createThought = function createThought(text) {
if (typeof(text) !== 'string' || !text.length) {
return Promise.reject('Please provide text for this new thought');
}

return fetch(
'http://thoughter.herokuapp.com/api/Thoughts',
{
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ content: text })
}
)
.then(function handleResponse(res) {
if (res.status > 299) {
console.error('Looks like a bad status code:', res.status);
return Promise.reject('Sorry, but there was a problem with your request.');
} else {
return res.json()
}
});
};

})();
2 changes: 1 addition & 1 deletion src/js/recent-thoughts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return;
}

recent = document.querySelector('.recent');
let recent = document.querySelector('.recent');
thoughts.forEach(function showThought(thought) {
if (!thought.content || !thought.createTime || !thought.id) {
return;
Expand Down
10 changes: 10 additions & 0 deletions src/sass/header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

header {
border-bottom: $themeBorder;

h1 {
font-size: $topHeaderFontSize;
font-weight: bold;
margin-left: $topHeaderShift;
}
}
7 changes: 7 additions & 0 deletions src/sass/login.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

.login {
form {
width: $loginWidth;
margin: 0 auto;
}
}
6 changes: 6 additions & 0 deletions src/sass/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@import 'variables';
@import 'header';
@import 'login';
// @import 'new-thought';
@import 'recent';
10 changes: 10 additions & 0 deletions src/sass/recent.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

.recent {
width: $recentContainerWidth;
margin: 0 auto;
display: flex;

article {
flex: 0 0 calc((100% / $thoughtColumns) - $thoughtMargin);
}
}
11 changes: 11 additions & 0 deletions src/sass/variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

$themeFontColor: #222222;
$themeBorder: 1px solid #99bbff;
$topHeaderFontSize: 1.2em;
$topHeaderShift: 5em;

$loginWidth: 60%;

$recentContainerWidth: 90%;
$thoughtColumns: 2;
$thoughtMargin: 2em;
19 changes: 19 additions & 0 deletions src/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function karmaConfig( config) {
config.set({
frameworks: ['mocha', 'chai'],
browsers: ['Chrome'],
singleRun: true,
files: [
// globbing pattern for searching src directory and any sub for any js
'src/js/*.js',
'node_modules/fetch-mock/es5/client-browserified.js',
'test/specs/**/*.js'
]
});
};
67 changes: 67 additions & 0 deletions test/specs/thoughter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(function() {
'use strict';

window.thoughter = window.thoughter || {};

let expect = chai.expect;
let showRecent = window.thoughter.showRecent;
let getRecent = window.thoughter.getRecent;

describe('thoughterDisplayModule', function() {

describe('recent thought function', function() {

beforeEach(function () {
let thoughtList = document.createElement('section');
thoughtList.classList.add('recent');
console.info('this is where I am using the console' + document.querySelector('body'));
document.querySelector('body').appendChild(thoughtList);
});

afterEach(function() {
(document.querySelectorAll('.recent')).forEach(function (recentSection) {
recentSection.parentNode.removeChild(recentSection);
});
});

let result;

it('should be a function', function() {
expect(showRecent).to.be.a('function');
});

it('should not change the page if passed any non-array parameter', function() {
result = showRecent('paramString');
expect(result).to.be.undefined;
result = showRecent();
expect(result).to.be.undefined;
});

it('should not add anything to the page when passed an empty array', function() {
showRecent([]);
expect(document.querySelectorAll('article.panel').length).to.eq(0);
});

it('should display valid thoughts', function() {
let thought = {'id': 'someNum', 'createTime': '9million o\'clock', 'content': "No thoughts were harmed in the making of this thought object"};
showRecent([thought]);
expect(document.querySelectorAll('article.panel').length).to.eq(1);
});

it('should not display invalid thoughts', function() {
let thought = {'id': 'someNum', 'content': "My thought is in pain"};
showRecent([thought]);
expect(document.querySelectorAll('article.panel').length).to.eq(0);
});

it('should add a thought for only valid thought objects in the passed array parameter', function() {
let thoughts = [{'id': 'someNum', 'createTime': '9million o\'clock', 'content': 'No thoughts were harmed in the making of this thought object'},
{'id': 'someNum', 'createTime': '9million o\'clock', 'content': 'No thoughts were harmed in the making of this thought object'},
{'id': 'someNum', 'content': 'This is an invalid thought. A thought was harmed in the making of this thought object'}];
showRecent(thoughts);
let thoughtPanel = document.querySelectorAll('.panel');
expect(thoughtPanel.length).to.eq(2);
});
});
});
})();