Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Hardware/Hardware/Printer/AirPrintReceipt/ReceiptRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ import UIKit
public final class ReceiptRenderer: UIPrintPageRenderer {
private let content: ReceiptContent

private let dateFormatter: DateFormatter = {
private lazy var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .none
formatter.locale = Locale.current
formatter.locale = locale
formatter.timeZone = timeZone

return formatter
}()

public init(content: ReceiptContent) {
private let locale: Locale
private let timeZone: TimeZone

public init(content: ReceiptContent, locale: Locale = .current, timeZone: TimeZone = .current) {
self.content = content
self.locale = locale
self.timeZone = timeZone

super.init()
}
Expand Down
11 changes: 6 additions & 5 deletions Hardware/HardwareTests/AirPrintReceipt/ReceiptRendererTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import Foundation
import CryptoKit

final class ReceiptRendererTest: XCTestCase {
let locale = Locale(identifier: "en_US_POSIX")
let timeZone = TimeZone(secondsFromGMT: 0)!
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: these could be private

Suggested change
let locale = Locale(identifier: "en_US_POSIX")
let timeZone = TimeZone(secondsFromGMT: 0)!
private let locale = Locale(identifier: "en_US_POSIX")
private let timeZone = TimeZone(secondsFromGMT: 0)!


func test_TextWithoutHtmlSymbols() {
let expectedResultWithoutHtmlSymbolsMd5Description = "MD5 digest: 4eaaad801b2e0da0c113fb1db9267197"
let content = generateReceiptContent()

let renderer = ReceiptRenderer(content: content)
let renderer = ReceiptRenderer(content: content, locale: locale, timeZone: timeZone)

XCTAssertEqual(
Insecure.MD5.hash(data: renderer.htmlContent().data(using: .utf8)!).description,
Expand All @@ -22,7 +25,7 @@ final class ReceiptRendererTest: XCTestCase {
let stringWithHtml = "<tt><table></table></footer>"
let content = generateReceiptContent(stringToAppend: stringWithHtml)

let renderer = ReceiptRenderer(content: content)
let renderer = ReceiptRenderer(content: content, locale: locale, timeZone: timeZone)

XCTAssertEqual(
Insecure.MD5.hash(data: renderer.htmlContent().data(using: .utf8)!).description,
Expand All @@ -36,9 +39,7 @@ final class ReceiptRendererTest: XCTestCase {
let attributeTwo = ReceiptLineAttribute(name: "name_attr_2", value: "value_attr_2")
let content = generateReceiptContent(attributes: [attributeOne, attributeTwo])

let renderer = ReceiptRenderer(content: content)

print(renderer.htmlContent())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, looks like a debug print.

let renderer = ReceiptRenderer(content: content, locale: locale, timeZone: timeZone)

XCTAssertEqual(
Insecure.MD5.hash(data: renderer.htmlContent().data(using: .utf8)!).description,
Expand Down