comparison Simoleon/Favorites.swift @ 93:529feb1fc8d5

Added UI Tests for capture screenshots
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 03 Aug 2021 12:33:32 +0100
parents 98852b65438c
children 04feeb708833
comparison
equal deleted inserted replaced
92:8386dbf80047 93:529feb1fc8d5
44 #endif 44 #endif
45 } 45 }
46 .if(UIDevice.current.userInterfaceIdiom == .phone) { content in 46 .if(UIDevice.current.userInterfaceIdiom == .phone) { content in
47 NavigationView { content } 47 NavigationView { content }
48 } 48 }
49 .onAppear(perform: generateFavoritesToScreenshots)
49 } 50 }
50 51
51 private func removeFromFavorites(offsets: IndexSet) { 52 private func removeFromFavorites(offsets: IndexSet) {
52 withAnimation { 53 withAnimation {
53 offsets.map { favorite[$0] }.forEach(viewContext.delete) 54 offsets.map { favorite[$0] }.forEach(viewContext.delete)
58 let nsError = error as NSError 59 let nsError = error as NSError
59 fatalError("Unresolved error \(nsError), \(nsError.userInfo)") 60 fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
60 } 61 }
61 } 62 }
62 } 63 }
64
65 private func generateFavoritesToScreenshots() {
66 #if DEBUG
67 if favorite.isEmpty {
68 let favoriteCurrencies = [
69 "EUR/USD", "BTC/USD", "USD/HKD", "USD/JPY", "AUD/USD", "XAU/GBP", "DASH/ETH", "EUR/USD",
70 "XAG/CAD", "XRP/RUB"
71 ]
72
73 for favoriteCurrency in favoriteCurrencies {
74 let favorite = Favorite(context: viewContext)
75 favorite.currencyPair = favoriteCurrency
76
77 do {
78 try viewContext.save()
79 } catch {
80 let nsError = error as NSError
81 fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
82 }
83 }
84 }
85 #endif
86 }
63 } 87 }
64 88
65 struct Favorites_Previews: PreviewProvider { 89 struct Favorites_Previews: PreviewProvider {
66 static var previews: some View { 90 static var previews: some View {
67 Favorites() 91 Favorites()
68 // .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) 92 .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
69 } 93 }
70 } 94 }