<commit_before>import Quick
import Nimble
import Nimble_Snapshots
import Interstellar
import UIKit
import SDWebImage


@testable
import Artsy

class LiveAuctionLotViewControllerTests: QuickSpec {
    override func spec() {

        // This is test target-wide.
        beforeSuite {
            cacheColoredImageForURL(Test_LiveAuctionLotViewModel().urlForProfile)
        }

        describe("snapshots") {

            var subject: LiveAuctionLotViewController!
            var auctionViewModel: Test_LiveAuctionViewModel!
            var lotViewModel: Test_LiveAuctionLotViewModel!
            var salesPerson: LiveAuctionsSalesPersonType!

            beforeEach {
                freezeTime()

                auctionViewModel = Test_LiveAuctionViewModel()
                auctionViewModel.auctionState.insert(.UserIsRegistered)
                auctionViewModel.saleAvailabilitySignal.update( .Active(liveAuctionDate: nil) )
                lotViewModel = Test_LiveAuctionLotViewModel()
                salesPerson = stub_auctionSalesPerson(auctionViewModel)

                subject = LiveAuctionLotViewController(index: 1, lotViewModel: lotViewModel, salesPerson: salesPerson)

                salesPerson.currentLotSignal.update(lotViewModel)
            }

            afterEach {
                unfreezeTime()
            }

            // The indices are known to be the closed/live/upcoming states respectively
            it("looks good for closed lots") {
                lotViewModel.lotStateSignal.update(.ClosedLot)
                expect(subject) == snapshot()
            }

            it("looks good for live lots") {
                auctionViewModel.currentLotSignal.update(lotViewModel)
                lotViewModel.lotStateSignal.update(.LiveLot)
                expect(subject) == snapshot()
            }

            it("looks good for upcoming lots") {
                auctionViewModel.distance = 1
                lotViewModel.lotStateSignal.update(.UpcomingLot)
                expect(subject) == snapshot()
            }

            it("doesnt show a live auction call to action when auction is closed") {
                lotViewModel.lotStateSignal.update(.ClosedLot)
                auctionViewModel.saleAvailabilitySignal.update(.Closed)
                expect(subject) == snapshot()
            }

            it("looks good when its lot becomes the current lot") {
                lotViewModel.lotStateSignal.update(.LiveLot)
                auctionViewModel.currentLotSignal.update(lotViewModel)
                expect(subject) == snapshot()
            }

            it("looks good for lots with a met reserve") {
                lotViewModel.reserveStatusSignal.update(.ReserveMet)
                expect(subject) == snapshot()
            }

            it("looks good for lots with a (not yet met) reserve") {
                lotViewModel.reserveStatusSignal.update(.ReserveNotMet)
                expect(subject) == snapshot()
            }

            it("looks good for out-of-order lots") {
                auctionViewModel.distance = -1
                expect(subject) == snapshot()
            }
        }
    }

}

class Test_LiveAuctionViewModel: LiveAuctionViewModelType {
    var startDate = NSDate().dateByAddingTimeInterval(-3600)
    var liveAuctionStartDate = NSDate().dateByAddingTimeInterval(-3600)
    var lotCount = 3
    var saleAvailabilitySignal: Observable<SaleAvailabilityState> = Observable()
    var currentLotSignal = Observable<LiveAuctionLotViewModelType?>(Test_LiveAuctionLotViewModel(lotID: "active-lot"))
    var auctionState: ARAuctionState = .Default


    var distance: Int?
    func distanceFromCurrentLot(lot: LiveAuctionLotViewModelType) -> Int? {
        return distance
    }
}

class Test_LiveAuctionLotViewModel: LiveAuctionLotViewModelType {
    var lotArtist = "Artist Name"
    var lotArtistBlurb: String? = "Artist Blurb"
    var lotArtworkDescription: String? = "Ipsum lorem whatever."
    var lotArtworkMedium: String? = "Star stuff"
    var lotArtworkDimensions: String? = "140 x 420 cm"
    var estimateString: String? = "$Estimate"
    var lotName = "Lot Name"
    var lotID = "lot-id"
    var lotPremium = "Lot Premium"
    var lotArtworkCreationDate: String? = "1985"
    var urlForThumbnail = NSURL(string: "http://example.com/")!
    var urlForProfile = NSURL(string: "http://example.com/")!
    var reserveStatusString = "is testing reserve"
    var numberOfDerivedEvents = 1
    var lotIndex = 1
    var numberOfBids = 1
    var currencySymbol = "$"
    var currentLotValue = UInt64(1234)
    var currentLotValueString = "$Value"
    var imageAspectRatio: CGFloat = 1
    var liveAuctionLotID = "lotID"
    var dateLotOpened: NSDate?
    var userIsHighestBidder: Bool = false
    var userIsBeingSoldTo: Bool = false
    var isBeingSold: Bool = false
    // Whether or not (all) events returned from this test VM should be cancelled.
    var cancelEvents = false

    func derivedEventAtPresentationIndex(index: Int) -> LiveAuctionEventViewModel {
        let event = LiveAuctionEventViewModel(event: LiveEvent(JSON: liveEventJSON), currencySymbol: "$")
        event.confirm()
        event.bidStatus = .Bid(isMine: false, isTop: false)
        if cancelEvents { event.cancel() }
        return event
    }

    var lotStateSignal = Observable(LotState.UpcomingLot)
    func computedLotStateSignal(auctionViewModel: LiveAuctionViewModelType) -> Observable<LotState> {<commit_msg>[Live] Fixes tests.<commit_after>import Quick
import Nimble
import Nimble_Snapshots
import Interstellar
import UIKit
import SDWebImage


@testable
import Artsy

class LiveAuctionLotViewControllerTests: QuickSpec {
    override func spec() {

        // This is test target-wide.
        beforeSuite {
            cacheColoredImageForURL(Test_LiveAuctionLotViewModel().urlForProfile)
        }

        describe("snapshots") {

            var subject: LiveAuctionLotViewController!
            var auctionViewModel: Test_LiveAuctionViewModel!
            var lotViewModel: Test_LiveAuctionLotViewModel!
            var salesPerson: LiveAuctionsSalesPersonType!

            beforeEach {
                freezeTime()

                auctionViewModel = Test_LiveAuctionViewModel()
                auctionViewModel.auctionState.insert(.UserIsRegistered)
                auctionViewModel.saleAvailabilitySignal.update( .Active(liveAuctionDate: nil) )
                lotViewModel = Test_LiveAuctionLotViewModel()
                salesPerson = stub_auctionSalesPerson(auctionViewModel)

                subject = LiveAuctionLotViewController(index: 1, lotViewModel: lotViewModel, salesPerson: salesPerson)

                salesPerson.currentLotSignal.update(lotViewModel)
            }

            afterEach {
                unfreezeTime()
            }

            // The indices are known to be the closed/live/upcoming states respectively
            it("looks good for closed lots") {
                lotViewModel.lotStateSignal.update(.ClosedLot)
                expect(subject) == snapshot()
            }

            it("looks good for live lots") {
                auctionViewModel.currentLotSignal.update(lotViewModel)
                lotViewModel.lotStateSignal.update(.LiveLot)
                expect(subject) == snapshot()
            }

            it("looks good for upcoming lots") {
                auctionViewModel.distance = 1
                lotViewModel.lotStateSignal.update(.UpcomingLot)
                expect(subject) == snapshot()
            }

            it("doesnt show a live auction call to action when auction is closed") {
                lotViewModel.lotStateSignal.update(.ClosedLot)
                auctionViewModel.saleAvailabilitySignal.update(.Closed)
                expect(subject) == snapshot()
            }

            it("looks good when its lot becomes the current lot") {
                lotViewModel.lotStateSignal.update(.LiveLot)
                auctionViewModel.currentLotSignal.update(lotViewModel)
                expect(subject) == snapshot()
            }

            it("looks good for lots with a met reserve") {
                lotViewModel.reserveStatusSignal.update(.ReserveMet)
                expect(subject) == snapshot()
            }

            it("looks good for lots with a (not yet met) reserve") {
                lotViewModel.reserveStatusSignal.update(.ReserveNotMet)
                expect(subject) == snapshot()
            }

            it("looks good for out-of-order lots") {
                auctionViewModel.distance = -1
                expect(subject) == snapshot()
            }
        }
    }

}

class Test_LiveAuctionViewModel: LiveAuctionViewModelType {
    var startDate = NSDate().dateByAddingTimeInterval(-3600)
    var liveAuctionStartDate = NSDate().dateByAddingTimeInterval(-3600)
    var lotCount = 3
    var saleAvailabilitySignal: Observable<SaleAvailabilityState> = Observable()
    var currentLotSignal = Observable<LiveAuctionLotViewModelType?>(Test_LiveAuctionLotViewModel(lotID: "active-lot"))
    var auctionState: ARAuctionState = .Default


    var distance: Int?
    func distanceFromCurrentLot(lot: LiveAuctionLotViewModelType) -> Int? {
        return distance
    }
}

class Test_LiveAuctionLotViewModel: LiveAuctionLotViewModelType {
    var lotArtist = "Artist Name"
    var lotArtistBlurb: String? = "Artist Blurb"
    var lotArtworkDescription: String? = "Ipsum lorem whatever."
    var lotArtworkMedium: String? = "Star stuff"
    var lotArtworkDimensions: String? = "140 x 420 cm"
    var estimateString: String? = "$Estimate"
    var lotName = "Lot Name"
    var lotID = "lot-id"
    var lotPremium = "Lot Premium"
    var lotArtworkCreationDate: String? = "1985"
    var urlForThumbnail = NSURL(string: "http://example.com/")!
    var urlForProfile = NSURL(string: "http://example.com/")!
    var reserveStatusString = "is testing reserve"
    var numberOfDerivedEvents = 1
    var lotIndex = 1
    var numberOfBids = 1
    var currencySymbol = "$"
    var currentLotValue = UInt64(1234)
    var currentLotValueString = "$Value"
    var imageAspectRatio: CGFloat = 1
    var liveAuctionLotID = "lotID"
    var dateLotOpened: NSDate?
    var userIsHighestBidder: Bool = false
    var userIsBeingSoldTo: Bool = false
    var userIsWinning: Bool = false
    var isBeingSold: Bool = false
    // Whether or not (all) events returned from this test VM should be cancelled.
    var cancelEvents = false

    func derivedEventAtPresentationIndex(index: Int) -> LiveAuctionEventViewModel {
        let event = LiveAuctionEventViewModel(event: LiveEvent(JSON: liveEventJSON), currencySymbol: "$")
        event.confirm()
        event.bidStatus = .Bid(isMine: false, isTop: false)
        if cancelEvents { event.cancel() }
        return event
    }

    var lotStateSignal = Observable(LotState.UpcomingLot)
    func computedLotStateSignal(auctionViewModel: LiveAuctionViewModelType) -> Observable<LotState> {
{'fraction_non_alphanumeric': 0.08007634975459008, 'fraction_numerical': 0.0058171241592437735, 'mean_word_length': 2.494125119085424, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6820408', 'n_tokens_mistral': 3156, 'n_tokens_neox': 2873, 'n_words': 684}