<commit_before>//
//  ChatMessageTextViewModelSpec.swift
//  Rocket.Chat
//
//  Created by <NAME> on 01/04/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import XCTest
@testable import Rocket_Chat

class ChatMessageTextViewModelSpec: XCTestCase {

    func testValidColor() {
        let attachment = Attachment()
        attachment.color = "#C1272D"
        let color = UIColor(hex: "#C1272D")
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.color == color, "Should have a valid color for a valid hexa code")
    }

    func testNilColor() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.color == UIColor.lightGray, "Should have a light gray color for an invalid hexa code")
    }

    func testTitle() {
        let attachment = Attachment()
        attachment.title = "Message title"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.title == attachment.title, "Should have a title")
    }

    func testText() {
        let attachment = Attachment()
        attachment.text = "Lorem ipsum"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == attachment.text, "Should have a text")
    }

    func testTextTitleLink() {
        let attachment = Attachment()
        attachment.text = "Lorem ipsum"
        attachment.titleLink = "http://foo.bar"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == localized("chat.message.open_file"), "Should have a text")
    }

    func testNilText() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == "", "Should have a nil text")
    }

    func testThumbURL() {
        let attachment = Attachment()
        attachment.thumbURL = "http://rocket.chat"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        guard let url = attachment.thumbURL else {
            XCTFail("Can't parse nil url string")
            return
        }

        XCTAssert(model.thumbURL == URL(string: url), "Should have a thumb url")
    }

    func testNilThumbURL() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        guard attachment.thumbURL != nil else {
            XCTAssert(model.thumbURL == nil, "Should have a thumb url")
            return
        }

        XCTFail("Should not have an URL")
    }

    func testCollapsed() {
        let attachment = Attachment()
        attachment.collapsed = true
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssertTrue(model.collapsed)
    }

    func testNotCollapsed() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssertFalse(model.collapsed)
    }

    func testToggleCollpased() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)
        model.toggleCollpase()
        XCTAssertTrue(model.collapsed)
    }

    func testHttpImage() {
        let attachment = Attachment()
        attachment.imageURL = "http://rocket.chat/"
        attachment.title = "http"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title + " (" + localized("alert.insecure_image.title") +  ")", "Should have insecurity warning")
            XCTAssertFalse(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }

    func testImageNoUrl() {
        let attachment = Attachment()
        attachment.title = "nil"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, "Label", "Should be default value")
        } else {
            XCTFail("View create failed")
        }
    }

    func testHttpsImage() {
        let attachment = Attachment()
        attachment.imageURL = "https://rocket.chat/"
        attachment.title = "https"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title, "Should be regular title")
            XCTAssertEqual(ChatMessageImageView.defaultHeight, view.fullHeightConstraint.constant, "Height should not change")
            XCTAssertTrue(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }

    func testHttpsImageDescription() {
        let attachment = Attachment()
        attachment.imageURL = "https://rocket.chat/"
        attachment.title = "https"
        attachment.desc = "I have description, that is maybe longer than one line and breaks on phones."
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title, "Should be regular title")
            XCTAssertGreaterThan(view.fullHeightConstraint.constant, ChatMessageImageView.defaultHeight)
            XCTAssertEqual(view.detailText.text, attachment.desc, "Attachment with description should be higher than without")
            XCTAssertTrue(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }
}
<commit_msg>Oh damn it; passing tests now.<commit_after>//
//  ChatMessageTextViewModelSpec.swift
//  Rocket.Chat
//
//  Created by <NAME> on 01/04/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import XCTest
@testable import Rocket_Chat

class ChatMessageTextViewModelSpec: XCTestCase {

    func testValidColor() {
        let attachment = Attachment()
        attachment.color = "#C1272D"
        let color = UIColor(hex: "#C1272D")
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.color == color, "Should have a valid color for a valid hexa code")
    }

    func testNilColor() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.color == UIColor.lightGray, "Should have a light gray color for an invalid hexa code")
    }

    func testTitle() {
        let attachment = Attachment()
        attachment.title = "Message title"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.title == attachment.title, "Should have a title")
    }

    func testText() {
        let attachment = Attachment()
        attachment.text = "Lorem ipsum"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == attachment.text, "Should have a text")
    }

    func testTextTitleLink() {
        let attachment = Attachment()
        attachment.text = "Lorem ipsum"
        attachment.titleLink = "http://foo.bar"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == localized("chat.message.open_file"), "Should have a text")
    }

    func testNilText() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssert(model.text == "", "Should have a nil text")
    }

    func testThumbURL() {
        let attachment = Attachment()
        attachment.thumbURL = "http://rocket.chat"
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        guard let url = attachment.thumbURL else {
            XCTFail("Can't parse nil url string")
            return
        }

        XCTAssert(model.thumbURL == URL(string: url), "Should have a thumb url")
    }

    func testNilThumbURL() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        guard attachment.thumbURL != nil else {
            XCTAssert(model.thumbURL == nil, "Should have a thumb url")
            return
        }

        XCTFail("Should not have an URL")
    }

    func testCollapsed() {
        let attachment = Attachment()
        attachment.collapsed = true
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssertTrue(model.collapsed)
    }

    func testNotCollapsed() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)

        XCTAssertFalse(model.collapsed)
    }

    func testToggleCollpased() {
        let attachment = Attachment()
        let model = ChatMessageTextViewModel(withAttachment: attachment)
        model.toggleCollpase()
        XCTAssertTrue(model.collapsed)
    }

    func testHttpImage() {
        let attachment = Attachment()
        attachment.imageURL = "http://rocket.chat/"
        attachment.title = "http"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title + " (" + localized("alert.insecure_image.title") +  ")", "Should have insecurity warning")
            XCTAssertFalse(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }

    func testImageNoUrl() {
        let attachment = Attachment()
        attachment.title = "nil"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, "Label", "Should be default value")
        } else {
            XCTFail("View create failed")
        }
    }

    func testHttpsImage() {
        let attachment = Attachment()
        attachment.imageURL = "https://rocket.chat/"
        attachment.title = "https"
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title, "Should be regular title")
            XCTAssertEqual(ChatMessageImageView.defaultHeight, view.fullHeightConstraint.constant, "Height should not change")
            XCTAssertTrue(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }

    func testHttpsImageDescription() {
        let attachment = Attachment()
        attachment.imageURL = "https://rocket.chat/"
        attachment.title = "https"
        attachment.descriptionText = "I have description, that is maybe longer than one line and breaks on phones."
        if let view = ChatMessageImageView.instantiateFromNib() {
            view.attachment = attachment
            let title = view.labelTitle?.text
            XCTAssertEqual(title, attachment.title, "Should be regular title")
            XCTAssertGreaterThan(view.fullHeightConstraint.constant, ChatMessageImageView.defaultHeight)
            XCTAssertEqual(view.detailText.text, attachment.descriptionText, "Attachment with description should be higher than without")
            XCTAssertTrue(view.isLoadable)
        } else {
            XCTFail("View create failed")
        }
    }
}

{'fraction_non_alphanumeric': 0.09224610564789835, 'fraction_numerical': 0.0031328866069097556, 'mean_word_length': 2.49194773625038, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6959655', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2972, 'n_words': 763}