bcquality/microsoft/knowledge/testing/ui-handlers-in-tests.good.al
wenjiefan 0561b12c96 Clarify restart-safe batches and scripted UI handler tests
Address Nikola's batching and UI-handler feedback on PR #132. Preserve existing false-positive guards and defer the unconfirmed IsHandled policy.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f841a18b-535a-498e-96f2-f279b5378da5
2026-09-14 09:29:35 +02:00

85 lines
2.6 KiB
AL

codeunit 50400 "Test UI Handler Capture Good"
{
Subtype = Test;
[Test]
[HandlerFunctions('CustomerCardHandler')]
procedure CustomerCardShowsSelectedCustomer()
var
Customer: Record Customer;
begin
LibrarySales.CreateCustomer(Customer);
CapturedCustomerNo := '';
Page.RunModal(Page::"Customer Card", Customer);
Assert.AreEqual(Customer."No.", CapturedCustomerNo, 'The customer card opened for the wrong customer.');
end;
[Test]
[HandlerFunctions('CustomerCardHandler,CreditLimitNotificationHandler')]
procedure CustomerCardOpensForCustomerWithinCreditLimit()
var
Customer: Record Customer;
begin
LibrarySales.CreateCustomer(Customer);
CapturedCustomerNo := '';
Page.RunModal(Page::"Customer Card", Customer);
Assert.AreEqual(Customer."No.", CapturedCustomerNo, 'The customer card opened for the wrong customer.');
end;
[Test]
[HandlerFunctions('ConfirmHandler,PostMessageHandler')]
procedure ConfirmPostingAndShowMessage()
begin
LibraryVariableStorage.Clear();
LibraryVariableStorage.Enqueue('Post this document?');
LibraryVariableStorage.Enqueue(true);
LibraryVariableStorage.Enqueue('Posting completed.');
Assert.IsTrue(RunPostingThatConfirmsAndMessages(), 'The posting confirmation was declined.');
LibraryVariableStorage.AssertEmpty();
end;
local procedure RunPostingThatConfirmsAndMessages(): Boolean
begin
if not Confirm('Post this document?', false) then
exit(false);
Message('Posting completed.');
exit(true);
end;
[ConfirmHandler]
procedure ConfirmHandler(Question: Text[1024]; var Reply: Boolean)
begin
Assert.ExpectedConfirm(LibraryVariableStorage.DequeueText(), Question);
Reply := LibraryVariableStorage.DequeueBoolean();
end;
[MessageHandler]
procedure PostMessageHandler(MessageText: Text[1024])
begin
Assert.ExpectedMessage(LibraryVariableStorage.DequeueText(), MessageText);
end;
[ModalPageHandler]
procedure CustomerCardHandler(var CustomerCard: TestPage "Customer Card")
begin
CapturedCustomerNo := CustomerCard."No.".Value();
end;
[SendNotificationHandler(true)]
procedure CreditLimitNotificationHandler(var CreditLimitNotification: Notification): Boolean
begin
exit(true);
end;
var
Assert: Codeunit "Library Assert";
LibrarySales: Codeunit "Library - Sales";
LibraryVariableStorage: Codeunit "Library - Variable Storage";
CapturedCustomerNo: Code[20];
}