Skip to content

Commit

Permalink
fix(bug): fixing nil bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Feb 17, 2023
1 parent 3cd4ac7 commit 1c260f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ArchivedItemsListViewModelTests: XCTestCase {
}

func test_shouldSelectCell_whenItemIsPending_returnsFalse() {
let items = [space.buildSavedItem(), space.buildSavedItem()]
let items = [space.buildPendingSavedItem(), space.buildSavedItem()]
archiveService._results = items.map { .loaded($0) }

let viewModel = subject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SavedItemsListViewModelTests: XCTestCase {

func test_shouldSelectCell_whenItemIsPending_returnsFalse() {
let viewModel = subject()
let item = space.buildSavedItem()
let item = space.buildPendingSavedItem()

source.stubObject { _ in
item
Expand All @@ -99,7 +99,7 @@ class SavedItemsListViewModelTests: XCTestCase {

func test_selectCell_whenItemIsArticle_setsSelectedItemToReaderView() {
let viewModel = subject()
let item = space.buildSavedItem()
let item = space.buildPendingSavedItem()

source.stubObject { _ in item }
viewModel.selectCell(with: .item(item.objectID), sender: UIView())
Expand Down
26 changes: 22 additions & 4 deletions PocketKit/Tests/PocketKitTests/Support/Space+factories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ extension Space {
return savedItem
}
}

@discardableResult
func buildPendingSavedItem() -> SavedItem {
context.performAndWait {
let savedItem: SavedItem = SavedItem(context: context, url: URL(string: "https://mozilla.com/example")!)
return savedItem
}
}
}

// MARK: - Item
Expand All @@ -77,11 +85,16 @@ extension Space {
isArticle: Bool = true,
article: Article? = nil
) throws -> Item {
try context.performAndWait {
var url = givenURL
if (url == nil) {
url = URL(string: "https://example.com/items/item-1")
}

return try context.performAndWait {
let item = buildItem(
remoteID: remoteID,
title: title,
givenURL: givenURL,
givenURL: url,
isArticle: isArticle,
article: article
)
Expand All @@ -103,8 +116,13 @@ extension Space {
article: Article? = nil,
syndicatedArticle: SyndicatedArticle? = nil
) -> Item {
context.performAndWait {
let item: Item = Item(context: context, givenURL: givenURL!, remoteID: remoteID)
var url = givenURL
if (url == nil) {
url = URL(string: "https://example.com/items/item-1")
}

return context.performAndWait {
let item: Item = Item(context: context, givenURL: url!, remoteID: remoteID)
item.remoteID = remoteID
item.title = title
item.resolvedURL = resolvedURL
Expand Down
11 changes: 8 additions & 3 deletions PocketKit/Tests/SyncTests/Support/Space+factories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ extension Space {
func buildItem(
remoteID: String = "item-1",
title: String = "Item 1",
givenURL: URL? = URL(string: "https://example.com/items/item-1")!,
givenURL: URL? = URL(string: "https://example.com/items/item-1"),
resolvedURL: URL? = nil,
isArticle: Bool = true
) -> Item {
context.performAndWait {
let item: Item = Item(context: context, givenURL: givenURL!, remoteID: remoteID)
var url = givenURL
if (url == nil) {
url = URL(string: "https://example.com/items/item-1")
}

return context.performAndWait {
let item: Item = Item(context: context, givenURL: url!, remoteID: remoteID)
item.title = title
item.resolvedURL = resolvedURL
item.isArticle = isArticle
Expand Down

0 comments on commit 1c260f6

Please sign in to comment.