summaryrefslogtreecommitdiff
path: root/spec/View_spec.rb
blob: 538b71fde1c714454b719aa711c9125607f3b201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = View_spec.rb -- PostRunner - Manage the data from your Garmin sport devices.
#
# Copyright (c) 2015 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#

require 'spec_helper'
require 'postrunner/View'
require 'postrunner/ViewButtons'
require 'postrunner/PagingButtons'

module PostRunner

  describe PostRunner::View do

    before(:all) do
      @view_names = %w( activities record )
      delete_files
    end

    after(:all) do
      delete_files
    end

    def delete_files
      @view_names.each do |vn|
        page_files(vn).each do |pf|
          File.delete(pf) if File.exists?(pf)
        end
      end
    end

    def page_files(vn)
      1.upto(vn == 'record' ? 5 : 3).map { |i| "#{vn}-page#{i}.html" }
    end

    it 'should generate view files with multiple pages' do
      views = ViewButtons.new(
        @view_names.map{ |vn| NavButtonDef.
                              new("#{vn}.png", "#{vn}-page1.html") }
      )
      @view_names.each do |vn|
        views.current_page = vn + '-page1.html'
        pages = PagingButtons.new(page_files(vn))
        page_files(vn).each do |file|
          pages.current_page = file
          PostRunner::View.new("Test File: #{file}", views, pages).body.
            write(file)
          File.exists?(file).should be true
        end
      end
    end

  end

end