This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { polyfill } from 'es6-promise' | ||
import 'isomorphic-fetch' | ||
|
||
polyfill() | ||
|
||
export default { | ||
create (id = null) { | ||
let url = (id) ? `http://www.colourlovers.com/api/palette/${encodeURIComponent(id)}?format=json` : null | ||
return Object.assign({ | ||
author: null, | ||
colors: [], | ||
get (callback) { | ||
if (!callback) { | ||
callback = (data) => { | ||
if (data.length === 1) { | ||
data = data[0] | ||
this.author = data.userName | ||
this.hexColors = data.colors | ||
this.title = data.title | ||
} | ||
} | ||
} | ||
if (this.id && this.url) { | ||
fetch(this.url).then((response) => { | ||
if (response.status >= 400) { | ||
throw new Error('Bad server response') | ||
} | ||
return response.json() | ||
}).then(callback) | ||
} | ||
}, | ||
hexColors: [], | ||
id, | ||
title: null, | ||
url | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Palette from './Palette' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { expect } from 'chai' | ||
import 'isomorphic-fetch' | ||
import nock from 'nock' | ||
import Palette from '../../src/js/Palette' | ||
import { polyfill } from 'es6-promise' | ||
|
||
polyfill() | ||
|
||
describe('Palette', () => { | ||
describe('create()', () => { | ||
it('should properly create a palette', () => { | ||
let palette = Palette.create() | ||
expect(palette.author).to.equal(null) | ||
expect(palette.colors).to.deep.equal([]) | ||
expect(palette.id).to.equal(null) | ||
expect(palette.hexColors).to.deep.equal([]) | ||
expect(palette.title).to.equal(null) | ||
expect(palette.url).to.equal(null) | ||
expect(palette.get).to.be.a('function') | ||
}) | ||
it('should properly handle parameters', () => { | ||
let palette = Palette.create('123') | ||
expect(palette.id).to.equal('123') | ||
expect(palette.url).to.deep.equal('http://www.colourlovers.com/api/palette/123?format=json') | ||
palette = Palette.create('star wars') | ||
expect(palette.url).to.deep.equal('http://www.colourlovers.com/api/palette/star%20wars?format=json') | ||
}) | ||
}) | ||
describe('get()', () => { | ||
let fakeData = [{ | ||
'id': 123, | ||
'title': 'Kurasaibo', | ||
'userName': 'rageforst', | ||
'numViews': 1516, | ||
'numVotes': 25, | ||
'numComments': 1, | ||
'numHearts': 0, | ||
'rank': 0, | ||
'dateCreated': '2005-06-04 23:00:34', | ||
'colors': ['FF0033', '000000', 'AEF504', 'EDE6EC'], | ||
'description': `ochi tochi morochi toshy....\r\ntakaque maseguata...wokitoki,\r\nshiro lama Kurasuraibo, nico\r\nkasuuuuu\r\n\r\nOkira yokisan karate shiro kato!!!\n\nthe Liquits, Mexican rock group`, | ||
'url': 'http://www.colourlovers.com/palette/123/Kurasaibo', | ||
'imageUrl': 'http://www.colourlovers.com/paletteImg/FF0033/000000/AEF504/EDE6EC/Kurasaibo.png', | ||
'badgeUrl': 'http://www.colourlovers.com/images/badges/p/0/123_Kurasaibo.png', | ||
'apiUrl': 'http://www.colourlovers.com/api/palette/123' | ||
}] | ||
before(() => { | ||
nock('http://www.colourlovers.com').get('/api/palette/123?format=json').reply(200, fakeData) | ||
}) | ||
it('should properly convert GET requests into objects', (done) => { | ||
let palette = Palette.create('123') | ||
palette.get((data) => { | ||
if (data.length === 1) { | ||
data = data[0] | ||
palette.author = data.userName | ||
palette.title = data.title | ||
palette.hexColors = data.colors | ||
try { | ||
expect(palette.author).to.be.equal(fakeData[0].userName) | ||
expect(palette.hexColors).to.be.deep.equal(fakeData[0].colors) | ||
expect(palette.title).to.be.equal(fakeData[0].title) | ||
done() | ||
} catch (error) { | ||
done(error) | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--compilers js:babel-core/register | ||
--full-trace | ||
--recursive | ||
--watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import path from 'path' | ||
import webpack from 'webpack' | ||
|
||
const sourcePath = path.resolve(__dirname, 'src') | ||
const jsPath = `${sourcePath}/js` | ||
|
||
export default { | ||
entry: [ | ||
`${jsPath}/sass-colour-lover.js` | ||
], | ||
module: { | ||
loaders: [ | ||
{test: /\.js$/, loader: 'babel-loader'} | ||
] | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: `${path.resolve(__dirname, 'build')}` | ||
}, | ||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin() | ||
] | ||
} |