color_object.js 1.1 KB

123456789101112131415161718192021
  1. test('test color object', function() {
  2. let hex = new App.ColorObject('#09f609')
  3. let hsl = new App.ColorObject([0.5, 0.2, 0.3])
  4. deepEqual(hex.asHslArray(), [1/3, 0.9294117647058824, 0.5], 'HEX converted to HSL components')
  5. deepEqual(hsl.asHslArray(), [0.5, 0.2, 0.3], 'HSL components returned as original input')
  6. equal(hex.asString(), '#09f609', 'HEX represented as original input')
  7. equal(hsl.asString(), 'hsl(180,20%,30%)', 'HSL components represented as HSL string')
  8. hex.updateWithString('#fff')
  9. equal(hex.asString(), '#fff', 'color updated')
  10. hsl.updateWithHslComponent(0.25, 1)
  11. deepEqual(hsl.asHslArray(), [0.5, 0.25, 0.3], 'given HSL component updated')
  12. deepEqual(Array.from(App.ColorObject.anyToRgb('#ff0000')), [255, 0, 0, 255], 'any to RGB')
  13. deepEqual(App.ColorObject.anyToHslArray('#ff0000'), [0,1,0.5], 'any to HSL components')
  14. equal(App.ColorObject.anyToHslString('#ff0000'), 'hsl(0,100%,50%)', 'any to HSL string')
  15. deepEqual(App.ColorObject.rgbToHslArray([255, 0, 0]), [0,1,0.5], 'RGB to HSL components')
  16. equal(App.ColorObject.hslArrayToHslString([0.5, 0.25, 0.3]), 'hsl(180,25%,30%)', 'HSL components to HSL string')
  17. })