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

[둘리] 3, 4단계 쇼핑 장바구니 제출합니다. #33

Merged
merged 47 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6f04e7e
refactor: 함수 간소화
hyemdooly May 15, 2023
e7af72c
refactor: supportActionBar Label 설정 삭제, manifest 이용
hyemdooly May 15, 2023
6977e5f
refactor: test 코드 수정
hyemdooly May 15, 2023
8c85cf2
feat: ProductList 상품 장바구니 추가 뷰 수정
hyemdooly May 16, 2023
723c091
docs: 3단계 요구사항 정리
hyemdooly May 16, 2023
b528d57
feat: 장바구니 버튼 생성
hyemdooly May 16, 2023
fd660c5
feat: ProductDetail 수량 선택 Dialog 구현
hyemdooly May 16, 2023
e9a1b6c
feat: CartActivity 하단 뷰 구현
hyemdooly May 16, 2023
7181e9b
feat: CartActivity Item layout 변경사항 수정
hyemdooly May 16, 2023
27b2a1b
feat: cart badge 생성
hyemdooly May 17, 2023
dd70d3b
feat: ProductListActivity List Count 구현
hyemdooly May 17, 2023
e230169
feat: ProductListActivity AppBar Cart Badge 구현
hyemdooly May 17, 2023
15dc571
feat: ProductDetailActivity 마지막으로 본 상품 startActivity
hyemdooly May 17, 2023
588a1ee
feat: ProductDetailActivity 다른 액티비티 실행 시 Stack 조절
hyemdooly May 17, 2023
dc79515
feat: Cart 아이콘 장바구니 비었으면 Gone으로 수정
hyemdooly May 17, 2023
7d0a2e3
feat: Cart 아이콘 장바구니 비었으면 Gone으로 수정
hyemdooly May 17, 2023
8f145f4
Merge remote-tracking branch 'origin/step4' into step4
hyemdooly May 17, 2023
9370658
feat: ProductListPresenter에서 삭제했던 최근 본 상품 복구
hyemdooly May 18, 2023
0337194
refactor: domain 코드 이동, ktlintformat
hyemdooly May 18, 2023
3e7fc30
feat: CartActivity 상품 개수 업데이트 구현
hyemdooly May 18, 2023
1c419ad
feat: CartActivity, CartSystem 선택 구현 (리팩토링 필수)
hyemdooly May 18, 2023
49e6293
feat: ProductListActivity <-> CartActivity 데이터 동일하게 연동
hyemdooly May 18, 2023
3200e3a
refactor: CartActivity LiveData 활용 리팩터링
hyemdooly May 19, 2023
cbcd2f4
refactor: DataBinding format 수정
hyemdooly May 19, 2023
01b5db9
fix: CartActivity 버그 수정
hyemdooly May 20, 2023
57a2b4d
refactor: ProductListActivity Presenter 리팩터링
hyemdooly May 20, 2023
f6d3645
fix: ProductListActivity Presenter 리팩터링 및 버그 수정
hyemdooly May 20, 2023
b5e1269
refactor: CartPresenterTest 코드 수정에 맞게 리팩터링 및 수정
hyemdooly May 20, 2023
dc3106f
refactor: ProductDetailPresenterTest 리팩터링 및 수정
hyemdooly May 20, 2023
47cb4a5
refactor: ProductListPresenterTest 수정, CartPresenterTest 테스트 통과 안되는 …
hyemdooly May 20, 2023
e23cdba
refactor: formatting
hyemdooly May 20, 2023
65cade1
feat: 4단계 MockServer 구현 및 적용
hyemdooly May 21, 2023
b3e732f
refactor: 강제종료 버그 수정, 패키지 정리
hyemdooly May 21, 2023
6869b1f
fix: 최근 본 상품 반대로 나오는 버그 수정, ProductDetialActivity 다이얼로그 dismiss 추가
hyemdooly May 21, 2023
ebdc9bd
docs: README 업데이트
hyemdooly May 21, 2023
ba1d77f
fix: 갯수 제한 걸리는 버그 수정
hyemdooly May 23, 2023
2797d74
Merge remote-tracking branch 'origin/step4' into step4
hyemdooly May 23, 2023
5cf4f06
refactor: CartProductModel의 isChecked, count variable -> valuable로 변경
hyemdooly May 27, 2023
c291ea5
refactor: ProductModel variable -> valuable로 수정
hyemdooly May 27, 2023
508e204
refactor: backing property 변수 위치 수정
hyemdooly May 27, 2023
b04a4af
refactor: lateinit var -> by lazy로 최대한 수정
hyemdooly May 27, 2023
8d09837
refactor: presenter에서 데이터를 내려주도록 수정
hyemdooly May 27, 2023
a9268da
refactor: AppCompatButton -> Button으로 수정
hyemdooly May 27, 2023
9bac38d
refactor: 요구사항에 없는 내용 삭제
hyemdooly May 27, 2023
261e924
refactor: 테스트코드 로직 최대한 삭제
hyemdooly May 27, 2023
9ec4930
refactor: ProductViewHolder 생성자에서 onClick 등록
hyemdooly May 27, 2023
1227d57
refactor: plus, minus 한계치 수정
hyemdooly May 27, 2023
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
Prev Previous commit
Next Next commit
refactor: ProductDetailPresenterTest 리팩터링 및 수정
  • Loading branch information
hyemdooly committed May 20, 2023
commit dc3106f5575ec2750c17e24d5720f87ee6b1cadb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ProductDetailActivity : AppCompatActivity(), ProductDetailContract.View {

private fun setUpPresenter() {
presenter =
ProductDetailPresenter(this, CartDbRepository(this), RecentViewedDbRepository(this))
ProductDetailPresenter(INITIAL_COUNT, this, CartDbRepository(this), RecentViewedDbRepository(this))
}

private fun forceQuit() {
Expand Down Expand Up @@ -120,6 +120,7 @@ class ProductDetailActivity : AppCompatActivity(), ProductDetailContract.View {
}

companion object {
private const val INITIAL_COUNT = 1
const val PRODUCT = "PRODUCT"
const val LAST_VIEWED_PRODUCT = "LAST_VIEWED"
private const val NOT_EXIST_DATA_ERROR = "데이터가 넘어오지 않았습니다."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import woowacourse.shopping.domain.RecentViewedRepository
import woowacourse.shopping.model.ProductModel

class ProductDetailPresenter(
initialCount: Int,
private val view: ProductDetailContract.View,
private val cartRepository: CartRepository,
private val recentViewedRepository: RecentViewedRepository,
) : ProductDetailContract.Presenter {
private val _count: MutableLiveData<Int> = MutableLiveData<Int>(1)
private val _count: MutableLiveData<Int> = MutableLiveData<Int>(initialCount)
override val count: LiveData<Int>
get() = _count

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package woowacourse.shopping

import io.mockk.every
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import io.mockk.mockk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
Expand All @@ -17,6 +18,9 @@ class ProductDetailPresenterTest {
private lateinit var view: ProductDetailContract.View
private lateinit var presenter: ProductDetailContract.Presenter

@get:Rule
val instantExecutorRule = InstantTaskExecutorRule()

private val products = mutableListOf(
CartProduct(
0,
Expand Down Expand Up @@ -59,10 +63,23 @@ class ProductDetailPresenterTest {
return mProducts
}

override fun find(id: Int): CartProduct? {
return mProducts.find { it.id == id }
}

override fun add(id: Int, count: Int) {
mProducts.add(CartProduct(id, count))
}

override fun update(id: Int, count: Int) {
val index = mProducts.indexOfFirst { it.id == id }
if (index == -1) {
mProducts.add(CartProduct(id, count))
return
}
mProducts[index] = CartProduct(id, count)
}

override fun remove(id: Int) {
mProducts.filter { it.id != id }.toList()
}
Expand All @@ -79,25 +96,24 @@ class ProductDetailPresenterTest {
@Before
fun setUp() {
view = mockk(relaxed = true)
presenter = ProductDetailPresenter(view, cartRepository, recentViewedRepository)
presenter = ProductDetailPresenter(1, view, cartRepository, recentViewedRepository)
}

@Test
fun `장바구니 담기 버튼을 클릭하면 장바구니에 상품이 담긴다`() {
every { view.startCartActivity() } answers { nothing }

val product = ProductModel(
10,
"락토핏",
"https://thumbnail6.coupangcdn.com/thumbnails/remote/230x230ex/image/retail/images/6769030628798948-183ad194-f24c-44e6-b92f-1ed198b347cd.jpg",
10000,
10
)
presenter.putInCart(product)
val expectedSize = 5
val actualSize = cartRepository.findAll().size

assertEquals(expectedSize, actualSize)
verify { view.startCartActivity() }
verify { view.finishActivity(true) }
}

@Test
Expand All @@ -110,4 +126,39 @@ class ProductDetailPresenterTest {

assertEquals(expectedSize, actualSize)
}

@Test
fun `현재 선택한 개수가 1이상 100 미만의 값이라면 개수 증가를 할 수 있다`() {
presenter = ProductDetailPresenter(3, view, cartRepository, recentViewedRepository)
presenter.plusCount()

val expectedCount = 4
val actualCount = presenter.count.value

assertEquals(expectedCount, actualCount)
}

@Test
fun `현재 선택한 개수가 100이라면 개수 증가를 할 수 없다`() {
presenter = ProductDetailPresenter(100, view, cartRepository, recentViewedRepository)
presenter.plusCount()

val expectedCount = 100
val actualCount = presenter.count.value

assertEquals(expectedCount, actualCount)
}



@Test
fun `현재 선택한 개수가 1이라면 개수 감소를 할 수 없다`() {
presenter = ProductDetailPresenter(1, view, cartRepository, recentViewedRepository)
presenter.minusCount()

val expectedCount = 1
val actualCount = presenter.count.value

assertEquals(expectedCount, actualCount)
}
}