diff options
| author | Randy Morgan <[email protected]> | 2012-04-21 11:28:07 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-21 11:28:07 +0900 |
| commit | a7072a25772a7613620ee60cb607e62ad2db743e (patch) | |
| tree | e11f90ac9b6bb96fa22a1f5fa76261594135a935 /test/workbook/worksheet/tc_conditional_formatting.rb | |
| parent | ab3364b7a88f4054a3b4b8f55263688b7e2bc9d7 (diff) | |
| download | caxlsx-a7072a25772a7613620ee60cb607e62ad2db743e.tar.gz caxlsx-a7072a25772a7613620ee60cb607e62ad2db743e.zip | |
adding in color scale for conditional formatting
Diffstat (limited to 'test/workbook/worksheet/tc_conditional_formatting.rb')
| -rw-r--r-- | test/workbook/worksheet/tc_conditional_formatting.rb | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb index 6feede10..2287c017 100644 --- a/test/workbook/worksheet/tc_conditional_formatting.rb +++ b/test/workbook/worksheet/tc_conditional_formatting.rb @@ -15,16 +15,27 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_equal("AA1:AB100", optioned.sqref) assert_equal([1, 2], optioned.rules) end - + def test_add_as_hash + + color_scale = Axlsx::ColorScale.new do |cs| + cs.colors.first.rgb = "FFDFDFDF" + cs.colors.last.rgb = "FF00FF00" + cs.value_objects.first.type = :percentile + cs.value_objects.first.val = 5 + end + cfs = @ws.add_conditional_formatting( "B2:B2", [{ :type => :containsText, :text => "TRUE", :dxfId => 0, :priority => 1, - :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))' }]) + :formula => 'NOT(ISERROR(SEARCH("FALSE",AB1)))', + :color_scale => color_scale}]) doc = Nokogiri::XML.parse(cfs.last.to_xml_string) assert_equal(1, doc.xpath(".//conditionalFormatting[@sqref='B2:B2']//cfRule[@type='containsText'][@dxfId=0][@priority=1]").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='containsText'][@dxfId=0][@priority=1]//formula='NOT(ISERROR(SEARCH(\"FALSE\",AB1)))'") + assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size, 2) + assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size, 2) end - + def test_single_rule doc = Nokogiri::XML.parse(@cf.to_xml_string) assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size) @@ -41,32 +52,32 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage='false'][@bottom='false'][@dxfId=0][@equalAverage='false'][@priority=2][@operator='lessThan'][@text=''][@percent='false'][@rank=0][@stdDev=1][@stopIfTrue='true'][@timePeriod='today']").size) assert doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage='false'][@bottom='false'][@dxfId=0][@equalAverage='false'][@priority=2][@operator='lessThan'][@text=''][@percent='false'][@rank=0][@stdDev=1][@stopIfTrue='true'][@timePeriod='today']//formula=0.0") end - + def test_to_xml doc = Nokogiri::XML.parse(@ws.to_xml_string) assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size) assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'") end - + def test_multiple_formats @ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :greaterThan, :formula => "1" } doc = Nokogiri::XML.parse(@ws.to_xml_string) assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='1'") - assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'") + assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'") end - + def test_sqref assert_raise(ArgumentError) { @cf.sqref = 10 } assert_nothing_raised { @cf.sqref = "A1:A1" } assert_equal(@cf.sqref, "A1:A1") end - + def test_type assert_raise(ArgumentError) { @cfr.type = "illegal" } assert_nothing_raised { @cfr.type = :containsBlanks } assert_equal(@cfr.type, :containsBlanks) end - + def test_above_average assert_raise(ArgumentError) { @cfr.aboveAverage = "illegal" } assert_nothing_raised { @cfr.aboveAverage = true } @@ -78,7 +89,7 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_nothing_raised { @cfr.equalAverage = true } assert_equal(@cfr.equalAverage, true) end - + def test_bottom assert_raise(ArgumentError) { @cfr.bottom = "illegal" } assert_nothing_raised { @cfr.bottom = true } @@ -90,7 +101,7 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_nothing_raised { @cfr.operator = :notBetween } assert_equal(@cfr.operator, :notBetween) end - + def test_dxf_id assert_raise(ArgumentError) { @cfr.dxfId = "illegal" } assert_nothing_raised { @cfr.dxfId = 1 } @@ -102,25 +113,25 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_nothing_raised { @cfr.priority = 1 } assert_equal(@cfr.priority, 1) end - + def test_text assert_raise(ArgumentError) { @cfr.text = 1.0 } assert_nothing_raised { @cfr.text = "testing" } assert_equal(@cfr.text, "testing") end - + def test_percent assert_raise(ArgumentError) { @cfr.percent = "10%" } #WRONG! assert_nothing_raised { @cfr.percent = true } assert_equal(@cfr.percent, true) end - + def test_rank assert_raise(ArgumentError) { @cfr.rank = -1 } assert_nothing_raised { @cfr.rank = 1 } assert_equal(@cfr.rank, 1) end - + def test_std_dev assert_raise(ArgumentError) { @cfr.stdDev = -1 } assert_nothing_raised { @cfr.stdDev = 1 } @@ -138,4 +149,5 @@ class TestConditionalFormatting < Test::Unit::TestCase assert_nothing_raised { @cfr.timePeriod = :today } assert_equal(@cfr.timePeriod, :today) end + end |
