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

[WEAV-49] Design System - Text Input 구현 #15

Merged
merged 4 commits into from
Sep 21, 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
37 changes: 37 additions & 0 deletions Projects/Core/CoreKit/Sources/String+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// String+Ext.swift
// CoreKit
//
// Created by 김지수 on 9/21/24.
// Copyright © 2024 com.weave. All rights reserved.
//

import Foundation

extension String {
/// 한국 휴대폰 번호 형식에 맞는지 체크(8자리)
public func isValidPhoneNumber() -> Bool {
let number = self.replacingOccurrences(of: "-", with: "")
let pattern = "^010\\d{8}$"
let regex = try? NSRegularExpression(pattern: pattern)
let range = NSRange(location: 0, length: number.utf16.count)
return regex?.firstMatch(in: number, options: [], range: range) != nil

}

public func formattedPhoneNumber() -> String {
let onlyNumbers = self.filter { $0.isNumber }

let firstPart = String(onlyNumbers.prefix(3))
let secondPart = String(onlyNumbers.dropFirst(3).prefix(4))
let thirdPart = String(onlyNumbers.dropFirst(7).prefix(4))

if onlyNumbers.count <= 3 {
return firstPart
} else if onlyNumbers.count <= 7 {
return "\(firstPart)-\(secondPart)"
} else {
return "\(firstPart)-\(secondPart)-\(thirdPart)"
}
}
}
25 changes: 25 additions & 0 deletions Projects/Core/CoreKit/Sources/UIApplication+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// UIApplication+Ext.swift
// CoreKit
//
// Created by 김지수 on 9/21/24.
// Copyright © 2024 com.weave. All rights reserved.
//

import UIKit

extension UIApplication {
public func hideKeyboard() {
guard let window = windows.first else { return }
let tapRecognizer = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing))
tapRecognizer.cancelsTouchesInView = false
tapRecognizer.delegate = self
window.addGestureRecognizer(tapRecognizer)
}
}

extension UIApplication: UIGestureRecognizerDelegate {
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
}
27 changes: 0 additions & 27 deletions Projects/Core/CoreKit/UnitTest/CoreKitTest.swift

This file was deleted.

157 changes: 157 additions & 0 deletions Projects/Core/CoreKit/UnitTest/StringExtensionText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//
// StringExtensionText.swift
// CoreKit-UnitTest
//
// Created by 김지수 on 9/21/24.
// Copyright © 2024 com.weave. All rights reserved.
//

import XCTest
@testable import CoreKit

final class PhoneNumberTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

// 전화번호 검증 성공
func testValidPhoneNumber() {
// 유효한 번호 (하이픈 없는 11자리 번호)
XCTAssertTrue(
"01012345678".isValidPhoneNumber(),
"유효한 번호 형식임에도 불구하고 false가 반환됨"
)
}

// 전화번호 검증 실패
func testInvalidPhoneNumber() {
// 유효하지 않은 번호 (형식이 잘못된 경우)
XCTAssertFalse(
"01112345678".isValidPhoneNumber(),
"유효하지 않은 번호 형식임에도 불구하고 true가 반환됨"
)
XCTAssertFalse(
"0101234567".isValidPhoneNumber(),
"유효하지 않은 번호 형식임에도 불구하고 true가 반환됨"
)
XCTAssertFalse(
"010123456789".isValidPhoneNumber(),
"유효하지 않은 번호 형식임에도 불구하고 true가 반환됨"
)
XCTAssertFalse(
"010-1234-5678".isValidPhoneNumber(),
"하이픈이 포함된 경우 유효하지 않은 번호 형식임에도 불구하고 true가 반환됨"
)

// 텍스트가 포함된 경우
XCTAssertFalse(
"010a2345678".isValidPhoneNumber(),
"문자가 포함된 경우에도 유효한 번호로 처리되고 있음"
)
XCTAssertFalse(
"010123456a8".isValidPhoneNumber(),
"끝에 문자가 포함된 경우에도 유효한 번호로 처리되고 있음"
)
XCTAssertFalse(
"a1012345678".isValidPhoneNumber(),
"번호 앞에 문자가 포함된 경우에도 유효한 번호로 처리되고 있음"
)
}

// 전화번호 "-" 붙이기 케이스
func testFormattedPhoneNumberAddHyphen() {
XCTAssertEqual(
"01012345678".formattedPhoneNumber(),
"010-1234-5678",
"포맷된 번호가 예상과 다릅니다."
)

XCTAssertEqual(
"010123456".formattedPhoneNumber(),
"010-1234-56",
"포맷된 번호가 예상과 다릅니다."
)

XCTAssertEqual(
"0104444".formattedPhoneNumber(),
"010-4444",
"포맷된 번호가 예상과 다릅니다."
)

XCTAssertEqual(
"010".formattedPhoneNumber(),
"010",
"포맷된 번호가 예상과 다릅니다."
)

XCTAssertEqual(
"01042".formattedPhoneNumber(),
"010-42",
"포맷된 번호가 예상과 다릅니다."
)

XCTAssertEqual(
"01".formattedPhoneNumber(),
"01",
"포맷된 번호가 예상과 다릅니다."
)
// 10자리 입력
XCTAssertEqual(
"0101234567".formattedPhoneNumber(),
"010-1234-567",
"포맷된 번호가 예상과 다릅니다."
)

// 7자리 입력
XCTAssertEqual(
"0101234".formattedPhoneNumber(),
"010-1234",
"포맷된 번호가 예상과 다릅니다."
)

// 6자리 입력
XCTAssertEqual(
"010123".formattedPhoneNumber(),
"010-123",
"포맷된 번호가 예상과 다릅니다."
)

// 5자리 입력
XCTAssertEqual(
"01012".formattedPhoneNumber(),
"010-12",
"포맷된 번호가 예상과 다릅니다."
)

// 4자리 입력
XCTAssertEqual(
"0101".formattedPhoneNumber(),
"010-1",
"포맷된 번호가 예상과 다릅니다."
)

// 3자리 입력
XCTAssertEqual(
"010".formattedPhoneNumber(),
"010",
"포맷된 번호가 예상과 다릅니다."
)

// 2자리 이하 입력
XCTAssertEqual(
"01".formattedPhoneNumber(),
"01",
"포맷된 번호가 예상과 다릅니다."
)
XCTAssertEqual(
"0".formattedPhoneNumber(),
"0",
"포맷된 번호가 예상과 다릅니다."
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "check_bold.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "flag_korea.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "search.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading