@internetarchive/ia-item-navigator 0.0.0-a12 → 0.0.0-a13

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,9 @@ import { html, fixture, expect } from '@open-wc/testing';
3
3
  import Sinon from 'sinon';
4
4
 
5
5
  import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
6
- import { IntNavController } from '../src/interfaces/nav-controller-interface';
7
- import { ItemNavigator } from '../src/item-navigator';
6
+ import { ModalManager } from '@internetarchive/modal-manager';
7
+ import { BookNavigator } from '../src/interfaces/nav-controller-interface';
8
+ import { ItemNavigator, ItemType } from '../src/item-navigator';
8
9
  import '../src/item-navigator';
9
10
 
10
11
  import '../test/book-nav-stub';
@@ -27,8 +28,10 @@ describe('ItemNavigator', () => {
27
28
  it('shows <book-navigator> if `this.itemType = "bookreader"`', async () => {
28
29
  const el = await fixture<ItemNavigator>(
29
30
  html`<ia-item-navigator
30
- .itemType=${`bookreader`}
31
+ .itemType=${ItemType.BOOK}
31
32
  .item=${new ItemStub()}
33
+ .modal=${new ModalManager()}
34
+ .sharedObserver=${new SharedResizeObserver()}
32
35
  ></ia-item-navigator>`
33
36
  );
34
37
 
@@ -39,7 +42,7 @@ describe('ItemNavigator', () => {
39
42
 
40
43
  const bookNavigator = el.shadowRoot?.querySelector(
41
44
  'book-navigator'
42
- ) as IntNavController;
45
+ ) as BookNavigator;
43
46
  await bookNavigator.updateComplete;
44
47
 
45
48
  console.log('132234234324324324');
@@ -91,10 +94,10 @@ describe('ItemNavigator', () => {
91
94
  await el.updateComplete;
92
95
  const spy = Sinon.spy();
93
96
  el.loadingStateUpdated = spy;
94
- el.loaded = false;
97
+ el.loaded = null;
95
98
  await el.updateComplete;
96
99
  // check base properties
97
- expect(el.loaded).to.equal(false);
100
+ expect(el.loaded).to.equal(null);
98
101
  expect(el.item).to.be.undefined;
99
102
 
100
103
  // hydrate item
@@ -108,50 +111,58 @@ describe('ItemNavigator', () => {
108
111
  });
109
112
 
110
113
  describe('`el.sharedObserver`', () => {
111
- it('can create one', async () => {
114
+ it('uses one', async () => {
115
+ const sharedObserver = new SharedResizeObserver();
112
116
  const el = await fixture<ItemNavigator>(
113
- html`<ia-item-navigator></ia-item-navigator>`
117
+ html`<ia-item-navigator
118
+ .sharedObserver=${sharedObserver}
119
+ ></ia-item-navigator>`
114
120
  );
115
- await el.updateComplete;
116
- expect(el.sharedObserver).to.not.be.null;
117
- expect(el.sharedObserver).to.be.instanceOf(SharedResizeObserver);
118
- });
119
121
 
120
- it('can recieve one', async () => {
122
+ expect(el.sharedObserver).to.equal(sharedObserver);
123
+ });
124
+ it('freshly registers handler', async () => {
121
125
  const sharedObserver = new SharedResizeObserver();
126
+ const addObserverSpy = Sinon.spy(sharedObserver, 'addObserver');
127
+ const removeObserverSpy = Sinon.spy(sharedObserver, 'removeObserver');
122
128
 
123
- const el = await fixture<ItemNavigator>(
129
+ await fixture<ItemNavigator>(
124
130
  html`<ia-item-navigator
125
131
  .sharedObserver=${sharedObserver}
126
132
  ></ia-item-navigator>`
127
133
  );
128
- await el.updateComplete;
129
- expect(el.sharedObserver).to.be.instanceOf(SharedResizeObserver);
130
- });
131
- });
132
134
 
133
- describe('`el.modal`', () => {
134
- it('can create one', async () => {
135
- const el = await fixture<ItemNavigator>(
136
- html`<ia-item-navigator></ia-item-navigator>`
137
- );
138
- await el.updateComplete;
139
- expect(el.sharedObserver).to.not.be.null;
140
- expect(el.sharedObserver).to.be.instanceOf(SharedResizeObserver);
135
+ // always calls to remove first, for posterity
136
+ expect(removeObserverSpy.callCount).to.equal(1);
137
+ expect(addObserverSpy.callCount).to.equal(1);
141
138
  });
142
-
143
- it('can recieve one', async () => {
139
+ it('removes handler when component disconnects', async () => {
144
140
  const sharedObserver = new SharedResizeObserver();
145
- const observerSpy = Sinon.stub(sharedObserver, 'addObserver');
141
+ const removeObserverSpy = Sinon.spy(sharedObserver, 'removeObserver');
146
142
 
147
143
  const el = await fixture<ItemNavigator>(
148
144
  html`<ia-item-navigator
149
145
  .sharedObserver=${sharedObserver}
150
146
  ></ia-item-navigator>`
151
147
  );
148
+
149
+ // called during setup `setResizeObserver`
150
+ expect(removeObserverSpy.callCount).to.equal(1);
151
+
152
+ el.disconnectedCallback();
152
153
  await el.updateComplete;
153
- expect(el.sharedObserver).to.be.instanceOf(SharedResizeObserver);
154
- expect(observerSpy.called).to.equal(true);
154
+
155
+ expect(removeObserverSpy.callCount).to.equal(2);
156
+ });
157
+ });
158
+
159
+ describe('`el.modal`', () => {
160
+ it('uses one', async () => {
161
+ const modal = new ModalManager();
162
+ const el = await fixture<ItemNavigator>(
163
+ html`<ia-item-navigator .modal=${modal}></ia-item-navigator>`
164
+ );
165
+ expect(el.modal).to.equal(modal);
155
166
  });
156
167
  });
157
168