Files
color-thief/cypress/integration/api_spec.js
2019-05-02 09:04:23 -07:00

74 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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('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);
// });
// })
})
function testPaletteCount(num) {
it(`returns ${num} color when colorCount set to ${num}`, function() {
cy.get(`[data-image="rainbow-horizontal.png"] .palette[data-count="${num}"] .output-palette`).should(($el) => {
const count = rgbCount($el.text())
expect(count).to.equal(num);
});
})
}
describe('getPalette()', function() {
beforeEach(function() {
cy.visit('http://localhost:8080');
})
// FULL TEST LIST = [1, 2, 3, 5, 7, 10, 20];
// Non-breaking tests
let testCounts = [5, 7];
testCounts.forEach((count) => testPaletteCount(count))
})