From d754e27821b83af27cb5a52a83ebfd6330ac8468 Mon Sep 17 00:00:00 2001 From: Durga Madhab Date: Sat, 2 Jun 2018 18:27:49 +0530 Subject: [PATCH] test case RGBA / HSLA added test case for RGB/RGBA and HSL/HSLA (uppercase) --- test/unit/color.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/unit/color.js b/test/unit/color.js index 4c0157c54e8..145b8c35fb2 100644 --- a/test/unit/color.js +++ b/test/unit/color.js @@ -88,8 +88,8 @@ var oColor = new fabric.Color('ffffffff'); assert.ok(typeof oColor.toHexa === 'function'); assert.equal(oColor.toHexa(), 'FFFFFFFF'); - oColor.setSource([255,255,255,0.8]); - assert.equal(oColor.toHexa(), 'FFFFFFCC'); + oColor.setSource([255,255,255,0.1]); + assert.equal(oColor.toHexa(), 'FFFFFF1A'); }); QUnit.test('getAlpha', function(assert) { @@ -173,6 +173,25 @@ assert.equal(oColor.toHex(), 'FFFFFF'); }); + QUnit.test('fromRgb (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromRgb === 'function'); + var originalRgb = 'RGB(255,255,255)'; + var oColor = fabric.Color.fromRgb(originalRgb); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), 'FFFFFF'); + }); + + QUnit.test('fromRgba (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromRgba === 'function'); + var originalRgba = 'RGBA(255,255,255,0.5)'; + var oColor = fabric.Color.fromRgba(originalRgba); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), 'FFFFFF'); + assert.equal(oColor.getAlpha(), 0.5, 'alpha should be set properly'); + }); + QUnit.test('fromRgba', function(assert) { assert.ok(typeof fabric.Color.fromRgba === 'function'); var originalRgba = 'rgba(255,255,255,0.5)'; @@ -253,6 +272,27 @@ assert.equal(oColor.toHex(), '180637'); }); + QUnit.test('fromHsl (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromHsl === 'function'); + var originalHsl = 'HSL(270,50%,40%)'; + var oColor = fabric.Color.fromHsl(originalHsl); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), '663399'); + assert.equal(oColor.toRgba(), 'rgba(102,51,153,1)'); + }); + + QUnit.test('fromHsla (uppercase)', function(assert) { + assert.ok(typeof fabric.Color.fromHsla === 'function'); + var originalHsla = 'HSLA(108,50%,50%,0.7)'; + var oColor = fabric.Color.fromHsla(originalHsla); + assert.ok(oColor); + assert.ok(oColor instanceof fabric.Color); + assert.equal(oColor.toHex(), '59BF40'); + assert.equal(oColor.toRgba(), 'rgba(89,191,64,0.7)'); + assert.equal(oColor.getAlpha(), 0.7, 'alpha should be set properly'); + }); + QUnit.test('fromHsla', function(assert) { assert.ok(typeof fabric.Color.fromHsla === 'function'); var originalHsla = 'hsla(262,80%,12%,0.2)';