Skip to content

Commit

Permalink
Merge pull request #238 from Team-Smeme/feat/#235-QA
Browse files Browse the repository at this point in the history
[Feat] #235 - 일기 첨삭 2차 QA
  • Loading branch information
cchanmi authored Dec 10, 2024
2 parents 209b006 + b0f6c02 commit 6b71fbb
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 21 deletions.
6 changes: 0 additions & 6 deletions Smeem-iOS/Smeem-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@
377B3BF12CF618B90086E0BC /* SwiftUI */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = SwiftUI; sourceTree = "<group>"; };
4A17370E2D05C02E00B772C3 /* Toast */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Toast; sourceTree = "<group>"; };
4A17370F2D05C03600B772C3 /* LoadingView */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = LoadingView; sourceTree = "<group>"; };
4A1737152D05C06E00B772C3 /* Components */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Components; sourceTree = "<group>"; };
4A1737192D05C07100B772C3 /* Store */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Store; sourceTree = "<group>"; };
4AB3494E2CF22A070047C484 /* Global */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Global; sourceTree = "<group>"; };
4AB3494F2CF22A250047C484 /* Button */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Button; sourceTree = "<group>"; };
4AB349502CF22A2E0047C484 /* TextView */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = TextView; sourceTree = "<group>"; };
Expand Down Expand Up @@ -615,8 +613,6 @@
isa = PBXGroup;
children = (
4AF050D82CEA01EA0055BC3F /* Coaching */,
4A1737192D05C07100B772C3 /* Store */,
4A1737152D05C06E00B772C3 /* Components */,
4AC047232A8FCA9700EBDC0E /* AuthManagement */,
4AA6FEE72C3ABD7C00E588E9 /* ResignSummray */,
4AA5E4B52BF24CEB00F308C8 /* BadgeBottomSheet */,
Expand Down Expand Up @@ -1744,8 +1740,6 @@
377B3BF12CF618B90086E0BC /* SwiftUI */,
4A17370E2D05C02E00B772C3 /* Toast */,
4A17370F2D05C03600B772C3 /* LoadingView */,
4A1737152D05C06E00B772C3 /* Components */,
4A1737192D05C07100B772C3 /* Store */,
4AB3494E2CF22A070047C484 /* Global */,
4AB3494F2CF22A250047C484 /* Button */,
4AB349502CF22A2E0047C484 /* TextView */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI

struct CoachingCompleteView: View {

@Binding var diaryText: String
@Binding var coachingAppData: CoachingAppData
@State var currentIndex = 0

Expand All @@ -21,16 +20,16 @@ struct CoachingCompleteView: View {
VStack(spacing: 16) {
HStack {
Text(coachingAppData.correctResultText)
.font(Font.custom("Pretendard", size: 16))
.font(Font.custom("Pretendard", size: 16)).fontWeight(.regular)
.foregroundColor(Color(UIColor.black))
.lineSpacing(0.375)
Spacer()
}

HStack {
Text(diaryText)
Text(coachingAppData.diaryText)
.modifier(HighlightModifier(
diaryText: diaryText,
diaryText: coachingAppData.diaryText,
corrections: coachingAppData.corrections,
highlightIndex: currentIndex
))
Expand All @@ -45,7 +44,6 @@ struct CoachingCompleteView: View {

Spacer()
}
.padding(.top)
.padding(.horizontal, screenWidth * 0.048)

VStack(spacing: 20) {
Expand Down Expand Up @@ -91,9 +89,11 @@ struct PageControl: View {
}
}

#Preview {
@State var diaryText = "I watched Avatar with my boyfriend at Hongdae CGV. I should have skimmed the previous season 
what they were saying and the universe(??). What I was annoyed then was 두팔 didn’t know that as me. I think 두팔 who is my boyfriend should study before wathcing…. but Avatar2 is amazing movie I think. In my personal opinion, the jjin main character "
@State var coachingResponse = CoachingAppData(corrections: CoachingsResponse.sample.corrections, correctResultText: "테스트")

CoachingCompleteView(diaryText: $diaryText, coachingAppData: $coachingResponse)
}
//#Preview {
// @State var diaryText = "I watched Avatar with my boyfriend at Hongdae CGV. I should have skimmed the previous season 
what they were saying and the universe(??). What I was annoyed then was 두팔 didn’t know that as me. I think 두팔 who is my boyfriend should study before wathcing…. but Avatar2 is amazing movie I think. In my personal opinion, the jjin main character "
// @State var coachingResponse = CoachingAppData(diaryText: "",
// corrections: CoachingsResponse.sample.corrections,
// correctResultText: "테스트")
//
// CoachingCompleteView(coachingAppData: coachingResponse, currentIndex: 0)
//}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

struct CoachingAppData {
var diaryText: String
var corrections: [CoachingResponse]
var correctResultText: String
}
Expand All @@ -30,7 +31,8 @@ final class CoachingStore: Store, ObservableObject {

struct State {
var detailDiaryResponse = DetailDiaryResponse.empty
var coachingAppData = CoachingAppData(corrections: CoachingsResponse.sample.corrections,
var coachingAppData = CoachingAppData(diaryText: "",
corrections: CoachingsResponse.sample.corrections,
correctResultText: "첨삭 중이에요")
var toastErrorMessage: SmeemError? = nil
var toastMessage: SmeemToast? = .completed
Expand Down Expand Up @@ -61,7 +63,8 @@ final class CoachingStore: Store, ObservableObject {
do {
state.hiddenIndex += 1
let coachingResponse = try await service.coachingPostAPI(diaryID: ID)
state.coachingAppData = CoachingAppData(corrections: coachingResponse.corrections,
state.coachingAppData = CoachingAppData(diaryText: combineCorrectionText(coachingResponse.corrections),
corrections: filiterCorrection(coachingResponse.corrections),
correctResultText: correctTextResult(coachingResponse.corrections.count))
state.hiddenIndex += 1
} catch let error {
Expand All @@ -73,6 +76,14 @@ final class CoachingStore: Store, ObservableObject {
}
}

func combineCorrectionText(_ response: [CoachingResponse]) -> String {
return response.map{ $0.originalSentence }.joined(separator: " ")
}

func filiterCorrection(_ response: [CoachingResponse]) -> [CoachingResponse] {
return response.filter { $0.isCorrected }.prefix(10).map{$0}
}

func correctTextResult(_ count: Int) -> String {
switch count {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ struct CoachingView: View {

// MARK: 첨삭 화면
} else {
CoachingCompleteView(diaryText: $store.state.detailDiaryResponse.content,
coachingAppData: $store.state.coachingAppData)
CoachingCompleteView(coachingAppData: $store.state.coachingAppData)
}

// MARK: 첫 진입시 토스트뷰 실행
Expand Down
89 changes: 89 additions & 0 deletions Smeem-iOS/Smeem-iOSTests/Coaching/Store/CoachingStoreTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CoachingStore.swift
// Smeem-iOSTests
//
// Created by 황찬미 on 12/10/24.
//

import XCTest

@testable import Smeem_iOS

final class CoachingStoreTest: XCTestCase {

var sut: CoachingStore!
var service: CoachingServiceProtocol!

override func setUpWithError() throws {
service = CoachingService()
sut = CoachingStore(service: service,
diaryResponse: PostDiaryResponse.empty)
}

override func tearDownWithError() throws {
sut = nil
}

func test_첨삭데이터15개일때_10개로잘필터하는지() {
// Given
var filterResult = [CoachingResponse]()
for _ in 1...15 {
filterResult.append(CoachingResponse(originalSentence: "",
correctedSentence: "",
reason: "",
isCorrected: true))
}

var expectedResult = [CoachingResponse]()
for _ in 1...10 {
expectedResult.append(CoachingResponse(originalSentence: "",
correctedSentence: "",
reason: "",
isCorrected: true))
}

// When
let outputResult = sut.filiterCorrection(filterResult)

// Then
XCTAssertEqual(outputResult, expectedResult)
}

func test_첨삭데이터0개일때_0개로잘필터하는지() {
// Given
var filterResult = [CoachingResponse]()
for _ in 1...15 {
filterResult.append(CoachingResponse(originalSentence: "",
correctedSentence: "",
reason: "",
isCorrected: false))
}

var expectedResult = [CoachingResponse]()

// When
let outputResult = sut.filiterCorrection(filterResult)

// Then
XCTAssertEqual(outputResult, expectedResult)
}

func test_원문일기_잘조합해주는지() {
// Given
var filterResult = [CoachingResponse]()
for i in 1...3 {
filterResult.append(CoachingResponse(originalSentence: "안녕",
correctedSentence: "",
reason: "",
isCorrected: false))
}

var expectedResult = "안녕 안녕 안녕"

// When
let outputResult = sut.combineCorrectionText(filterResult)

// Then
XCTAssertEqual(outputResult, expectedResult)
}
}

0 comments on commit 6b71fbb

Please sign in to comment.