-
Robert Knight authored
Change the relationship between the `Guest` and `Sidebar` classes from one of inheritance to one where `Sidebar` receives a reference to the `Guest` instance and calls methods on it or subscribes to events from it. The `Guest` also no longer "owns" references to the bucket bar / toolbar objects that logically belong to the sidebar. Instead it emits events which the sidebar responds to. This change makes the interface of the `Guest` used by the `Sidebar` more explicit and ensures a better boundary between the two. This also makes it easier for the `Sidebar` tests to be concerned only with the interface of the `Guest` and not its implementation details. In future this change will also make it possible to have a frame which does not contain a sidebar but is not annotateable. We had a need for this historically when integrating with epub viewers, although it was never implemented. Updating the tests for `PdfSidebar` was complicated by the fact that the `PdfSidebar` tests are not pure unit tests. They instantiate the `Sidebar` base class and so depend on many implementation details of it. To make this change and others easier, the `PdfSidebar` tests have been changed to mock the `Sidebar` base class. The steps involved in this are non-obvious so I extracted the logic into a utility function. - Change `Sidebar` to no longer inherit `Guest` but accept it as a constructor argument - Remove direct references to the `BucketBar` and `ToolbarController` instances from the `Guest` class and instead emit events from the `Guest` which the `Sidebar` responds to. - Add a `mockBaseClass` testing helper in `src/test-util/mock-base.js` and change the `PdfSidebar` tests to use it, so that they are less coupled to `Sidebar` implementation details.
b52f00e0