OfficeDev / OfficeDev/Office-Addin-Scripts
Office Addin Mock does not support basic API usage of `.items` to get array of PowerPoint.Slide
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 194
- Forks
- 117
- Avg merge
- 1d 32m
- Merged PRs (30d)
- 2
Description
Prerequisites
Please answer the following questions before submitting an issue.
YOU MAY DELETE THE PREREQUISITES SECTION.
-
I checked to make sure that this issue has not already been filed
-
I checked the documentation and found no answer
Expected behavior
I should be able to access an array PowerPoint.Slide by accessing PowerPoint.SlideCollection.items field. This works just fine outside of the tests.
example:
context.presentation.load("slides/id")
await context.sync()
context.presentation.slides.items // an array of PowerPoint.Slide
Current behavior
The current behavior does not allow me to use the items field which is available in PowerPoint.SlideCollection, and all other collections. I see two issues:
itemsis not included in the props argument for thecontext.loadmethod in production. But it seems that the OfficeMock is executing the navigational properties to be explicitly available- It seems like OfficeMock does not handle the
itemsarray well (see bellow code) from what I could tell, any items in the array do not get turned into an officeMock object.
Steps to Reproduce
run this test
const mockData = {
context: {
presentation: {
slides: {
items: [{
id: "a1",
tags: { key: "mock", value: "mock" },
}]
}
},
},
run: async function (callback) {
await callback(this.context);
},
}
describe("unable to mock powerpoint object correctly", () => {
beforeAll(() => {
window.PowerPoint = new OfficeMockObject(mockData, "powerpoint");
})
test("unable to complete", async () => {
await window.PowerPoint.run(async (context) => {
context.presentation.load("slides/id") // ERROR: Property id needs to be present in object model before load is called
await context.sync()
expect(context.presentation.slides.items[0].key).toEqual("a1")
})
})
})
Please provide detailed steps for reproducing the issue.
- copy this code in .test.js file, I use vitest but jest should work just fine.
- run the test
- you will get the following error
Error: Property id needs to be present in object model before load is called
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- Operating System: macOS 14.0 (23A344)
- Node version: v20.16.0
- Office version: N/A
- Tool version: N/A
- Office-Addin-Mock version: 2.4.5
Failure Logs
Error: Property id needs to be present in object model before load is called.
❯ OfficeMockObject.loadScalar node_modules/office-addin-mock/src/officeMockObject.ts:144:13
❯ OfficeMockObject.loadNavigational node_modules/office-addin-mock/src/officeMockObject.ts:130:34
❯ node_modules/office-addin-mock/src/officeMockObject.ts:106:16
❯ OfficeMockObject.loadMultipleProperties node_modules/office-addin-mock/src/officeMockObject.ts:105:10
❯ node_modules/office-addin-mock/src/officeMockObject.ts:48:12
❯ OfficeMockObject.load node_modules/office-addin-mock/src/officeMockObject.ts:47:16
❯ callback src/power-point/tools/tests/slide-locator.unit.test.js:32:34
30|
31| await window.PowerPoint.run(async (context) => {
32| context.presentation.load("slides/id") // Property id need…
| ^
33| await context.sync()
34| expect(context.presentation.slides.items[0].key).toEqual("…
❯ OfficeMockObject.run src/power-point/tools/tests/slide-locator.unit.test.js:19:15
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproduction in src/power-point/tools/tests/slide-locator.unit.test.js and trace OfficeMockObject.load through loadMultipleProperties, loadNavigational, and loadScalar at the reported source locations. Done means the slides/id load succeeds and context.presentation.slides.items exposes the supplied entry as a usable mock object without the missing-id error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100