Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13165 from aholstrup/Addressbook
Address Book for BC
- Loading branch information
Showing
12 changed files
with
881 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"id": "ecf211a8-de81-49dc-b8a7-399405d70665", | ||
"name": "Address Book Test", | ||
"publisher": "Microsoft", | ||
"brief": "Tests for the Address Book module", | ||
"description": "Tests for the Address Book module", | ||
"version": "19.0.0.0", | ||
"privacyStatement": "https://go.microsoft.com/fwlink/?linkid=724009", | ||
"EULA": "https://go.microsoft.com/fwlink/?linkid=2009120", | ||
"help": "https://go.microsoft.com/fwlink/?linkid=2103698", | ||
"url": "https://go.microsoft.com/fwlink/?linkid=724011", | ||
"logo": "", | ||
"dependencies": [ | ||
{ | ||
"id": "9c4a2cf2-be3a-4aa3-833b-99a5ffd11f25", | ||
"name": "Email", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "949b9041-d2cb-4e69-bf31-c1e8fcb9462b", | ||
"name": "Email Test Library", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "47397d83-32ba-4ef0-8988-ef72539bfe36", | ||
"name": "Client Type Management Test Library", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "5095f467-0a01-4b99-99d1-9ff1237d286f", | ||
"name": "Library Variable Storage", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "e31ad830-3d46-472e-afeb-1d3d35247943", | ||
"name": "BLOB Storage", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "0846d207-5dec-4c1b-afd8-6a25e1e14b9d", | ||
"name": "Base64 Convert", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "dd0be2ea-f733-4d65-bb34-a28f4624fb14", | ||
"name": "Library Assert", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "e7320ebb-08b3-4406-b1ec-b4927d3e280b", | ||
"name": "Any", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
}, | ||
{ | ||
"id": "40860557-a18d-42ad-aecb-22b7dd80dc80", | ||
"name": "Permissions Mock", | ||
"publisher": "Microsoft", | ||
"version": "19.0.0.0" | ||
} | ||
], | ||
"screenshots": [ | ||
|
||
], | ||
"platform": "18.0.0.0", | ||
"idRanges": [ | ||
{ | ||
"from": 134698, | ||
"to": 134700 | ||
} | ||
], | ||
"contextSensitiveHelpUrl": "https://go.microsoft.com/fwlink/?linkid=2134520", | ||
"target": "OnPrem" | ||
} |
242 changes: 242 additions & 0 deletions
242
Modules/System Tests/Address Book/src/AddressBookTests.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
codeunit 134699 "Address Book Tests" | ||
{ | ||
SubType = Test; | ||
Permissions = tabledata "Email Outbox" = rd, | ||
tabledata "Sent Email" = rd, | ||
tabledata Address = rimd; | ||
EventSubscriberInstance = Manual; | ||
|
||
var | ||
Assert: Codeunit "Library Assert"; | ||
PermissionsMock: Codeunit "Permissions Mock"; | ||
|
||
|
||
[Test] | ||
[HandlerFunctions('EmailRecipientLookupHandler')] | ||
procedure AddressBookTest() | ||
var | ||
TempAccount: Record "Email Account"; | ||
SentEmail: Record "Sent Email"; | ||
//Outbox: Record "Email Outbox"; | ||
ConnectorMock: Codeunit "Connector Mock"; | ||
Message: Codeunit "Email Message"; | ||
Email: Codeunit Email; | ||
EmailAccConnMock: Codeunit "Email Accounts Selection Mock"; | ||
AddressBookMock: Codeunit "Address Book Mock"; | ||
EditorPage: TestPage "Email Editor"; | ||
Recipients: List of [Text]; | ||
Recipient1, Recipient2 : Text; | ||
begin | ||
// [SCENARIO] Adding an extra ToRecipient and adding a CcRecipient with the addressbook | ||
|
||
// [GIVEN] A connector is installed and an account is added | ||
//Outbox.DeleteAll(); | ||
//SentEmail.DeleteAll(); | ||
ConnectorMock.Initialize(); | ||
ConnectorMock.AddAccount(TempAccount); | ||
BindSubscription(EmailAccConnMock); | ||
BindSubscription(AddressBookMock); | ||
PermissionsMock.Set('Email Edit'); | ||
|
||
// [GIVEN] An email message with a recipient, subject, body and related record | ||
Message.Create('test@test.com', 'Subject', 'Body'); | ||
Email.AddRelation(Message, 0, CreateGuid(), Enum::"Email Relation Type"::"Primary Source"); | ||
|
||
// [WHEN] Opening the email message in the email editor and performing a Lookup on ToRecipient field | ||
EditorPage.Trap(); | ||
Email.OpenInEditor(Message, TempAccount); | ||
|
||
EditorPage.ToField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an extra email address is added | ||
Assert.AreEqual('test@test.com;johndoe@test.com;', EditorPage.ToField.Value(), 'Email addresses in To field does not match'); | ||
|
||
// [WHEN] Performing a lookup on CcRecipient Field | ||
EditorPage.CcField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an email address is added to Ccfield | ||
Assert.AreEqual('johndoe@test.com;', EditorPage.CcField.Value(), 'Email address in CC field does not match'); | ||
|
||
// [WHEN] Performing a lookup on BccRecipient Field | ||
EditorPage.BccField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an email address is added to Bccfield | ||
Assert.AreEqual('johndoe@test.com;', EditorPage.BccField.Value(), 'Email address in Bcc field does not match'); | ||
|
||
//EditorPage.ToField.SetValue('recipient@test.com'); | ||
EditorPage.SubjectField.SetValue('Test Subject'); | ||
EditorPage.BodyField.SetValue('Test body'); | ||
|
||
// [WHEN] The send action is invoked, no error appears and the email is sent | ||
EditorPage.Send.Invoke(); | ||
|
||
// [THEN] Verify the data | ||
Message.Get(ConnectorMock.GetEmailMessageID()); | ||
SentEmail.SetRange("Message Id", Message.GetId()); | ||
Assert.IsTrue(SentEmail.FindFirst(), 'A Sent Email record should have been inserted.'); | ||
Assert.AreEqual('Test Subject', SentEmail.Description, 'The email subject should be "Subject"'); | ||
Assert.AreEqual(TempAccount."Account Id", SentEmail."Account Id", 'A different account was expected'); | ||
Assert.AreEqual(TempAccount."Email Address", SentEmail."Sent From", 'A different sent from was expected'); | ||
Assert.AreEqual(Enum::"Email Connector"::"Test Email Connector", SentEmail.Connector, 'A different connector was expected'); | ||
|
||
Message.GetRecipients(Enum::"Email Recipient Type"::"To", Recipients); | ||
Assert.AreEqual(2, Recipients.Count(), ''); | ||
|
||
Recipients.Get(1, Recipient1); | ||
Recipients.Get(2, Recipient2); | ||
Assert.AreEqual('johndoe@test.com', Recipient1, ''); | ||
Assert.AreEqual('test@test.com', Recipient2, ''); | ||
|
||
Message.GetRecipients(Enum::"Email Recipient Type"::"Cc", Recipients); | ||
Assert.AreEqual(1, Recipients.Count(), ''); | ||
|
||
Recipients.Get(1, Recipient1); | ||
Assert.AreEqual('johndoe@test.com', Recipient1, ''); | ||
|
||
Message.GetRecipients(Enum::"Email Recipient Type"::"Bcc", Recipients); | ||
Assert.AreEqual(1, Recipients.Count(), ''); | ||
|
||
Recipients.Get(1, Recipient1); | ||
Assert.AreEqual('johndoe@test.com', Recipient1, ''); | ||
end; | ||
|
||
[Test] | ||
[HandlerFunctions('EmailRecipientLookupCancelHandler')] | ||
procedure AddressBookCancelTest() | ||
var | ||
TempAccount: Record "Email Account"; | ||
ConnectorMock: Codeunit "Connector Mock"; | ||
Message: Codeunit "Email Message"; | ||
Email: Codeunit Email; | ||
EmailAccConnMock: Codeunit "Email Accounts Selection Mock"; | ||
AddressBookMock: Codeunit "Address Book Mock"; | ||
EditorPage: TestPage "Email Editor"; | ||
begin | ||
// [SCENARIO] Adding an extra ToRecipient and adding a CcRecipient with the addressbook | ||
|
||
// [GIVEN] A connector is installed and an account is added | ||
//Outbox.DeleteAll(); | ||
//SentEmail.DeleteAll(); | ||
ConnectorMock.Initialize(); | ||
ConnectorMock.AddAccount(TempAccount); | ||
BindSubscription(EmailAccConnMock); | ||
BindSubscription(AddressBookMock); | ||
PermissionsMock.Set('Email Edit'); | ||
|
||
// [GIVEN] An email message with a recipient, subject, body and related record | ||
Message.Create('test@test.com', 'Subject', 'Body'); | ||
Email.AddRelation(Message, 0, CreateGuid(), Enum::"Email Relation Type"::"Primary Source"); | ||
|
||
// [WHEN] Opening the email message in the email editor and performing a Lookup on ToRecipient field | ||
EditorPage.Trap(); | ||
Email.OpenInEditor(Message, TempAccount); | ||
|
||
EditorPage.ToField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an extra email address is added | ||
Assert.AreEqual('test@test.com', EditorPage.ToField.Value(), 'Email addresses in To field does not match'); | ||
|
||
// [WHEN] Performing a lookup on CcRecipient Field | ||
EditorPage.CcField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an email address is added to Ccfield | ||
Assert.AreEqual('', EditorPage.CcField.Value(), 'Email address in CC field does not match'); | ||
end; | ||
|
||
[Test] | ||
[HandlerFunctions('EmailRecipientLookupEntitiesHandler,SaveAsDraftOnCloseHandler,EmailEntitiesHandler')] | ||
procedure AddressBookLookupFromEntitiesTest() | ||
var | ||
TempAccount: Record "Email Account"; | ||
ConnectorMock: Codeunit "Connector Mock"; | ||
Message: Codeunit "Email Message"; | ||
Email: Codeunit Email; | ||
EmailAccConnMock: Codeunit "Email Accounts Selection Mock"; | ||
AddressBookMock: Codeunit "Address Book Mock"; | ||
EditorPage: TestPage "Email Editor"; | ||
begin | ||
// [SCENARIO] Adding an extra ToRecipient and adding a CcRecipient with the addressbook | ||
|
||
// [GIVEN] A connector is installed and an account is added | ||
//Outbox.DeleteAll(); | ||
//SentEmail.DeleteAll(); | ||
ConnectorMock.Initialize(); | ||
ConnectorMock.AddAccount(TempAccount); | ||
BindSubscription(EmailAccConnMock); | ||
BindSubscription(AddressBookMock); | ||
PermissionsMock.Set('Email Edit'); | ||
|
||
// [GIVEN] An email message with a recipient, subject, body and related record | ||
Message.Create('test@test.com', 'Subject', 'Body'); | ||
Email.AddRelation(Message, 0, CreateGuid(), Enum::"Email Relation Type"::"Primary Source"); | ||
|
||
// [WHEN] Opening the email message in the email editor and performing a Lookup on ToRecipient field | ||
EditorPage.Trap(); | ||
Email.OpenInEditor(Message, TempAccount); | ||
|
||
EditorPage.ToField.Lookup(); | ||
|
||
// After the Lookup Modal is handled by EmailRecipientLookupHandler, an extra email address is added | ||
Assert.AreEqual('test@test.com', EditorPage.ToField.Value(), 'Email addresses in To field does not match'); | ||
|
||
//EditorPage.ToField.SetValue('recipient@test.com'); | ||
EditorPage.SubjectField.SetValue('Test Subject'); | ||
EditorPage.BodyField.SetValue('Test body'); | ||
end; | ||
|
||
|
||
[ModalPageHandler] | ||
[Scope('OnPrem')] | ||
procedure EmailRecipientLookupHandler(var EmailAddress: TestPage "Email Address") | ||
begin | ||
EmailAddress.First(); | ||
Assert.AreEqual('johndoe@test.com', EmailAddress."Email Address".Value(), 'Email address in addressbook does not match'); | ||
Assert.AreEqual('John Doe', EmailAddress.Name.Value(), 'Name in addressbook does not match'); | ||
Assert.AreEqual('Cronos', EmailAddress.Company.Value(), 'Company in addressbook does not match'); | ||
Assert.AreEqual('Customer', EmailAddress.Source.Value(), 'Customer name in addressbook does not match'); | ||
EmailAddress.OK().Invoke(); | ||
end; | ||
|
||
[ModalPageHandler] | ||
[Scope('OnPrem')] | ||
procedure EmailRecipientLookupCancelHandler(var EmailAddress: TestPage "Email Address") | ||
begin | ||
EmailAddress.Cancel().Invoke(); | ||
end; | ||
|
||
[ModalPageHandler] | ||
[Scope('OnPrem')] | ||
procedure EmailRecipientLookupEntitiesHandler(var EmailAddress: TestPage "Email Address") | ||
begin | ||
EmailAddress.ManualLookup.Invoke(); | ||
end; | ||
|
||
[ModalPageHandler] | ||
[Scope('OnPrem')] | ||
procedure EmailAccountLookUpHandler(var EmailAccounts: TestPage "Email Accounts") | ||
begin | ||
EmailAccounts.First(); | ||
EmailAccounts.OK().Invoke(); | ||
end; | ||
|
||
[ModalPageHandler] | ||
[Scope('OnPrem')] | ||
procedure EmailEntitiesHandler(var EmailAddressEntity: TestPage "Email Address Entity") | ||
begin | ||
EmailAddressEntity.First(); | ||
Assert.AreEqual('Contact', EmailAddressEntity."Type".Value(), ''); | ||
EmailAddressEntity.OK().Invoke(); | ||
end; | ||
|
||
[StrMenuHandler] | ||
[Scope('OnPrem')] | ||
procedure SaveAsDraftOnCloseHandler(Options: Text[1024]; var Choice: Integer; Instruction: Text[1024]) | ||
begin | ||
Choice := 1; | ||
end; | ||
} |
35 changes: 35 additions & 0 deletions
35
Modules/System Tests/Address Book/src/Mocks/AddressBookMock.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
/// <summary> | ||
/// Used to mock email address entities. | ||
/// </summary> | ||
codeunit 134698 "Address Book Mock" | ||
{ | ||
Access = Internal; | ||
EventSubscriberInstance = Manual; | ||
|
||
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Address Book", 'OnGetSuggestedAddresses', '', true, true)] | ||
local procedure GetSuggestedAddresses(SourceTableNo: Integer; SourceSystemID: Guid; var Address: Record Address) | ||
begin | ||
Address.Init(); | ||
Address.Name := 'John Doe'; | ||
Address."E-Mail Address" := 'johndoe@test.com'; | ||
Address.Company := 'Cronos'; | ||
Address."Source Name" := 'Customer'; | ||
Address.SourceTable := 0; | ||
Address.Insert(); | ||
end; | ||
|
||
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Address Book", 'OnGetEmailAddressEntity', '', true, true)] | ||
local procedure GetEmailAddressEntity(var AddressEntity: Record "Address Entity") | ||
begin | ||
AddressEntity.Init(); | ||
AddressEntity."Source Name" := 'Contact'; | ||
AddressEntity.SourceTable := 42; | ||
AddressEntity.Insert(); | ||
end; | ||
|
||
} |
Oops, something went wrong.