Skip to content

Commit e85a6f2

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

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import { PosApp } from '../pos-app/pos-app';
55
import { PosResource } from './pos-resource';
66
import { PosLabel } from '../pos-label/pos-label';
77
import { when } from 'jest-when';
8+
import { ReplaySubject } from 'rxjs';
89

910
describe('pos-resource with a pos-label child', () => {
1011
it('renders label for successfully loaded resource', async () => {
1112
const os = mockPodOS();
1213
when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());
14+
const observedLabel$ = new ReplaySubject<string>();
15+
observedLabel$.next('Test Resource');
1316
when(os.store.get)
1417
.calledWith('https://resource.test')
1518
.mockReturnValue({
16-
label: () => 'Test Resource',
19+
observeLabel: () => observedLabel$,
1720
});
1821
const page = await newSpecPage({
1922
components: [PosApp, PosResource, PosLabel],
@@ -46,10 +49,12 @@ describe('pos-resource with a pos-label child', () => {
4649
const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));
4750
const os = mockPodOS();
4851
when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);
52+
const observedLabel$ = new ReplaySubject<string>();
53+
observedLabel$.next('Test Resource');
4954
when(os.store.get)
5055
.calledWith('https://resource.test')
5156
.mockReturnValue({
52-
label: () => 'Test Resource',
57+
observeLabel: () => observedLabel$,
5358
});
5459
const page = await newSpecPage({
5560
components: [PosApp, PosResource, PosLabel],
@@ -159,10 +164,12 @@ describe('pos-resource with a pos-label child', () => {
159164
it('renders multiple labels for successfully loaded resource', async () => {
160165
const os = mockPodOS();
161166
when(os.fetch).calledWith('https://resource.test').mockReturnValue(Promise.resolve());
167+
const observedLabel$ = new ReplaySubject<string>();
168+
observedLabel$.next('Test Resource');
162169
when(os.store.get)
163170
.calledWith('https://resource.test')
164171
.mockReturnValue({
165-
label: () => 'Test Resource',
172+
observeLabel: () => observedLabel$,
166173
});
167174
const page = await newSpecPage({
168175
components: [PosApp, PosResource, PosLabel],
@@ -207,10 +214,12 @@ describe('pos-resource with a pos-label child', () => {
207214
const loadingPromise = new Promise(resolve => setTimeout(resolve, 1));
208215
const os = mockPodOS();
209216
when(os.fetch).calledWith('https://resource.test').mockReturnValue(loadingPromise);
217+
const observedLabel$ = new ReplaySubject<string>();
218+
observedLabel$.next('Test Resource');
210219
when(os.store.get)
211220
.calledWith('https://resource.test')
212221
.mockReturnValue({
213-
label: () => 'Test Resource',
222+
observeLabel: () => observedLabel$,
214223
});
215224
const page = await newSpecPage({
216225
components: [PosApp, PosResource, PosLabel],
@@ -256,10 +265,12 @@ describe('pos-resource with a pos-label child', () => {
256265
it('renders label for lazy resource that would fetch to fail', async () => {
257266
const os = mockPodOS();
258267
when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));
268+
const observedLabel$ = new ReplaySubject<string>();
269+
observedLabel$.next('Test Resource');
259270
when(os.store.get)
260271
.calledWith('https://resource.test')
261272
.mockReturnValue({
262-
label: () => 'Test Resource',
273+
observeLabel: () => observedLabel$,
263274
});
264275
const page = await newSpecPage({
265276
components: [PosApp, PosResource, PosLabel],
@@ -291,10 +302,12 @@ describe('pos-resource with a pos-label child', () => {
291302
it('renders error for lazy resource fails when fetched', async () => {
292303
const os = mockPodOS();
293304
when(os.fetch).calledWith('https://resource.test').mockRejectedValue(new Error('not found'));
305+
const observedLabel$ = new ReplaySubject<string>();
306+
observedLabel$.next('Test Resource');
294307
when(os.store.get)
295308
.calledWith('https://resource.test')
296309
.mockReturnValueOnce({
297-
label: () => 'Test Resource',
310+
observeLabel: () => observedLabel$,
298311
});
299312
const page = await newSpecPage({
300313
components: [PosApp, PosResource, PosLabel],
@@ -344,13 +357,17 @@ describe('pos-resource with a pos-label child', () => {
344357
it('rerenders child after lazy resource was fetched', async () => {
345358
const os = mockPodOS();
346359
when(os.fetch).calledWith('https://resource.test').mockResolvedValue(null);
360+
const observedLabel1$ = new ReplaySubject<string>();
361+
observedLabel1$.next('Test Resource');
362+
const observedLabel2$ = new ReplaySubject<string>();
363+
observedLabel2$.next('Updated Test Resource');
347364
when(os.store.get)
348365
.calledWith('https://resource.test')
349366
.mockReturnValueOnce({
350-
label: () => 'Test Resource',
367+
observeLabel: () => observedLabel1$,
351368
})
352369
.mockReturnValueOnce({
353-
label: () => 'Updated Test Resource',
370+
observeLabel: () => observedLabel2$,
354371
});
355372
const page = await newSpecPage({
356373
components: [PosApp, PosResource, PosLabel],

0 commit comments

Comments
 (0)