column_lookup_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Created by IntelliJ IDEA.
  2. # User: mrs
  3. # Date: 6/20/15
  4. # Time: 8:43 PM
  5. # To change this template use File | Settings | File Templates.
  6. java_import com.jbidwatcher.auction.AuctionEntry
  7. java_import java.lang.StringBuffer
  8. java_import com.jbidwatcher.ui.commands.UserActions
  9. java_import com.jbidwatcher.ui.commands.MenuCommand
  10. require 'column_lookup'
  11. require 'ostruct'
  12. describe ColumnLookup do
  13. let(:lookup) { ColumnLookup.new }
  14. let(:entry) { AuctionEntry.new }
  15. before :each do
  16. entry.set("identifier", "12345678")
  17. entry.set("numBids", "1")
  18. entry.set("currency", "USD")
  19. entry.set("curBid", "12.50")
  20. end
  21. it "should not be nil" do
  22. expect(lookup).to_not be_nil
  23. end
  24. it "should give an identifier when asked for column 0" do
  25. expect(lookup.get_value(entry, TableColumnController::ID)).to eq("12345678")
  26. end
  27. context "current bid" do
  28. it "should give a sane current bid amount" do
  29. expect(lookup.get_value(entry, TableColumnController::CUR_BID)).to eq("$12.50 (1)")
  30. end
  31. context "fixed price" do
  32. before :each do
  33. entry.set("fixed_price", "1")
  34. entry.set("quantity", "1")
  35. entry.set("currency", "USD")
  36. entry.set("curBid", "9.99")
  37. end
  38. it "should show (FP)" do
  39. expect(lookup.get_value(entry, TableColumnController::CUR_BID)).to eq("$9.99 (FP)")
  40. end
  41. it "should show (FP x n) when quantity > 1" do
  42. entry.set("quantity", "2")
  43. expect(lookup.get_value(entry, TableColumnController::CUR_BID)).to eq("$9.99 (FP x 2)")
  44. end
  45. end
  46. end
  47. context "max bid" do
  48. it "should give a simple max bid if one is present" do
  49. entry.set("last_bid_amount", "14.01")
  50. expect(lookup.get_value(entry, TableColumnController::MAX)).to eq("$14.01")
  51. end
  52. it "should note an error if an error page is present" do
  53. entry.set("last_bid_amount", "14.01")
  54. entry.error_page = StringBuffer.new
  55. expect(lookup.get_value(entry, TableColumnController::MAX)).to eq("*$14.01")
  56. end
  57. it "should say 'n/a' if no bid present" do
  58. expect(lookup.get_value(entry, TableColumnController::MAX)).to eq("n/a")
  59. end
  60. end
  61. end