From 40947e428c405146ceb75c37ea113e4b539acb6c Mon Sep 17 00:00:00 2001 From: Indrashish Ghosh Date: Sun, 20 May 2018 01:11:21 +0530 Subject: [PATCH] Added check for duplicate gradients. Closes #380 #329 --- README.md | 2 ++ gradients.json | 14 ++++------ test/unit/specs/Display.spec.js | 44 ++++++++++++++++++------------- test/unit/specs/Gradients.spec.js | 23 ++++++++++++++++ 4 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 test/unit/specs/Gradients.spec.js diff --git a/README.md b/README.md index c12958fc..ca19af63 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ A few open source projects built with uiGradients - [Uigradients iOS Viewer](https://github.com/thexande/uiGradients-Viewer-iOS) - Open source iOS app for viewing gradients - [Potion](http://numberpicture.com/build) - React components for declaratively composing animated, interactive visualizations +  + ## License [MIT](https://github.com/ghosh/uiGradients/blob/master/LICENSE.md) diff --git a/gradients.json b/gradients.json index 18cde04c..b3ce4c78 100644 --- a/gradients.json +++ b/gradients.json @@ -1,5 +1,5 @@ [ - { + { "name": "Blu", "colors": ["#00416A", "#E4E5E6"] }, @@ -813,7 +813,7 @@ "colors": ["#808080", "#3fada8"] }, { - "name": "Dusk", + "name": "Jupiter", "colors": ["#ffd89b", "#19547b"] }, { @@ -1107,10 +1107,6 @@ "name": "Digital Water", "colors": ["#74ebd5","#ACB6E5"] }, - { - "name": "Velvet Sun", - "colors": ["#e1eec3", "#f05053"] - }, { "name": "Orange Fun", "colors": ["#fc4a1a", "#f7b733"] @@ -1323,9 +1319,9 @@ { "name": "JShine", "colors": ["#12c2e9","#c471ed","#f64f59"] - }, - { + }, + { "name": "Moonlit Asteroid", "colors": ["#0F2027", "#203A43", "#2C5364"] - } + } ] diff --git a/test/unit/specs/Display.spec.js b/test/unit/specs/Display.spec.js index 7a8699cf..0d1bb588 100644 --- a/test/unit/specs/Display.spec.js +++ b/test/unit/specs/Display.spec.js @@ -1,23 +1,31 @@ -import { mount } from 'avoriaz'; -import Display from '@/components/Display'; +import Gradients from '../../../gradients.json'; -const wrapper = mount(Display, { - propsData: { - direction: 'to left', - gradient: { - colors: ['#1FA2FF', '#21DCF6', '#A6FFCB'], - name: 'Stripe', - }, - }, -}); +const findDuplicatesinArrayByKeyValue = (array, propertyName) => { + let seenDuplicate = false; + let testObject = {}; + let dupes = []; + + array.map((item) => { + var itemPropertyName = item[propertyName]; + if (itemPropertyName in testObject) { + dupes.push(itemPropertyName); + testObject[itemPropertyName].duplicate = true; + item.duplicate = true; + seenDuplicate = true; + } + else { + testObject[itemPropertyName] = item; + delete item.duplicate; + } + }) + + return seenDuplicate; +} -describe('Display.vue', () => { - it('It renders element correctly', () => { - expect(wrapper.is('.display')).to.equal(true); - }); - it('should have a gradient as background style', () => { - expect(wrapper.hasStyle('background', 'linear-gradient(to left, #1FA2FF,#21DCF6,#A6FFCB)')) - .to.equal(true); +describe('Duplicate gradients', () => { + it('Has no duplicate gradient names', () => { + const dupes = findDuplicatesinArrayByKeyValue(Gradients, 'name'); + expect(dupes).to.equal(false); }); }); diff --git a/test/unit/specs/Gradients.spec.js b/test/unit/specs/Gradients.spec.js new file mode 100644 index 00000000..7a8699cf --- /dev/null +++ b/test/unit/specs/Gradients.spec.js @@ -0,0 +1,23 @@ +import { mount } from 'avoriaz'; +import Display from '@/components/Display'; + +const wrapper = mount(Display, { + propsData: { + direction: 'to left', + gradient: { + colors: ['#1FA2FF', '#21DCF6', '#A6FFCB'], + name: 'Stripe', + }, + }, +}); + +describe('Display.vue', () => { + it('It renders element correctly', () => { + expect(wrapper.is('.display')).to.equal(true); + }); + + it('should have a gradient as background style', () => { + expect(wrapper.hasStyle('background', 'linear-gradient(to left, #1FA2FF,#21DCF6,#A6FFCB)')) + .to.equal(true); + }); +});