OSDN Git Service

TweenMain.RefreshTimelineメソッドに対するテストコードを追加
authorKimura Youichi <kim.upsilon@bucyou.net>
Wed, 10 Jan 2024 22:20:29 +0000 (07:20 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 11 Jan 2024 07:39:46 +0000 (16:39 +0900)
OpenTween.Tests/Models/TabModelTest.cs
OpenTween.Tests/Models/TwitterPostFactoryTest.cs
OpenTween.Tests/TweenMainTest.cs
OpenTween/Tween.cs

index f256d15..df6cd62 100644 (file)
@@ -674,6 +674,88 @@ namespace OpenTween.Models
         }
 
         [Fact]
+        public void IndexOf_SingleFoundTest()
+        {
+            var tab = new PublicSearchTabModel("search");
+
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("100"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
+                TextFromApi = "aaa",
+            });
+            tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
+            tab.AddSubmit();
+
+            Assert.Equal(0, tab.IndexOf(new TwitterStatusId("100")));
+        }
+
+        [Fact]
+        public void IndexOf_SingleNotFoundTest()
+        {
+            var tab = new PublicSearchTabModel("search");
+
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("100"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
+                TextFromApi = "aaa",
+            });
+            tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
+            tab.AddSubmit();
+
+            Assert.Equal(-1, tab.IndexOf(new TwitterStatusId("200")));
+        }
+
+        [Fact]
+        public void IndexOf_MultipleFoundTest()
+        {
+            var tab = new PublicSearchTabModel("search");
+
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("100"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
+                TextFromApi = "aaa",
+            });
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("200"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 1),
+                TextFromApi = "bbb",
+            });
+            tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
+            tab.AddSubmit();
+
+            var actual = tab.IndexOf(new[] { new TwitterStatusId("200"), new TwitterStatusId("100") });
+            Assert.Equal(new[] { 1, 0 }, actual);
+        }
+
+        [Fact]
+        public void IndexOf_MultiplePartiallyFoundTest()
+        {
+            var tab = new PublicSearchTabModel("search");
+
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("100"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
+                TextFromApi = "aaa",
+            });
+            tab.AddPostQueue(new()
+            {
+                StatusId = new TwitterStatusId("200"),
+                CreatedAtForSorting = new(2023, 1, 1, 0, 0, 1),
+                TextFromApi = "bbb",
+            });
+            tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
+            tab.AddSubmit();
+
+            var actual = tab.IndexOf(new[] { new TwitterStatusId("100"), new TwitterStatusId("999") });
+            Assert.Equal(new[] { 0, -1 }, actual);
+        }
+
+        [Fact]
         public void SearchPostsAll_Test()
         {
             var tab = new PublicSearchTabModel("search");
index 88718fd..6a31f01 100644 (file)
@@ -287,6 +287,27 @@ namespace OpenTween.Models
         }
 
         [Fact]
+        public void GetReceivedHashtags_Test()
+        {
+            var factory = new TwitterPostFactory(this.CreateTabinfo());
+            var status = this.CreateStatus();
+            status.FullText = "hoge #OpenTween";
+            status.Entities.Hashtags = new[]
+            {
+                new TwitterEntityHashtag
+                {
+                    Indices = new[] { 5, 15 },
+                    Text = "OpenTween",
+                },
+            };
+
+            _ = factory.CreateFromStatus(status, selfUserId: 20000L, followerIds: EmptyIdSet);
+
+            Assert.Equal(new[] { "#OpenTween" }, factory.GetReceivedHashtags());
+            Assert.Empty(factory.GetReceivedHashtags());
+        }
+
+        [Fact]
         public void CreateFromStatus_MediaAltTest()
         {
             var factory = new TwitterPostFactory(this.CreateTabinfo());
index 2b6da79..178237d 100644 (file)
@@ -23,6 +23,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;
@@ -55,6 +56,11 @@ namespace OpenTween
             using var iconAssets = new IconAssetsManager();
             var thumbnailGenerator = new ThumbnailGenerator(new(autoupdate: false));
 
+            // TabInformation.GetInstance() で取得できるようにする
+            var field = typeof(TabInformations).GetField("Instance",
+                BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField);
+            field.SetValue(null, tabinfo);
+
             using var tweenMain = new TweenMain(settings, tabinfo, twitter, imageCache, iconAssets, thumbnailGenerator);
             var context = new TestContext(settings, tabinfo);
 
@@ -175,6 +181,36 @@ namespace OpenTween
         }
 
         [WinFormsFact]
+        public void RefreshTimeline_Test()
+        {
+            this.UsingTweenMain((tweenMain, context) =>
+            {
+                var tabPage = tweenMain.ListTab.TabPages[0];
+                Assert.Equal("Recent", tabPage.Text);
+
+                var listView = (DetailsListView)tabPage.Controls[0];
+                Assert.Equal(0, listView.VirtualListSize);
+
+                var post = new PostClass
+                {
+                    StatusId = new TwitterStatusId("100"),
+                    Text = "hoge",
+                    UserId = 111L,
+                    ScreenName = "opentween",
+                    CreatedAt = new(2024, 1, 1, 0, 0, 0),
+                };
+                context.TabInfo.AddPost(post);
+                context.TabInfo.DistributePosts();
+                tweenMain.RefreshTimeline();
+
+                Assert.Equal(1, listView.VirtualListSize);
+
+                var listItem = listView.Items[0];
+                Assert.Equal("opentween", listItem.SubItems[4].Text);
+            });
+        }
+
+        [WinFormsFact]
         public void FormatStatusText_NewLineTest()
         {
             this.UsingTweenMain((tweenMain, _) =>
index f2d9080..90832f7 100644 (file)
@@ -811,7 +811,7 @@ namespace OpenTween
             _ = this.saveConfigDebouncer.Call();
         }
 
-        private void RefreshTimeline()
+        internal void RefreshTimeline()
         {
             var curListView = this.CurrentListView;