From 2e5a033965984f40bae17850fe000a4b32027c78 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Thu, 11 Jan 2024 04:42:45 +0900 Subject: [PATCH] =?UTF-8?q?TweenMain.AddNewTab=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenTween.Tests/ListElementTest.cs | 54 ++++++++++++++ OpenTween.Tests/TweenMainTest.cs | 115 ++++++++++++++++++++++++++++- OpenTween/ListElement.cs | 2 +- 3 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 OpenTween.Tests/ListElementTest.cs diff --git a/OpenTween.Tests/ListElementTest.cs b/OpenTween.Tests/ListElementTest.cs new file mode 100644 index 000000000..cba9f40c5 --- /dev/null +++ b/OpenTween.Tests/ListElementTest.cs @@ -0,0 +1,54 @@ +// OpenTween - Client of Twitter +// Copyright (c) 2024 kim_upsilon (@kim_upsilon) +// All rights reserved. +// +// This file is part of OpenTween. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program. If not, see , or write to +// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +// Boston, MA 02110-1301, USA. + +using Xunit; + +namespace OpenTween +{ + public class ListElementTest + { + [Fact] + public void ToString_PublicTest() + { + var list = new ListElement + { + Id = 12345L, + Name = "tetete", + Username = "opentween", + IsPublic = true, + }; + Assert.Equal("@opentween/tetete [Public]", list.ToString()); + } + + [Fact] + public void ToString_ProtectedTest() + { + var list = new ListElement + { + Id = 12345L, + Name = "tetete", + Username = "opentween", + IsPublic = false, + }; + Assert.Equal("@opentween/tetete [Protected]", list.ToString()); + } + } +} diff --git a/OpenTween.Tests/TweenMainTest.cs b/OpenTween.Tests/TweenMainTest.cs index 8beba3b2c..2b6da7991 100644 --- a/OpenTween.Tests/TweenMainTest.cs +++ b/OpenTween.Tests/TweenMainTest.cs @@ -30,6 +30,7 @@ using OpenTween.Api.DataModel; using OpenTween.Connection; using OpenTween.Models; +using OpenTween.OpenTweenCustomControl; using OpenTween.Setting; using OpenTween.Thumbnail; using Xunit; @@ -40,7 +41,8 @@ namespace OpenTween public class TweenMainTest { private record TestContext( - SettingManager Settings + SettingManager Settings, + TabInformations TabInfo ); private void UsingTweenMain(Action func) @@ -54,7 +56,7 @@ private void UsingTweenMain(Action func) var thumbnailGenerator = new ThumbnailGenerator(new(autoupdate: false)); using var tweenMain = new TweenMain(settings, tabinfo, twitter, imageCache, iconAssets, thumbnailGenerator); - var context = new TestContext(settings); + var context = new TestContext(settings, tabinfo); func(tweenMain, context); } @@ -63,6 +65,115 @@ private void UsingTweenMain(Action func) public void Initialize_Test() => this.UsingTweenMain((_, _) => { }); + [WinFormsFact] + public void AddNewTab_FilterTabTest() + { + this.UsingTweenMain((tweenMain, context) => + { + Assert.Equal(4, tweenMain.ListTab.TabPages.Count); + + var tab = new FilterTabModel("hoge"); + context.TabInfo.AddTab(tab); + tweenMain.AddNewTab(tab, startup: false); + + Assert.Equal(5, tweenMain.ListTab.TabPages.Count); + + var tabPage = tweenMain.ListTab.TabPages[4]; + Assert.Equal("hoge", tabPage.Text); + Assert.Single(tabPage.Controls); + Assert.IsType(tabPage.Controls[0]); + }); + } + + [WinFormsFact] + public void AddNewTab_UserTimelineTabTest() + { + this.UsingTweenMain((tweenMain, context) => + { + Assert.Equal(4, tweenMain.ListTab.TabPages.Count); + + var tab = new UserTimelineTabModel("hoge", "twitterapi"); + context.TabInfo.AddTab(tab); + tweenMain.AddNewTab(tab, startup: false); + + Assert.Equal(5, tweenMain.ListTab.TabPages.Count); + + var tabPage = tweenMain.ListTab.TabPages[4]; + Assert.Equal("hoge", tabPage.Text); + Assert.Equal(2, tabPage.Controls.Count); + Assert.IsType(tabPage.Controls[0]); + + var label = Assert.IsType