Skip to content

Commit

Permalink
[#26] Add surveyquestion view test
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Jan 11, 2023
1 parent 4ec77b7 commit 432e618
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 43 deletions.
16 changes: 16 additions & 0 deletions iosApp/Survey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
09D09DD429682CBC009F88AF /* ViewId+SurveyDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DBD2967EA5F009F88AF /* ViewId+SurveyDetail.swift */; };
09D09DD529682CBF009F88AF /* ViewId+SurveyDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DBD2967EA5F009F88AF /* ViewId+SurveyDetail.swift */; };
09D09DFD296E6B35009F88AF /* SurveyQuestionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DFC296E6B35009F88AF /* SurveyQuestionView.swift */; };
09D09DFF296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DFE296E7BFD009F88AF /* ViewId+SurveyQuestion.swift */; };
09D09E00296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DFE296E7BFD009F88AF /* ViewId+SurveyQuestion.swift */; };
09D09E01296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09DFE296E7BFD009F88AF /* ViewId+SurveyQuestion.swift */; };
09D09E05296E7CF9009F88AF /* SurveyQuestionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09E02296E7CF9009F88AF /* SurveyQuestionSpec.swift */; };
09D09E09296E7D55009F88AF /* SurveyQuestionScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09D09E06296E7D55009F88AF /* SurveyQuestionScreen.swift */; };
09E6ABF32951D105007F1EE3 /* KIF+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E6ABF12951D103007F1EE3 /* KIF+Swift.swift */; };
09E6ABFD2951D32F007F1EE3 /* ViewId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636B1428D8148C00A5CB97 /* ViewId.swift */; };
09E6ABFE2951D333007F1EE3 /* ViewId+General.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636B2F28D8267D00A5CB97 /* ViewId+General.swift */; };
Expand Down Expand Up @@ -300,6 +305,9 @@
09D09DCD29682B78009F88AF /* SurveyItemOverlayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyItemOverlayView.swift; sourceTree = "<group>"; };
09D09DD129682C98009F88AF /* SurveyDetailScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyDetailScreen.swift; sourceTree = "<group>"; };
09D09DFC296E6B35009F88AF /* SurveyQuestionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyQuestionView.swift; sourceTree = "<group>"; };
09D09DFE296E7BFD009F88AF /* ViewId+SurveyQuestion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewId+SurveyQuestion.swift"; sourceTree = "<group>"; };
09D09E02296E7CF9009F88AF /* SurveyQuestionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyQuestionSpec.swift; sourceTree = "<group>"; };
09D09E06296E7D55009F88AF /* SurveyQuestionScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyQuestionScreen.swift; sourceTree = "<group>"; };
09E6ABE42951CF3E007F1EE3 /* SurveyKIFUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SurveyKIFUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
09E6ABF12951D103007F1EE3 /* KIF+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KIF+Swift.swift"; sourceTree = "<group>"; };
09E6AC0B2951D5DD007F1EE3 /* AccountSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSpec.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -588,6 +596,7 @@
09495F6728FF97490036BDFB /* ViewId+Splash.swift */,
09495F7728FFF2D50036BDFB /* ViewId+SurveySelection.swift */,
09495F9B290A35BA0036BDFB /* ViewId+Account.swift */,
09D09DFE296E7BFD009F88AF /* ViewId+SurveyQuestion.swift */,
);
path = ViewId;
sourceTree = "<group>";
Expand Down Expand Up @@ -729,6 +738,7 @@
09A9F8DA2952B54F009DE583 /* SurveyScreen.swift */,
09A9F8DD2952B582009DE583 /* AccountScreen.swift */,
09D09DD129682C98009F88AF /* SurveyDetailScreen.swift */,
09D09E06296E7D55009F88AF /* SurveyQuestionScreen.swift */,
09A9F8D72952B42D009DE583 /* GenericScreen.swift */,
);
path = Screens;
Expand Down Expand Up @@ -948,6 +958,7 @@
09E6AC0B2951D5DD007F1EE3 /* AccountSpec.swift */,
09D09DB1295C56A1009F88AF /* SurveySelectionSpec.swift */,
09D09DCB29682965009F88AF /* SurveyDetailSpec.swift */,
09D09E02296E7CF9009F88AF /* SurveyQuestionSpec.swift */,
);
path = Module;
sourceTree = "<group>";
Expand Down Expand Up @@ -1838,6 +1849,9 @@
09D09DD329682CAE009F88AF /* SurveyDetailScreen.swift in Sources */,
09E6ABFF2951D333007F1EE3 /* ViewId+SurveySelection.swift in Sources */,
09D09DB2295C56A1009F88AF /* SurveySelectionSpec.swift in Sources */,
09D09E05296E7CF9009F88AF /* SurveyQuestionSpec.swift in Sources */,
09D09E01296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */,
09D09E09296E7D55009F88AF /* SurveyQuestionScreen.swift in Sources */,
09D09DD429682CBC009F88AF /* ViewId+SurveyDetail.swift in Sources */,
09E6AC042951D333007F1EE3 /* ViewId+Splash.swift in Sources */,
09E6ABF32951D105007F1EE3 /* KIF+Swift.swift in Sources */,
Expand Down Expand Up @@ -1880,6 +1894,7 @@
0982A80629278E9000FC1976 /* SurveyItemLoading.swift in Sources */,
09A9F8F329544F5E009DE583 /* AccountView+DataSource.swift in Sources */,
09495F0928E410A00036BDFB /* PageControlView.swift in Sources */,
09D09DFF296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */,
09636AFD28D484CA00A5CB97 /* R+SwiftUI.swift in Sources */,
09495FCB291107760036BDFB /* Image+Constants.swift in Sources */,
09D09DC02968039F009F88AF /* ScreenParameters.swift in Sources */,
Expand Down Expand Up @@ -1942,6 +1957,7 @@
09D09DD529682CBF009F88AF /* ViewId+SurveyDetail.swift in Sources */,
0982A79E2921DF7E00FC1976 /* SurveySelectionSpec.swift in Sources */,
09C2F4032934588B00F44818 /* TimeInterval+Constants.swift in Sources */,
09D09E00296E7BFD009F88AF /* ViewId+SurveyQuestion.swift in Sources */,
0964B1CA294051CE00946FA1 /* ArgumentedXCUIApplication.swift in Sources */,
09C2F40A29346A8800F44818 /* XCUIElement+Label.swift in Sources */,
09495FB1290A93650036BDFB /* XCUIApplication+.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "Close Icon.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ extension Double {

/// 0.7
static var appearing: Self { 0.7.speedModified }
/// 0.01
static var instant: Self { 0.01.speedModified }
/// 0.2
static var fast: Self { 0.2.speedModified }
/// 0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ struct SurveyDetailView: View {

@State var isAnimatingBack = false
@State var isAnimating = true
@State var isShowingTitle = true
@State var isShowingTitleNavigationBar = true

var body: some View {
ZStack {
surveyView
}
.accessibilityElement(children: .contain)
.accessibility(.surveyDetail(.view))
.backButton {
didPressBack()
.if(isShowingTitleNavigationBar) { view in
view.backButton {
didPressBack()
}
}
.if(!isShowingTitleNavigationBar) { view in
view.navigationBarItems(trailing: closeButton)
}
.onLoad {
DispatchQueue.main.async {
Expand All @@ -44,38 +51,92 @@ struct SurveyDetailView: View {
ZStack {
SurveyDetailImage(isAnimating: $isAnimating, survey: survey)

VStack(alignment: .leading) {
Text(survey.title)
.lineLimit(3)
.padding(.top, .mediumPadding)
.foregroundColor(.white)
.font(.boldLarge)
.accessibility(.surveyDetail(.titleText))
Text(survey.description_)
.lineLimit(.max)
.padding(.top, .lineSpacing)
.foregroundColor(.white)
.font(.regularBody)
.accessibility(.surveyDetail(.detailText))
VStack {
surveyQuestionView
Spacer()
HStack {
Spacer()
Button {
// TODO: Add action when press next
} label: {
Text(String.localizeId.survey_detail_start_button())
.primaryButton()
}
.padding(.bottom, .mediumPadding)
.accessibility(.surveyDetail(.startButton))
}
nextButton
}
.frame(maxWidth: .infinity)
.padding(.horizontal, .smallPadding)
.opacity(isAnimating ? 0.0 : 1.0)
}
}

var surveyQuestionView: some View {
VStack {
if isShowingTitle {
surveyTitleView
.transition(.move(edge: .leading).combined(with: .opacity))
} else {
SurveyQuestionView()
.transition(.move(edge: .trailing).combined(with: .opacity))
}
}
}

var surveyTitleView: some View {
VStack(alignment: .leading) {
Text(survey.title)
.lineLimit(3)
.padding(.top, .mediumPadding)
.foregroundColor(.white)
.font(.boldLarge)
.accessibility(.surveyDetail(.titleText))
Text(survey.description_)
.lineLimit(.max)
.padding(.top, .lineSpacing)
.foregroundColor(.white)
.font(.regularBody)
.accessibility(.surveyDetail(.detailText))
}
.frame(maxWidth: .infinity, alignment: .leading)
}

var nextButton: some View {
HStack {
Spacer()
if isShowingTitle {
Button {
// TODO: Add action when press next. Move following line to real logic.
isShowingTitleNavigationBar = false
DispatchQueue.main.asyncAfter(deadline: .now() + .instant) {
withAnimation(.easeIn(duration: .viewTransition)) {
self.isShowingTitle = false
}
}
} label: {
Text(String.localizeId.survey_detail_start_button())
.primaryButton()
}
.padding(.bottom, .mediumPadding)
.accessibility(.surveyDetail(.startButton))
} else {
Button {
// TODO: Add action when press next
} label: {
Assets.nextButton
.image
.resizable()
.frame(width: 56.0, height: 56.0)
}
.padding(.bottom, .mediumPadding)
.accessibility(.surveyQuestion(.nextButton))
}
}
}

var closeButton: some View {
Button {
// TODO: Implement close button
didPressBack()
} label: {
Assets.closeButton
.image
.resizable()
.frame(width: 28.0, height: 28.0)
.accessibility(.surveyQuestion(.closeButton))
}
}

func didPressBack() {
guard !isAnimatingBack else { return }
isAnimatingBack = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,20 @@ import SwiftUI
struct SurveyQuestionView: View {

var body: some View {
VStack {
VStack(alignment: .leading) {
// TODO: Use real data
Text("1/5")
.font(.boldMedium)
.foregroundColor(.white)
.opacity(0.5)
Text("")
.padding(.top, .largePadding)
.accessibility(.surveyQuestion(.detailText))
Text("Howd?")
.font(.boldLarge)
.foregroundColor(.white)
.padding(.top, .tinyPadding)
Spacer()
HStack {
Spacer()
Button {
// TODO: Add action when press next
} label: {
Assets.nextButton
.image
.resizable()
.frame(width: 56.0, height: 56.0)
}
.padding(.bottom, .mediumPadding)
.accessibility(.surveyDetail(.startButton))
}
.accessibility(.surveyQuestion(.titleText))
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ViewId+SurveyQuestion.swift
// Survey
//
// Created by Bliss on 11/1/23.
// Copyright © 2023 Nimble. All rights reserved.
//

extension ViewId {

enum SurveyQuestion: String {

case nextButton = "survey.question.next.button"
case titleText = "survey.question.title.text"
case detailText = "survey.question.detail.text"
case closeButton = "survey.question.close.button"
}
}
2 changes: 2 additions & 0 deletions iosApp/Survey/Sources/Presentation/ViewId/ViewId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum ViewId {
case surveySelection(SurveySelection)
case surveyLoading(SurveyLoading)
case surveyDetail(SurveyDetail)
case surveyQuestion(SurveyQuestion)
case account(Account)
case general(General)

Expand All @@ -29,6 +30,7 @@ enum ViewId {
case let .surveySelection(surveySelection): return surveySelection.rawValue
case let .surveyLoading(surveyLoading): return surveyLoading.rawValue
case let .surveyDetail(surveyDetail): return surveyDetail.rawValue
case let .surveyQuestion(surveyQuestion): return surveyQuestion.rawValue
case let .account(account): return account.rawValue
case let .general(general): return general.rawValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ extension CGFloat {
static var defaultPadding: CGFloat = 24.0
/// 26.0
static var mediumPadding: CGFloat = 26.0
/// 32.0
static var largePadding: CGFloat = 32.0
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ final class SurveyDetailScreen: GenericScreen {
func waitForAppearance() {
tester.waitForView(withAccessibilityIdentifier: ViewId.surveyDetail(.view)())
}

func tapNextButton() {
tester.tapView(withAccessibilityIdentifier: ViewId.surveyDetail(.startButton)())
}
}
18 changes: 18 additions & 0 deletions iosApp/SurveyKIFUITests/Sources/Screens/SurveyQuestionScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// SurveyQuestionScreen.swift
// Survey
//
// Created by Bliss on 11/1/23.
// Copyright © 2023 Nimble. All rights reserved.
//

final class SurveyQuestionScreen: GenericScreen {

func waitForAppearance() {
tester.waitForView(withAccessibilityIdentifier: ViewId.surveyQuestion(.titleText)())
}

func tapCloseButton() {
tester.tapView(withAccessibilityIdentifier: ViewId.surveyQuestion(.closeButton)())
}
}
Loading

0 comments on commit 432e618

Please sign in to comment.