Skip to content

Commit 0b380d7

Browse files
committed
Add UI Test.
1 parent 97ae9f4 commit 0b380d7

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Atata;
2+
using Lombiq.Tests.UI.Attributes;
3+
using Lombiq.Tests.UI.Extensions;
4+
using Lombiq.Tests.UI.Services;
5+
using OpenQA.Selenium;
6+
using Shouldly;
7+
using Xunit;
8+
9+
namespace OrchardCore.Commerce.Tests.UI.Tests.ProductTests;
10+
11+
public class SkuGeneratorTests : UITestBase
12+
{
13+
public SkuGeneratorTests(ITestOutputHelper testOutputHelper)
14+
: base(testOutputHelper)
15+
{
16+
}
17+
18+
[Theory, Chrome]
19+
public Task GuidSkuGeneratorShouldWork(Browser browser) =>
20+
ExecuteTestAfterSetupAsync(
21+
async context =>
22+
{
23+
string GetValue(string id) =>
24+
context.Get(By.Id(id)).GetValue() ?? string.Empty;
25+
26+
async Task CreateProductAsync(bool isSkuDisabled)
27+
{
28+
await context.CreateNewContentItemAsync("Product", onlyIfNotAlreadyThere: false);
29+
context
30+
.Get(By.Id("ProductPart_Sku"))
31+
.GetAttribute("readonly")
32+
.ShouldBe(isSkuDisabled ? "true" : null);
33+
34+
await context.ClickAndFillInWithRetriesAsync(By.Id("TitlePart_Title"), "SKU Test Product");
35+
await context.ClickPublishAsync();
36+
}
37+
38+
// Verify baseline product creation (SKU field must be filled manually).
39+
await context.SignInDirectlyAsync();
40+
await CreateProductAsync(isSkuDisabled: false);
41+
context.ErrorMessageExists("SKU must not be empty.");
42+
43+
// Verify altered product creation (SKU field is disabled, value is auto-generated).
44+
await context.EnableFeatureDirectlyAsync(CommerceConstants.Features.SkuGeneratorGuid);
45+
await CreateProductAsync(isSkuDisabled: true);
46+
context.ShouldBeSuccess();
47+
48+
// Verify published product.
49+
GetValue("TitlePart_Title").ShouldBe("SKU Test Product");
50+
GetValue("ProductPart_Sku").ToUpperInvariant().ShouldMatch("^[0-9A-F]{32}$");
51+
},
52+
browser);
53+
}

0 commit comments

Comments
 (0)