require "eitil_integrate/application_exporter" RSpec.describe "EitilIntegrate::RubyXL::AutoSum" do let(:input) do { 0 =>["Cafe eitje, geëxporteerd op maandag 6 sept. 2021",nil,"01/06/2021 – 30/06/2021","",nil,"Abel van Hoek","Astrid Spanjers","Billy Wilson","Hannah Broek","Joris Rood (12345678)","Lara Welting ()","Mascha de Graaf","Merel Verkaart","Sara Brouwer","Tammy Warren","Walter Watson"], 1 =>[nil, nil, nil, "Gewerkte uren", nil, "92,75", "0,0", "94,75", "0,0", "0,0", "0,0", "0,0", "38,75", "0,0", "0,0", "0,0"], 2 =>[nil, nil, nil, "Verlof opgenomen", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 3 =>[nil, nil, nil, "Ziekte-uren", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 4 =>[nil, nil, nil, "Bijzonder verlof", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 5 =>[nil, nil, nil, "Totaal maaltijden", nil, "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], 6 =>[nil, nil, nil, "Toeslag: Alle dagen (18:00-23:59)", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 7 =>[nil, nil, nil, "Toeslag: Shiftleader toeslag", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 8 =>[nil, nil, nil, "Toeslag: Feestdagen", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 9 =>[nil, nil, nil, "Toeslag: Feestdagen", nil, "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0", "0,0"], 10=>[nil, nil, nil, "01/06/2021", nil, "", "", "", "", "", "", "", "7,75", "", "", ""], 11=>[nil, nil, nil, "02/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 12=>[nil, nil, nil, "03/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 13=>[nil, nil, nil, "04/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 14=>[nil, nil, nil, "05/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 15=>[nil, nil, nil, "06/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 16=>[nil, nil, nil, "07/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 17=>[nil, nil, nil, "08/06/2021", nil, "", "", "", "", "", "", "", "7,75", "", "", ""], 18=>[nil, nil, nil, "09/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 19=>[nil, nil, nil, "10/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 20=>[nil, nil, nil, "11/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 21=>[nil, nil, nil, "12/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 22=>[nil, nil, nil, "13/06/2021", nil, "", "", "8,5", "", "", "", "", "", "", "", ""], 23=>[nil, nil, nil, "14/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 24=>[nil, nil, nil, "15/06/2021", nil, "", "", "", "", "", "", "", "7,75", "", "", ""], 25=>[nil, nil, nil, "16/06/2021", nil, "7,5", "", "", "", "", "", "", "", "", "", ""], 26=>[nil, nil, nil, "17/06/2021", nil, "", "", "7,75", "", "", "", "", "", "", "", ""], 27=>[nil, nil, nil, "18/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 28=>[nil, nil, nil, "19/06/2021", nil, "7,75", "", "", "", "", "", "", "", "", "", ""], 29=>[nil, nil, nil, "20/06/2021", nil, "10:00", "10:00", "00:15", "00:15", "7", ""], # sum test 30=>[nil, nil, nil, "21/06/2021", nil, "10:00", "10:00", "00:15", "00:15", "", "", ""], # sum test 31=>[nil, nil, nil, "22/06/2021", nil, "7,0", "", "", "", "", "", "", "", "", "", ""], # rounding test 32=>[nil, nil, nil, "23/06/2021", nil, "7,1", "", "", "", "", "", "", "", "", "", ""], # rounding test 33=>[nil, nil, nil, "24/06/2021", nil, 7, 7.5, "7,5", "7", "7.5", "", "", "", "", ""], # sum test 34=>[nil, nil, nil, "25/06/2021", nil, 7, 7, 7, "", "", "", "", "", "", "", ""], # sum test 35=>[nil, nil, nil, "26/06/2021", nil, 7.5, 7.5, 7.5, "", "", "", "", "", "", "", ""], # sum test 36=>[nil, nil, nil, "27/06/2021", nil, "7", "7", "7", "", "", "", "", "", "", "", ""], # sum test 37=>[nil, nil, nil, "28/06/2021", nil, "7.5", "7.5", "7.5", "", "", "", "", "", "", ""], # sum test 38=>[nil, nil, nil, "29/06/2021", nil, "7,5", "7,5", "7,5", "", "", "", "", "", ""], # sum test 39=>[nil, nil, nil, "30/06/2021", nil, "", "", "", "", "", "", "", "", "", "", ""] # nil test } end let(:autosum) { EitilIntegrate::RubyXL::AutoSum.perform(input) } it "should reduce all columns (represented as arrays) into a single string or nil" do expect(autosum).to be_a Hash expect(autosum.values).to be_a Array expect(autosum.values.all? { |v| v.is_a?(String) || v.is_a?(NilClass) }).to be_truthy end it "should sum integers correctly" do expect(autosum[34]).to eq "21" end it "should sum floats correctly" do expect(autosum[35]).to eq "22.5" end it "should sum stringified integers (e.g. '7') correctly" do expect(autosum[36]).to eq "21" end it "should sum stringified floats (e.g. '7.5') correctly" do expect(autosum[37]).to eq "22.5" end it "should sum stringified comma floats (e.g. '7,5') correctly" do expect(autosum[38]).to eq "22.5" end it "should sum stringified times (e.g. '10:00') correctly" do expect(autosum[30]).to eq "20:30" end it "should sum a combination of all different numeric formats correctly" do expect(autosum[33]).to eq "36.5" end it "should not sum a combination of a numeric format and time format, but return nil instead" do expect(autosum[29]).to be_nil end it "should convert summed floats into integers, if the number is whole and therefore could be represented as integer" do expect(autosum[31]).to eq "7" end it "should not convert summed floats into integers, if the number is not whole and therefore could not be represented as integer" do expect(autosum[32]).to eq "7.1" end it "should replace the first column's values with a title called 'Totaal'" do expect(autosum[0]).to eq 'Totaal' end end