OutputManagerTest.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // OutputManagerTest.swift
  3. //
  4. // Created by jason on 31/8/23.
  5. //
  6. import Quick
  7. import Nimble
  8. @testable import CutBoxCLICore
  9. class OutputManagerSpec: QuickSpec {
  10. override func spec() {
  11. describe("OutputManager") {
  12. var mockOutput: MockOutput!
  13. var historyEntries: [HistoryEntry]!
  14. var subject: OutputManager!
  15. beforeEach {
  16. mockOutput = MockOutput()
  17. historyEntries = [HistoryEntry]()
  18. historyEntries.append(HistoryEntry(string: "Test 1", timestamp: "1970-01-01T00:00:00Z", favorite: nil))
  19. historyEntries.append(HistoryEntry(string: "Test 2", timestamp: "1970-01-02T00:00:00Z", favorite: nil))
  20. historyEntries.append(HistoryEntry(string: "Test 3", timestamp: "1970-01-03T00:00:00Z", favorite: nil))
  21. subject = OutputManager()
  22. }
  23. it("outputs history entries") {
  24. let params = CommandParams(out: mockOutput, arguments: [])
  25. subject.printEntries(historyEntries, params: params, out: mockOutput)
  26. expect(mockOutput.printLog) == "Test 1\nTest 2\nTest 3\n"
  27. }
  28. it("outputs history entries with timestamps") {
  29. let params = CommandParams(out: mockOutput, arguments: ["--show-time"])
  30. subject.printEntries(historyEntries, params: params, out: mockOutput)
  31. expect(mockOutput.printLog) ==
  32. "1970-01-01T00:00:00Z: Test 1\n" +
  33. "1970-01-02T00:00:00Z: Test 2\n" +
  34. "1970-01-03T00:00:00Z: Test 3\n"
  35. }
  36. it("outputs history entries with UNKNOWN for missing timestamps") {
  37. let params = CommandParams(out: mockOutput, arguments: ["--show-time"])
  38. historyEntries.append(HistoryEntry(string: "Test 4",
  39. timestamp: nil,
  40. favorite: nil))
  41. subject.printEntries(historyEntries, params: params, out: mockOutput)
  42. expect(mockOutput.printLog) ==
  43. "1970-01-01T00:00:00Z: Test 1\n" +
  44. "1970-01-02T00:00:00Z: Test 2\n" +
  45. "1970-01-03T00:00:00Z: Test 3\n" +
  46. "UNKNOWN DATETIME: Test 4\n"
  47. }
  48. }
  49. }
  50. }