fix bubble calculator tests

// FREEBIE
This commit is contained in:
Michael Kirk 2017-07-11 13:01:32 -04:00
parent 3eb90ba383
commit d15da6e6d4
3 changed files with 41 additions and 57 deletions

View File

@ -164,6 +164,6 @@ SPEC CHECKSUMS:
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
PODFILE CHECKSUM: 01ecc4364fb2fdfda23d3cfcfd40db751738cc4a
PODFILE CHECKSUM: 23e9e80dd9f88092af75b917d37a459cfad37b7c
COCOAPODS: 1.2.1

View File

@ -4,6 +4,7 @@
#import <Foundation/Foundation.h>
#import "TSMessageAdapter.h"
#import "AttachmentSharing.h"
#import "Environment.h"
#import "FLAnimatedImage.h"

View File

@ -1,39 +1,9 @@
// Created by Michael Kirk on 11/2/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
import XCTest
class FakeMessageData: NSObject, JSQMessageData {
public func senderId() -> String! {
return "fake-sender-id"
}
func senderDisplayName() -> String! {
return "fake-senderDisplayName"
}
func date() -> Date! {
return Date()
}
@objc func isMediaMessage() -> Bool {
return false
}
@objc func messageHash() -> UInt {
return 1
}
var bodyText: String? = "fake message data text"
func text() -> String? {
return self.bodyText
}
init(text: String?) {
self.bodyText = text;
}
}
class FakeiPhone6JSQMessagesCollectionViewFlowLayout: JSQMessagesCollectionViewFlowLayout {
// This value was nabbed by inspecting the super class layout.itemSize while debugging the `messageBubbleSizeForMessageData`.
// It requires the view to actually be rendered to get a proper size, so we're baking it in here.
@ -44,81 +14,94 @@ class FakeiPhone6JSQMessagesCollectionViewFlowLayout: JSQMessagesCollectionViewF
/**
* This is a brittle test, which will break if our layout changes. It serves mostly as documentation for cases to
* consider when changing the bubble size calculator. Primarly these test cases came out of a bug introduced in iOS10,
* which prevents us from computing proper boudning box for text that uses the UIEmoji font.
* which prevents us from computing proper bounding box for text that uses the UIEmoji font.
*
* If one of these tests breaks, it should be OK to update the expected value so long as you've tested the result renders
* correctly in the running app (the reference sizes ewre computed in the context of an iphone6 layour.
* correctly in the running app (the reference sizes were computed in the context of an iphone6 layout.
* @see `FakeiPhone6JSQMessagesCollectionViewFlowLayout`
*/
class MesssagesBubblesSizeCalculatorTest: XCTestCase {
let indexPath = IndexPath()
let layout = FakeiPhone6JSQMessagesCollectionViewFlowLayout()
let calculator = MessagesBubblesSizeCalculator()
let thread = TSContactThread()!
let contactsManager = OWSContactsManager()
func messageDataForForText(_ text: String?) -> JSQMessageData {
let interaction = TSOutgoingMessage(timestamp: 0, in: thread, messageBody: text)
interaction.save()
return TSMessageAdapter.messageViewData(with: interaction, in: thread, contactsManager: self.contactsManager)
}
func testHeightForNilMessage() {
let messageData = FakeMessageData(text:nil)
let text: String? = nil
let messageData = self.messageDataForForText(text)
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(16, actual.height);
XCTAssertEqual(37, actual.height)
}
func testHeightForShort1LineMessage() {
let messageData = FakeMessageData(text:"foo")
let text = "foo"
let messageData = self.messageDataForForText(text)
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(38, actual.height);
XCTAssertEqual(38, actual.height)
}
func testHeightForLong1LineMessage() {
let messageData = FakeMessageData(text:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 x")
let text = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 x"
let messageData = self.messageDataForForText(text)
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(38, actual.height);
XCTAssertEqual(38, actual.height)
}
func testHeightForShort2LineMessage() {
let messageData = FakeMessageData(text:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 x 1")
let text = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 x 1"
let messageData = self.messageDataForForText(text)
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(59, actual.height);
XCTAssertEqual(59, actual.height)
}
func testHeightForLong2LineMessage() {
let messageData = FakeMessageData(text:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 x")
let text = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 x"
let messageData = self.messageDataForForText(text)
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(59, actual.height);
XCTAssertEqual(59, actual.height)
}
func testHeightForiOS10EmojiBug() {
let messageData = FakeMessageData(text:"Wunderschönen Guten Morgaaaahhhn 😝 - hast du gut geschlafen ☺️😘")
let messageData = self.messageDataForForText("Wunderschönen Guten Morgaaaahhhn 😝 - hast du gut geschlafen ☺️😘")
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(85.5, actual.height);
XCTAssertEqual(85.5, actual.height)
}
func testHeightForiOS10EmojiBug2() {
let messageData = FakeMessageData(text:"Test test test test test test test test test test test test 😊❤️❤️")
let messageData = self.messageDataForForText("Test test test test test test test test test test test test 😊❤️❤️")
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
XCTAssertEqual(62, actual.height);
XCTAssertEqual(62, actual.height)
}
func testHeightForChineseWithEmojiBug() {
let messageData = FakeMessageData(text:"一二三四五六七八九十甲乙丙😝戊己庚辛壬圭咖啡牛奶餅乾水果蛋糕")
let messageData = self.messageDataForForText("一二三四五六七八九十甲乙丙😝戊己庚辛壬圭咖啡牛奶餅乾水果蛋糕")
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
// erroneously seeing 69 with the emoji fix in place.
XCTAssertEqual(85.5, actual.height);
XCTAssertEqual(85.5, actual.height)
}
func testHeightForChineseWithoutEmojiBug() {
let messageData = FakeMessageData(text:"一二三四五六七八九十甲乙丙丁戊己庚辛壬圭咖啡牛奶餅乾水果蛋糕")
let messageData = self.messageDataForForText("一二三四五六七八九十甲乙丙丁戊己庚辛壬圭咖啡牛奶餅乾水果蛋糕")
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
// erroneously seeing 69 with the emoji fix in place.
XCTAssertEqual(81, actual.height);
XCTAssertEqual(81, actual.height)
}
func testHeightForiOS10DoubleSpaceNumbersBug() {
let messageData = FakeMessageData(text:"")
let messageData = self.messageDataForForText("")
let actual = calculator.messageBubbleSize(for: messageData, at: indexPath, with: layout)
// erroneously seeing 51 with emoji fix in place. It's the call to "fix string"
XCTAssertEqual(59, actual.height);
XCTAssertEqual(59, actual.height)
}
}