Skip to content

Commit 5af4f89

Browse files
committed
Merge remote-tracking branch 'origin/main' into more-eslint
2 parents 968c233 + 610062b commit 5af4f89

11 files changed

Lines changed: 657 additions & 146 deletions

src/app/core/data/base/base-data.service.spec.ts

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('BaseDataService', () => {
106106
remoteDataMocks = {
107107
RequestPending: new RemoteData(undefined, msToLive, timeStamp, RequestEntryState.RequestPending, undefined, undefined, undefined),
108108
ResponsePending: new RemoteData(undefined, msToLive, timeStamp, RequestEntryState.ResponsePending, undefined, undefined, undefined),
109+
ResponsePendingStale: new RemoteData(undefined, msToLive, timeStamp, RequestEntryState.ResponsePendingStale, undefined, undefined, undefined),
109110
Success: new RemoteData(timeStamp, msToLive, timeStamp, RequestEntryState.Success, undefined, payload, statusCodeSuccess),
110111
SuccessStale: new RemoteData(timeStamp, msToLive, timeStamp, RequestEntryState.SuccessStale, undefined, payload, statusCodeSuccess),
111112
Error: new RemoteData(timeStamp, msToLive, timeStamp, RequestEntryState.Error, errorMessage, undefined, statusCodeError),
@@ -314,19 +315,21 @@ describe('BaseDataService', () => {
314315

315316
it(`should not emit a cached stale RemoteData, but only start emitting after the state first changes to RequestPending`, () => {
316317
testScheduler.run(({ cold, expectObservable }) => {
317-
spyOn(rdbService, 'buildSingle').and.returnValue(cold('a-b-c-d-e', {
318-
a: remoteDataMocks.SuccessStale,
319-
b: remoteDataMocks.RequestPending,
320-
c: remoteDataMocks.ResponsePending,
321-
d: remoteDataMocks.Success,
322-
e: remoteDataMocks.SuccessStale,
318+
spyOn(rdbService, 'buildSingle').and.returnValue(cold('a-b-c-d-e-f-g', {
319+
a: remoteDataMocks.ResponsePendingStale,
320+
b: remoteDataMocks.SuccessStale,
321+
c: remoteDataMocks.ErrorStale,
322+
d: remoteDataMocks.RequestPending,
323+
e: remoteDataMocks.ResponsePending,
324+
f: remoteDataMocks.Success,
325+
g: remoteDataMocks.SuccessStale,
323326
}));
324-
const expected = '--b-c-d-e';
327+
const expected = '------d-e-f-g';
325328
const values = {
326-
b: remoteDataMocks.RequestPending,
327-
c: remoteDataMocks.ResponsePending,
328-
d: remoteDataMocks.Success,
329-
e: remoteDataMocks.SuccessStale,
329+
d: remoteDataMocks.RequestPending,
330+
e: remoteDataMocks.ResponsePending,
331+
f: remoteDataMocks.Success,
332+
g: remoteDataMocks.SuccessStale,
330333
};
331334

332335
expectObservable(service.findByHref(selfLink, true, true, ...linksToFollow)).toBe(expected, values);
@@ -365,19 +368,21 @@ describe('BaseDataService', () => {
365368

366369
it(`should not emit a cached stale RemoteData, but only start emitting after the state first changes to RequestPending`, () => {
367370
testScheduler.run(({ cold, expectObservable }) => {
368-
spyOn(rdbService, 'buildSingle').and.returnValue(cold('a-b-c-d-e', {
369-
a: remoteDataMocks.SuccessStale,
370-
b: remoteDataMocks.RequestPending,
371-
c: remoteDataMocks.ResponsePending,
372-
d: remoteDataMocks.Success,
373-
e: remoteDataMocks.SuccessStale,
371+
spyOn(rdbService, 'buildSingle').and.returnValue(cold('a-b-c-d-e-f-g', {
372+
a: remoteDataMocks.ResponsePendingStale,
373+
b: remoteDataMocks.SuccessStale,
374+
c: remoteDataMocks.ErrorStale,
375+
d: remoteDataMocks.RequestPending,
376+
e: remoteDataMocks.ResponsePending,
377+
f: remoteDataMocks.Success,
378+
g: remoteDataMocks.SuccessStale,
374379
}));
375-
const expected = '--b-c-d-e';
380+
const expected = '------d-e-f-g';
376381
const values = {
377-
b: remoteDataMocks.RequestPending,
378-
c: remoteDataMocks.ResponsePending,
379-
d: remoteDataMocks.Success,
380-
e: remoteDataMocks.SuccessStale,
382+
d: remoteDataMocks.RequestPending,
383+
e: remoteDataMocks.ResponsePending,
384+
f: remoteDataMocks.Success,
385+
g: remoteDataMocks.SuccessStale,
381386
};
382387

383388
expectObservable(service.findByHref(selfLink, false, true, ...linksToFollow)).toBe(expected, values);
@@ -498,19 +503,21 @@ describe('BaseDataService', () => {
498503

499504
it(`should not emit a cached stale RemoteData, but only start emitting after the state first changes to RequestPending`, () => {
500505
testScheduler.run(({ cold, expectObservable }) => {
501-
spyOn(rdbService, 'buildList').and.returnValue(cold('a-b-c-d-e', {
502-
a: remoteDataMocks.SuccessStale,
503-
b: remoteDataMocks.RequestPending,
504-
c: remoteDataMocks.ResponsePending,
505-
d: remoteDataMocks.Success,
506-
e: remoteDataMocks.SuccessStale,
506+
spyOn(rdbService, 'buildList').and.returnValue(cold('a-b-c-d-e-f-g', {
507+
a: remoteDataMocks.ResponsePendingStale,
508+
b: remoteDataMocks.SuccessStale,
509+
c: remoteDataMocks.ErrorStale,
510+
d: remoteDataMocks.RequestPending,
511+
e: remoteDataMocks.ResponsePending,
512+
f: remoteDataMocks.Success,
513+
g: remoteDataMocks.SuccessStale,
507514
}));
508-
const expected = '--b-c-d-e';
515+
const expected = '------d-e-f-g';
509516
const values = {
510-
b: remoteDataMocks.RequestPending,
511-
c: remoteDataMocks.ResponsePending,
512-
d: remoteDataMocks.Success,
513-
e: remoteDataMocks.SuccessStale,
517+
d: remoteDataMocks.RequestPending,
518+
e: remoteDataMocks.ResponsePending,
519+
f: remoteDataMocks.Success,
520+
g: remoteDataMocks.SuccessStale,
514521
};
515522

516523
expectObservable(service.findListByHref(selfLink, findListOptions, true, true, ...linksToFollow)).toBe(expected, values);
@@ -549,21 +556,24 @@ describe('BaseDataService', () => {
549556

550557
it(`should not emit a cached stale RemoteData, but only start emitting after the state first changes to RequestPending`, () => {
551558
testScheduler.run(({ cold, expectObservable }) => {
552-
spyOn(rdbService, 'buildList').and.returnValue(cold('a-b-c-d-e', {
553-
a: remoteDataMocks.SuccessStale,
554-
b: remoteDataMocks.RequestPending,
555-
c: remoteDataMocks.ResponsePending,
556-
d: remoteDataMocks.Success,
557-
e: remoteDataMocks.SuccessStale,
559+
spyOn(rdbService, 'buildList').and.returnValue(cold('a-b-c-d-e-f-g', {
560+
a: remoteDataMocks.ResponsePendingStale,
561+
b: remoteDataMocks.SuccessStale,
562+
c: remoteDataMocks.ErrorStale,
563+
d: remoteDataMocks.RequestPending,
564+
e: remoteDataMocks.ResponsePending,
565+
f: remoteDataMocks.Success,
566+
g: remoteDataMocks.SuccessStale,
558567
}));
559-
const expected = '--b-c-d-e';
568+
const expected = '------d-e-f-g';
560569
const values = {
561-
b: remoteDataMocks.RequestPending,
562-
c: remoteDataMocks.ResponsePending,
563-
d: remoteDataMocks.Success,
564-
e: remoteDataMocks.SuccessStale,
570+
d: remoteDataMocks.RequestPending,
571+
e: remoteDataMocks.ResponsePending,
572+
f: remoteDataMocks.Success,
573+
g: remoteDataMocks.SuccessStale,
565574
};
566575

576+
567577
expectObservable(service.findListByHref(selfLink, findListOptions, false, true, ...linksToFollow)).toBe(expected, values);
568578
});
569579
});

src/app/core/data/base/base-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
291291
// call it isn't immediately returned, but we wait until the remote data for the new request
292292
// is created. If useCachedVersionIfAvailable is false it also ensures you don't get a
293293
// cached completed object
294-
skipWhile((rd: RemoteData<T>) => useCachedVersionIfAvailable ? rd.isStale : rd.hasCompleted),
294+
skipWhile((rd: RemoteData<T>) => rd.isStale || (!useCachedVersionIfAvailable && rd.hasCompleted)),
295295
this.reRequestStaleRemoteData(reRequestOnStale, () =>
296296
this.findByHref(href$, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),
297297
);
@@ -325,7 +325,7 @@ export class BaseDataService<T extends CacheableObject> implements HALDataServic
325325
// call it isn't immediately returned, but we wait until the remote data for the new request
326326
// is created. If useCachedVersionIfAvailable is false it also ensures you don't get a
327327
// cached completed object
328-
skipWhile((rd: RemoteData<PaginatedList<T>>) => useCachedVersionIfAvailable ? rd.isStale : rd.hasCompleted),
328+
skipWhile((rd: RemoteData<PaginatedList<T>>) => rd.isStale || (!useCachedVersionIfAvailable && rd.hasCompleted)),
329329
this.reRequestStaleRemoteData(reRequestOnStale, () =>
330330
this.findListByHref(href$, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)),
331331
);
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import {
2+
hasCompleted,
3+
hasFailed,
4+
hasSucceeded,
5+
isError,
6+
isErrorStale,
7+
isLoading,
8+
isRequestPending,
9+
isResponsePending,
10+
isResponsePendingStale,
11+
isStale,
12+
isSuccess,
13+
isSuccessStale,
14+
RequestEntryState,
15+
} from './request-entry-state.model';
16+
17+
describe(`isRequestPending`, () => {
18+
it(`should only return true if the given state is RequestPending`, () => {
19+
expect(isRequestPending(RequestEntryState.RequestPending)).toBeTrue();
20+
21+
expect(isRequestPending(RequestEntryState.ResponsePending)).toBeFalse();
22+
expect(isRequestPending(RequestEntryState.Error)).toBeFalse();
23+
expect(isRequestPending(RequestEntryState.Success)).toBeFalse();
24+
expect(isRequestPending(RequestEntryState.ResponsePendingStale)).toBeFalse();
25+
expect(isRequestPending(RequestEntryState.ErrorStale)).toBeFalse();
26+
expect(isRequestPending(RequestEntryState.SuccessStale)).toBeFalse();
27+
});
28+
});
29+
30+
describe(`isError`, () => {
31+
it(`should only return true if the given state is Error`, () => {
32+
expect(isError(RequestEntryState.Error)).toBeTrue();
33+
34+
expect(isError(RequestEntryState.RequestPending)).toBeFalse();
35+
expect(isError(RequestEntryState.ResponsePending)).toBeFalse();
36+
expect(isError(RequestEntryState.Success)).toBeFalse();
37+
expect(isError(RequestEntryState.ResponsePendingStale)).toBeFalse();
38+
expect(isError(RequestEntryState.ErrorStale)).toBeFalse();
39+
expect(isError(RequestEntryState.SuccessStale)).toBeFalse();
40+
});
41+
});
42+
43+
describe(`isSuccess`, () => {
44+
it(`should only return true if the given state is Success`, () => {
45+
expect(isSuccess(RequestEntryState.Success)).toBeTrue();
46+
47+
expect(isSuccess(RequestEntryState.RequestPending)).toBeFalse();
48+
expect(isSuccess(RequestEntryState.ResponsePending)).toBeFalse();
49+
expect(isSuccess(RequestEntryState.Error)).toBeFalse();
50+
expect(isSuccess(RequestEntryState.ResponsePendingStale)).toBeFalse();
51+
expect(isSuccess(RequestEntryState.ErrorStale)).toBeFalse();
52+
expect(isSuccess(RequestEntryState.SuccessStale)).toBeFalse();
53+
});
54+
});
55+
56+
describe(`isErrorStale`, () => {
57+
it(`should only return true if the given state is ErrorStale`, () => {
58+
expect(isErrorStale(RequestEntryState.ErrorStale)).toBeTrue();
59+
60+
expect(isErrorStale(RequestEntryState.RequestPending)).toBeFalse();
61+
expect(isErrorStale(RequestEntryState.ResponsePending)).toBeFalse();
62+
expect(isErrorStale(RequestEntryState.Error)).toBeFalse();
63+
expect(isErrorStale(RequestEntryState.Success)).toBeFalse();
64+
expect(isErrorStale(RequestEntryState.ResponsePendingStale)).toBeFalse();
65+
expect(isErrorStale(RequestEntryState.SuccessStale)).toBeFalse();
66+
});
67+
});
68+
69+
describe(`isSuccessStale`, () => {
70+
it(`should only return true if the given state is SuccessStale`, () => {
71+
expect(isSuccessStale(RequestEntryState.SuccessStale)).toBeTrue();
72+
73+
expect(isSuccessStale(RequestEntryState.RequestPending)).toBeFalse();
74+
expect(isSuccessStale(RequestEntryState.ResponsePending)).toBeFalse();
75+
expect(isSuccessStale(RequestEntryState.Error)).toBeFalse();
76+
expect(isSuccessStale(RequestEntryState.Success)).toBeFalse();
77+
expect(isSuccessStale(RequestEntryState.ResponsePendingStale)).toBeFalse();
78+
expect(isSuccessStale(RequestEntryState.ErrorStale)).toBeFalse();
79+
});
80+
});
81+
82+
describe(`isResponsePending`, () => {
83+
it(`should only return true if the given state is ResponsePending`, () => {
84+
expect(isResponsePending(RequestEntryState.ResponsePending)).toBeTrue();
85+
86+
expect(isResponsePending(RequestEntryState.RequestPending)).toBeFalse();
87+
expect(isResponsePending(RequestEntryState.Error)).toBeFalse();
88+
expect(isResponsePending(RequestEntryState.Success)).toBeFalse();
89+
expect(isResponsePending(RequestEntryState.ResponsePendingStale)).toBeFalse();
90+
expect(isResponsePending(RequestEntryState.ErrorStale)).toBeFalse();
91+
expect(isResponsePending(RequestEntryState.SuccessStale)).toBeFalse();
92+
});
93+
});
94+
95+
describe(`isResponsePendingStale`, () => {
96+
it(`should only return true if the given state is requestPending`, () => {
97+
expect(isResponsePendingStale(RequestEntryState.ResponsePendingStale)).toBeTrue();
98+
99+
expect(isResponsePendingStale(RequestEntryState.RequestPending)).toBeFalse();
100+
expect(isResponsePendingStale(RequestEntryState.ResponsePending)).toBeFalse();
101+
expect(isResponsePendingStale(RequestEntryState.Error)).toBeFalse();
102+
expect(isResponsePendingStale(RequestEntryState.Success)).toBeFalse();
103+
expect(isResponsePendingStale(RequestEntryState.ErrorStale)).toBeFalse();
104+
expect(isResponsePendingStale(RequestEntryState.SuccessStale)).toBeFalse();
105+
});
106+
});
107+
108+
describe(`isLoading`, () => {
109+
it(`should only return true if the given state is RequestPending, ResponsePending or ResponsePendingStale`, () => {
110+
expect(isLoading(RequestEntryState.RequestPending)).toBeTrue();
111+
expect(isLoading(RequestEntryState.ResponsePending)).toBeTrue();
112+
expect(isLoading(RequestEntryState.ResponsePendingStale)).toBeTrue();
113+
114+
expect(isLoading(RequestEntryState.Error)).toBeFalse();
115+
expect(isLoading(RequestEntryState.Success)).toBeFalse();
116+
expect(isLoading(RequestEntryState.ErrorStale)).toBeFalse();
117+
expect(isLoading(RequestEntryState.SuccessStale)).toBeFalse();
118+
});
119+
});
120+
121+
describe(`hasFailed`, () => {
122+
describe(`when the state is loading`, () => {
123+
it(`should return undefined`, () => {
124+
expect(hasFailed(RequestEntryState.RequestPending)).toBeUndefined();
125+
expect(hasFailed(RequestEntryState.ResponsePending)).toBeUndefined();
126+
expect(hasFailed(RequestEntryState.ResponsePendingStale)).toBeUndefined();
127+
});
128+
});
129+
130+
describe(`when the state has completed`, () => {
131+
it(`should only return true if the given state is Error or ErrorStale`, () => {
132+
expect(hasFailed(RequestEntryState.Error)).toBeTrue();
133+
expect(hasFailed(RequestEntryState.ErrorStale)).toBeTrue();
134+
135+
expect(hasFailed(RequestEntryState.Success)).toBeFalse();
136+
expect(hasFailed(RequestEntryState.SuccessStale)).toBeFalse();
137+
});
138+
});
139+
});
140+
141+
describe(`hasSucceeded`, () => {
142+
describe(`when the state is loading`, () => {
143+
it(`should return undefined`, () => {
144+
expect(hasSucceeded(RequestEntryState.RequestPending)).toBeUndefined();
145+
expect(hasSucceeded(RequestEntryState.ResponsePending)).toBeUndefined();
146+
expect(hasSucceeded(RequestEntryState.ResponsePendingStale)).toBeUndefined();
147+
});
148+
});
149+
150+
describe(`when the state has completed`, () => {
151+
it(`should only return true if the given state is Error or ErrorStale`, () => {
152+
expect(hasSucceeded(RequestEntryState.Success)).toBeTrue();
153+
expect(hasSucceeded(RequestEntryState.SuccessStale)).toBeTrue();
154+
155+
expect(hasSucceeded(RequestEntryState.Error)).toBeFalse();
156+
expect(hasSucceeded(RequestEntryState.ErrorStale)).toBeFalse();
157+
});
158+
});
159+
});
160+
161+
162+
describe(`hasCompleted`, () => {
163+
it(`should only return true if the given state is Error, Success, ErrorStale or SuccessStale`, () => {
164+
expect(hasCompleted(RequestEntryState.Error)).toBeTrue();
165+
expect(hasCompleted(RequestEntryState.Success)).toBeTrue();
166+
expect(hasCompleted(RequestEntryState.ErrorStale)).toBeTrue();
167+
expect(hasCompleted(RequestEntryState.SuccessStale)).toBeTrue();
168+
169+
expect(hasCompleted(RequestEntryState.RequestPending)).toBeFalse();
170+
expect(hasCompleted(RequestEntryState.ResponsePending)).toBeFalse();
171+
expect(hasCompleted(RequestEntryState.ResponsePendingStale)).toBeFalse();
172+
});
173+
});
174+
175+
describe(`isStale`, () => {
176+
it(`should only return true if the given state is ResponsePendingStale, SuccessStale or ErrorStale`, () => {
177+
expect(isStale(RequestEntryState.ResponsePendingStale)).toBeTrue();
178+
expect(isStale(RequestEntryState.SuccessStale)).toBeTrue();
179+
expect(isStale(RequestEntryState.ErrorStale)).toBeTrue();
180+
181+
expect(isStale(RequestEntryState.RequestPending)).toBeFalse();
182+
expect(isStale(RequestEntryState.ResponsePending)).toBeFalse();
183+
expect(isStale(RequestEntryState.Error)).toBeFalse();
184+
expect(isStale(RequestEntryState.Success)).toBeFalse();
185+
});
186+
});

src/app/core/data/request-entry-state.model.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ export enum RequestEntryState {
33
ResponsePending = 'ResponsePending',
44
Error = 'Error',
55
Success = 'Success',
6+
ResponsePendingStale = 'ResponsePendingStale',
67
ErrorStale = 'ErrorStale',
7-
SuccessStale = 'SuccessStale'
8+
SuccessStale = 'SuccessStale',
89
}
910

1011
/**
@@ -42,12 +43,21 @@ export const isSuccessStale = (state: RequestEntryState) =>
4243
*/
4344
export const isResponsePending = (state: RequestEntryState) =>
4445
state === RequestEntryState.ResponsePending;
46+
4547
/**
46-
* Returns true if the given state is RequestPending or ResponsePending,
47-
* false otherwise
48+
* Returns true if the given state is ResponsePendingStale, false otherwise
49+
*/
50+
export const isResponsePendingStale = (state: RequestEntryState) =>
51+
state === RequestEntryState.ResponsePendingStale;
52+
53+
/**
54+
* Returns true if the given state is RequestPending, RequestPendingStale, ResponsePending, or
55+
* ResponsePendingStale, false otherwise
4856
*/
4957
export const isLoading = (state: RequestEntryState) =>
50-
isRequestPending(state) || isResponsePending(state);
58+
isRequestPending(state) ||
59+
isResponsePending(state) ||
60+
isResponsePendingStale(state);
5161

5262
/**
5363
* If isLoading is true for the given state, this method returns undefined, we can't know yet.
@@ -82,7 +92,10 @@ export const hasCompleted = (state: RequestEntryState) =>
8292
!isLoading(state);
8393

8494
/**
85-
* Returns true if the given state is SuccessStale or ErrorStale, false otherwise
95+
* Returns true if the given state is isRequestPendingStale, isResponsePendingStale, SuccessStale or
96+
* ErrorStale, false otherwise
8697
*/
8798
export const isStale = (state: RequestEntryState) =>
88-
isSuccessStale(state) || isErrorStale(state);
99+
isResponsePendingStale(state) ||
100+
isSuccessStale(state) ||
101+
isErrorStale(state);

0 commit comments

Comments
 (0)