diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 0606184d6..f9a3dc998 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -203,6 +203,7 @@ 46562110EE202E580A5FFD9C /* RoomScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93CF7B19FFCF8EFBE0A8696A /* RoomScreenViewModelTests.swift */; }; 46A261AA898344A1F3C406B1 /* ReportContentScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CCE3636E3D01477C8B2E9D0 /* ReportContentScreenModels.swift */; }; 46BA7F4B4D3A7164DED44B88 /* FullscreenDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565F1B2B300597C616B37888 /* FullscreenDialog.swift */; }; + 46D1E2940ED8CCBF62FE8854 /* CreatePollScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27EA0F71A3A400A202E15318 /* CreatePollScreen.swift */; }; 47305C0911C9E1AA774A4000 /* TemplateScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA90BD288E5AE6BC643AFDDF /* TemplateScreenCoordinator.swift */; }; 4799A852132F1744E2825994 /* CreateRoomViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340179A0FC1AD4AEDA7FC134 /* CreateRoomViewModelProtocol.swift */; }; 491D62ACD19E6F134B1766AF /* RoomNotificationSettingsUserDefinedScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3203C6566DC17B7AECC1B7FD /* RoomNotificationSettingsUserDefinedScreen.swift */; }; @@ -221,6 +222,7 @@ 4E8F17EBA24FBBA6ABB62ECB /* MockBackgroundTaskService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3948D16F021DFDB2CD26EAA8 /* MockBackgroundTaskService.swift */; }; 4E945AD6862C403F74E57755 /* RoomTimelineItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 105B2A8426404EF66F00CFDB /* RoomTimelineItemFactory.swift */; }; 4EA1CE0E88EA68E862FF0EA2 /* NotificationSettingsEditScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B564D748B67A156F413CD97 /* NotificationSettingsEditScreenModels.swift */; }; + 4EB1B717C1EFE3A7ABFBC0A8 /* CreatePollScreenViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A22A3A4109959414EBC6113 /* CreatePollScreenViewModelProtocol.swift */; }; 4FC085B1E5D1EB804495E2F4 /* MockMediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD6E621CC5E6D4830D96D2D /* MockMediaProvider.swift */; }; 4FC1EFE4968A259CBBACFAFB /* RoomProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A65F140F9FE5E8D4DAEFF354 /* RoomProxy.swift */; }; 4FDC8A9764CFDA90CE035725 /* Duration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7FB2253D36E81E045E1CB432 /* Duration.swift */; }; @@ -267,6 +269,7 @@ 5D7960B32C350FA93F48D02B /* OnboardingModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB33A751BFDA223BDD106EC0 /* OnboardingModels.swift */; }; 5DD85A0FE3D85AEC3C7EFE36 /* DeveloperOptionsScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7C7CFA6B2A62A685FF6CE3 /* DeveloperOptionsScreenCoordinator.swift */; }; 5E0F2E612718BB4397A6D40A /* TextRoomTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9E785D5137510481733A3E8 /* TextRoomTimelineView.swift */; }; + 5E415EF9A5D31B1690CE27F5 /* CreatePollScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5DDF245FA51CF75F89E58A4 /* CreatePollScreenUITests.swift */; }; 5F06AD3C66884CE793AE6119 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DF593C3F7AF4B2FBAEB05D /* FileManager.swift */; }; 5F28C9146694B381BB82E18C /* AnalyticsPromptScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B65A314DF40B6BBF775C2BC /* AnalyticsPromptScreenCoordinator.swift */; }; 5F5488FBC9CFEB6F433D74A4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7109E709A7738E6BCC4553E6 /* Localizable.strings */; }; @@ -330,6 +333,7 @@ 7361B011A79BF723D8C9782B /* EmojiCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C1A3D524D63815B28FA4D62 /* EmojiCategory.swift */; }; 7405B4824D45BA7C3D943E76 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0CBC76C80E04345E11F2DB /* Application.swift */; }; 743790BF6A5B0577EA74AF14 /* ReadMarkerRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3D25B3EDB283B5807EADCF /* ReadMarkerRoomTimelineItem.swift */; }; + 744114780862F0BD1A2D57D6 /* CreatePollScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB23BEAF8831DC6A57E39F52 /* CreatePollScreenCoordinator.swift */; }; 74604ACFDBE7F54260E7B617 /* ApplicationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8903A9F615BBD0E6D7CD133 /* ApplicationProtocol.swift */; }; 748F482FEF4E04D61C39AAD7 /* EmojiPickerScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = F174A5627CDB3CAF280D1880 /* EmojiPickerScreenModels.swift */; }; 7501442D52A65F73DF79FFD4 /* PaginationIndicatorRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B987FC3FDBAA0E1C5AA235C /* PaginationIndicatorRoomTimelineItem.swift */; }; @@ -530,6 +534,7 @@ AF33B9044498211C3D82F1E1 /* UNTextInputNotificationResponse+Creator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 130ED565A078F7E0B59D9D25 /* UNTextInputNotificationResponse+Creator.swift */; }; AF4232E6F08C3DB86FFA9BBD /* NotificationSettingsScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B83BC0DC9A2DF2DD60F9B6E9 /* NotificationSettingsScreenUITests.swift */; }; AF8BFA37791E1756EE243E08 /* SettingsScreenCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B8F0ED874DF8C9A51B0AB6F /* SettingsScreenCoordinator.swift */; }; + AFC518DCC38B821537EBF549 /* CreatePollScreenModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4ADC55DFF46083BC957E0019 /* CreatePollScreenModels.swift */; }; B037C365CF8A58A0D149A2DB /* AuthenticationIconImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97755C01C3971474EFAD5367 /* AuthenticationIconImage.swift */; }; B064D42BA087649ACAE462E8 /* SoftLogoutUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55F30E764BED111C81739844 /* SoftLogoutUITests.swift */; }; B09DC6E3D0EE87C4D4ABFAB3 /* EncryptedHistoryRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0140615D2232612C813FD6C /* EncryptedHistoryRoomTimelineItem.swift */; }; @@ -664,6 +669,7 @@ D7CDBAE82782BD0529DECB5F /* AttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52BD6ED18E2EB61E28C340AD /* AttributedString.swift */; }; D8359F67AF3A83516E9083C1 /* MockUserSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4756C5A8C8649AD6C10C615 /* MockUserSession.swift */; }; D8385A51A3D0FA9283556281 /* RoundedLabelItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 745323FCF9AF21A117252C53 /* RoundedLabelItem.swift */; }; + D84D5BDFB1B915389AC807B4 /* CreatePollScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A328F9E556F5CFA89332017 /* CreatePollScreenViewModel.swift */; }; D85D4FA590305180B4A41795 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3073CCD77D906B330BC1D6 /* Tests.swift */; }; D871C8CF46950F959C9A62C3 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = C54464351F170D570110AFCA /* WelcomeScreen.swift */; }; D876EC0FED3B6D46C806912A /* AvatarSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24B88AD3D1599E8CB1376E0 /* AvatarSize.swift */; }; @@ -723,6 +729,7 @@ EB88DBD77221E2CFE463018C /* NSE.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 0D8F620C8B314840D8602E3F /* NSE.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; EBE13FAB4E29738AC41BD3E5 /* InfoPlistReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A580295A56B55A856CC4084 /* InfoPlistReader.swift */; }; EC280623A42904341363EAAF /* Collections in Frameworks */ = {isa = PBXBuildFile; productRef = A20EA00CCB9DBE0FFB17DD09 /* Collections */; }; + EC658A57E715699C52DFBC77 /* CreatePollScreenViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EB1D0C69FEDD93404DF927E /* CreatePollScreenViewModelTests.swift */; }; ECA636DAF071C611FDC2BB57 /* Strings+Untranslated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A18F6CE4D694D21E4EA9B25 /* Strings+Untranslated.swift */; }; EDC1031A7CFB3406A9DA3175 /* AnalyticsLocationType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AD6299F4516797E9BBE14C3 /* AnalyticsLocationType.swift */; }; EDF8919F15DE0FF00EF99E70 /* DocumentPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F5567A7EF6F2AB9473236F6 /* DocumentPicker.swift */; }; @@ -956,6 +963,7 @@ 277C20CDD5B64510401B6D0D /* ServerConfigurationScreenViewStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerConfigurationScreenViewStateTests.swift; sourceTree = ""; }; 27A1AD6389A4659AF0CEAE62 /* NotificationServiceExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationServiceExtension.swift; sourceTree = ""; }; 27B8315A340B46F98B9C5AF0 /* TimelineTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineTableViewController.swift; sourceTree = ""; }; + 27EA0F71A3A400A202E15318 /* CreatePollScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreen.swift; sourceTree = ""; }; 287FC98AF2664EAD79C0D902 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = ""; }; 28C19F54A0C4FC9AB7ABD583 /* TextRoomTimelineItemContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRoomTimelineItemContent.swift; sourceTree = ""; }; 2A5C6FBF97B6EED3D4FA5EFF /* AttributedStringBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedStringBuilder.swift; sourceTree = ""; }; @@ -997,6 +1005,7 @@ 3948D16F021DFDB2CD26EAA8 /* MockBackgroundTaskService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockBackgroundTaskService.swift; sourceTree = ""; }; 398817652FA8ABAE0A31AC6D /* ReadableFrameModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadableFrameModifier.swift; sourceTree = ""; }; 39B6C8690AEA1E49FF1BAF95 /* MediaUploadPreviewScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadPreviewScreenUITests.swift; sourceTree = ""; }; + 3A328F9E556F5CFA89332017 /* CreatePollScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenViewModel.swift; sourceTree = ""; }; 3B5E97E9615A158C76B2AB77 /* DateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = ""; }; 3BFDAF6918BB096C44788FC9 /* RoomDetailsScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomDetailsScreenUITests.swift; sourceTree = ""; }; 3C1A3D524D63815B28FA4D62 /* EmojiCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCategory.swift; sourceTree = ""; }; @@ -1010,6 +1019,7 @@ 3DFE4453AB0B34C203447162 /* ImageRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageRoomTimelineItem.swift; sourceTree = ""; }; 3E6A9B9DFEE964962C179DE3 /* RoomAttachmentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomAttachmentPicker.swift; sourceTree = ""; }; 3E93A1BE7D8A2EBCAD51EEB4 /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; + 3EB1D0C69FEDD93404DF927E /* CreatePollScreenViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenViewModelTests.swift; sourceTree = ""; }; 3EF1AC723C2609C7705569CA /* MediaLoaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaLoaderTests.swift; sourceTree = ""; }; 3F40F48279322E504153AB0D /* MockClientProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockClientProxy.swift; sourceTree = ""; }; 3F684BDD23ECEADB3053BA5A /* DeveloperOptionsScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperOptionsScreenUITests.swift; sourceTree = ""; }; @@ -1049,6 +1059,7 @@ 4A4AD793D50748F8997E5B15 /* TimelineItemMacContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemMacContextMenu.swift; sourceTree = ""; }; 4AB7D7DAAAF662DED9D02379 /* MockMediaLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMediaLoader.swift; sourceTree = ""; }; 4AD6299F4516797E9BBE14C3 /* AnalyticsLocationType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsLocationType.swift; sourceTree = ""; }; + 4ADC55DFF46083BC957E0019 /* CreatePollScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenModels.swift; sourceTree = ""; }; 4B41FABA2B0AEF4389986495 /* LoginMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginMode.swift; sourceTree = ""; }; 4B5046BB295AEAFA6FB81655 /* SessionVerificationScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationScreenModels.swift; sourceTree = ""; }; 4BD371B60E07A5324B9507EF /* AnalyticsSettingsScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsSettingsScreenCoordinator.swift; sourceTree = ""; }; @@ -1132,6 +1143,7 @@ 69B63F817FE305548DB4B512 /* RoomMembersListViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMembersListViewModelTests.swift; sourceTree = ""; }; 69CB8242D69B7E4D0B32E18D /* AggregatedReactionMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AggregatedReactionMock.swift; sourceTree = ""; }; 69D42EE0102D2857933625DD /* CreateRoomViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateRoomViewModelTests.swift; sourceTree = ""; }; + 6A22A3A4109959414EBC6113 /* CreatePollScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenViewModelProtocol.swift; sourceTree = ""; }; 6A4C9547BBFEEF30AA11329B /* TimelineItemStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemStatusView.swift; sourceTree = ""; }; 6A580295A56B55A856CC4084 /* InfoPlistReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoPlistReader.swift; sourceTree = ""; }; 6A6C4BE591FE5C38CE9C7EF3 /* UserProperties+Element.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserProperties+Element.swift"; sourceTree = ""; }; @@ -1290,6 +1302,7 @@ A4756C5A8C8649AD6C10C615 /* MockUserSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockUserSession.swift; sourceTree = ""; }; A58DB8EFB91BE920762025D0 /* NCE.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.app-extension"; path = NCE.appex; sourceTree = BUILT_PRODUCTS_DIR; }; A58E93D91DE3288010390DEE /* EmojiDetectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiDetectionTests.swift; sourceTree = ""; }; + A5DDF245FA51CF75F89E58A4 /* CreatePollScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenUITests.swift; sourceTree = ""; }; A65F140F9FE5E8D4DAEFF354 /* RoomProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomProxy.swift; sourceTree = ""; }; A6B891A6DA826E2461DBB40F /* PHGPostHogConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PHGPostHogConfiguration.swift; sourceTree = ""; }; A73A07BAEDD74C48795A996A /* AsyncSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncSequence.swift; sourceTree = ""; }; @@ -1356,6 +1369,7 @@ BA241DEEF7C8A7181C0AEDC9 /* UserPreferenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPreferenceTests.swift; sourceTree = ""; }; BA40B98B098B6F0371B750B3 /* TemplateScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateScreenModels.swift; sourceTree = ""; }; BA919F521E9F0EE3638AFC85 /* BugReportScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BugReportScreen.swift; sourceTree = ""; }; + BB23BEAF8831DC6A57E39F52 /* CreatePollScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenCoordinator.swift; sourceTree = ""; }; BB3073CCD77D906B330BC1D6 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; BB33A751BFDA223BDD106EC0 /* OnboardingModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingModels.swift; sourceTree = ""; }; BB8BC4C791D0E88CFCF4E5DF /* ServerSelectionScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionScreenCoordinator.swift; sourceTree = ""; }; @@ -2562,6 +2576,7 @@ EFFD3200F9960D4996159F10 /* BugReportServiceTests.swift */, 7AB7ED3A898B07976F3AA90F /* BugReportViewModelTests.swift */, CA29952595B804DA221A0C1D /* ComposerToolbarViewModelTests.swift */, + 3EB1D0C69FEDD93404DF927E /* CreatePollScreenViewModelTests.swift */, 69D42EE0102D2857933625DD /* CreateRoomViewModelTests.swift */, 3B5E97E9615A158C76B2AB77 /* DateTests.swift */, 6D0A27607AB09784C8501B5C /* DeveloperOptionsScreenViewModelTests.swift */, @@ -2897,6 +2912,18 @@ path = HTMLParsing; sourceTree = ""; }; + 90DC2E28718955ED87AD1456 /* CreatePollScreen */ = { + isa = PBXGroup; + children = ( + BB23BEAF8831DC6A57E39F52 /* CreatePollScreenCoordinator.swift */, + 4ADC55DFF46083BC957E0019 /* CreatePollScreenModels.swift */, + 3A328F9E556F5CFA89332017 /* CreatePollScreenViewModel.swift */, + 6A22A3A4109959414EBC6113 /* CreatePollScreenViewModelProtocol.swift */, + D57A6F3FC292425BEBDF58BF /* View */, + ); + path = CreatePollScreen; + sourceTree = ""; + }; 90F48FEF84016ED42A94BA24 /* LoginScreen */ = { isa = PBXGroup; children = ( @@ -2968,6 +2995,7 @@ 7D0CBC76C80E04345E11F2DB /* Application.swift */, 5D2D0A6F1ABC99D29462FB84 /* AuthenticationCoordinatorUITests.swift */, C6FEA87EA3752203065ECE27 /* BugReportUITests.swift */, + A5DDF245FA51CF75F89E58A4 /* CreatePollScreenUITests.swift */, F8CEB4634C0DD7779C4AB504 /* CreateRoomScreenUITests.swift */, 3F684BDD23ECEADB3053BA5A /* DeveloperOptionsScreenUITests.swift */, 4D6E4C37E9F0E53D3DF951AC /* HomeScreenUITests.swift */, @@ -3509,6 +3537,14 @@ path = RoomMemberListScreen; sourceTree = ""; }; + D57A6F3FC292425BEBDF58BF /* View */ = { + isa = PBXGroup; + children = ( + 27EA0F71A3A400A202E15318 /* CreatePollScreen.swift */, + ); + path = View; + sourceTree = ""; + }; D977D4E565C06D3F41C8F8FC /* Virtual */ = { isa = PBXGroup; children = ( @@ -3594,6 +3630,7 @@ E74CD7681375AD2EAA34D66B /* Authentication */, 53FB148CD26AFB6A5B9E20B3 /* BugReportScreen */, 27F2500AC8736AAE774520C0 /* ComposerToolbar */, + 90DC2E28718955ED87AD1456 /* CreatePollScreen */, C18958141C8ED6D778F779A4 /* CreateRoom */, F5A65D1D3B83593598DC278D /* EmojiPickerScreen */, 448435400B561C40E514BE1C /* FilePreviewScreen */, @@ -4255,6 +4292,7 @@ C7CFDB4929DDD9A3B5BA085D /* BugReportViewModelTests.swift in Sources */, B5321A1F5B26A0F3EC54909E /* CollapsibleFlowLayoutTests.swift in Sources */, 0C932A5158C1D0604DFC5750 /* ComposerToolbarViewModelTests.swift in Sources */, + EC658A57E715699C52DFBC77 /* CreatePollScreenViewModelTests.swift in Sources */, D3FD96913D2B1AAA3149DAC7 /* CreateRoomViewModelTests.swift in Sources */, CD0088B763CD970CF1CBF8CB /* DateTests.swift in Sources */, 864C69CF951BF36D25BE0C03 /* DeveloperOptionsScreenViewModelTests.swift in Sources */, @@ -4419,6 +4457,11 @@ EA6613B29BA671F39CE1B1D2 /* ConfirmationDialog.swift in Sources */, AC7AA215D60FBC307F984028 /* Consumable.swift in Sources */, C3522917C0C367C403429EEC /* CoordinatorProtocol.swift in Sources */, + 46D1E2940ED8CCBF62FE8854 /* CreatePollScreen.swift in Sources */, + 744114780862F0BD1A2D57D6 /* CreatePollScreenCoordinator.swift in Sources */, + AFC518DCC38B821537EBF549 /* CreatePollScreenModels.swift in Sources */, + D84D5BDFB1B915389AC807B4 /* CreatePollScreenViewModel.swift in Sources */, + 4EB1B717C1EFE3A7ABFBC0A8 /* CreatePollScreenViewModelProtocol.swift in Sources */, 564BF06B3E93D6DD55F903B2 /* CreateRoomCoordinator.swift in Sources */, C32765D740C81AD4C42E8F50 /* CreateRoomFlowParameters.swift in Sources */, FB53CD9B74A15B3B94F9F788 /* CreateRoomModels.swift in Sources */, @@ -4883,6 +4926,7 @@ ACF094CF3BF02DBFA6DFDE60 /* AuthenticationCoordinatorUITests.swift in Sources */, 7756C4E90CABE6F14F7920A0 /* BugReportUITests.swift in Sources */, 94D0F36A87E596A93C0C178A /* Bundle.swift in Sources */, + 5E415EF9A5D31B1690CE27F5 /* CreatePollScreenUITests.swift in Sources */, 9F19096BFA629C0AC282B1E4 /* CreateRoomScreenUITests.swift in Sources */, C1F863E16BDBC87255D23B57 /* DeveloperOptionsScreenUITests.swift in Sources */, 9DC5FB22B8F86C3B51E907C1 /* HomeScreenUITests.swift in Sources */, diff --git a/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/Contents.json b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/Contents.json new file mode 100644 index 000000000..b773ae0a6 --- /dev/null +++ b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "filename" : "timeline-poll-attachment.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/timeline-poll-attachment.pdf b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/timeline-poll-attachment.pdf new file mode 100644 index 000000000..ebadfda9f --- /dev/null +++ b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll-attachment.imageset/timeline-poll-attachment.pdf @@ -0,0 +1,95 @@ +%PDF-1.7 + +1 0 obj + << >> +endobj + +2 0 obj + << /Length 3 0 R >> +stream +/DeviceRGB CS +/DeviceRGB cs +q +1.000000 0.000000 -0.000000 1.000000 2.000000 3.000000 cm +0.000000 0.000000 0.000000 scn +4.500000 0.000000 m +1.000000 0.000000 l +0.450000 0.000000 0.000000 0.450001 0.000000 1.000000 c +0.000000 11.000000 l +0.000000 11.550000 0.450000 12.000000 1.000000 12.000000 c +4.500000 12.000000 l +5.050000 12.000000 5.500000 11.550000 5.500000 11.000000 c +5.500000 1.000000 l +5.500000 0.450001 5.050000 0.000000 4.500000 0.000000 c +h +11.750000 18.000000 m +8.250000 18.000000 l +7.700000 18.000000 7.250000 17.549999 7.250000 17.000000 c +7.250000 1.000000 l +7.250000 0.450001 7.700000 0.000000 8.250000 0.000000 c +11.750000 0.000000 l +12.300000 0.000000 12.750000 0.450001 12.750000 1.000000 c +12.750000 17.000000 l +12.750000 17.549999 12.300000 18.000000 11.750000 18.000000 c +h +19.000000 10.000000 m +15.500000 10.000000 l +14.950000 10.000000 14.500000 9.550000 14.500000 9.000000 c +14.500000 1.000000 l +14.500000 0.450001 14.950000 0.000000 15.500000 0.000000 c +19.000000 0.000000 l +19.549999 0.000000 20.000000 0.450001 20.000000 1.000000 c +20.000000 9.000000 l +20.000000 9.550000 19.549999 10.000000 19.000000 10.000000 c +h +f +n +Q + +endstream +endobj + +3 0 obj + 1151 +endobj + +4 0 obj + << /Annots [] + /Type /Page + /MediaBox [ 0.000000 0.000000 24.000000 24.000000 ] + /Resources 1 0 R + /Contents 2 0 R + /Parent 5 0 R + >> +endobj + +5 0 obj + << /Kids [ 4 0 R ] + /Count 1 + /Type /Pages + >> +endobj + +6 0 obj + << /Pages 5 0 R + /Type /Catalog + >> +endobj + +xref +0 7 +0000000000 65535 f +0000000010 00000 n +0000000034 00000 n +0000001241 00000 n +0000001264 00000 n +0000001437 00000 n +0000001511 00000 n +trailer +<< /ID [ (some) (id) ] + /Root 6 0 R + /Size 7 +>> +startxref +1570 +%%EOF \ No newline at end of file diff --git a/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll.imageset/Contents.json b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll.imageset/Contents.json index 1fc3f5c11..45afb6961 100644 --- a/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll.imageset/Contents.json +++ b/ElementX/Resources/Assets.xcassets/images/timeline/timeline-poll.imageset/Contents.json @@ -8,5 +8,8 @@ "info" : { "author" : "xcode", "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" } } diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index e15ec140b..e8c77a8b4 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -41,6 +41,7 @@ final class AppSettings { case swiftUITimelineEnabled case pollsInTimeline case richTextEditorEnabled + case pollsCreationEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -241,4 +242,7 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.richTextEditorEnabled, defaultValue: false, storageType: .userDefaults(store)) var richTextEditorEnabled + + @UserPreference(key: UserDefaultsKeys.pollsCreationEnabled, defaultValue: false, storageType: .userDefaults(store)) + var pollsCreationEnabled } diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index 3d7e1e103..cc74ea2b4 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -146,6 +146,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { return .messageForwarding(roomID: roomID, itemID: itemID) case (.dismissMessageForwarding, .messageForwarding(let roomID, _)): return .room(roomID: roomID) + case (.presentMapNavigator, .room(let roomID)): return .mapNavigator(roomID: roomID) case (.dismissMapNavigator, .mapNavigator(let roomID)): @@ -155,6 +156,12 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { return .notificationSettingsScreen(roomID: roomID) case (.dismissNotificationSettingsScreen, .notificationSettingsScreen(let roomID)): return .roomDetails(roomID: roomID, isRoot: false) + + case (.presentCreatePollForm, .room(let roomID)): + return .createPollForm(roomID: roomID) + case (.dismissCreatePollForm, .createPollForm(let roomID)): + return .room(roomID: roomID) + default: return nil } @@ -217,6 +224,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { presentMessageForwarding(for: itemID) case (.messageForwarding, .dismissMessageForwarding, .room): break + case (.room, .presentMapNavigator(let mode), .mapNavigator): presentMapNavigator(interactionMode: mode) case (.mapNavigator, .dismissMapNavigator, .room): @@ -227,6 +235,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { case (.notificationSettingsScreen, .dismissNotificationSettingsScreen, .roomDetails): break + case (.room, .presentCreatePollForm, .createPollForm): + presentCreatePollForm() + case (.createPollForm, .dismissCreatePollForm, .room): + break + default: fatalError("Unknown transition: \(context)") } @@ -324,6 +337,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { stateMachine.tryEvent(.presentEmojiPicker(itemID: itemID, selectedEmojis: selectedEmojis)) case .presentLocationPicker: stateMachine.tryEvent(.presentMapNavigator(interactionMode: .picker)) + case .presentPollForm: + stateMachine.tryEvent(.presentCreatePollForm) case .presentLocationViewer(_, let geoURI, let description): stateMachine.tryEvent(.presentMapNavigator(interactionMode: .viewOnly(geoURI: geoURI, description: description))) case .presentRoomMemberDetails(member: let member): @@ -559,7 +574,48 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { self?.stateMachine.tryEvent(.dismissMapNavigator) } } - + + private func presentCreatePollForm() { + let navigationStackCoordinator = NavigationStackCoordinator() + let coordinator = CreatePollScreenCoordinator(parameters: .init()) + navigationStackCoordinator.setRootCoordinator(coordinator) + + coordinator.actions + .sink { [weak self] action in + guard let self else { + return + } + + self.navigationSplitCoordinator.setSheetCoordinator(nil) + + switch action { + case .cancel: + break + case let .create(question, options, pollKind): + Task { + guard let roomProxy = self.roomProxy else { + self.userIndicatorController.submitIndicator(UserIndicator(title: L10n.errorUnknown)) + return + } + + let result = await roomProxy.createPoll(question: question, answers: options, pollKind: pollKind) + + switch result { + case .success: + break + case .failure: + self.userIndicatorController.submitIndicator(UserIndicator(title: L10n.errorUnknown)) + } + } + } + } + .store(in: &cancellables) + + navigationSplitCoordinator.setSheetCoordinator(navigationStackCoordinator) { [weak self] in + self?.stateMachine.tryEvent(.dismissCreatePollForm) + } + } + private func presentRoomMemberDetails(member: RoomMemberProxyProtocol) { guard let roomProxy else { fatalError() @@ -689,6 +745,7 @@ private extension RoomFlowCoordinator { case roomMemberDetails(roomID: String, member: HashableRoomMemberWrapper) case messageForwarding(roomID: String, itemID: TimelineItemIdentifier) case notificationSettingsScreen(roomID: String) + case createPollForm(roomID: String) } struct EventUserInfo { @@ -726,6 +783,9 @@ private extension RoomFlowCoordinator { case presentNotificationSettingsScreen case dismissNotificationSettingsScreen + + case presentCreatePollForm + case dismissCreatePollForm } } diff --git a/ElementX/Sources/Generated/Assets.swift b/ElementX/Sources/Generated/Assets.swift index 8c1e53449..3a2f768cb 100644 --- a/ElementX/Sources/Generated/Assets.swift +++ b/ElementX/Sources/Generated/Assets.swift @@ -42,6 +42,7 @@ internal enum Asset { internal static let locationPointerFull = ImageAsset(name: "images/location-pointer-full") internal static let locationPointer = ImageAsset(name: "images/location-pointer") internal static let timelineComposerSendMessage = ImageAsset(name: "images/timeline-composer-send-message") + internal static let timelinePollAttachment = ImageAsset(name: "images/timeline-poll-attachment") internal static let timelinePoll = ImageAsset(name: "images/timeline-poll") internal static let timelineReactionAddMore = ImageAsset(name: "images/timeline-reaction-add-more") internal static let waitingGradient = ImageAsset(name: "images/waiting-gradient") diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 8ef94c293..1f9f6e29f 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -1464,6 +1464,27 @@ class RoomProxyMock: RoomProxyProtocol { return canUserRedactUserIDReturnValue } } + //MARK: - createPoll + + var createPollQuestionAnswersPollKindCallsCount = 0 + var createPollQuestionAnswersPollKindCalled: Bool { + return createPollQuestionAnswersPollKindCallsCount > 0 + } + var createPollQuestionAnswersPollKindReceivedArguments: (question: String, answers: [String], pollKind: Poll.Kind)? + var createPollQuestionAnswersPollKindReceivedInvocations: [(question: String, answers: [String], pollKind: Poll.Kind)] = [] + var createPollQuestionAnswersPollKindReturnValue: Result! + var createPollQuestionAnswersPollKindClosure: ((String, [String], Poll.Kind) async -> Result)? + + func createPoll(question: String, answers: [String], pollKind: Poll.Kind) async -> Result { + createPollQuestionAnswersPollKindCallsCount += 1 + createPollQuestionAnswersPollKindReceivedArguments = (question: question, answers: answers, pollKind: pollKind) + createPollQuestionAnswersPollKindReceivedInvocations.append((question: question, answers: answers, pollKind: pollKind)) + if let createPollQuestionAnswersPollKindClosure = createPollQuestionAnswersPollKindClosure { + return await createPollQuestionAnswersPollKindClosure(question, answers, pollKind) + } else { + return createPollQuestionAnswersPollKindReturnValue + } + } } class RoomTimelineProviderMock: RoomTimelineProviderProtocol { var updatePublisher: AnyPublisher { diff --git a/ElementX/Sources/Other/AccessibilityIdentifiers.swift b/ElementX/Sources/Other/AccessibilityIdentifiers.swift index 68c8ea061..f0aa88bfc 100644 --- a/ElementX/Sources/Other/AccessibilityIdentifiers.swift +++ b/ElementX/Sources/Other/AccessibilityIdentifiers.swift @@ -40,6 +40,7 @@ struct A11yIdentifiers { static let migrationScreen = MigrationScreen() static let notificationSettingsScreen = NotificationSettingsScreen() static let notificationSettingsEditScreen = NotificationSettingsEditScreen() + static let createPollScreen = CreatePollScreen() struct AnalyticsPromptScreen { let title = "analytics_prompt-title" @@ -181,6 +182,19 @@ struct A11yIdentifiers { let roomTopic = "create_room-room_topic" } + struct CreatePollScreen { + let question = "create_poll-question" + let create = "create_poll-create" + let addOption = "create_poll-add_option" + let pollKind = "create_poll-kind" + + private let optionPrefix = "create_poll-option" + + func optionID(_ index: Int) -> String { + "\(optionPrefix)-\(index)" + } + } + struct WelcomeScreen { let letsGo = "welcome_screen-lets_go" } diff --git a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarModels.swift b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarModels.swift index 668c92af8..f99b749c8 100644 --- a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarModels.swift +++ b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarModels.swift @@ -24,6 +24,7 @@ enum ComposerToolbarViewModelAction { case displayMediaPicker case displayDocumentPicker case displayLocationPicker + case displayPollForm case handlePasteOrDrop(provider: NSItemProvider) @@ -40,6 +41,7 @@ enum ComposerToolbarViewAction { case displayMediaPicker case displayDocumentPicker case displayLocationPicker + case displayPollForm case handlePasteOrDrop(provider: NSItemProvider) } diff --git a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift index 255101792..dfd9a92a8 100644 --- a/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift +++ b/ElementX/Sources/Screens/ComposerToolbar/ComposerToolbarViewModel.swift @@ -78,6 +78,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool actionsSubject.send(.displayDocumentPicker) case .displayLocationPicker: actionsSubject.send(.displayLocationPicker) + case .displayPollForm: + actionsSubject.send(.displayPollForm) case .handlePasteOrDrop(let provider): actionsSubject.send(.handlePasteOrDrop(provider: provider)) } diff --git a/ElementX/Sources/Screens/ComposerToolbar/View/RoomAttachmentPicker.swift b/ElementX/Sources/Screens/ComposerToolbar/View/RoomAttachmentPicker.swift index 37c517810..291a43cb7 100644 --- a/ElementX/Sources/Screens/ComposerToolbar/View/RoomAttachmentPicker.swift +++ b/ElementX/Sources/Screens/ComposerToolbar/View/RoomAttachmentPicker.swift @@ -65,6 +65,15 @@ struct RoomAttachmentPicker: View { PickerLabel(title: L10n.screenRoomAttachmentSourceLocation, icon: Image(asset: Asset.Images.locationPin)) } .accessibilityLabel(A11yIdentifiers.roomScreen.attachmentPickerLocation) + + if ServiceLocator.shared.settings.pollsCreationEnabled { + Button { + context.showAttachmentPopover = false + context.send(viewAction: .displayPollForm) + } label: { + PickerLabel(title: L10n.screenRoomAttachmentSourcePoll, icon: Image(asset: Asset.Images.timelinePollAttachment)) + } + } } .padding(.top, isPresented ? 20 : 0) .background { diff --git a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenCoordinator.swift b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenCoordinator.swift new file mode 100644 index 000000000..8d6dbac25 --- /dev/null +++ b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenCoordinator.swift @@ -0,0 +1,61 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Combine +import SwiftUI + +struct CreatePollScreenCoordinatorParameters { } + +enum CreatePollScreenCoordinatorAction { + case cancel + case create(question: String, options: [String], pollKind: Poll.Kind) +} + +final class CreatePollScreenCoordinator: CoordinatorProtocol { + private let parameters: CreatePollScreenCoordinatorParameters + private var viewModel: CreatePollScreenViewModelProtocol + private let actionsSubject: PassthroughSubject = .init() + private var cancellables: Set = .init() + + var actions: AnyPublisher { + actionsSubject.eraseToAnyPublisher() + } + + init(parameters: CreatePollScreenCoordinatorParameters) { + self.parameters = parameters + + viewModel = CreatePollScreenViewModel() + } + + func start() { + viewModel.actions.sink { [weak self] action in + MXLog.info("Coordinator: received view model action: \(action)") + + guard let self else { return } + switch action { + case let .create(question, options, pollKind): + self.actionsSubject.send(.create(question: question, options: options, pollKind: pollKind)) + case .cancel: + self.actionsSubject.send(.cancel) + } + } + .store(in: &cancellables) + } + + func toPresentable() -> AnyView { + AnyView(CreatePollScreen(context: viewModel.context)) + } +} diff --git a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenModels.swift b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenModels.swift new file mode 100644 index 000000000..4c866fb09 --- /dev/null +++ b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenModels.swift @@ -0,0 +1,49 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation + +enum CreatePollScreenViewModelAction { + case create(question: String, options: [String], pollKind: Poll.Kind) + case cancel +} + +struct CreatePollScreenViewState: BindableState { + let maxNumberOfOptions = 20 + var bindings: CreatePollScreenViewStateBindings = .init() +} + +struct CreatePollScreenViewStateBindings { + var question = "" + var options: [Option] = [.init(), .init()] + var isUndisclosed = false + + struct Option: Identifiable, Equatable { + let id = UUID() + var text = "" + } + + var isCreateButtonDisabled: Bool { + question.isEmpty || options.count < 2 || options.contains { $0.text.isEmpty } + } +} + +enum CreatePollScreenViewAction { + case cancel + case create + case deleteOption(index: Int) + case addOption +} diff --git a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift new file mode 100644 index 000000000..0f006954b --- /dev/null +++ b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift @@ -0,0 +1,59 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Combine +import SwiftUI + +typealias CreatePollScreenViewModelType = StateStoreViewModel + +class CreatePollScreenViewModel: CreatePollScreenViewModelType, CreatePollScreenViewModelProtocol { + private var actionsSubject: PassthroughSubject = .init() + + var actions: AnyPublisher { + actionsSubject.eraseToAnyPublisher() + } + + init() { + super.init(initialViewState: .init()) + } + + // MARK: - Public + + override func process(viewAction: CreatePollScreenViewAction) { + switch viewAction { + case .create: + actionsSubject.send(.create(question: state.bindings.question, + options: state.bindings.options.map(\.text), + pollKind: state.bindings.isUndisclosed ? .undisclosed : .disclosed)) + case .cancel: + actionsSubject.send(.cancel) + case .deleteOption(let index): + // fixes a crash that caused an index out of range when an option with the keyboard focus was deleted + Task { + try await Task.sleep(for: .milliseconds(100)) + guard state.bindings.options.indices.contains(index) else { + return + } + state.bindings.options.remove(at: index) + } + case .addOption: + guard state.bindings.options.count < state.maxNumberOfOptions else { + return + } + state.bindings.options.append(.init()) + } + } +} diff --git a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModelProtocol.swift b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModelProtocol.swift new file mode 100644 index 000000000..2f39a4ecf --- /dev/null +++ b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModelProtocol.swift @@ -0,0 +1,23 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Combine + +@MainActor +protocol CreatePollScreenViewModelProtocol { + var actions: AnyPublisher { get } + var context: CreatePollScreenViewModelType.Context { get } +} diff --git a/ElementX/Sources/Screens/CreatePollScreen/View/CreatePollScreen.swift b/ElementX/Sources/Screens/CreatePollScreen/View/CreatePollScreen.swift new file mode 100644 index 000000000..3f63b54e5 --- /dev/null +++ b/ElementX/Sources/Screens/CreatePollScreen/View/CreatePollScreen.swift @@ -0,0 +1,168 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Compound +import SwiftUI + +struct CreatePollScreen: View { + @ObservedObject var context: CreatePollScreenViewModel.Context + @FocusState var focus: Focus? + + enum Focus: Hashable { + case question + case option(index: Int) + } + + var body: some View { + Form { + questionSection + optionsSection + showResultsSection + } + .compoundForm() + .scrollDismissesKeyboard(.immediately) + .environment(\.editMode, .constant(.active)) + .navigationTitle(L10n.screenCreatePollTitle) + .navigationBarTitleDisplayMode(.inline) + .toolbar { toolbar } + .animation(.elementDefault, value: context.options) + } + + // MARK: - Private + + private var questionSection: some View { + Section(L10n.screenCreatePollQuestionDesc) { + TextField(text: $context.question) { + Text(L10n.screenCreatePollQuestionHint) + .compoundFormTextFieldPlaceholder() + } + .introspect(.textField, on: .iOS(.v16)) { textField in + textField.clearButtonMode = .whileEditing + } + .textFieldStyle(.compoundForm) + .focused($focus, equals: .question) + .accessibilityIdentifier(A11yIdentifiers.createPollScreen.question) + } + .compoundFormSection() + } + + private var optionsSection: some View { + Section { + ForEach(context.options) { option in + if let index = context.options.firstIndex(of: option) { + CreatePollOptionView(text: $context.options[index].text.limited(to: 240), + placeholder: L10n.screenCreatePollAnswerHint(index + 1), + canDeleteItem: context.options.count > 2) { + if case .option(let focusedIndex) = focus, focusedIndex == index { + focus = nil + } + + context.send(viewAction: .deleteOption(index: index)) + } + .focused($focus, equals: .option(index: index)) + .accessibilityIdentifier(A11yIdentifiers.createPollScreen.optionID(index)) + } + } + .onMove { offsets, toOffset in + context.options.move(fromOffsets: offsets, toOffset: toOffset) + } + + if context.options.count < context.viewState.maxNumberOfOptions { + Button(L10n.screenCreatePollAddOptionBtn) { + context.send(viewAction: .addOption) + } + .accessibilityIdentifier(A11yIdentifiers.createPollScreen.addOption) + } + } + .compoundFormSection() + } + + private var showResultsSection: some View { + Section { + Toggle(L10n.screenCreatePollAnonymousDesc, isOn: $context.isUndisclosed) + .accessibilityIdentifier(A11yIdentifiers.createPollScreen.pollKind) + } + .compoundFormSection() + } + + @ToolbarContentBuilder + private var toolbar: some ToolbarContent { + ToolbarItem(placement: .navigationBarLeading) { + Button(L10n.actionCancel) { + context.send(viewAction: .cancel) + } + } + + ToolbarItem(placement: .confirmationAction) { + Button(L10n.actionCreate) { + context.send(viewAction: .create) + } + .disabled(context.viewState.bindings.isCreateButtonDisabled) + .accessibilityIdentifier(A11yIdentifiers.createPollScreen.create) + } + } +} + +private struct CreatePollOptionView: View { + @Environment(\.editMode) var editMode + @Binding var text: String + let placeholder: String + let canDeleteItem: Bool + let deleteAction: () -> Void + + var body: some View { + HStack { + if editMode?.wrappedValue == .active { + Button(action: deleteAction) { + CompoundIcon(\.delete) + .font(.system(size: 24)) + .foregroundColor(.compound.iconCriticalPrimary) + } + .disabled(!canDeleteItem) + .buttonStyle(PlainButtonStyle()) + } + TextField(text: $text) { + Text(placeholder) + .compoundFormTextFieldPlaceholder() + } + .introspect(.textField, on: .iOS(.v16)) { textField in + textField.clearButtonMode = .whileEditing + } + .textFieldStyle(.compoundForm) + } + } +} + +// MARK: - Previews + +struct CreatePollScreen_Previews: PreviewProvider { + static let viewModel = CreatePollScreenViewModel() + static var previews: some View { + NavigationStack { + CreatePollScreen(context: viewModel.context) + } + } +} + +private extension Binding where Value == String { + func limited(to limit: Int) -> Self { + .init { + wrappedValue + } set: { newValue in + wrappedValue = String(newValue.prefix(limit)) + } + } +} diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index a7f2cc734..330fabd23 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -31,6 +31,7 @@ enum RoomScreenCoordinatorAction { case presentMediaUploadPreviewScreen(URL) case presentRoomDetails case presentLocationPicker + case presentPollForm case presentLocationViewer(body: String, geoURI: GeoURI, description: String?) case presentEmojiPicker(itemID: TimelineItemIdentifier, selectedEmojis: Set) case presentRoomMemberDetails(member: RoomMemberProxyProtocol) @@ -86,6 +87,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol { actionsSubject.send(.presentMediaUploadPicker(.documents)) case .displayLocationPicker: actionsSubject.send(.presentLocationPicker) + case .displayPollForm: + actionsSubject.send(.presentPollForm) case .displayMediaUploadPreviewScreen(let url): actionsSubject.send(.presentMediaUploadPreviewScreen(url)) case .displayRoomMemberDetails(let member): diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 8997a4b3b..0d1c2b780 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -28,6 +28,7 @@ enum RoomScreenViewModelAction { case displayMediaPicker case displayDocumentPicker case displayLocationPicker + case displayPollForm case displayMediaUploadPreviewScreen(url: URL) case displayRoomMemberDetails(member: RoomMemberProxyProtocol) case displayMessageForwarding(itemID: TimelineItemIdentifier) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 240e8f5d8..50b8545bc 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -158,6 +158,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol actionsSubject.send(.displayDocumentPicker) case .displayLocationPicker: actionsSubject.send(.displayLocationPicker) + case .displayPollForm: + actionsSubject.send(.displayPollForm) case .handlePasteOrDrop(let provider): handlePasteOrDrop(provider) case .composerModeChanged(mode: let mode): diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 5950e827a..c517e6aec 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -52,6 +52,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var swiftUITimelineEnabled: Bool { get set } var pollsInTimelineEnabled: Bool { get set } var richTextEditorEnabled: Bool { get set } + var pollsCreationEnabled: Bool { get set } } extension AppSettings: DeveloperOptionsProtocol { } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index af2288c96..1d5e5d753 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -70,6 +70,10 @@ struct DeveloperOptionsScreen: View { Toggle(isOn: $context.pollsInTimelineEnabled) { Text("View polls in timeline") } + + Toggle(isOn: $context.pollsCreationEnabled) { + Text("View polls creation flow") + } } Section("Rich Text Editor") { diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index f916be1c3..d02996670 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -684,6 +684,17 @@ class RoomProxy: RoomProxyProtocol { } } + func createPoll(question: String, answers: [String], pollKind: Poll.Kind) async -> Result { + await Task.dispatch(on: .global()) { + do { + return try .success(self.room.createPoll(question: question, answers: answers, maxSelections: 1, pollKind: .init(pollKind: pollKind), txnId: genTransactionId())) + } catch { + MXLog.error("Failed creating a poll: \(error)") + return .failure(.failedCreatingPoll) + } + } + } + // MARK: - Private /// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener @@ -770,3 +781,14 @@ private final class RoomInfoUpdateListener: RoomInfoListener { onUpdateClosure() } } + +private extension MatrixRustSDK.PollKind { + init(pollKind: Poll.Kind) { + switch pollKind { + case .disclosed: + self = .disclosed + case .undisclosed: + self = .undisclosed + } + } +} diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 91116ef2e..453582228 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -42,6 +42,7 @@ enum RoomProxyError: Error, Equatable { case failedRemovingAvatar case failedUploadingAvatar case failedCheckingPermission + case failedCreatingPoll } // sourcery: AutoMockable @@ -165,6 +166,8 @@ protocol RoomProxyProtocol { func uploadAvatar(media: MediaInfo) async -> Result func canUserRedact(userID: String) async -> Result + + func createPoll(question: String, answers: [String], pollKind: Poll.Kind) async -> Result } extension RoomProxyProtocol { diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift index be99a390b..0d102b6c2 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift @@ -606,7 +606,7 @@ private extension LocationRoomTimelineItemContent.AssetType { } } -private extension Poll.Kind { +extension Poll.Kind { init(pollKind: MatrixRustSDK.PollKind) { switch pollKind { case .disclosed: diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index f29d464b4..f781f13ad 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -666,6 +666,11 @@ class MockScreen: Identifiable { let coordinator = CreateRoomCoordinator(parameters: parameters) navigationStackCoordinator.setRootCoordinator(coordinator) return navigationStackCoordinator + case .createPoll: + let navigationStackCoordinator = NavigationStackCoordinator() + let coordinator = CreatePollScreenCoordinator(parameters: .init()) + navigationStackCoordinator.setRootCoordinator(coordinator) + return navigationStackCoordinator } }() } diff --git a/ElementX/Sources/UITests/UITestsScreenIdentifier.swift b/ElementX/Sources/UITests/UITestsScreenIdentifier.swift index 3297737fd..d09d87550 100644 --- a/ElementX/Sources/UITests/UITestsScreenIdentifier.swift +++ b/ElementX/Sources/UITests/UITestsScreenIdentifier.swift @@ -75,6 +75,7 @@ enum UITestsScreenIdentifier: String { case inviteUsersInRoomExistingMembers case createRoom case createRoomNoUsers + case createPoll } extension UITestsScreenIdentifier: CustomStringConvertible { diff --git a/UITests/Sources/CreatePollScreenUITests.swift b/UITests/Sources/CreatePollScreenUITests.swift new file mode 100644 index 000000000..6ba374e37 --- /dev/null +++ b/UITests/Sources/CreatePollScreenUITests.swift @@ -0,0 +1,66 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import ElementX +import XCTest + +@MainActor +class CreatePollScreenUITests: XCTestCase { + func testEmptyScreen() async throws { + let app = Application.launch(.createPoll) + try await app.assertScreenshot(.createPoll) + } + + func testFilledPoll() async throws { + let app = Application.launch(.createPoll) + let questionTextField = app.textFields[A11yIdentifiers.createPollScreen.question] + questionTextField.tap() + questionTextField.typeText("Do you like polls?") + + let option1TextField = app.textFields[A11yIdentifiers.createPollScreen.optionID(0)] + option1TextField.tap() + option1TextField.typeText("Yes") + + let option2TextField = app.textFields[A11yIdentifiers.createPollScreen.optionID(1)] + option2TextField.tap() + option2TextField.typeText("No") + + let createButton = app.buttons[A11yIdentifiers.createPollScreen.create] + XCTAssertTrue(createButton.isEnabled) + + try await app.assertScreenshot(.createPoll, step: 1) + } + + func testMaxOptions() async throws { + let app = Application.launch(.createPoll) + let createButton = app.buttons[A11yIdentifiers.createPollScreen.create] + let addOption = app.buttons[A11yIdentifiers.createPollScreen.addOption] + + for _ in 1...18 { + if !addOption.exists { + app.swipeUp() + } + addOption.tap() + } + + app.swipeUp() + + XCTAssertFalse(addOption.exists) + XCTAssertFalse(createButton.isEnabled) + + try await app.assertScreenshot(.createPoll, step: 2) + } +} diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-1.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-1.png new file mode 100644 index 000000000..3fd0f4266 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29a2bba04064c1ed0e839bf7fe29d51bf2c6488b0e4e0992deecff1c30aeb092 +size 157226 diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-2.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-2.png new file mode 100644 index 000000000..13ce13a82 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f63af9f1e715da12f55d7e91279c47219b42b27125e44f915c47227321a12bdb +size 185844 diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll.png new file mode 100644 index 000000000..bb566469e --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPad-9th-generation.createPoll.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:467a21fa9a0d2a535887851f4ba65b91f106f38a1663eec31dd5b33ad4316fef +size 89795 diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-1.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-1.png new file mode 100644 index 000000000..68cba63d1 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a934baa838db31b290f69fff6037d6764789615a25f34c94b8273abde4b8c83a +size 170170 diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-2.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-2.png new file mode 100644 index 000000000..498f7ba1c --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f425a4f8ff36e11084da41350cc5ccae122be06cac59d1e9b03adab4f1c50d15 +size 308853 diff --git a/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll.png b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll.png new file mode 100644 index 000000000..2fe40fd06 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/en-GB-iPhone-14.createPoll.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d07086d5750c676a1f935366289bf803ed50cd2d83e962227edb50e4be432cf7 +size 103803 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-1.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-1.png new file mode 100644 index 000000000..3c9602c3f --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8de87274b05142ffd494ef3e539e222241461521d9c12da6c60fe2bb8a894de +size 161620 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-2.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-2.png new file mode 100644 index 000000000..127731524 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5952c0897de9cce140b877dda5413f2ee2a611d5bdfe7747b24289c3280534ef +size 223668 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll.png new file mode 100644 index 000000000..394914ea8 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPad-9th-generation.createPoll.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bb7f282056f9db7bc3edd8c9be0493d9252b407800ee6214da367b60eef5867 +size 97972 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-1.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-1.png new file mode 100644 index 000000000..aab743579 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75784ba1bcc96f0db74fa476073241c7e27dc809b35516a4a7fe35ee127b5748 +size 183973 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-2.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-2.png new file mode 100644 index 000000000..259c97ed9 --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a71198a895a22048cb9ace7b98bb9bb6f8ea531e01502e07a6a6c4db87738873 +size 351270 diff --git a/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll.png b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll.png new file mode 100644 index 000000000..a46ac023e --- /dev/null +++ b/UITests/Sources/__Snapshots__/Application/pseudo-iPhone-14.createPoll.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac225c17efd828512b67ee40d4de6ea63b6173bac280156945d8a77622a12556 +size 125867 diff --git a/UnitTests/Sources/CreatePollScreenViewModelTests.swift b/UnitTests/Sources/CreatePollScreenViewModelTests.swift new file mode 100644 index 000000000..89251a7ed --- /dev/null +++ b/UnitTests/Sources/CreatePollScreenViewModelTests.swift @@ -0,0 +1,69 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import XCTest + +@testable import ElementX + +@MainActor +class CreatePollScreenViewModelTests: XCTestCase { + var viewModel: CreatePollScreenViewModelProtocol! + + var context: CreatePollScreenViewModelType.Context { + viewModel.context + } + + override func setUpWithError() throws { + viewModel = CreatePollScreenViewModel() + } + + func testInitialState() { + XCTAssertEqual(context.options.count, 2) + XCTAssertTrue(context.options.allSatisfy(\.text.isEmpty)) + XCTAssertTrue(context.question.isEmpty) + XCTAssertTrue(context.viewState.bindings.isCreateButtonDisabled) + XCTAssertFalse(context.viewState.bindings.isUndisclosed) + } + + func testValidPoll() async throws { + context.question = "foo" + context.options[0].text = "bla1" + context.options[1].text = "bla2" + XCTAssertFalse(context.viewState.bindings.isCreateButtonDisabled) + + let deferred = deferFulfillment(viewModel.actions.first()) + context.send(viewAction: .create) + let action = try await deferred.fulfill() + + guard case .create(let question, let options, let kind) = action else { + XCTFail("Unexpected action") + return + } + XCTAssertEqual(question, "foo") + XCTAssertEqual(options.count, 2) + XCTAssertEqual(options[0], "bla1") + XCTAssertEqual(options[1], "bla2") + XCTAssertEqual(kind, .disclosed) + } + + func testInvalidPollEmptyOption() { + context.question = "foo" + context.options[0].text = "bla" + context.options[1].text = "bla" + context.send(viewAction: .addOption) + XCTAssertTrue(context.viewState.bindings.isCreateButtonDisabled) + } +}