Skip to content

Commit

Permalink
Merge pull request #148 from DeveloperAcademy-POSTECH/feature/#52
Browse files Browse the repository at this point in the history
#52/�테스트 파일 추가
  • Loading branch information
ungchun authored Apr 29, 2024
2 parents 4b44e12 + 4cc3f06 commit 2441de9
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 24 deletions.
8 changes: 8 additions & 0 deletions Projects/App/Tests/AppTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// AppTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
76 changes: 72 additions & 4 deletions Projects/Core/Sources/Common/Extensions/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,77 @@

import SwiftUI

extension View {
public func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder),
to: nil, from: nil, for: nil)
public extension View {
dynamic func dismissKeyboard(on gestures: [Gestures] = Gestures.allCases,
onDismiss: (() -> Void)? = nil) -> some View {
return ModifiedContent(content: self,
modifier: DismissingKeyboard(gestures: gestures,
onDismiss: onDismiss))
}
}

// MARK: - DismissingKeyboard

private struct DismissingKeyboard: ViewModifier {
var gestures: [Gestures] = Gestures.allCases
var onDismiss: (() -> Void)?

private func action() {
let forcing = true
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).first
keyWindow?.endEditing(forcing)
}

private func handleOnDismiss() {
action()
onDismiss?()
}

dynamic func body(content: Content) -> some View {
return gestures.reduce(AnyView(content)) { $1.apply(to: $0, perform: handleOnDismiss) }
}
}

public enum Gestures: Hashable, CaseIterable {
case tap, longPress, drag, magnification, rotation
}

public protocol ValueGesture: Gesture where Value: Equatable {
func onChanged(_ action: @escaping (Value) -> Void) -> _ChangedGesture<Self>
}

extension LongPressGesture: ValueGesture {}
extension DragGesture: ValueGesture {}
extension MagnificationGesture: ValueGesture {}
extension RotationGesture: ValueGesture {}

public extension Gestures {
@discardableResult
func apply<V>(to view: V, perform voidAction: @escaping () -> Void) -> AnyView where V: View {

func highPrio<G>(
gesture: G
) -> AnyView where G: ValueGesture {
AnyView(view.highPriorityGesture(
gesture.onChanged { value in
_ = value
voidAction()
}
))
}

switch self {
case .tap:
return AnyView(view.gesture(TapGesture().onEnded(voidAction)))
case .longPress: return highPrio(gesture: LongPressGesture())
case .drag: return highPrio(gesture: DragGesture())
case .magnification: return highPrio(gesture: MagnificationGesture())
case .rotation: return highPrio(gesture: RotationGesture())
}
}
}
8 changes: 8 additions & 0 deletions Projects/Core/Tests/CoreTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// CoreTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/DesignSystem/Tests/DesignSystemTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// DesignSystemTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/Feature/Tests/FetureTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FetureTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/FeatureCategory/Tests/FeatureCategoryTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureCategoryTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureEncyclopediaTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/FeatureHome/Tests/FeatureHomeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureHomeTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
37 changes: 18 additions & 19 deletions Projects/FeatureInformation/Scene/InformationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public struct InformationView: View {
@StateObject var viewModel: InformationViewModel

public init(makHolyId: Int, mpParamters: MPInfoClosedEventParameters) {
self._viewModel = StateObject(wrappedValue: InformationViewModel(makHolyId: makHolyId,
maHolyRepo: DefaultMakgeolliRepository(),
userRepo: DefaultUserRepository(),
mpParameters: mpParamters))
self._viewModel = StateObject(
wrappedValue: InformationViewModel(makHolyId: makHolyId,
maHolyRepo: DefaultMakgeolliRepository(),
userRepo: DefaultUserRepository(),
mpParameters: mpParamters))
}

public var body: some View {
Expand All @@ -31,19 +32,18 @@ public struct InformationView: View {
InformationCardView(viewModel: viewModel)
.padding(.top, 28.5)
InformationDetailView(viewModel: viewModel)

}
.alert(isPresented: $viewModel.showDeleteAlert) {
Alert(title: Text("코멘트 삭제"), message: Text("코멘트를 삭제하시겠어요?"),
primaryButton: .cancel(
Text("취소"),
action: {}
), secondaryButton: .destructive(
Text("삭제하기"),
action: {
viewModel.deleteComment()
}
))
primaryButton: .cancel(
Text("취소"),
action: {}
), secondaryButton: .destructive(
Text("삭제하기"),
action: {
viewModel.deleteComment()
}
))
}
HStack {
InfoBookMarkButton(viewModel: viewModel)
Expand All @@ -52,7 +52,7 @@ public struct InformationView: View {
.padding(.horizontal, 16)
.alert(isPresented: $viewModel.errorState) {
Alert(title: Text("네트워크 에러"), message: Text("인터넷 연결상태를 확인해주세요."),
dismissButton: .default(Text("확인")))
dismissButton: .default(Text("확인")))
}
}
}
Expand All @@ -70,14 +70,16 @@ public struct InformationView: View {
}
.padding(.horizontal, 16)
}
.dismissKeyboard(on: [.tap, .drag])
.statusBarHidden(true)
.onAppear(perform: {
viewModel.fetchDatas()
MixpanelManager.shared.informationViewAppeared()
})
//코멘트 상세 Modal 화면
.sheet(isPresented: $viewModel.showDetailCommentListSheet, content: {
InfoLikeCommentDetailView(isPresented: $viewModel.showDetailCommentListSheet, comments: viewModel.comments, makHolyName: viewModel.makHoly.name)
InfoLikeCommentDetailView(isPresented: $viewModel.showDetailCommentListSheet,
comments: viewModel.comments, makHolyName: viewModel.makHoly.name)
})
// 코멘트 수정 ActionSheet
.confirmationDialog("", isPresented: $viewModel.showActionSheet, titleVisibility: .hidden) {
Expand Down Expand Up @@ -114,9 +116,6 @@ public struct InformationView: View {
viewModel.insertComment(myComment: myComment)
})
}

})
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureInformationTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/FeatureOnboarding/Tests/FeatureOnboardingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureOnboardingTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/FeatureProfile/Tests/FeatureProfileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureProfileTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/FeatureSearch/Tests/FeatureSearchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// FeatureSearchTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
8 changes: 8 additions & 0 deletions Projects/Utils/Tests/UtilsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// UtilsTests.swift
// ProjectDescriptionHelpers
//
// Created by Kim SungHun on 4/27/24.
//

import Foundation
2 changes: 1 addition & 1 deletion Tuist/ProjectDescriptionHelpers/Project+Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public extension Project {
bundleId: "\(organizationName).\(name)Tests",
deploymentTarget: deploymentTarget,
infoPlist: .default,
// sources: ["Tests/**"],
sources: ["Tests/**"],
dependencies: [.target(name: name)]
)

Expand Down

0 comments on commit 2441de9

Please sign in to comment.