Class: ODDB::State::Drugs::TestResult

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
test/test_state/drugs/result.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) expect_init(mock, atc_classes)



86
87
88
89
90
91
92
93
# File 'test/test_state/drugs/result.rb', line 86

def expect_init(mock, atc_classes)
  mock.__next(:session=) { "foo" }
  mock.__next(:atc_classes) { atc_classes}
  if(atc_classes.is_a?(Array) && !atc_classes.empty?)
    mock.__next(:atc_classes) { atc_classes }
    mock.__next(:atc_sorted) { atc_classes }
  end
end

- (Object) test_empty_list



94
95
96
97
98
99
100
101
# File 'test/test_state/drugs/result.rb', line 94

def test_empty_list
  model = Mock.new("model")
  expect_init(model, nil)
  state = State::Drugs::Result.new(StubResultSession.new, model)
  state.sortby = [:size, :price, :mice]
  assert_equal(View::Drugs::EmptyResult, state.default_view)
  model.__verify
end

- (Object) test_filter



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'test/test_state/drugs/result.rb', line 102

def test_filter
  p1 = StubResultPackage.new(1,2,3)
  p2 = StubResultPackage.new(3,2,1)
  atc = StubResultAtc.new
  atc.packages = [p1, p2]
  model = Mock.new("model")
  expect_init(model, Array.new(250, atc))
  state = State::Drugs::Result.new(StubResultSession.new, model)
  filter = state.filter
  assert_instance_of(Proc, filter)
  state.session.user_input = { :page=>0 }
  result = filter.call(nil)
  assert_instance_of(State::PageFacade, result)
  assert_equal(75, result.size)
  state.session.user_input = { :page=>3 }
  result = filter.call(nil)
  assert_instance_of(State::PageFacade, result)
  assert_equal(25, result.size)
end

- (Object) test_page



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'test/test_state/drugs/result.rb', line 121

def test_page
  p1 = StubResultPackage.new(1,2,3)
  p2 = StubResultPackage.new(3,2,1)
  atc = StubResultAtc.new
  atc.packages = [p1, p2]
  model = Mock.new("model")
  expect_init(model, Array.new(150, atc))
  state = State::Drugs::Result.new(StubResultSession.new, model)
  assert_instance_of(State::PageFacade, state.page)
  assert_equal(0, state.page.to_i)
  state.session.user_input = { :page => 1 }
  assert_equal(1, state.page.to_i)
  state.session.user_input = {}
  assert_equal(1, state.page.to_i)
end