ydim-html 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +29 -0
  4. data/Gemfile +12 -0
  5. data/History.txt +11 -0
  6. data/LICENSE.txt +339 -0
  7. data/Manifest.txt +47 -0
  8. data/Rakefile +21 -0
  9. data/bin/ydim-htmld +38 -0
  10. data/doc/favicon.ico +0 -0
  11. data/doc/index.rbx +16 -0
  12. data/doc/resources/javascript/dojo.js +5940 -0
  13. data/doc/resources/javascript/iframe_history.html +53 -0
  14. data/doc/resources/javascript/ydim.js +67 -0
  15. data/doc/resources/ydim/ydim.css +113 -0
  16. data/lib/ydim/html.rb +10 -0
  17. data/lib/ydim/html/config.rb +37 -0
  18. data/lib/ydim/html/state/ajax_values.rb +17 -0
  19. data/lib/ydim/html/state/autoinvoice.rb +94 -0
  20. data/lib/ydim/html/state/confirm.rb +16 -0
  21. data/lib/ydim/html/state/debitor.rb +82 -0
  22. data/lib/ydim/html/state/debitors.rb +24 -0
  23. data/lib/ydim/html/state/global.rb +100 -0
  24. data/lib/ydim/html/state/global_predefine.rb +14 -0
  25. data/lib/ydim/html/state/init.rb +21 -0
  26. data/lib/ydim/html/state/invoice.rb +180 -0
  27. data/lib/ydim/html/state/invoices.rb +70 -0
  28. data/lib/ydim/html/state/pdf.rb +17 -0
  29. data/lib/ydim/html/util/lookandfeel.rb +133 -0
  30. data/lib/ydim/html/util/server.rb +37 -0
  31. data/lib/ydim/html/util/session.rb +29 -0
  32. data/lib/ydim/html/util/validator.rb +63 -0
  33. data/lib/ydim/html/version.rb +7 -0
  34. data/lib/ydim/html/view/ajax_values.rb +27 -0
  35. data/lib/ydim/html/view/autoinvoice.rb +80 -0
  36. data/lib/ydim/html/view/autoinvoices.rb +42 -0
  37. data/lib/ydim/html/view/confirm.rb +28 -0
  38. data/lib/ydim/html/view/debitor.rb +118 -0
  39. data/lib/ydim/html/view/debitors.rb +45 -0
  40. data/lib/ydim/html/view/htmlgrid.rb +104 -0
  41. data/lib/ydim/html/view/init.rb +30 -0
  42. data/lib/ydim/html/view/invoice.rb +218 -0
  43. data/lib/ydim/html/view/invoices.rb +159 -0
  44. data/lib/ydim/html/view/navigation.rb +29 -0
  45. data/lib/ydim/html/view/pdf.rb +24 -0
  46. data/lib/ydim/html/view/template.rb +71 -0
  47. data/readme.md +28 -0
  48. data/spec/smoketest_spec.rb +234 -0
  49. data/spec/spec_helper.rb +117 -0
  50. data/spec/stub/http_server.rb +157 -0
  51. data/test/selenium.rb +1690 -0
  52. data/test/selenium/selenium-server.jar +0 -0
  53. data/test/selenium/test_autoinvoice.rb +319 -0
  54. data/test/selenium/test_debitor.rb +344 -0
  55. data/test/selenium/test_debitors.rb +47 -0
  56. data/test/selenium/test_init.rb +105 -0
  57. data/test/selenium/test_invoice.rb +296 -0
  58. data/test/selenium/test_invoices.rb +176 -0
  59. data/test/selenium/unit.rb +125 -0
  60. data/test/stub/http_server.rb +141 -0
  61. data/test/suite.rb +15 -0
  62. data/ydim-html.gemspec +36 -0
  63. metadata +302 -0
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Navigation -- ydim -- 13.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/divcomposite'
6
+ require 'htmlgrid/link'
7
+
8
+ module YDIM
9
+ module Html
10
+ module View
11
+ class NavigationLink < HtmlGrid::Link
12
+ def init
13
+ super
14
+ self.value = @lookandfeel.lookup(@name)
15
+ self.href = @lookandfeel._event_url(@name)
16
+ end
17
+ end
18
+ class Navigation < HtmlGrid::DivComposite
19
+ COMPONENTS = {
20
+ [0,0] => :debitors,
21
+ [1,0] => :invoices,
22
+ [2,0] => :logout,
23
+ }
24
+ CSS_ID_MAP = ['navigation']
25
+ DEFAULT_CLASS = NavigationLink
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Pdf -- ydim -- 17.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/component'
6
+
7
+ module YDIM
8
+ module Html
9
+ module View
10
+ class Pdf < HtmlGrid::Component
11
+ def to_html(context)
12
+ @model.to_pdf :sortby => (@session.state.sortby || []).first,
13
+ :sort_reverse => @session.state.sort_reverse
14
+ end
15
+ def http_headers(*args)
16
+ super.update(
17
+ 'Content-Type' => 'application/pdf',
18
+ 'Content-Disposition' => "attachment; filename=#{@model.unique_id}.pdf"
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Template -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/divtemplate'
6
+ require 'htmlgrid/span'
7
+ require 'ydim/html/view/htmlgrid'
8
+ require 'ydim/html/view/navigation'
9
+
10
+ module YDIM
11
+ module Html
12
+ module View
13
+ class Template < HtmlGrid::DivTemplate
14
+ COMPONENTS = {
15
+ [0,0] => :subnavigation,
16
+ [1,0] => :foot,
17
+ [0,1] => :content,
18
+ [0,2] => :version,
19
+ [1,2] => 'ydim',
20
+ }
21
+ CSS_MAP = ['head', 'content', 'foot',]
22
+ DIV_CLASS = 'template'
23
+ FOOT = Navigation
24
+ LEGACY_INTERFACE = false
25
+ def content(model)
26
+ @content ||= super
27
+ end
28
+ def cpr_link(model)
29
+ link = standard_link(:cpr_link, model)
30
+ link.href = 'http://www.ywesee.com'
31
+ link
32
+ end
33
+ def lgpl_license(model)
34
+ link = standard_link(:lgpl_license, model)
35
+ link.href = 'http://www.gnu.org/copyleft/lesser.html'
36
+ link
37
+ end
38
+ def other_html_headers(context)
39
+ res = super
40
+ ['dojo', 'ydim'].each { |name|
41
+ properties = {
42
+ "language" => "JavaScript",
43
+ "type" => "text/javascript",
44
+ "src" => @lookandfeel.resource_global(:javascript, "#{name}.js"),
45
+ }
46
+ res << context.script(properties)
47
+ }
48
+ res
49
+ end
50
+ def standard_link(key, model)
51
+ HtmlGrid::Link.new(key, model, @session, self)
52
+ end
53
+ def version(model)
54
+ span = HtmlGrid::Span.new(model, @session, self)
55
+ span.css_id = 'version'
56
+ span.value = [
57
+ lgpl_license(model), @lookandfeel.lookup('comma'), Time.now.year.to_s,
58
+ cpr_link(model), @lookandfeel.lookup('comma'), ydim_version(model),
59
+ ]
60
+ span
61
+ end
62
+ def ydim_version(model)
63
+ link = standard_link(:ydim_version, model)
64
+ link.href = 'https://github.com/zdavatz/ydim-html'
65
+ link.set_attribute('title', YDIM_VERSION)
66
+ link
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ # ydim_html
2
+
3
+ * https://github.com/zdavatz/ydim-html.git
4
+
5
+ ## DESCRIPTION:
6
+
7
+ ywesee Distributed Invoice Manager HTML Interface, Ruby
8
+
9
+ This is an application. Therefore it is not distributed as a gem, instead it has Gemfile which specifies all dependencies.
10
+
11
+ ## INSTALL:
12
+
13
+ * bundle install
14
+
15
+ ## TEST:
16
+
17
+ Currently we have neither working unit tnor spec tests.
18
+
19
+ ## DEVELOPERS:
20
+
21
+ * Masaomi Hatakeyama
22
+ * Zeno R.R. Davatz
23
+ * Hannes Wyss (up to Version 1.0)
24
+ * Niklaus Giger (ported to Ruby 2.3.0)
25
+
26
+ ## LICENSE:
27
+
28
+ * GPLv2
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'spec_helper'
4
+ require 'ydim/invoice'
5
+
6
+ describe "ydim-html" do
7
+ include FlexMock::TestCase
8
+
9
+ before :all do
10
+ @idx ||= 0
11
+ puts "setup_ydim_test before all @browser is #{@browser} @idx #{@idx}"
12
+ end
13
+
14
+ before :each do
15
+ @idx += 1
16
+ puts "before each @idx: #{@idx}"
17
+ setup_ydim_test
18
+ # waitForYdimToBeReady(@browser)
19
+ end
20
+
21
+ after :each do
22
+ @idx += 10
23
+ puts "after each @idx: #{@idx}"
24
+ teardown_ydim_test
25
+ # createScreenshot(@browser, '_'+@idx.to_s)
26
+ end
27
+ after :all do
28
+ puts "after :all @browser #{@browser.class} $browser #{$browser.class}"
29
+ $browser.close if $browser
30
+ end
31
+
32
+ # next test work, if only one test is invoked, else we get nil error
33
+ it "should be possible to use login from spec_helper" do
34
+ @session = login
35
+ debitor = OpenStruct.new
36
+ debitor.unique_id = 1
37
+ @session.should_ignore_missing
38
+ @session.should_receive(:create_debitor).and_return(debitor)
39
+ @browser.button(:name => 'create_debitor').click
40
+ expect(@browser.url).to match /debitor/
41
+ end if false
42
+ it "should allow to log in" do
43
+ @browser.goto "#{YDIM::Html.config.http_server}:10080/de/"
44
+ windowSize = @browser.windows.size
45
+ expect(@browser.url).to match YDIM::Html.config.http_server
46
+ text = @browser.text.clone
47
+ # binding.pry unless /Email/.match text
48
+ expect(text).to match /Email\nPasswort\n/
49
+ expect(@browser.title).to eql 'YDIM'
50
+ @browser.element(:name => 'email').wait_until_present
51
+ @browser.text_field(:name => 'email').set 'test@ywesee.com'
52
+ @browser.element(:name => 'pass').wait_until_present
53
+ @browser.text_field(:name => 'pass').set 'secret'
54
+ @browser.element(:name => 'login').wait_until_present
55
+ expect(@browser.forms.size).to eql 1
56
+ @browser.forms.first.submit
57
+ # @browser.button(:name => 'login').click
58
+ text = @browser.text.clone
59
+ expect(text).to match /Nächste Rechnung/ # UTF-8 Problem
60
+ expect(text).to match /Rechnungen/
61
+ end
62
+
63
+ it "should succedd creating an invoice" do
64
+ @session = login()
65
+ expect(@browser.title).to eql 'YDIM'
66
+ @debitor_values = {
67
+ "contact" => "Contact",
68
+ "contact_firstname" => "Firstname",
69
+ "contact_title" => "Dr.",
70
+ "address_lines" => "Street 45",
71
+ "location" => "8006 Zuerich",
72
+ "emails" => "testywesee.com",
73
+ "phone" => "043 540 0549",
74
+ }
75
+ create_debitor(@debitor_values)
76
+ check_debitor(@debitor_values)
77
+ end if false
78
+
79
+ def create_debitor(values= Hash.new)
80
+ @session = login()
81
+ # click "update"
82
+
83
+ expect(@browser.title).to eql 'YDIM'
84
+ @invoice = YDIM::AutoInvoice.new(10001)
85
+ @invoice.debitor = setup_debitor
86
+ @invoice.description = 'AutoInvoice'
87
+ flexstub(@invoice).should_receive(:odba_store)
88
+ item = YDIM::Item.new(:text => 'Item', :price => '100',
89
+ :quantity => 5)
90
+ @invoice.add_item(item)
91
+ expect(@browser.title).to eql 'YDIM'
92
+ @session.should_receive(:debitor).and_return(@debitor)
93
+ @session.should_receive(:autoinvoice).and_return(@invoice)
94
+ @session.should_receive(:generate_invoice).and_return(@invoice)
95
+ @session.should_ignore_missing
96
+ binding.pry
97
+ values.each do |key, value|
98
+ @browser.text_field(:name => 'key').set value
99
+ end
100
+ end if false
101
+ def check_debitor(values = Hash.new)
102
+ # click "update"
103
+
104
+ binding.pry
105
+ expect(@browser.title).to eql 'YDIM'
106
+ values.each do |key, value|
107
+ expect(@browser.text_field(:name => 'key').value).to eq value
108
+ end
109
+ end
110
+
111
+ def setup_debitor
112
+ @debitor = YDIM::Debitor.new(1)
113
+ @debitor.name = 'Foo'
114
+ @debitor.email = 'debitor@ywesee.com'
115
+ @debitor.phone = '0041435400549'
116
+ @debitor.debitor_type = 'dt_pharmacy'
117
+ @debitor
118
+ end
119
+
120
+ if false
121
+ # next test work, if only one test is invoked, else we get nil error
122
+ it "should be possible to use login from spec_helper" do
123
+ login
124
+ end
125
+ it "should succedd creating an invoice" do
126
+ # binding.pry
127
+ TODO = %(
128
+ click "link=Foo"
129
+ wait_for_page_to_load "30000"
130
+ assert_equal "YDIM", get_title
131
+
132
+ click "create_invoice"
133
+ wait_for_page_to_load "30000"
134
+ assert_equal "YDIM", get_title
135
+
136
+ type "description", "Newly created Invoice"
137
+
138
+ @invoice = nil
139
+ @session.should_receive(:create_invoice).and_return {
140
+ @invoice = Invoice.new(10001)
141
+ @invoice.debitor = debitor
142
+ flexstub(invoice).should_receive(:odba_store)
143
+ @invoice
144
+ }
145
+
146
+ click "update"
147
+ wait_for_page_to_load "30000"
148
+
149
+ assert_equal("Newly created Invoice", invoice.description)
150
+ assert_equal(Date.today, invoice.date)
151
+ assert_equal("CHF", invoice.currency)
152
+ assert_equal(2, invoice.precision)
153
+
154
+ assert !is_text_present('Bitte geben Sie das Feld "Beschreibung" an.')
155
+ assert is_element_present("update")
156
+ assert is_element_present("create_item")
157
+ assert !is_element_present("pdf")
158
+ assert !is_element_present("send_invoice")
159
+
160
+ assert_equal "Newly created Invoice",
161
+ get_value("//input[@name='description']")
162
+
163
+ item = nil
164
+ @session.should_receive(:add_items).and_return { |invoice_id, items, invoice_key|
165
+ assert_equal(10001, invoice_id)
166
+ assert_equal(:invoice, invoice_key)
167
+ assert_equal(1, items.size)
168
+ hash = items.first
169
+ assert_instance_of(Hash, hash)
170
+ assert_equal(1, hash.size)
171
+ assert_instance_of(Time, hash[:time])
172
+ item = YDIM::Item.new(hash)
173
+ item.index = 0
174
+ @invoice.items.push(item)
175
+ item
176
+ }
177
+ click "create_item"
178
+ ## waitForElementPresent:
179
+ assert !60.times {
180
+ break if (is_element_present("text[0]") rescue false)
181
+ sleep 1
182
+ }
183
+ assert is_element_present("quantity[0]")
184
+ assert is_element_present("unit[0]")
185
+ assert is_element_present("price[0]")
186
+ assert_equal "0.00", get_text("total_netto0")
187
+
188
+ assert is_element_present("update")
189
+ assert is_element_present("create_item")
190
+ assert !is_element_present("pdf")
191
+ assert !is_element_present("send_invoice")
192
+
193
+ @session.should_receive(:update_item).and_return { |invoice_id, item_index, data, invoice_key|
194
+ assert_equal(10001, invoice_id)
195
+ assert_equal(0, item_index)
196
+ assert_equal(:invoice, invoice_key)
197
+ data.each { |key, val|
198
+ item.send("\#{key}=", val)
199
+ }
200
+ item
201
+ }
202
+
203
+ type "text[0]", "Item 1"
204
+ type "quantity[0]", "2"
205
+ type "unit[0]", "pieces"
206
+ type "price[0]", "3.25"
207
+ sleep 0.1
208
+ assert_equal "6.50", get_text("total_netto0")
209
+
210
+ assert is_element_present("update")
211
+ assert is_element_present("create_item")
212
+ assert !is_element_present("pdf")
213
+ assert !is_element_present("send_invoice")
214
+
215
+ click "update"
216
+ wait_for_page_to_load "30000"
217
+
218
+ assert is_text_present("Total Netto")
219
+ assert is_text_present("MwSt. (7.6%)")
220
+ assert is_text_present("Total Brutto")
221
+
222
+ assert is_element_present("update")
223
+ assert is_element_present("create_item")
224
+ assert is_element_present("pdf")
225
+ assert is_element_present("send_invoice")
226
+
227
+ click "link=debitor@ywesee.com"
228
+ wait_for_page_to_load "30000"
229
+ assert is_text_present("Newly created Invoice")
230
+ )
231
+ end if false
232
+ end
233
+ end
234
+
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # require 'simplecov'
4
+ # SimpleCov.start
5
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
+ require 'ydim/html/config'
7
+ require 'digest'
8
+ require 'minitest/autorun'
9
+ require 'flexmock/test_unit'
10
+ require_relative 'stub/http_server'
11
+ require 'ydim/html/util/server'
12
+ require 'watir'
13
+ require "watir-webdriver/wait"
14
+ begin
15
+ require 'pry'
16
+ rescue LoadError
17
+ end
18
+
19
+ RSpec.configure do |config|
20
+ config.mock_with :flexmock
21
+ config.expect_with :rspec do |c|
22
+ c.syntax = [:expect]
23
+ end
24
+ end
25
+
26
+ BreakIntoPry = false
27
+ begin
28
+ require 'pry'
29
+ rescue LoadError
30
+ # ignore error for Travis-CI
31
+ end
32
+
33
+ @homeUrl ||= "http://localhost:8752"
34
+ YdimUrl = @homeUrl
35
+ ImageDest = File.join(Dir.pwd, 'images')
36
+ FileUtils.makedirs(ImageDest, :verbose => true) unless File.exists?(ImageDest)
37
+ $browser ||= Watir::Browser.new :firefox
38
+ WEBrick::BasicLog.new(nil, WEBrick::BasicLog::DEBUG)
39
+
40
+ def setup_ydim_test
41
+ @browser = $browser
42
+ include FlexMock::TestCase
43
+ YDIM::Html.config.email = 'test@ywesee.com'
44
+ YDIM::Html.config.md5_pass = Digest::MD5.hexdigest('secret')
45
+ YDIM::Html.config.config=['/tmp/ignore_if_not_exists']
46
+
47
+ debitors=[]
48
+ session = flexmock('session')
49
+ @ydim_server = flexmock('ydim_server')
50
+ @ydim_server.should_receive(:login).and_return(session).by_default
51
+ @ydim_server.should_receive(:logout)
52
+ session.should_receive(:debitors).and_return(debitors)
53
+ # created ssh-keygen -f id_dsa -t dsa (with empty-passphrase
54
+ @server = YDIM::Html::Util::Server.new(@ydim_server)
55
+ @server.extend(DRbUndumped)
56
+ drb_url = "druby://localhost:10081"
57
+ @drb = Thread.new {
58
+ @drb_server = DRb.start_service(drb_url, @server)
59
+ }
60
+ @drb.abort_on_exception = true
61
+ @http_server = YDIM::Html::Stub.http_server(drb_url)
62
+ @http_server.logger.level = WEBrick::BasicLog::DEBUG
63
+ @webrick = Thread.new { @http_server.start }
64
+ puts "setup_ydim_test #{@http_server.class} #{@drb_server.class}"
65
+ end
66
+
67
+ def teardown_ydim_test
68
+ @http_server ||= false
69
+ @drb_server ||= false
70
+ puts "teardown_ydim_test #{@http_server.class} #{@drb_server.class} @browser #{@browser.class}"
71
+ @drb_server.stop_service if @drb_server
72
+ @http_server.shutdown if @http_server
73
+ @ydim_server = nil
74
+ end
75
+
76
+ def small_delay
77
+ sleep(0.1)
78
+ end
79
+
80
+ def createScreenshot(browser=@browser, added=nil)
81
+ small_delay
82
+ if browser.url.index('?')
83
+ name = File.join(ImageDest, File.basename(browser.url.split('?')[0]).gsub(/\W/, '_'))
84
+ else
85
+ name = File.join(ImageDest, browser.url.split('/')[-1].gsub(/\W/, '_'))
86
+ end
87
+ name = "#{name}#{added}.png"
88
+ browser.screenshot.save (name)
89
+ puts "createScreenshot: #{name} done" if $VERBOSE
90
+ end
91
+
92
+ def login(debitors=[])
93
+ session = flexmock('session')
94
+ @ydim_server.should_receive(:login).and_return(session).by_default
95
+ session.should_receive(:debitors).and_return(debitors)
96
+ @ydim_server.should_receive(:logout)
97
+ # @browser.link(:name => 'logout').click if @browser.link(:name => 'logout').present?
98
+ @browser.goto "#{YDIM::Html.config.http_server}:10080/"
99
+ sleep 0.5
100
+ puts @browser.text
101
+ @browser.element(:name => 'email').wait_until_present(3) # wait at most 3 seconds
102
+ expect(@browser.title).to eql 'YDIM'
103
+ expect(@browser.text).to match /Email\nPasswort\n/
104
+ @browser.text_field(:name => 'email').set 'test@ywesee.com'
105
+ @browser.element(:name => 'pass').wait_until_present
106
+ @browser.text_field(:name => 'pass').set 'secret'
107
+ @browser.element(:name => 'login').wait_until_present
108
+ @browser.forms.first.submit
109
+
110
+ converter = flexmock('session')
111
+ converter.should_receive(:convert).and_return { |amount, from, to|
112
+ amount
113
+ }
114
+ session.should_receive(:currency_converter).and_return(converter)
115
+ session
116
+ end
117
+