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

Marcin Pałosz #6

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d6e4410
Add Character VC and VM
marcinpalosz Mar 29, 2022
82fcce7
Update Pods
marcinpalosz Mar 29, 2022
35d97de
Update WorkspaceSettings
marcinpalosz Mar 29, 2022
ca423eb
Fix issue with cell height
marcinpalosz Mar 29, 2022
396ef56
Fix issue with button callbacks in cells by introducing UITableViewDe…
marcinpalosz Mar 29, 2022
418cf2e
Open proper CharacterDetailsVC on cell tap
marcinpalosz Mar 29, 2022
65211f3
Layout and configure views inside CharacterDetailsVC
marcinpalosz Mar 29, 2022
07aa1a2
Fix issue with conficting constraints
marcinpalosz Mar 29, 2022
aadf388
Add assets for male and female gender
marcinpalosz Mar 30, 2022
037f4d4
Add required fields to Character model
marcinpalosz Mar 30, 2022
9a6c331
Add implementation service for Character
marcinpalosz Mar 30, 2022
77e1c91
Use fetched data to display in VC
marcinpalosz Mar 30, 2022
16365fd
Rename Resource enum, Service protocol and add page variable to fetch…
marcinpalosz Mar 31, 2022
fb4d5cd
Add info variable to get pages count with character data
marcinpalosz Mar 31, 2022
8a02885
Add localization string for CharacterListVC, CharacterDetalsVC and VM
marcinpalosz Mar 31, 2022
22a5178
Use localized strings to descibe labels
marcinpalosz Mar 31, 2022
c067233
Add functionality to increment pages
marcinpalosz Mar 31, 2022
ba12f87
Add missing case to CharacterGender extension
marcinpalosz Mar 31, 2022
a541b32
Fix broken pbxproj
marcinpalosz Mar 31, 2022
90f75fb
Clean up project to be able to run tests
marcinpalosz Mar 31, 2022
bcbd581
Add a couple of tests for VMs
marcinpalosz Mar 31, 2022
daab662
Update tests
marcinpalosz Mar 31, 2022
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
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 6247cb6411c9a6486ecf6672c9cb0f33c93e8ca6

COCOAPODS: 1.9.3
COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CharactersDetailsViewModelTests.swift
// ios-dev-interview-tests
//
// Created by Adam Majczyk on 15/09/2020.
// Copyright © 2020 Goodylabs. All rights reserved.
//

import XCTest
import RxSwift
import Foundation

@testable import IOS_DEV_INTERVIEW

final class CharactersDetailsViewModelTests: XCTestCase {

func testFetchCharacterShouldUpdateCharacter() {
// Given
let character = ResponseMock.character
let service = CharacterServiceMock(character: character)
let viewModel = CharacterDetailsViewModel(service: service, id: character.id!)
// When
viewModel.fetchCharacter()
// Then
XCTAssertNotNil(viewModel.character.value)
XCTAssertEqual(viewModel.character.value!.id, character.id)
XCTAssertEqual(viewModel.character.value!.name, character.name)
XCTAssertEqual(viewModel.character.value!.status, character.status)
XCTAssertEqual(viewModel.character.value!.species, character.species)
XCTAssertEqual(viewModel.character.value!.image, character.image)
XCTAssertEqual(viewModel.character.value!.gender, character.gender)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CharactersListViewModelTests.swift
// ios-dev-interview-tests
//
// Created by Marcin Pałosz on 31/03/2022.
// Copyright © 2022 Flipside Group. All rights reserved.
//

import XCTest
import RxSwift
import Foundation

@testable import IOS_DEV_INTERVIEW

final class CharactersListViewModelTests: XCTestCase {

func testFetchCharactersListShouldUpdateCharacters() {
// Given
let characters = ResponseMock.characters
let service = CharacterServiceMock(characters: characters)
let viewModel = CharactersListViewModel(service: service)
// When
viewModel.fetchCharacters(page: 0)
// Then
XCTAssertEqual(viewModel.characters.value[0].id, characters.results![0].id)
XCTAssertEqual(viewModel.characters.value[0].name, characters.results![0].name)
XCTAssertEqual(viewModel.characters.value[1].id, characters.results![1].id)
XCTAssertEqual(viewModel.characters.value[1].name, characters.results![1].name)
// Analogically we could test other fields
}

}

This file was deleted.

37 changes: 37 additions & 0 deletions ios-dev-interview-tests/Characters/Unit/Mocks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Mocks.swift
// ios-dev-interview-tests
//
// Created by Marcin Pałosz on 31/03/2022.
// Copyright © 2022 Flipside Group. All rights reserved.
//

import Foundation
import RxSwift
@testable import IOS_DEV_INTERVIEW

enum ResponseMock {
static let characters = CharacterResponse(info: .init(pages: 0), results: [
Character(id: 5, name: "Morty Smith", status: "Alive", species: "Human", image: "https://rickandmortyapi.com/api/character/avatar/2.jpeg", gender: .male),
Character(id: 8, name: "Arthricia", status: "Alive", species: "Human", image: "https://rickandmortyapi.com/api/character/avatar/1.jpeg", gender: .female)
])

static let character = Character(id: 5, name: "Morty Smith", status: "Alive", species: "Alien", image: "https://rickandmortyapi.com/api/character/avatar/2.jpeg", gender: .male)
}

final class CharacterServiceMock: CharacterService {

func getCharacters(page: Int) -> Observable<CharacterResponse> { characters }

func getCharacter(id: Int) -> Observable<Character> { character }

let characters: Observable<CharacterResponse>
let character: Observable<Character>

init(characters: CharacterResponse? = nil, character: Character? = nil) {
self.characters = characters != nil ? Observable.just(characters!) : Observable.error(CharacterServiceError())
self.character = character != nil ? Observable.just(character!) : Observable.error(CharacterServiceError())
}
}

struct CharacterServiceError: Error { }
200 changes: 0 additions & 200 deletions ios-dev-interview-tests/TestResources/ApiService.swift

This file was deleted.

17 changes: 0 additions & 17 deletions ios-dev-interview-tests/TestResources/BundleService.swift

This file was deleted.

Loading