# frozen_string_literal: true

require 'test_helper'

class ProjectVulnerabilityReportsHelperTest < ActionView::TestCase
  include ProjectVulnerabilityReportsHelper

  it 'must return the width of the scale when its security score' do
    pvr = stub(security_score: 23.12)
    _(pointer(pvr, pvs: false)).must_equal '23.12%'
  end

  it 'must return the width of the scale relative to right margin when its security score' do
    pvr = stub(security_score: 73.76)
    _(pointer_from_right(pvr, pvs: false)).must_equal '26.24%'
  end
  it 'must return the width of the scale relative to right margin when its security score more than 100%' do
    pvr = stub(security_score: 134.85)
    _(pointer_from_right(pvr, pvs: false)).must_equal '0.00%'
  end

  it 'must return the width of the scale when its vulnerability score' do
    create(:project_vulnerability_report, vulnerability_score: 1000.00)
    pvr = stub(vulnerability_score: 400.00)
    _(pointer(pvr, pvs: true)).must_equal '40.00%'
  end

  it 'must return the width of the scale relative to right margin when its vulnerability score' do
    create(:project_vulnerability_report, vulnerability_score: 1000.00)
    pvr = stub(vulnerability_score: 400.00)
    _(pointer_from_right(pvr, pvs: true)).must_equal '60.00%'
  end

  it 'must return the formatted security score' do
    pvr = stub(security_score: 67.20)
    _(pss_content(pvr)).must_equal '67.2%'
  end

  it 'must return the maximum score' do
    create(:project_vulnerability_report, vulnerability_score: 3456)
    _(max_score).must_equal 3456.0
  end

  it 'must get the tooltip content' do
    pvr = create(:project_vulnerability_report, vulnerability_score: 2139)
    _(pvs_content(pvr)).must_equal 'Score: 2139.0 <br/> Percentage: 100.00000% <br/> Rank: 1st of 1'
  end
end
