-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEAV-49] Design System - Text Input 구현 (#15)
* [WEAV-49] TextInput 생성 * [WEAV-49] Design Preview 생성 * [WEAV-49] 전화번호 검증 텍스트필드 생성 * [WEAV-49] 전화번호 검증 테스트코드 작성
- Loading branch information
1 parent
c82ade1
commit d797f88
Showing
19 changed files
with
484 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
157 changes: 157 additions & 0 deletions
157
Projects/Core/CoreKit/UnitTest/StringExtensionText.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
"포맷된 번호가 예상과 다릅니다." | ||
) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...esignSystem/DesignCore/Resources/Images/Images.xcassets/check_bold.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Binary file added
BIN
+301 Bytes
.../DesignCore/Resources/Images/Images.xcassets/check_bold.imageset/check_bold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+452 Bytes
...signCore/Resources/Images/Images.xcassets/check_bold.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+602 Bytes
...signCore/Resources/Images/Images.xcassets/check_bold.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
...esignSystem/DesignCore/Resources/Images/Images.xcassets/flag_korea.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Binary file added
BIN
+1 KB
.../DesignCore/Resources/Images/Images.xcassets/flag_korea.imageset/flag_korea.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.38 KB
...signCore/Resources/Images/Images.xcassets/flag_korea.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.05 KB
...signCore/Resources/Images/Images.xcassets/flag_korea.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions
23
...ts/DesignSystem/DesignCore/Resources/Images/Images.xcassets/search.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Binary file added
BIN
+570 Bytes
...gnSystem/DesignCore/Resources/Images/Images.xcassets/search.imageset/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+958 Bytes
...ystem/DesignCore/Resources/Images/Images.xcassets/search.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.27 KB
...ystem/DesignCore/Resources/Images/Images.xcassets/search.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.