diff --git a/cypress/integration/api_spec.js b/cypress/integration/api_spec.js index 688b447..6fc6b71 100644 --- a/cypress/integration/api_spec.js +++ b/cypress/integration/api_spec.js @@ -1,12 +1,52 @@ -describe('API', function() { +function rgbCount(text) { + const vals = text.split(','); + for (const val of vals) { + if (val < 0 || val > 255) { + throw 'Invalid RGB color value'; + } + } + return vals.length / 3 +} + +describe('getColor()', function() { beforeEach(function() { cy.visit('http://localhost:8080'); }) - it('Does not do much!', function() { - // console.log(colorThief); - expect(true).to.equal(true); - // cy.get('.nav__item').contains('Blog').click(); - // cy.url().should('contain', 'blog'); + it('returns valid color from black image', function() { + cy.get('[data-image="black.png"] .output-color').should(($el) => { + const count = rgbCount($el.text()) + expect(count).to.equal(1); + }); }) + + it('returns valid color from red image', function() { + cy.get('[data-image="red.png"] .output-color').should(($el) => { + const count = rgbCount($el.text()) + expect(count).to.equal(1); + }); + }) + + it('returns valid color from rainbow image', function() { + cy.get('[data-image="rainbow-horizontal.png"] .output-color').should(($el) => { + const count = rgbCount($el.text()) + expect(count).to.equal(1); + }); + }) + + // ⚠️BREAKS + // it('returns valid color from white image', function() { + // cy.get('[data-image="white.png"] .output-color').should(($el) => { + // const count = rgbCount($el.text()) + // expect(count).to.equal(1); + // }); + // }) + + // ⚠️BREAKS + // it('returns valid color from transparent image', function() { + // cy.get('[data-image="transparent.png"] .output-color').should(($el) => { + // const count = rgbCount($el.text()) + // expect(count).to.equal(1); + // }); + // }) }) diff --git a/examples/js/demo.js b/examples/js/demo.js index 7f045fc..0692cde 100644 --- a/examples/js/demo.js +++ b/examples/js/demo.js @@ -28,7 +28,6 @@ document.querySelectorAll('.image').forEach((image) => { // Run Color Thief functions and display results below image. // We also log execution time of functions for display. const showColorsForImage = function(image, section) { - const file = section.src; const start = Date.now(); const color = colorThief.getColor(image); const elapsedTimeForGetColor = Date.now() - start; diff --git a/index.html b/index.html index cb8bfbe..c727948 100755 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@