|
| 1 | +using System.Text.RegularExpressions; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Microsoft.Playwright; |
| 4 | +using Microsoft.Playwright.Xunit; |
| 5 | +using Xunit; |
| 6 | +using Xunit.Abstractions; |
| 7 | + |
| 8 | +namespace PluginBuilder.Tests.PluginTests; |
| 9 | + |
| 10 | +[Collection("Playwright Tests")] |
| 11 | +public class OwnersUITests(ITestOutputHelper output) : PageTest |
| 12 | +{ |
| 13 | + private readonly XUnitLogger _log = new("OwnersUITest", output); |
| 14 | + |
| 15 | + [Fact] |
| 16 | + public async Task Ownership_Flow_Works() |
| 17 | + { |
| 18 | + await using var t = new PlaywrightTester(_log); |
| 19 | + t.Server.ReuseDatabase = false; |
| 20 | + await t.StartAsync(); |
| 21 | + |
| 22 | + await t.GoToUrl("/register"); |
| 23 | + var userA = await t.RegisterNewUser(); |
| 24 | + await Expect(t.Page!.Locator("body")).ToContainTextAsync("Builds"); |
| 25 | + |
| 26 | + var slug = "owners-" + PlaywrightTester.GetRandomUInt256()[..8]; |
| 27 | + await t.GoToUrl("/plugins/create"); |
| 28 | + await Expect(t.Page).ToHaveURLAsync(new Regex("/account/details$", RegexOptions.IgnoreCase)); |
| 29 | + await Expect(t.Page.Locator(".alert-warning")).ToBeVisibleAsync(); |
| 30 | + |
| 31 | + await t.VerifyEmailAndGithubAsync(userA); |
| 32 | + await t.GoToUrl("/plugins/create"); |
| 33 | + await t.Page!.FillAsync("#PluginSlug", slug); |
| 34 | + await t.Page.ClickAsync("#Create"); |
| 35 | + await t.GoToUrl($"/plugins/{slug}/owners"); |
| 36 | + await t.AssertNoError(); |
| 37 | + await Expect(t.Page.Locator("table tbody tr")).ToContainTextAsync(userA); |
| 38 | + await Expect(t.Page.Locator("table tbody tr")).ToContainTextAsync("Primary Owner"); |
| 39 | + |
| 40 | + await t.Logout(); |
| 41 | + await t.GoToUrl("/register"); |
| 42 | + var userB = await t.RegisterNewUser(); |
| 43 | + await Expect(t.Page.Locator("body")).ToContainTextAsync("Builds"); |
| 44 | + await t.Logout(); |
| 45 | + |
| 46 | + await t.GoToLogin(); |
| 47 | + await t.LogIn(userA); |
| 48 | + await t.GoToUrl($"/plugins/{slug}/owners"); |
| 49 | + |
| 50 | + var addForm = t.Page.Locator("form[method='post'] >> input[name='email']"); |
| 51 | + |
| 52 | + await addForm.FillAsync(userB); |
| 53 | + await t.Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Add" }).ClickAsync(); |
| 54 | + await Expect(t.Page.Locator(".alert-warning")).ToBeVisibleAsync(); |
| 55 | + |
| 56 | + await t.VerifyEmailAndGithubAsync(userB); |
| 57 | + await addForm.FillAsync(userB); |
| 58 | + await t.Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Add" }).ClickAsync(); |
| 59 | + |
| 60 | + var bRow = t.Page.Locator("table tbody tr").Filter(new LocatorFilterOptions { HasText = userB }); |
| 61 | + await Expect(bRow).ToBeVisibleAsync(); |
| 62 | + |
| 63 | + var removeBtn = bRow.GetByRole(AriaRole.Button, new LocatorGetByRoleOptions { Name = "Remove" }); |
| 64 | + await removeBtn.ClickAsync(); |
| 65 | + var confirmBtn = t.Page.Locator("#ConfirmContinue"); |
| 66 | + await Expect(confirmBtn).ToBeVisibleAsync(); |
| 67 | + await confirmBtn.ClickAsync(); |
| 68 | + await Expect(t.Page.Locator("table tbody tr").Filter(new LocatorFilterOptions { HasText = userB })).ToHaveCountAsync(0); |
| 69 | + |
| 70 | + await addForm.FillAsync(userB); |
| 71 | + await t.Page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Add" }).ClickAsync(); |
| 72 | + bRow = t.Page.Locator("table tbody tr").Filter(new LocatorFilterOptions { HasText = userB }); |
| 73 | + await Expect(bRow).ToBeVisibleAsync(); |
| 74 | + var transferBtn = bRow.GetByRole(AriaRole.Button, new LocatorGetByRoleOptions { Name = "Transfer Primary" }); |
| 75 | + await transferBtn.ClickAsync(); |
| 76 | + await Expect(t.Page.Locator("#ConfirmContinue")).ToBeVisibleAsync(); |
| 77 | + await t.Page.ClickAsync("#ConfirmContinue"); |
| 78 | + await Expect(bRow).ToContainTextAsync("Primary Owner"); |
| 79 | + await Expect(t.Page.Locator("form[method='post'] >> input[name='email']")).ToHaveCountAsync(0); |
| 80 | + |
| 81 | + var aRow = t.Page.Locator("table tbody tr").Filter(new LocatorFilterOptions { HasText = userA }); |
| 82 | + var leaveBtn = aRow.GetByRole(AriaRole.Button, new LocatorGetByRoleOptions { Name = "Leave" }); |
| 83 | + await leaveBtn.ClickAsync(); |
| 84 | + await Task.WhenAll( |
| 85 | + t.Page.WaitForURLAsync(url => !url.EndsWith($"/plugins/{slug}/owners")), |
| 86 | + t.Page.ClickAsync("#ConfirmContinue") |
| 87 | + ); |
| 88 | + |
| 89 | + await Expect(t.Page.Locator(".alert-success")) |
| 90 | + .ToContainTextAsync(new Regex("(Owner removed|You have left)", RegexOptions.IgnoreCase)); |
| 91 | + |
| 92 | + await t.Logout(); |
| 93 | + await t.GoToLogin(); |
| 94 | + await t.LogIn(userB); |
| 95 | + |
| 96 | + await t.GoToUrl($"/plugins/{slug}"); |
| 97 | + await t.AssertNoError(); |
| 98 | + await Expect(t.Page).ToHaveURLAsync(new Regex($"/plugins/{Regex.Escape(slug)}")); |
| 99 | + |
| 100 | + var createNewBuildLink = t.Page.Locator("#CreateNewBuild"); |
| 101 | + await Expect(createNewBuildLink).ToBeVisibleAsync(); |
| 102 | + await createNewBuildLink.ClickAsync(); |
| 103 | + |
| 104 | + await Expect(t.Page).ToHaveURLAsync(new Regex($"/plugins/{Regex.Escape(slug)}/create$")); |
| 105 | + |
| 106 | + await Expect(t.Page.Locator("#GitRepository")).ToBeVisibleAsync(); |
| 107 | + await Expect(t.Page.Locator("#GitRef")).ToBeVisibleAsync(); |
| 108 | + await Expect(t.Page.Locator("#PluginDirectory")).ToBeVisibleAsync(); |
| 109 | + await Expect(t.Page.Locator("#BuildConfig")).ToBeVisibleAsync(); |
| 110 | + await Expect(t.Page.Locator("#Create")).ToBeVisibleAsync(); |
| 111 | + |
| 112 | + await t.AssertNoError(); |
| 113 | + } |
| 114 | +} |
0 commit comments