-
Notifications
You must be signed in to change notification settings - Fork 15
Tutorial 4
PhuocLe edited this page Aug 26, 2018
·
12 revisions
- Create Javascript Unit Test WebResource
- Finish Tutorial 1: Plugin
- Finish Tutorial 2: Unit Test Plugin
- Finish Tutorial 3: WebResource
- Add
New Item
09. JavaScript Test
totest
folder ofPaz.LuckeyMonkey.WebResource
project- A popup form
Add new Js Test Class
opened - Click button
><
to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKit
loaded all entities and bind to dropdownEntity
- Select
Lead
in theEntity
- Click
OK
- A popup form
-
PL.DynamicsCrm.DevKit
createdLead.test.js
file under foldertest
- Rebuild solution to restore
NuGet
packages - Make sure you have
node_modules
in the projectPaz.LuckeyMonkey.WebResource
, ifNOT
you should runnpm install
in theCommand Windows Promt
of the project folderPaz.LuckeyMonkey.WebResource
- Back to the
Lead.js
file and edit the return value of variableformLead
like bellow
return {
OnLoad: onLoad,
OnSave: onSave,
__SubjectAddOnChange__: SubjectAddOnChange,
__PhoneAddOnChange__: PhoneAddOnChange
};
- Edit the
Lead.test.js
///<reference path="../entities/Lead.intellisense.js" />
///<reference path="mock.intellisense.js" />
define(['xrm-mock', 'sinon'], function (xrm_mock, sinon) {
var mock = new DevKitXrmMock(xrm_mock, "lead");
var server = new DevKitServerMock(sinon);
describe('Lead.js Test', function () {
it("OnLoad - FormCreate", function () {
//setup
mock.FormType = OptionSet.FormType.Create;
mock.Field("subject", "hello");
mock.Field("telephone1", "123");
mock.Field("mobilephone", "456");
//execute
formLead.OnLoad();
formLead.__SubjectAddOnChange__();
formLead.__PhoneAddOnChange__();
//result
var form = new LuckeyMonkey.FormLead();
expect(form.Body.Subject.Disabled).toBe(false);
expect(form.Body.Subject.Value).toBe("HELLO");
expect(form.Body.Telephone1.RequiredLevel).toBe(OptionSet.FieldRequiredLevel.Required);
expect(form.Body.MobilePhone.RequiredLevel).toBe(OptionSet.FieldRequiredLevel.Required);
//setup again
form.Body.Telephone1.Value = null;
form.Body.MobilePhone.Value = null;
//run again
formLead.__PhoneAddOnChange__();
//result again
expect(form.Body.Telephone1.RequiredLevel).toBe(OptionSet.FieldRequiredLevel.None);
expect(form.Body.MobilePhone.RequiredLevel).toBe(OptionSet.FieldRequiredLevel.None);
});
it("OnLoad - FormEdit", function () {
//setup
mock.Field("subject", "hello");
mock.FormType = OptionSet.FormType.Update;
//execute
formLead.OnLoad();
//result
var form = new LuckeyMonkey.FormLead();
expect(form.Body.Subject.Disabled).toBe(true);
});
});
});
- Please
DON'T
copy/paste code. Trytyping
to getintellisense
thatPL.DynamicsCrm.DevKit
support - Right-click on code window
Lead.test.js
and selectRun JS Tests
menu of theChutzpah Extensions
and you get the result below
------ Test started: File: C:\src\github\Dynamics-Crm-DevKit\tutorials\Paz.LuckeyMonkey.WebResource\test\Lead.test.js ------
2 passed, 0 failed, 2 total (chutzpah).
========== Total Tests: 2 passed, 0 failed, 2 total ==========
- You can run view the
code coverage
by select menuRun Chutzpah With
>Coverage
- Check-in all files to your source control
- You finished this tutorial
This tutorial, you know howto