Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhauck committed Jan 9, 2025
1 parent 255007c commit 69f1a32
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/common/src/featureServiceHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export function cacheContingentValues(id: string, fieldInfos: any, itemTemplate:
* @returns An updated instance of the fieldInfos
*/
export function cacheIndexes(layer: any, fieldInfos: any): any {
/* istanbul ignore else */
if (Array.isArray(layer.indexes)) {
const oidField = layer.objectIdField;
const guidField = layer.globalIdField;
Expand Down
53 changes: 49 additions & 4 deletions packages/common/test/featureServiceHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

import {
cacheIndexes,
getFeatureServiceRelatedRecords,
templatize,
deleteViewProps,
Expand Down Expand Up @@ -556,15 +557,15 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
it("should not fail with undefined", () => {
let fieldInfos: any = {};
const layer: any = undefined;
fieldInfos = cacheFieldInfos(layer, fieldInfos, true);
fieldInfos = cacheFieldInfos(layer, fieldInfos, true, false);
expect(layer).toBeUndefined();
expect(fieldInfos).toEqual({});
});

it("should not fail without key properties on the layer", () => {
let fieldInfos: any = {};
const layer: any = {};
fieldInfos = cacheFieldInfos(layer, fieldInfos, false);
fieldInfos = cacheFieldInfos(layer, fieldInfos, false, false);
expect(layer).toEqual({});
expect(fieldInfos).toEqual({});
});
Expand Down Expand Up @@ -676,12 +677,56 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
},
};

fieldInfos = cacheFieldInfos(layer, fieldInfos, false);
fieldInfos = cacheFieldInfos(layer, fieldInfos, false, true);
expect(layer).toEqual(expectedLayer);
expect(fieldInfos).toEqual(expectedFieldInfos);
});
});

describe("cacheIndexes", () => {
it("should cache specific indexes and remove them from the layer", () => {
const layer = {
id: "0",
objectIdField: "objectid",
globalIdField: "globalid",
indexes: [
{
isUnique: true,
fields: "B",
indexType: "",
name: "B_Unique",
},
{
isUnique: true,
fields: "objectid",
indexType: "",
name: "C_objectid",
},
{
isUnique: false,
fields: "A",
indexType: "FullText",
name: "A _ FullText",
},
],
} as any;

const id = "0";
let fieldInfos: any = {};
fieldInfos[id] = {};
fieldInfos = cacheIndexes(layer, fieldInfos);

const expectedLayer = {
id: "0",
objectIdField: "objectid",
globalIdField: "globalid",
};
expect(layer).toEqual(expectedLayer);
expect(fieldInfos["0"].indexes.length).toEqual(2);
expect(fieldInfos["0"].indexes[1].name).toEqual("A_FullText");
});
});

describe("cacheContingentValues", () => {
it("should get contingent values from feature service properties", () => {
const id = "0";
Expand Down Expand Up @@ -3607,7 +3652,7 @@ describe("Module `featureServiceHelpers`: utility functions for feature-service
const layer1 = mockItems.getAGOLLayerOrTable(1, "ROW Permit Comment", "Table", [
mockItems.createAGOLRelationship(0, 1, "esriRelRoleDestination"),
]);
const fieldInfos = cacheFieldInfos(layer1, cacheFieldInfos(layer0, {}, false), false);
const fieldInfos = cacheFieldInfos(layer1, cacheFieldInfos(layer0, {}, false, false), false, false);

Object.keys(fieldInfos).forEach((k) => {
fieldInfos[k].sourceFields[1].visible = false;
Expand Down
19 changes: 18 additions & 1 deletion packages/common/test/restHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,13 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
subtypeField: "SubtypeField",
defaultSubtypeCode: "0",
subtypes: [{ a: "A" }],
indexes: [{ name: "index" }],
},
1: {
b: "b",
type: "B",
id: 1,
indexes: [{ name: "index2" }],
},
};

Expand All @@ -1940,7 +1947,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
authentication: MOCK_USER_SESSION,
};

const updates: any[] = restHelpers.getLayerUpdates(args, false);
const updates: any[] = restHelpers.getLayerUpdates(args, true);

const _object: any = Object.assign({}, objects[0]);
delete _object.type;
Expand Down Expand Up @@ -1995,6 +2002,7 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
params: {
addToDefinition: {
subtypes: [{ a: "A" }],
indexes: [{ name: "index" }]
},
},
args,
Expand Down Expand Up @@ -2029,6 +2037,15 @@ describe("Module `restHelpers`: common REST utility functions shared across pack
},
args,
},
{
url: adminUrl + "1/addToDefinition",
params: {
addToDefinition: {
indexes: [{ name: "index2" }]
},
},
args,
},
];
expect(updates).toEqual(expected);
});
Expand Down

0 comments on commit 69f1a32

Please sign in to comment.