Skip to content

Commit 6f4adac

Browse files
test(elements): migrate pos-list.integration to observeLabel mock
1 parent 0d68a70 commit 6f4adac

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

elements/src/components/pos-list/pos-list.integration.spec.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PosLabel } from '../pos-label/pos-label';
55
import { PosList } from './pos-list';
66
import { PosResource } from '../pos-resource/pos-resource';
77
import { when } from 'jest-when';
8-
import { Subject } from 'rxjs';
8+
import { ReplaySubject, Subject } from 'rxjs';
99
import { Relation, Thing } from '@pod-os/core';
1010

1111
describe('pos-list', () => {
@@ -21,12 +21,16 @@ describe('pos-list', () => {
2121
} as unknown as Relation,
2222
],
2323
} as unknown as Thing);
24+
const observedLabel1$ = new ReplaySubject<string>();
25+
observedLabel1$.next('Video 1');
2426
when(os.store.get)
2527
.calledWith('https://video.test/video-1')
26-
.mockReturnValue({ uri: 'https://video.test/video-1', label: () => 'Video 1' } as unknown as Thing);
28+
.mockReturnValue({ uri: 'https://video.test/video-1', observeLabel: () => observedLabel1$ } as unknown as Thing);
29+
const observedLabel2$ = new ReplaySubject<string>();
30+
observedLabel2$.next('Video 2');
2731
when(os.store.get)
2832
.calledWith('https://video.test/video-2')
29-
.mockReturnValue({ uri: 'https://video.test/video-2', label: () => 'Video 2' } as unknown as Thing);
33+
.mockReturnValue({ uri: 'https://video.test/video-2', observeLabel: () => observedLabel2$ } as unknown as Thing);
3034
const page = await newSpecPage({
3135
components: [PosApp, PosLabel, PosList, PosResource],
3236
supportsShadowDom: false,
@@ -70,15 +74,18 @@ describe('pos-list', () => {
7074

7175
it('children render label for all things of the given type, reactively', async () => {
7276
const os = mockPodOS();
73-
const observed$ = new Subject<string[]>();
74-
when(os.store.observeFindMembers).calledWith('http://schema.org/Video').mockReturnValue(observed$);
77+
const observedMembers$ = new Subject<string[]>();
78+
when(os.store.observeFindMembers).calledWith('http://schema.org/Video').mockReturnValue(observedMembers$);
79+
const observedLabel1$ = new ReplaySubject<string>();
80+
observedLabel1$.next('Video 1');
7581
when(os.store.get)
7682
.calledWith('https://video.test/video-1')
77-
.mockReturnValue({ uri: 'https://video.test/video-1', label: () => 'Video 1' } as unknown as Thing);
83+
.mockReturnValue({ uri: 'https://video.test/video-1', observeLabel: () => observedLabel1$ } as unknown as Thing);
84+
const observedLabel2$ = new ReplaySubject<string>();
85+
observedLabel2$.next('Video 2');
7886
when(os.store.get)
7987
.calledWith('https://video.test/video-2')
80-
.mockReturnValue({ uri: 'https://video.test/video-2', label: () => 'Video 2' } as unknown as Thing);
81-
88+
.mockReturnValue({ uri: 'https://video.test/video-2', observeLabel: () => observedLabel2$ } as unknown as Thing);
8289
const page = await newSpecPage({
8390
components: [PosApp, PosLabel, PosList, PosResource],
8491
supportsShadowDom: false,
@@ -95,14 +102,14 @@ describe('pos-list', () => {
95102
let resources = page.root ? page.root.querySelectorAll('pos-list pos-resource') : [];
96103
expect(resources).toHaveLength(0);
97104

98-
observed$.next(['https://video.test/video-1']);
105+
observedMembers$.next(['https://video.test/video-1']);
99106
await page.waitForChanges();
100107
resources = page.root ? page.root.querySelectorAll('pos-list pos-resource') : [];
101108
expect(resources).toHaveLength(1);
102109
expect(resources[0].getAttribute('about')).toEqual('https://video.test/video-1');
103110
expect(resources[0].textContent).toEqual('Video 1');
104111

105-
observed$.next(['https://video.test/video-1', 'https://video.test/video-2']);
112+
observedMembers$.next(['https://video.test/video-1', 'https://video.test/video-2']);
106113
await page.waitForChanges();
107114
resources = page.root ? page.root.querySelectorAll('pos-list pos-resource') : [];
108115
expect(resources).toHaveLength(2);
@@ -111,7 +118,7 @@ describe('pos-list', () => {
111118
expect(resources[1].getAttribute('about')).toEqual('https://video.test/video-2');
112119
expect(resources[1].textContent).toEqual('Video 2');
113120

114-
observed$.next(['https://video.test/video-2']);
121+
observedMembers$.next(['https://video.test/video-2']);
115122
await page.waitForChanges();
116123
resources = page.root ? page.root.querySelectorAll('pos-list pos-resource') : [];
117124
expect(resources).toHaveLength(1);

0 commit comments

Comments
 (0)