Skip to content

Commit 78bf908

Browse files
committed
Фикс баги в dropdownMenu
1 parent 5389dc0 commit 78bf908

File tree

6 files changed

+17
-79
lines changed

6 files changed

+17
-79
lines changed

src/Controls.Extensions/DropdownMenuExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,4 @@ public static async Task WaitToContainItemsAsync(
7070
int timeoutInMilliseconds = 10000
7171
) => await dropdownMenu.ExpectV2().ToContainItemsAsync(expectedItemsText, timeoutInMilliseconds)
7272
.ConfigureAwait(false);
73-
74-
public static async Task WaitToBeFocusedAsync(
75-
this DropdownMenu dropdownMenu,
76-
LocatorAssertionsToBeFocusedOptions? options = default
77-
) => await dropdownMenu.ExpectV2().ToBeFocusedAsync(options).ConfigureAwait(false);
78-
79-
public static async Task WaitNotToBeFocusedAsync(
80-
this DropdownMenu dropdownMenu,
81-
LocatorAssertionsToBeFocusedOptions? options = default
82-
) => await dropdownMenu.ExpectV2().NotToBeFocusedAsync(options).ConfigureAwait(false);
8373
}

src/Controls/Assertions/DropdownMenuAssertionsV2.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ public DropdownMenuAssertionsV2(DropdownMenu dropdownMenu)
1919
}
2020

2121
public async Task ToBeEnabledAsync(LocatorAssertionsToBeEnabledOptions? options = default)
22-
=> await dropdownMenu.ButtonLocator.Expect().ToBeEnabledAsync(options).ConfigureAwait(false);
22+
=> await dropdownMenu.CaptionLocator.Expect().ToBeEnabledAsync(options).ConfigureAwait(false);
2323

2424
public async Task ToBeDisabledAsync(LocatorAssertionsToBeDisabledOptions? options = default)
25-
=> await dropdownMenu.ButtonLocator.Expect().ToBeDisabledAsync(options).ConfigureAwait(false);
25+
=> await dropdownMenu.CaptionLocator.Expect().ToBeDisabledAsync(options).ConfigureAwait(false);
2626

2727
public async Task ToHaveTextAsync(string text, LocatorAssertionsToHaveTextOptions? options = default)
28-
=> await dropdownMenu.ButtonLocator.Expect().ToHaveTextAsync(text, options).ConfigureAwait(false);
28+
=> await dropdownMenu.CaptionLocator.Expect().ToHaveTextAsync(text, options).ConfigureAwait(false);
2929

3030
public async Task NotToHaveTextAsync(string text, LocatorAssertionsToHaveTextOptions? options = default)
31-
=> await dropdownMenu.ButtonLocator.Expect().Not.ToHaveTextAsync(text, options).ConfigureAwait(false);
31+
=> await dropdownMenu.CaptionLocator.Expect().Not.ToHaveTextAsync(text, options).ConfigureAwait(false);
3232

3333
public async Task ToHaveTextAsync(Regex regex, LocatorAssertionsToHaveTextOptions? options = default)
34-
=> await dropdownMenu.ButtonLocator.Expect().ToHaveTextAsync(regex, options).ConfigureAwait(false);
34+
=> await dropdownMenu.CaptionLocator.Expect().ToHaveTextAsync(regex, options).ConfigureAwait(false);
3535

3636
public async Task NotToHaveTextAsync(Regex regex, LocatorAssertionsToHaveTextOptions? options = default)
37-
=> await dropdownMenu.ButtonLocator.Expect().Not.ToHaveTextAsync(regex, options).ConfigureAwait(false);
37+
=> await dropdownMenu.CaptionLocator.Expect().Not.ToHaveTextAsync(regex, options).ConfigureAwait(false);
3838

3939
public async Task ToContainTextAsync(string text, LocatorAssertionsToContainTextOptions? options = default)
40-
=> await dropdownMenu.ButtonLocator.Expect().ToContainTextAsync(text, options).ConfigureAwait(false);
40+
=> await dropdownMenu.CaptionLocator.Expect().ToContainTextAsync(text, options).ConfigureAwait(false);
4141

4242
public async Task NotToContainTextAsync(string text, LocatorAssertionsToContainTextOptions? options = default)
43-
=> await dropdownMenu.ButtonLocator.Expect().Not.ToContainTextAsync(text, options).ConfigureAwait(false);
43+
=> await dropdownMenu.CaptionLocator.Expect().Not.ToContainTextAsync(text, options).ConfigureAwait(false);
4444

4545
public async Task ToContainTextAsync(Regex regex, LocatorAssertionsToContainTextOptions? options = default)
46-
=> await dropdownMenu.ButtonLocator.Expect().ToContainTextAsync(regex, options).ConfigureAwait(false);
46+
=> await dropdownMenu.CaptionLocator.Expect().ToContainTextAsync(regex, options).ConfigureAwait(false);
4747

4848
public async Task NotToContainTextAsync(Regex regex, LocatorAssertionsToContainTextOptions? options = default)
49-
=> await dropdownMenu.ButtonLocator.Expect().Not.ToContainTextAsync(regex, options).ConfigureAwait(false);
49+
=> await dropdownMenu.CaptionLocator.Expect().Not.ToContainTextAsync(regex, options).ConfigureAwait(false);
5050

5151
public async Task ToContainItemsAsync(string[] expectedItemsText, int timeoutInMilliseconds = 10000)
5252
{
@@ -80,10 +80,4 @@ public async Task ToContainItemsAsync(string[] expectedItemsText, int timeoutInM
8080
throw new TimeoutException(
8181
$"Не дождались наличия элементов [{string.Join(", ", expectedItemsText)}] в списке DropdownMenu за {timeoutInMilliseconds}ms.");
8282
}
83-
84-
public async Task ToBeFocusedAsync(LocatorAssertionsToBeFocusedOptions? options = default)
85-
=> await dropdownMenu.ButtonLocator.Expect().ToBeFocusedAsync(options).ConfigureAwait(false);
86-
87-
public async Task NotToBeFocusedAsync(LocatorAssertionsToBeFocusedOptions? options = default)
88-
=> await dropdownMenu.ButtonLocator.Expect().Not.ToBeFocusedAsync(options).ConfigureAwait(false);
8983
}

src/Controls/DropdownMenu.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99

1010
namespace Playwright.ReactUI.Controls;
1111

12-
public class DropdownMenu : ControlBase, IFocusable
12+
public class DropdownMenu : ControlBase
1313
{
1414
private readonly Portal portal;
1515

1616
public DropdownMenu(ILocator rootLocator)
1717
: base(rootLocator)
1818
{
1919
portal = new Portal(rootLocator.Locator("noscript"));
20-
ButtonLocator = RootLocator.Locator("button");
20+
CaptionLocator = RootLocator.Locator("[data-tid='PopupMenu__caption']");
2121
}
2222

23-
public ILocator ButtonLocator { get; }
23+
public ILocator CaptionLocator { get; }
2424

2525
public async Task<string> GetTextAsync(LocatorInnerTextOptions? options = default)
26-
=> await ButtonLocator.InnerTextAsync(options).ConfigureAwait(false);
26+
=> await CaptionLocator.InnerTextAsync(options).ConfigureAwait(false);
2727

2828
public async Task<bool> IsMenuOpenedAsync()
2929
{
@@ -75,18 +75,7 @@ public async Task SelectByIndexAsync(int index, bool isMenuClosedAfterSelect = t
7575
}
7676

7777
public override async Task ClickAsync(LocatorClickOptions? options = default)
78-
=> await ButtonLocator.ClickAsync(options).ConfigureAwait(false);
79-
80-
public async Task FocusAsync(LocatorFocusOptions? options = default)
81-
{
82-
await ExpectV2()
83-
.ToBeEnabledAsync(new LocatorAssertionsToBeEnabledOptions { Timeout = options?.Timeout })
84-
.ConfigureAwait(false);
85-
await ButtonLocator.FocusAsync(options).ConfigureAwait(false);
86-
}
87-
88-
public async Task BlurAsync(LocatorBlurOptions? options = default)
89-
=> await ButtonLocator.BlurAsync(options).ConfigureAwait(false);
78+
=> await CaptionLocator.ClickAsync(options).ConfigureAwait(false);
9079

9180
public async Task<Tooltip> GetTooltipAsync(TooltipType type)
9281
=> await TooltipProvider.GetTooltipAsync(type, this).ConfigureAwait(false);
@@ -142,7 +131,7 @@ public async Task WaitItemWithTextAsync(string text)
142131

143132
[Obsolete("Используй ExpectV2. В будущих версиях этот метод будет удален")]
144133
public override ILocatorAssertions Expect()
145-
=> new DropdownMenuAssertions(RootLocator.Expect(), ButtonLocator.Expect());
134+
=> new DropdownMenuAssertions(RootLocator.Expect(), CaptionLocator.Expect());
146135

147136
public new DropdownMenuAssertionsV2 ExpectV2() => new(this);
148137

@@ -168,7 +157,7 @@ private async Task<ILocator> GetPortalContainerAsync()
168157
{
169158
if (!await IsMenuOpenedAsync().ConfigureAwait(false))
170159
{
171-
await ButtonLocator.ClickAsync().ConfigureAwait(false);
160+
await CaptionLocator.ClickAsync().ConfigureAwait(false);
172161
}
173162

174163
return await portal.GetContainerAsync().ConfigureAwait(false);

src/Tests/Assertions/DropdownMenuAssertionsV2Tests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,6 @@ await dropdownMenu.ExpectV2().ToContainItemsAsync(new[] { "Here goes the header"
117117
.ConfigureAwait(false);
118118
}
119119

120-
[Test]
121-
public async Task ToBeFocused_And_NotToBeFocused()
122-
{
123-
var dropdownMenu = await GetDropdownMenuAsync("default").ConfigureAwait(false);
124-
125-
await dropdownMenu.ExpectV2().NotToBeFocusedAsync().ConfigureAwait(false);
126-
127-
await dropdownMenu.ButtonLocator.FocusAsync().ConfigureAwait(false);
128-
await dropdownMenu.ExpectV2().ToBeFocusedAsync().ConfigureAwait(false);
129-
}
130-
131120
private async Task<DropdownMenu> GetDropdownMenuAsync(string storyName)
132121
{
133122
// ReSharper disable once StringLiteralTypo

src/Tests/Controls/DropdownMenuTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,6 @@ await tooltipLocator.WaitForAsync(new LocatorWaitForOptions { State = WaitForSel
226226
await tooltipLocator.Expect().ToBeVisibleAsync().ConfigureAwait(false);
227227
}
228228

229-
[Test]
230-
public async Task Focus_And_Blur()
231-
{
232-
var dropdownMenu = await GetDropdownMenuAsync("default").ConfigureAwait(false);
233-
await dropdownMenu.ButtonLocator.Expect().Not.ToBeFocusedAsync().ConfigureAwait(false);
234-
235-
await dropdownMenu.FocusAsync().ConfigureAwait(false);
236-
await dropdownMenu.ButtonLocator.Expect().ToBeFocusedAsync().ConfigureAwait(false);
237-
238-
await dropdownMenu.BlurAsync().ConfigureAwait(false);
239-
await dropdownMenu.ButtonLocator.Expect().Not.ToBeFocusedAsync().ConfigureAwait(false);
240-
}
241-
242229
[Test]
243230
public async Task GetTooltip()
244231
{

src/Tests/Extensions/DropdownMenuExtensionsTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,6 @@ await dropdownMenu.WaitToContainItemsAsync(new[] { "Here goes the header", "TODO
118118
.ConfigureAwait(false);
119119
}
120120

121-
[Test]
122-
public async Task WaitToBeFocused_And_WaitNotToBeFocused()
123-
{
124-
var dropdownMenu = await GetDropdownMenuAsync("default").ConfigureAwait(false);
125-
126-
await dropdownMenu.WaitNotToBeFocusedAsync().ConfigureAwait(false);
127-
128-
await dropdownMenu.ButtonLocator.FocusAsync().ConfigureAwait(false);
129-
await dropdownMenu.WaitToBeFocusedAsync().ConfigureAwait(false);
130-
}
131-
132121
private async Task<DropdownMenu> GetDropdownMenuAsync(string storyName)
133122
{
134123
// ReSharper disable once StringLiteralTypo

0 commit comments

Comments
 (0)