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

Test UI of the followunfollow feature #315

Merged
merged 29 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
77b132b
Setup of follow/unfollow test class
AlexTMIT Nov 20, 2024
5d5947f
Add playwright project
AlexTMIT Nov 20, 2024
61fef0d
register user for alex for testing
AlexTMIT Nov 20, 2024
1b951bd
add test user
AlexTMIT Nov 20, 2024
2c48952
setup of before each with login
AlexTMIT Nov 20, 2024
6c880d6
update setup method with register and login of new user for test purp…
AlexTMIT Nov 20, 2024
ff221c8
sets up writer user, write cheep, then sets up user who follows
AlexTMIT Nov 20, 2024
842472b
bugfixing confirmation nullpointer exception
AlexTMIT Nov 20, 2024
60ed226
delete unused
AlexTMIT Nov 20, 2024
c1a9fd1
Now compiles! ;D
AlexTMIT Nov 20, 2024
750d66b
Fixing bug in end to end test.
AlexTMIT Nov 20, 2024
8b5ff7b
Write Can Follow test.
AlexTMIT Nov 20, 2024
52e1790
Write Can Unfollow author test.
AlexTMIT Nov 20, 2024
0dea4da
Update Can Unfollow Auhtor test
AlexTMIT Nov 20, 2024
14b8fc2
Bugfixing CrossSiteScriptingTest
AlexTMIT Nov 20, 2024
9351fd1
Bugfixing EndToEnd tests
AlexTMIT Nov 20, 2024
b794098
tests compile and pass after rolling back to sub-optimal test setup.
AlexTMIT Nov 20, 2024
7ceeed1
Expect for unfollow test
AlexTMIT Nov 20, 2024
30bd24f
Write user cannot follow self test.
AlexTMIT Nov 20, 2024
79d8cd8
fix cannot follow self test!
AlexTMIT Nov 20, 2024
dd9915a
Write CanOnlySeeOwnAndFollowedCheeps() :D
AlexTMIT Nov 20, 2024
8c364da
Write UserStaysOnPageAfterUnfollowOnPrivateTimeline()
AlexTMIT Nov 20, 2024
278d221
Write UserStaysOnPageAfterFollowAndUnfollowOnPublicTimeline()
AlexTMIT Nov 20, 2024
9397f3f
formatting :)
AlexTMIT Nov 20, 2024
62f6ad4
complete rewrite of tests to eliminate code duplication and enhance c…
AlexTMIT Nov 20, 2024
6d642e2
removed unused import
AlexTMIT Nov 20, 2024
e114adb
small unimportant bugfix
AlexTMIT Nov 20, 2024
47ed289
Fixed errors in tests
stoftot Nov 20, 2024
90aac57
Shouldet be pushed
stoftot Nov 20, 2024
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
1 change: 1 addition & 0 deletions Chirp/src/Chirp.Web/Chirp.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.48.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.6" />
</ItemGroup>

Expand Down
Binary file removed Chirp/src/Chirp.Web/database/Chirp.db
Binary file not shown.
Binary file removed Chirp/src/Chirp.Web/database/Chirp.db-shm
Binary file not shown.
Binary file removed Chirp/src/Chirp.Web/database/Chirp.db-wal
Binary file not shown.
4 changes: 2 additions & 2 deletions Chirp/test/PlaywrightTests/CrossSiteScriptingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public async Task CrossSiteScripting_CheepForm()
await Page.GetByLabel("Confirm Password").ClickAsync();
await Page.GetByLabel("Confirm Password").FillAsync(password);
await Page.GetByRole(AriaRole.Button, new() { Name = "Register" }).ClickAsync();
await Page.GetByRole(AriaRole.Link, new() { Name = "Click here to confirm your" }).ClickAsync();
await Expect(Page.GetByText("Thank you for confirming your")).ToBeVisibleAsync();
await Page.GetByRole(AriaRole.Link, new() { Name = "Click here to confirm your account" }).ClickAsync();
await Expect(Page.GetByText("Thank you for confirming")).ToBeVisibleAsync();

await Page.GetByRole(AriaRole.Link, new() { Name = "login" }).ClickAsync();
await Page.GetByPlaceholder("Username").ClickAsync();
Expand Down
4 changes: 2 additions & 2 deletions Chirp/test/PlaywrightTests/EndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public async Task EndToEnd_RegisterLoginCheepAndLogout()
await Page.GetByLabel("Confirm Password").ClickAsync();
await Page.GetByLabel("Confirm Password").FillAsync(password);
await Page.GetByRole(AriaRole.Button, new() { Name = "Register" }).ClickAsync();
await Page.GetByRole(AriaRole.Link, new() { Name = "Click here to confirm your" }).ClickAsync();
await Expect(Page.GetByText("Thank you for confirming your")).ToBeVisibleAsync();
await Page.GetByRole(AriaRole.Link, new() { Name = "Click here to confirm your account" }).ClickAsync();
await Expect(Page.GetByText("Thank you for confirming")).ToBeVisibleAsync();

await Page.GetByRole(AriaRole.Link, new() { Name = "login" }).ClickAsync();
await Page.GetByPlaceholder("Username").ClickAsync();
Expand Down
154 changes: 154 additions & 0 deletions Chirp/test/PlaywrightTests/FollowUnfollowTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using Microsoft.Playwright;
using PlaywrightTests.Utils;

namespace PlaywrightTests;

[TestFixture]
[NonParallelizable]
public class FollowUnfollowTests : PageTestWithRazorPlaywrightWebApplicationFactory
{
private const string DefaultPassword = "Password123!";

// helper method: register a user
private async Task RegisterUser(string userName, string email, string password)
{
await Page.GotoAsync("/");
await Page.GetByRole(AriaRole.Link, new() { Name = "register" }).ClickAsync();
await Page.GetByPlaceholder("name", new() { Exact = true }).ClickAsync();
await Page.GetByPlaceholder("name", new() { Exact = true }).FillAsync(userName);
await Page.GetByPlaceholder("name@example.com").ClickAsync();
await Page.GetByPlaceholder("name@example.com").FillAsync(email);
await Page.GetByLabel("Password", new() { Exact = true }).ClickAsync();
await Page.GetByLabel("Password", new() { Exact = true }).FillAsync(password);
await Page.GetByLabel("Confirm Password").ClickAsync();
await Page.GetByLabel("Confirm Password").FillAsync(password);
await Page.GetByRole(AriaRole.Button, new() { Name = "Register" }).ClickAsync();
await Page.GetByRole(AriaRole.Link, new() { Name = "Click here to confirm your account" }).ClickAsync();
}

// helper method: log in as a user
private async Task LoginAsUser(string userName, string password)
{
await Page.GetByRole(AriaRole.Link, new() { Name = "login" }).ClickAsync();
await Page.GetByPlaceholder("Username").ClickAsync();
await Page.GetByPlaceholder("Username").FillAsync(userName);
await Page.GetByPlaceholder("password").ClickAsync();
await Page.GetByPlaceholder("password").FillAsync(password);
await Page.GetByRole(AriaRole.Button, new() { Name = "Log in" }).ClickAsync();
}

// helper method for log out
private async Task Logout()
{
await Page.GetByRole(AriaRole.Link, new() { Name = "logout" }).ClickAsync();
await Page.GetByRole(AriaRole.Button, new() { Name = "Click here to Logout" }).ClickAsync();
}

// helper method for write a cheep
private async Task WriteCheep(string message)
{
await Page.Locator("#Message").ClickAsync();
await Page.Locator("#Message").FillAsync(message);
await Page.GetByRole(AriaRole.Button, new() { Name = "Share" }).ClickAsync();
}

// helper method for following author
private async Task FollowAuthor(string authorCheepText)
{
await Page.Locator("li").Filter(new() { HasText = authorCheepText }).GetByRole(AriaRole.Button).ClickAsync();
}

// helper method for unfollow an author
private async Task UnfollowAuthor(string authorCheepText)
{
await Page.Locator("li").Filter(new() { HasText = authorCheepText }).GetByRole(AriaRole.Button).ClickAsync();
}

// helper method for navigating to public timeline
private async Task GoToPublicTimeline()
{
await Page.GetByRole(AriaRole.Link, new() { Name = "public timeline" }).ClickAsync();
}

// helper method fpr navigating to private timeline
private async Task GoToPrivateTimeline()
{
await Page.GetByRole(AriaRole.Link, new() { Name = "my timeline" }).ClickAsync();
}

[SetUp]
public async Task SetUp()
{
await RegisterUser("author", "author@itu.dk", DefaultPassword);
await LoginAsUser("author", DefaultPassword);
await WriteCheep("test");
await Logout();

await RegisterUser("follower", "follower@itu.dk", DefaultPassword);
await LoginAsUser("follower", DefaultPassword);
}

[Test]
public async Task UserCanFollowAuthor()
{
await GoToPublicTimeline();
await FollowAuthor("author follow test");
await GoToPrivateTimeline();
await Expect(Page.GetByText("author unfollow test")).ToBeVisibleAsync();
}

[Test]
public async Task UserCanUnfollowAuthor()
{
await GoToPublicTimeline();
await FollowAuthor("author follow test");
await GoToPrivateTimeline();
await UnfollowAuthor("author unfollow test");
await Expect(Page.GetByText("There are no cheeps so far.")).ToBeVisibleAsync();
}

[Test]
public async Task UserCannotFollowSelf()
{
await Logout();
await LoginAsUser("author", DefaultPassword);
var followButton = Page.Locator("li").Filter(new() { HasText = "author follow test" }).GetByRole(AriaRole.Button);
await Expect(followButton).ToBeHiddenAsync();
}

[Test]
public async Task CanOnlySeeOwnAndFollowedCheeps()
{
await Logout();
await RegisterUser("author2", "author2@itu.dk", DefaultPassword);
await LoginAsUser("author2", DefaultPassword);
await WriteCheep("this is author2's cheep");
await Logout();
await LoginAsUser("follower", DefaultPassword);
await GoToPublicTimeline();
await FollowAuthor("author follow test");
await GoToPrivateTimeline();
await Expect(Page.Locator("li").Filter(new() { HasText = "author2 follow this is author2's cheep" })).ToBeHiddenAsync();
await Expect(Page.Locator("li").Filter(new() { HasText = "author unfollow test" })).ToBeVisibleAsync();
}

[Test]
public async Task UserStaysOnPageAfterUnfollowOnPrivateTimeline()
{
await GoToPublicTimeline();
await FollowAuthor("author follow test");
await GoToPrivateTimeline();
await UnfollowAuthor("author unfollow test");
await Expect(Page.GetByText("There are no cheeps so far.")).ToBeVisibleAsync();
}

[Test]
public async Task UserStaysOnPageAfterFollowAndUnfollowOnPublicTimeline()
{
await GoToPublicTimeline();
await FollowAuthor("author follow test");
await UnfollowAuthor("author unfollow test");
await Expect(Page.Locator("li").Filter(new() { HasText = "author follow test" })).ToBeVisibleAsync();
await Expect(Page.GetByText("There are no cheeps so far.")).ToBeHiddenAsync();
}
}
Loading