Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TweenMain.AddNewTabメソッドに対するテストコードを追加 #295

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions OpenTween.Tests/ListElementTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// OpenTween - Client of Twitter
// Copyright (c) 2024 kim_upsilon (@kim_upsilon) <https://upsilo.net/~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 <http://www.gnu.org/licenses/>, 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());
}
}
}
115 changes: 113 additions & 2 deletions OpenTween.Tests/TweenMainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +41,8 @@ namespace OpenTween
public class TweenMainTest
{
private record TestContext(
SettingManager Settings
SettingManager Settings,
TabInformations TabInfo
);

private void UsingTweenMain(Action<TweenMain, TestContext> func)
Expand All @@ -54,7 +56,7 @@ private void UsingTweenMain(Action<TweenMain, TestContext> 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);
}
Expand All @@ -63,6 +65,115 @@ private void UsingTweenMain(Action<TweenMain, TestContext> 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<DetailsListView>(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<DetailsListView>(tabPage.Controls[0]);

var label = Assert.IsType<Label>(tabPage.Controls[1]);
Assert.Equal("twitterapi's Timeline", label.Text);
});
}

[WinFormsFact]
public void AddNewTab_ListTimelineTabTest()
{
this.UsingTweenMain((tweenMain, context) =>
{
Assert.Equal(4, tweenMain.ListTab.TabPages.Count);

var list = new ListElement
{
Id = 12345L,
Name = "tetete",
Username = "opentween",
IsPublic = false,
};
var tab = new ListTimelineTabModel("hoge", list);
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<DetailsListView>(tabPage.Controls[0]);

var label = Assert.IsType<Label>(tabPage.Controls[1]);
Assert.Equal("@opentween/tetete [Protected]", label.Text);
});
}

[WinFormsFact]
public void AddNewTab_PublicSearchTabTest()
{
this.UsingTweenMain((tweenMain, context) =>
{
Assert.Equal(4, tweenMain.ListTab.TabPages.Count);

var tab = new PublicSearchTabModel("hoge")
{
SearchWords = "#OpenTween",
SearchLang = "ja",
};
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<DetailsListView>(tabPage.Controls[0]);

var panel = Assert.IsType<Panel>(tabPage.Controls[1]);
Assert.Equal(4, panel.Controls.Count);

var comboSearchWord = Assert.IsType<ComboBox>(panel.Controls[0]);
Assert.Equal("#OpenTween", comboSearchWord.Text);

var comboSearchLang = Assert.IsType<ComboBox>(panel.Controls[1]);
Assert.Equal("ja", comboSearchLang.Text);

Assert.IsType<Button>(panel.Controls[2]);
Assert.IsType<Label>(panel.Controls[3]);
});
}

[WinFormsFact]
public void FormatStatusText_NewLineTest()
{
Expand Down
2 changes: 1 addition & 1 deletion OpenTween/ListElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public async Task GetMoreMembers()
.ConfigureAwait(false);

public override string ToString()
=> $"@{this.Username}/{this.Name} [{(this.IsPublic ? "public" : "Protected")}]";
=> $"@{this.Username}/{this.Name} [{(this.IsPublic ? "Public" : "Protected")}]";
}
}