# -*- coding: utf-8 -*-

require 'helper'

class TestRegressionCondFormat18 < Minitest::Test
  def setup
    setup_dir_var
  end

  def teardown
    @tempfile.close(true)
  end

  def test_cond_format18
    @xlsx = 'cond_format18.xlsx'
    workbook  = WriteXLSX.new(@io)
    worksheet = workbook.add_worksheet

    worksheet.write('A1', 1)
    worksheet.write('A2', 2)
    worksheet.write('A3', 3)
    worksheet.write('A4', 4)
    worksheet.write('A5', 5)
    worksheet.write('A6', 6)
    worksheet.write('A7', 7)
    worksheet.write('A8', 8)
    worksheet.write('A9', 9)

    worksheet.write('A12', 75)

    worksheet.conditional_formatting(
      'A1',
      {
        type:          'icon_set',
        icon_style:    '3_arrows',
        reverse_icons: 1
      }
    )

    worksheet.conditional_formatting(
      'A2',
      {
        type:       'icon_set',
        icon_style: '3_flags',
        icons_only: 1
      }
    )

    worksheet.conditional_formatting(
      'A3',
      {
        type:          'icon_set',
        icon_style:    '3_traffic_lights_rimmed',
        icons_only:    1,
        reverse_icons: 1
      }
    )

    worksheet.conditional_formatting(
      'A4',
      {
        type:       'icon_set',
        icon_style: '3_symbols_circled',
        icons:      [
          { value: 80 },
          { value: 20 }
        ]
      }
    )

    worksheet.conditional_formatting(
      'A5',
      {
        type:       'icon_set',
        icon_style: '4_arrows',
        icons:      [
          { criteria: '>' },
          { criteria: '>' },
          { criteria: '>' }
        ]
      }
    )

    worksheet.conditional_formatting(
      'A6',
      {
        type:       'icon_set',
        icon_style: '4_red_to_black',
        icons:      [
          { criteria: '>=', type: 'number',     value: 90 },
          { criteria: '<',  type: 'percentile', value: 50 },
          { criteria: '<=', type: 'percent',    value: 25 }
        ]
      }
    )

    worksheet.conditional_formatting(
      'A7',
      {
        type:       'icon_set',
        icon_style: '4_traffic_lights',
        icons:      [{ value: '=$A$12' }]
      }
    )

    worksheet.conditional_formatting(
      'A8',
      {
        type:       'icon_set',
        icon_style: '5_arrows_gray',
        icons:      [{ type: 'formula', value: '=$A$12' }]
      }
    )

    worksheet.conditional_formatting(
      'A9',
      {
        type:          'icon_set',
        icon_style:    '5_quarters',
        icons:         [
          { value: 70 },
          { value: 50 },
          { value: 30 },
          { value: 10 }
        ],
        reverse_icons: 1
      }
    )

    workbook.close
    compare_for_regression(
      nil,
      { 'xl/workbook.xml' => ['<workbookView'] }
    )
  end
end
