Skip to content

Commit

Permalink
Merge pull request #40 from camelCaseDave/assume-entity
Browse files Browse the repository at this point in the history
updates doc to match opinionated entity name
  • Loading branch information
camelCaseDave committed Jul 17, 2019
2 parents 6197736 + 5ff8f02 commit d18f607
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Import `XrmMockGenerator` in your unit test file
Initialise a global `Xrm` object

```typescript
XrmMockGenerator.initialise("contact");
XrmMockGenerator.initialise();
```

Customise your form by [adding attributes](https://github.com/camelCaseDave/xrm-mock/wiki/Adding-Attributes)
Expand Down Expand Up @@ -64,7 +64,7 @@ import { XrmMockGenerator } from "xrm-mock";

describe("Contact", () => {
beforeEach(() => {
XrmMockGenerator.initialise("contact");
XrmMockGenerator.initialise();
XrmMockGenerator.Attribute.createString("firstname", "Joe");
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xrm-mock",
"description": "A fake implementation of the Xrm object model. Used for testing Dynamics 365 client-side scripts.",
"version": "3.4.12",
"version": "3.4.13",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"directories": {
Expand Down
44 changes: 22 additions & 22 deletions test/xrm-mock-generator/attribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("XrmMockGenerator.Attribute", () => {

it("should create a string control with Label", () => {
XrmMockGenerator.Control.createString(StringAttributeMock.create("firstname"), "firstname", true, false,
"First Name");
"First Name");
expect(Xrm.Page.getControl("firstname").getLabel()).toBe("First Name");
});

Expand Down Expand Up @@ -74,18 +74,18 @@ describe("XrmMockGenerator.Attribute", () => {
// This is the Sample Code that is displayed on the wiki:
// https://github.com/camelCaseDave/xrm-mock/wiki/Adding-Attributes
const stringAttribute = XrmMockGenerator.Attribute.createString("firstname", "Joe");
const boolAttribute = XrmMockGenerator.Attribute.createBoolean("isapproved", true);
const dateAttribute = XrmMockGenerator.Attribute.createDate("birthdate", new Date(1980, 12, 25));
const boolAttribute = XrmMockGenerator.Attribute.createBoolean("isapproved", true);
const dateAttribute = XrmMockGenerator.Attribute.createDate("birthdate", new Date(1980, 12, 25));
const numberAttribute = XrmMockGenerator.Attribute.createNumber("units", 2);
const lookupAttribute = XrmMockGenerator.Attribute.createLookup("primarycustomerid", {
entityType: "contact",
id: "{00000000-0000-0000-0000-000000000001}",
name: "Joe Bloggs",
});
const optionSetAttribute = XrmMockGenerator.Attribute.createOptionSet("countries", 0, [
{ text: "Austria", value: 0 },
{ text: "France", value: 1 },
{ text: "Spain", value: 2 },
{ text: "Austria", value: 0 },
{ text: "France", value: 1 },
{ text: "Spain", value: 2 },
]);

expect(page.getAttribute("firstname").getValue()).toBe("Joe");
Expand All @@ -102,12 +102,12 @@ describe("XrmMockGenerator.Attribute", () => {
const stringAttribute = XrmMockGenerator.Attribute.createNumber({
name: "number",
},
// This can be a single instance of control components, or an array of control components as it is here
[{
label: "Number 1",
}, {
label: "Number 2",
}]);
// This can be a single instance of control components, or an array of control components as it is here
[{
label: "Number 1",
}, {
label: "Number 2",
}]);
const controls = page.getAttribute("number").controls;
expect(controls.getLength()).toBe(2);
expect(controls.get("number")).toBeTruthy();
Expand All @@ -128,16 +128,16 @@ describe("XrmMockGenerator.Attribute", () => {
submitMode: "always", // Applies to all standard attributes
value: "test@test.com", // Applies to all standard attributes, but type is attribute specific
},
// This can be a single instance of control components, or an array of control components as it is here
[{
disabled: true,
label: "Email",
name: "emailaddress1",
visible: false,
}, {
label: "Notification Email",
name: "header_emailaddress1",
}]);
// This can be a single instance of control components, or an array of control components as it is here
[{
disabled: true,
label: "Email",
name: "emailaddress1",
visible: false,
}, {
label: "Notification Email",
name: "header_emailaddress1",
}]);

expect(page.getAttribute("emailaddress1").getValue()).toBe("test@test.com");
expect(page.getControl("emailaddress1").getVisible()).toBe(false);
Expand Down
20 changes: 20 additions & 0 deletions test/xrm-mock-generator/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,24 @@ describe("XrmMockGenerator", () => {

expect(expected).toBe(XrmMockGenerator.formContext);
});

it("should default entity name to contact", () => {
XrmMockGenerator.initialise();

const expected = Xrm.Page.data.entity.getEntityName();

expect(expected).toBe("contact");
});

it("should initialise given an entity name", () => {
XrmMockGenerator.initialise({
entity: {
entityName: "account",
},
});

const expected = Xrm.Page.data.entity.getEntityName();

expect(expected).toBe("account");
});
});

0 comments on commit d18f607

Please sign in to comment.