Skip to content

Commit

Permalink
Adding UI test
Browse files Browse the repository at this point in the history
  • Loading branch information
porgabi committed Nov 13, 2023
1 parent 19b024a commit 48212f2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Modules/OrchardCore.Commerce/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ public override void ConfigureServices(IServiceCollection services)
// Page
services.AddScoped<IDataMigration, PageMigrations>();

// Checkout
services.AddScoped<ICheckoutEvents, InventoryCheckoutEvents>();

// Exposing models to liquid templates
services.Configure<TemplateOptions>(option =>
{
Expand Down Expand Up @@ -371,6 +368,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IProductEstimationContextUpdater, InventoryProductEstimationContextUpdater>();
services.AddScoped<IOrderEvents, InventoryOrderEvents>();
services.AddScoped<IProductInventoryService, ProductInventoryService>();
services.AddScoped<ICheckoutEvents, InventoryCheckoutEvents>();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public InventoryBehaviourTests(ITestOutputHelper testOutputHelper)
{
}

public const string CheckoutUnavailableMessage = "Checkout unavailable — an item is out of stock.";

[Theory, Chrome]
public Task InventoryChecksOnCartUpdateShouldWorkProperly(Browser browser) =>
ExecuteTestAfterSetupAsync(
Expand Down Expand Up @@ -73,6 +75,56 @@ await UpdateCartAndAssertErrorsAsync(
},
browser);

[Theory, Chrome]
public Task UnavailableProductInCartShouldPreventCheckout(Browser browser) =>
ExecuteTestAfterSetupAsync(
async context =>
{
await context.SignInDirectlyAndGoToRelativeUrlAsync("/testproduct");
await context.ClickReliablyOnAsync(By.XPath("//button[contains(., 'Add to cart')]"));

// Set Inventory of product in cart to 0.
await context.GoToAdminRelativeUrlAsync($"/Contents/ContentItems/{TestProduct}/Edit");
await context.ClickReliablyOnAsync(By.XPath("//label[contains(., 'Allows Back Order')]"));
await context.ClickAndFillInWithRetriesAsync(By.Name("InventoryPart.Inventory[TESTPRODUCT]"), "0");
await context.ClickPublishAsync();

// Verify checkout is unavailable.
await context.GoToRelativeUrlAsync("/cart");
context.Exists(By.XPath($"//p[contains(., '{CheckoutUnavailableMessage}')]"));
await context.GoToRelativeUrlAsync("/checkout");
context.Exists(By.XPath($"//div[contains(., '{CheckoutUnavailableMessage}')]"));

// Add an available product to cart and verify checkout is still not possible.
await context.GoToRelativeUrlAsync("testfreeproduct");
await context.ClickReliablyOnAsync(By.XPath("//button[contains(., 'Add to cart')]"));
context.Exists(By.XPath($"//p[contains(., '{CheckoutUnavailableMessage}')]"));
await context.GoToRelativeUrlAsync("/checkout");
context.Exists(By.XPath($"//div[contains(., '{CheckoutUnavailableMessage}')]"));

// Set Ignore Inventory to true and verify checkout is available.
await context.GoToAdminRelativeUrlAsync($"/Contents/ContentItems/{TestProduct}/Edit");
await context.ClickReliablyOnAsync(By.XPath("//label[contains(., 'Ignore Inventory')]"));
await context.ClickPublishAsync();

await context.GoToRelativeUrlAsync("/cart");
context.Missing(By.XPath($"//p[contains(., '{CheckoutUnavailableMessage}')]"));
await context.GoToRelativeUrlAsync("/checkout");
context.Missing(By.XPath($"//div[contains(., '{CheckoutUnavailableMessage}')]"));

// Set Allows Back Order to true and verify checkout is available.
await context.GoToAdminRelativeUrlAsync($"/Contents/ContentItems/{TestProduct}/Edit");
await context.ClickReliablyOnAsync(By.XPath("//label[contains(., 'Ignore Inventory')]"));
await context.ClickReliablyOnAsync(By.XPath("//label[contains(., 'Allows Back Order')]"));
await context.ClickPublishAsync();

await context.GoToRelativeUrlAsync("/cart");
context.Missing(By.XPath($"//p[contains(., '{CheckoutUnavailableMessage}')]"));
await context.GoToRelativeUrlAsync("/checkout");
context.Missing(By.XPath($"//div[contains(., '{CheckoutUnavailableMessage}')]"));
},
browser);

private static async Task UpdateCartAndAssertErrorsAsync(
UITestContext context,
int quantity,
Expand Down

0 comments on commit 48212f2

Please sign in to comment.