Skip to content
Open
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
7 changes: 7 additions & 0 deletions SampleAppSwiftUI/Network/ResponseModels/AllCoinResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ struct CoinData: Codable, Hashable, Identifiable {
detail: CoinRaw(usd: RawUsd(price: 29467.560,
changeAmount: 28.015,
changePercentage: 29.74)))

static func demoCoin(from name: String) -> CoinData {
CoinData(coinInfo: CoinMarketCapsCoinInfo(code: name, title: "Demo"),
detail: CoinRaw(usd: RawUsd(price: 29467.560,
changeAmount: 28.015,
changePercentage: 29.74)))
}
}

// MARK: - CoinInfo
Expand Down
14 changes: 13 additions & 1 deletion SampleAppSwiftUI/Scenes/Favorites/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sucu, Ege on 16.03.2023.
//

import PreviewSnapshots
import SwiftUI

struct FavoritesView: View {
Expand Down Expand Up @@ -48,7 +49,18 @@ struct FavoritesView: View {
}

struct FavoritesView_Previews: PreviewProvider {
static private let router = Router()

static var previews: some View {
FavoritesView()
snapshot.previews
}

static var snapshot: PreviewSnapshots<Void?> {
.init(configurations: [
.init(name: "Favorites View", state: nil)
], configure: { _ in
FavoritesView()
.environmentObject(router)
})
}
}
21 changes: 18 additions & 3 deletions SampleAppSwiftUI/Scenes/Home/Coin/CoinListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import PreviewSnapshots

struct CoinListView<ViewModel: ViewModelProtocol>: View {
@ObservedObject var viewModel: ViewModel
Expand Down Expand Up @@ -76,8 +77,22 @@ struct CoinListView<ViewModel: ViewModelProtocol>: View {

struct CoinListView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
CoinListView(viewModel: HomeViewModel(), filteredCoins: .constant([.demo, .demo, .demo]), favoriteChanged: {})
}
snapshots.previews
}

static var snapshots: PreviewSnapshots<[CoinData]> {
.init(configurations: [
.init(name: "One coin", state: [.demo]),
.init(name: "Two coins", state: [.demo, CoinData.demoCoin(from: "DOGE")]),
.init(name: "Three coins", state: [.demo,
CoinData.demoCoin(from: "DOGE"),
CoinData.demoCoin(from: "ETH")]),
.init(name: "Four coins", state: [.demo,
CoinData.demoCoin(from: "DOGE"),
CoinData.demoCoin(from: "ETH"),
CoinData.demoCoin(from: "FTM")])
], configure: { state in
CoinListView(viewModel: HomeViewModel(), filteredCoins: .constant(state), favoriteChanged: {})
})
}
}
20 changes: 11 additions & 9 deletions SampleAppSwiftUI/Scenes/Home/Coin/CoinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sucu, Ege on 21.03.2023.
//

import PreviewSnapshots
import SwiftUI

struct CoinView: View {
Expand Down Expand Up @@ -79,15 +80,16 @@ struct CoinView: View {

struct CoinView_Previews: PreviewProvider {
static var previews: some View {
Group {
CoinView(coinInfo: .demo)
CoinView(coinInfo: .demo)
.preferredColorScheme(.dark)
}
.previewLayout(.sizeThatFits)
.frame(height: Dimensions.coinCellSize)
.padding(.horizontal, Paddings.side)
.padding(.vertical)
snapshots.previews
}

static var snapshots: PreviewSnapshots<CoinData> {
PreviewSnapshots(configurations: [
.init(name: "BTC", state: .demo),
.init(name: "DOGE", state: CoinData.demoCoin(from: "DOGE")),
.init(name: "ETH", state: CoinData.demoCoin(from: "ETH"))
]) { state in
CoinView(coinInfo: state)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Abay, Batuhan on 22.05.2023.
//

import PreviewSnapshots
import SwiftUI

struct ChangePercentageView: View {
Expand All @@ -29,6 +30,16 @@ struct ChangePercentageView: View {

struct ChangePercentageView_Previews: PreviewProvider {
static var previews: some View {
ChangePercentageView(changeRate: CoinData.demo.detail?.usd ?? .init())
snapshots.previews
}

static var snapshots: PreviewSnapshots<RawUsd> {
.init(configurations: [
.init(name: "Positive Change", state: CoinData.demo.detail?.usd ?? .init()),
.init(name: "Neutral", state: RawUsd(changePercentage: 0)),
.init(name: "Negative", state: RawUsd(changePercentage: -14.33))
]) { state in
ChangePercentageView(changeRate: state)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Abay, Batuhan on 30.05.2023.
//

import PreviewSnapshots
import SwiftUI

struct CoinChartHistoryRangeButtons: View {
Expand Down Expand Up @@ -36,6 +37,20 @@ struct CoinChartHistoryRangeButtons: View {

struct CoinChartHistoryRangeButtons_Previews: PreviewProvider {
static var previews: some View {
CoinChartHistoryRangeButtons(selection: .constant(.oneMonth))
snapshots.previews
}

static var snapshots: PreviewSnapshots<CoinChartHistoryRange> {
.init(configurations: [
.init(name: "One day", state: .oneDay),
.init(name: "One week", state: .oneWeek),
.init(name: "One month", state: .oneMonth),
.init(name: "Three months", state: .threeMonth),
.init(name: "Six months", state: .sixMonth),
.init(name: "One year", state: .oneYear),
.init(name: "All dates", state: .all)
]) { state in
CoinChartHistoryRangeButtons(selection: .constant(state))
}
}
}
19 changes: 12 additions & 7 deletions SampleAppSwiftUI/Scenes/Home/Coin/Detail/CoinDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Abay, Batuhan on 22.05.2023.
//

import PreviewSnapshots
import SwiftUI

struct CoinDetailView: View {
Expand Down Expand Up @@ -84,8 +85,8 @@ struct CoinDetailView: View {
viewModel.updateCoinFavoriteState()
} label: {
viewModel.isFavorite
? Image(systemName: Images.favorites)
: Image(systemName: Images.star)
? Image(systemName: Images.favorites)
: Image(systemName: Images.star)
}
.tint(.gray)
}
Expand All @@ -99,12 +100,16 @@ struct CoinDetailView: View {

struct CoinDetailView_Previews: PreviewProvider {
static var previews: some View {
Group {
CoinDetailView(coinData: CoinData.demo)
NavigationView {
snapshots.previews
}
}

NavigationView {
CoinDetailView(coinData: CoinData.demo)
}
static var snapshots: PreviewSnapshots<CoinData> {
.init(configurations: [
.init(name: "Coin detail view", state: .demo)
]) { state in
CoinDetailView(coinData: state)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// Created by Abay, Batuhan on 31.05.2023.
//

import SwiftUI
import Charts
import PreviewSnapshots
import SwiftUI

struct CoinPriceHistoryChartView: View {
@StateObject private var viewModel: CoinPriceHistoryChartViewModel
Expand Down Expand Up @@ -140,29 +141,18 @@ struct CoinPriceHistoryChartView: View {

struct CoinPriceHistoryChartView_Previews: PreviewProvider {
static var previews: some View {
Group {
Group {
ForEach(CoinChartHistoryRange.allCases) { item in
CoinPriceHistoryChartView(
selectedRange: item,
dataModel: .demo,
selectedXDateText: .constant("")
)
.previewDisplayName(item.rawValue)
}
}
snapshots.previews
}

Group {
ForEach(CoinChartHistoryRange.allCases) { item in
CoinPriceHistoryChartView(
selectedRange: item,
dataModel: .demo,
selectedXDateText: .constant("")
)
.previewDisplayName(item.rawValue + "DARK")
}
}
.preferredColorScheme(.dark)
static var snapshots: PreviewSnapshots<CoinChartHistoryRange> {
let charts = CoinChartHistoryRange.allCases.map { PreviewSnapshots.Configuration(name: $0.rawValue, state: $0) }
return .init(configurations: charts) { state in
CoinPriceHistoryChartView(
selectedRange: state,
dataModel: .demo,
selectedXDateText: .constant("")
)
.previewDisplayName(state.rawValue)
}
}
}
14 changes: 13 additions & 1 deletion SampleAppSwiftUI/Scenes/Home/HomeFilterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sucu, Ege on 28.03.2023.
//

import PreviewSnapshots
import SwiftUI

struct HomeFilterView: View {
Expand All @@ -20,6 +21,17 @@ struct HomeFilterView: View {

struct HomeFilterView_Previews: PreviewProvider {
static var previews: some View {
HomeFilterView(filterTitle: "")
snapshots.previews
}

static var snapshots: PreviewSnapshots<String> {
.init(configurations: [
.init(name: "Empty text", state: .empty),
.init(name: "Short text", state: "cupidatat"),
.init(name: "Long text", state: "Ad tempor cupidatat culpa aliqua amet consectetur velit dolor do est amet.")
]) { state in
HomeFilterView(filterTitle: state)
.padding(.horizontal)
}
}
}
14 changes: 13 additions & 1 deletion SampleAppSwiftUI/Scenes/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2022 Adesso Turkey. All rights reserved.
//

import PreviewSnapshots
import SwiftUI

struct HomeView: View {
Expand Down Expand Up @@ -44,7 +45,18 @@ struct HomeView: View {
}

struct HomeView_Previews: PreviewProvider {
private static let router = Router()

static var previews: some View {
HomeView()
snapshots.previews
}

static var snapshots: PreviewSnapshots<Void?> {
.init(configurations: [
.init(name: "Home view", state: nil)
]) { _ in
HomeView()
.environmentObject(router)
}
}
}
16 changes: 12 additions & 4 deletions SampleAppSwiftUI/Scenes/Home/SearchBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Sucu, Ege on 17.03.2023.
//

import PreviewSnapshots
import SwiftUI

struct SearchBarView: View {
Expand Down Expand Up @@ -34,9 +35,16 @@ struct SearchBarView: View {

struct SearchBarView_Previews: PreviewProvider {
static var previews: some View {
SearchBarView(searchText: .constant(""), topPadding: Paddings.SearchBar.shortTop)
.previewLayout(.sizeThatFits)
.frame(width: .infinity, height: Dimensions.searchBarHeight)
.padding(.vertical)
snapshots.previews.previewLayout(.sizeThatFits)
}

static var snapshots: PreviewSnapshots<String> {
.init(configurations: [
.init(name: "Empty text", state: ""),
.init(name: "Short text", state: "Culpa occaecat nostrud."),
.init(name: "Long text", state: "Non veniam occaecat et ullamco ad aliquip laborum elit ea incididunt id non Lorem deserunt.")
]) { state in
SearchBarView(searchText: .constant(state), topPadding: 0)
}
}
}
14 changes: 12 additions & 2 deletions SampleAppSwiftUI/Scenes/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright © 2022 Adesso Turkey. All rights reserved.
//

import PreviewSnapshots
import SwiftUI

struct MainView: View {

@StateObject private var storageManager = StorageManager.shared
@EnvironmentObject private var router: Router
var body: some View {
Expand Down Expand Up @@ -39,7 +39,17 @@ struct MainView: View {
}

struct MainView_Previews: PreviewProvider {
private static let router = Router()
static var previews: some View {
MainView()
snapshots.previews
}

static var snapshots: PreviewSnapshots<Void?> {
.init(configurations: [
.init(name: "Main View", state: .none)
]) { _ in
MainView()
.environmentObject(router)
}
}
}
Loading