<commit_before>//
//  CharactersViewControllerTests.swift
//  StarWars
//
//  Created by <NAME> on 5/14/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

@testable import StarWars
import Quick
import Nimble


class CharactersViewControllerTests: QuickSpec {
    
    var sut: CharactersViewController!
    var charactersViewControllerPresenterMock: CharactersViewControllerPresenterMock!
    var charactersList: [[String: String]]!
    
    
    override func spec() {
        
        beforeSuite {
            self.sut = CharactersViewController()
            self.charactersViewControllerPresenterMock = CharactersViewControllerPresenterMock()
            self.sut.presenter = self.charactersViewControllerPresenterMock
        }
        
        
        describe("The View being loaded") {
            beforeEach {
                self.sut.viewDidLoad()
            }
            
            it("Should notify the Presenter about its life cycle") {
                expect(self.charactersViewControllerPresenterMock.notifiedWhenViewLoaded).to(beTrue())
            }

            it("Should have an UITableView not null") {
                expect(self.sut.charactersTableView).toNot(beNil())
            }

            it("Should have an UITableView as a child view") {
                expect(self.sut.view.subviews.contains(self.sut.charactersTableView)).to(beTrue())
            }

            it("Should conform to UITableViewDataSource protocol") {
                expect(self.sut.conformsToProtocol(UITableViewDataSource)).to(beTrue())
            }

            it("Should have an UITableView with DataSource") {
                expect(self.sut.charactersTableView.dataSource).toNot(beNil())
            }

            it("Should have an UILabel for empty dataset message as a child view") {
                expect(self.sut.view.subviews.contains(self.sut.emptyDataSetLabel)).to(beTrue())
            }
        }


        describe("The View being told to show the characters list") {
            beforeEach {
                self.charactersList = [[:]]
                self.sut.showCharactersList(self.charactersList)
            }

            it("Should have the table view set as visible") {
                expect(self.sut.charactersTableView.hidden).to(beFalse())
            }

            it("Should have the empty dataset message label set as invisible") {
                expect(self.sut.emptyDataSetLabel.hidden).to(beTrue())
            }
            
            it("Should set the characters' list for the data source") {
                expect(self.sut.charactersList).to(equal(self.charactersList))
            }

            it("Should have a row for each character in the table view") {
                let expectedRows = self.charactersList.count
                print("Expected rows: \(expectedRows)")
                expect(self.sut.charactersTableView.numberOfRowsInSection(0)).to(equal(expectedRows))
            }
            
            it("Should return a valid cell when it's dequeued from the table view") {
                let cell = self.sut.charactersTableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))
                expect(cell).notTo(beNil())
            }
        }


        describe("The View being told to show the empty dataset screen") {
            beforeEach {
                self.sut.showEmptyDatasetScreen()
            }

            it("Should shown the proper message in the empty dataset label") {
                expect(self.sut.emptyDataSetLabel.text).to(equal("No characters to show =("))
            }

            it("Should have the empty dataset message label set as visible") {
                expect(self.sut.emptyDataSetLabel.hidden).to(beFalse())
            }

            it("Should have the table view set as invisible") {
                expect(self.sut.charactersTableView.hidden).to(beTrue())
            }

            it("Should have a row for each character in the table view") {
                let expectedRows = self.sut.charactersList.count
                expect(self.sut.charactersTableView.numberOfRowsInSection(0)).to(equal(expectedRows))
            }
        }
        
        
        describe("The characters list being set") {
            beforeEach {
                self.sut.charactersTableView = CharactersTableViewMock()
                self.sut.charactersList = []
            }
            
            it("Should reload the characters' table view data") {
                expect((self.sut.charactersTableView as! CharactersTableViewMock).reloadDataCalled).to(beTrue())
            }
        }
        
        
        afterSuite {
            self.sut = nil
            self.charactersViewControllerPresenterMock = nil
        }
    }
}


class CharactersViewControllerPresenterMock: CharactersPresentation {<commit_msg>Removes unnecessary test within the view<commit_after>//
//  CharactersViewControllerTests.swift
//  StarWars
//
//  Created by <NAME> on 5/14/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

@testable import StarWars
import Quick
import Nimble


class CharactersViewControllerTests: QuickSpec {
    
    var sut: CharactersViewController!
    var charactersViewControllerPresenterMock: CharactersViewControllerPresenterMock!
    var charactersList: [[String: String]]!
    
    
    override func spec() {
        
        beforeSuite {
            self.sut = CharactersViewController()
            self.charactersViewControllerPresenterMock = CharactersViewControllerPresenterMock()
            self.sut.presenter = self.charactersViewControllerPresenterMock
        }
        
        
        describe("The View being loaded") {
            beforeEach {
                self.sut.viewDidLoad()
            }
            
            it("Should notify the Presenter about its life cycle") {
                expect(self.charactersViewControllerPresenterMock.notifiedWhenViewLoaded).to(beTrue())
            }

            it("Should have an UITableView not null") {
                expect(self.sut.charactersTableView).toNot(beNil())
            }

            it("Should have an UITableView as a child view") {
                expect(self.sut.view.subviews.contains(self.sut.charactersTableView)).to(beTrue())
            }

            it("Should conform to UITableViewDataSource protocol") {
                expect(self.sut.conformsToProtocol(UITableViewDataSource)).to(beTrue())
            }

            it("Should have an UITableView with DataSource") {
                expect(self.sut.charactersTableView.dataSource).toNot(beNil())
            }

            it("Should have an UILabel for empty dataset message as a child view") {
                expect(self.sut.view.subviews.contains(self.sut.emptyDataSetLabel)).to(beTrue())
            }
        }


        describe("The View being told to show the characters list") {
            beforeEach {
                self.charactersList = [[:]]
                self.sut.showCharactersList(self.charactersList)
            }

            it("Should have the table view set as visible") {
                expect(self.sut.charactersTableView.hidden).to(beFalse())
            }

            it("Should have the empty dataset message label set as invisible") {
                expect(self.sut.emptyDataSetLabel.hidden).to(beTrue())
            }
            
            it("Should set the characters' list for the data source") {
                expect(self.sut.charactersList).to(equal(self.charactersList))
            }

            it("Should have a row for each character in the table view") {
                let expectedRows = self.charactersList.count
                print("Expected rows: \(expectedRows)")
                expect(self.sut.charactersTableView.numberOfRowsInSection(0)).to(equal(expectedRows))
            }
            
            it("Should return a valid cell when it's dequeued from the table view") {
                let cell = self.sut.charactersTableView.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))
                expect(cell).notTo(beNil())
            }
        }


        describe("The View being told to show the empty dataset screen") {
            beforeEach {
                self.sut.showEmptyDatasetScreen()
            }

            it("Should shown the proper message in the empty dataset label") {
                expect(self.sut.emptyDataSetLabel.text).to(equal("No characters to show =("))
            }

            it("Should have the empty dataset message label set as visible") {
                expect(self.sut.emptyDataSetLabel.hidden).to(beFalse())
            }

            it("Should have the table view set as invisible") {
                expect(self.sut.charactersTableView.hidden).to(beTrue())
            }
        }
        
        
        describe("The characters list being set") {
            beforeEach {
                self.sut.charactersTableView = CharactersTableViewMock()
                self.sut.charactersList = []
            }
            
            it("Should reload the characters' table view data") {
                expect((self.sut.charactersTableView as! CharactersTableViewMock).reloadDataCalled).to(beTrue())
            }
        }
        
        
        afterSuite {
            self.sut = nil
            self.charactersViewControllerPresenterMock = nil
        }
    }
}


class CharactersViewControllerPresenterMock: CharactersPresentation {
{'fraction_non_alphanumeric': 0.08912354804646251, 'fraction_numerical': 0.0026399155227032735, 'mean_word_length': 1.8769744835965978, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '978015', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2339, 'n_words': 528}