Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/code cleanup #972

Merged
merged 4 commits into from
Sep 10, 2024
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
4 changes: 4 additions & 0 deletions UpcomingMovies.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@
E2C42E1824C3F9BF0047A8EF /* ProfileMockFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C42E1724C3F9BF0047A8EF /* ProfileMockFactory.swift */; };
E2C44C192616C6B0004B9C9B /* ToastSuccessConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C44C182616C6B0004B9C9B /* ToastSuccessConfiguration.swift */; };
E2C44C1F2616C6D0004B9C9B /* ToastFailureConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C44C1E2616C6D0004B9C9B /* ToastFailureConfiguration.swift */; };
E2C75E5C2C900320004174BB /* SearchOptionsDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C75E5B2C90031F004174BB /* SearchOptionsDataSourceTests.swift */; };
E2C8FFBF2C3F8AE500EB983D /* MovieSearchModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C8FFBE2C3F8AE500EB983D /* MovieSearchModelTests.swift */; };
E2C8FFC12C3F8B8A00EB983D /* GenreProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C8FFC02C3F8B8A00EB983D /* GenreProtocol.swift */; };
E2C951B42C4E1CF3005297D8 /* MockUserProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C951B32C4E1CF3005297D8 /* MockUserProtocol.swift */; };
Expand Down Expand Up @@ -928,6 +929,7 @@
E2C42E1724C3F9BF0047A8EF /* ProfileMockFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileMockFactory.swift; sourceTree = "<group>"; };
E2C44C182616C6B0004B9C9B /* ToastSuccessConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastSuccessConfiguration.swift; sourceTree = "<group>"; };
E2C44C1E2616C6D0004B9C9B /* ToastFailureConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastFailureConfiguration.swift; sourceTree = "<group>"; };
E2C75E5B2C90031F004174BB /* SearchOptionsDataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchOptionsDataSourceTests.swift; sourceTree = "<group>"; };
E2C8FFBE2C3F8AE500EB983D /* MovieSearchModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieSearchModelTests.swift; sourceTree = "<group>"; };
E2C8FFC02C3F8B8A00EB983D /* GenreProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenreProtocol.swift; sourceTree = "<group>"; };
E2C951B32C4E1CF3005297D8 /* MockUserProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUserProtocol.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2322,6 +2324,7 @@
children = (
E279169D28F092360092B592 /* SearchOptionsViewModelTests.swift */,
E2D61C932C8581FF00339AD1 /* DefaultSearchOptionTests.swift */,
E2C75E5B2C90031F004174BB /* SearchOptionsDataSourceTests.swift */,
);
path = SearchOptions;
sourceTree = "<group>";
Expand Down Expand Up @@ -3331,6 +3334,7 @@
E2B2D2942BBD0A17000690AF /* MockMovieProtocol.swift in Sources */,
E2A991992A4C0C5F0006C9C3 /* MovieDetailPosterCoordinatorTests.swift in Sources */,
E26A81292A84A796002C7029 /* TestError.swift in Sources */,
E2C75E5C2C900320004174BB /* SearchOptionsDataSourceTests.swift in Sources */,
E2B8C49B28B738E2006A8ECC /* FavoritesSavedMoviesInteractorTests.swift in Sources */,
E2A958CC2A3677B70004FC5C /* AccountInteractorTests.swift in Sources */,
E2A958D52A367C970004FC5C /* MovieDetailOptionTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@

final class SearchOptionsDataSource: NSObject, UITableViewDataSource {

private var viewModel: SearchOptionsViewModelProtocol?
private let viewModel: SearchOptionsViewModelProtocol

init(viewModel: SearchOptionsViewModelProtocol?) {
init(viewModel: SearchOptionsViewModelProtocol) {

Check warning on line 15 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift#L15

Added line #L15 was not covered by tests
self.viewModel = viewModel
}

func numberOfSections(in tableView: UITableView) -> Int {
guard let viewModel = viewModel else { return 0 }
return viewModel.viewState.value.sections.count
viewModel.viewState.value.sections.count

Check warning on line 20 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift#L20

Added line #L20 was not covered by tests
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let viewModel = viewModel else { return nil }
let sections = viewModel.viewState.value.sections
return sections[section].title
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let viewModel = viewModel else { return 0 }
switch viewModel.section(at: section) {
case .recentlyVisited:
return 1
Expand All @@ -40,7 +37,6 @@
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let viewModel = viewModel else { return UITableViewCell() }
switch viewModel.section(at: indexPath.section) {
case .recentlyVisited:
return recentlyVisitedDataSource(tableView, at: indexPath)
Expand All @@ -52,7 +48,6 @@
}

private func recentlyVisitedDataSource(_ tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
guard let viewModel = viewModel else { fatalError() }
let cell = tableView.dequeueReusableCell(with: RecentlyVisitedMoviesTableViewCell.self, for: indexPath)
cell.selectionStyle = .none
cell.delegate = self
Expand All @@ -62,13 +57,13 @@

private func defaultSearchOptionDataSource(_ tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(with: DefaultSearchOptionTableViewCell.self, for: indexPath)
cell.viewModel = viewModel?.defaultSearchOptionsCells[indexPath.row]
cell.viewModel = viewModel.defaultSearchOptionsCells[indexPath.row]

Check warning on line 60 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift#L60

Added line #L60 was not covered by tests
return cell
}

private func genreSearchOptionDataSource(_ tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(with: GenreSearchOptionTableViewCell.self, for: indexPath)
cell.viewModel = viewModel?.genreCells[indexPath.row]
cell.viewModel = viewModel.genreCells[indexPath.row]

Check warning on line 66 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift#L66

Added line #L66 was not covered by tests
return cell
}

Expand All @@ -80,7 +75,7 @@

func recentlyVisitedMoviesTableViewCell(_ recentlyVisitedMoviesTableViewCell: RecentlyVisitedMoviesTableViewCell,
didSelectMovieAt indexPath: IndexPath) {
viewModel?.getRecentlyVisitedMovieSelection(by: indexPath.row)
viewModel.getRecentlyVisitedMovieSelection(by: indexPath.row)

Check warning on line 78 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsDataSource.swift#L78

Added line #L78 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

private func setupDataSource() {
dataSource = SearchOptionsDataSource(viewModel: viewModel)
dataSource = viewModel.flatMap { SearchOptionsDataSource(viewModel: $0) }

Check warning on line 49 in UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsViewController.swift

View check run for this annotation

Codecov / codecov/patch

UpcomingMovies/Scenes/Movies/SearchMovies/SearchOptions/SearchOptionsViewController.swift#L49

Added line #L49 was not covered by tests
tableView.dataSource = dataSource
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SearchOptionsDataSourceTests.swift
// UpcomingMoviesTests
//
// Created by Alonso on 9/09/24.
// Copyright © 2024 Alonso. All rights reserved.
//

import XCTest
@testable import UpcomingMovies

final class SearchOptionsDataSourceTests: XCTestCase {

private var dataSource: SearchOptionsDataSource!
private var viewModel: MockSearchOptionsViewModel!

override func setUpWithError() throws {
try super.setUpWithError()
viewModel = MockSearchOptionsViewModel()
dataSource = SearchOptionsDataSource(viewModel: viewModel)
}

override func tearDownWithError() throws {
dataSource = nil
viewModel = nil
try super.tearDownWithError()
}

}
Loading