@openmrs/esm-react-utils 10.0.1-pre.5602 → 10.0.1-pre.5607

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 55 files with swc (297.01ms)
1
+ [0] Successfully compiled: 55 files with swc (154.62ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "10.0.1-pre.5602",
3
+ "version": "10.0.1-pre.5607",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "type": "module",
@@ -60,17 +60,17 @@
60
60
  "single-spa-react": "^6.0.2"
61
61
  },
62
62
  "peerDependencies": {
63
- "@openmrs/esm-api": "^10.0.1-pre.5602",
64
- "@openmrs/esm-config": "^10.0.1-pre.5602",
65
- "@openmrs/esm-context": "^10.0.1-pre.5602",
66
- "@openmrs/esm-emr-api": "^10.0.1-pre.5602",
67
- "@openmrs/esm-error-handling": "^10.0.1-pre.5602",
68
- "@openmrs/esm-extensions": "^10.0.1-pre.5602",
69
- "@openmrs/esm-feature-flags": "^10.0.1-pre.5602",
70
- "@openmrs/esm-globals": "^10.0.1-pre.5602",
71
- "@openmrs/esm-navigation": "^10.0.1-pre.5602",
72
- "@openmrs/esm-state": "^10.0.1-pre.5602",
73
- "@openmrs/esm-utils": "^10.0.1-pre.5602",
63
+ "@openmrs/esm-api": "^10.0.1-pre.5607",
64
+ "@openmrs/esm-config": "^10.0.1-pre.5607",
65
+ "@openmrs/esm-context": "^10.0.1-pre.5607",
66
+ "@openmrs/esm-emr-api": "^10.0.1-pre.5607",
67
+ "@openmrs/esm-error-handling": "^10.0.1-pre.5607",
68
+ "@openmrs/esm-extensions": "^10.0.1-pre.5607",
69
+ "@openmrs/esm-feature-flags": "^10.0.1-pre.5607",
70
+ "@openmrs/esm-globals": "^10.0.1-pre.5607",
71
+ "@openmrs/esm-navigation": "^10.0.1-pre.5607",
72
+ "@openmrs/esm-state": "^10.0.1-pre.5607",
73
+ "@openmrs/esm-utils": "^10.0.1-pre.5607",
74
74
  "dayjs": "1.x",
75
75
  "i18next": "25.x",
76
76
  "react": "18.x",
@@ -79,17 +79,17 @@
79
79
  "swr": "2.x"
80
80
  },
81
81
  "devDependencies": {
82
- "@openmrs/esm-api": "10.0.1-pre.5602",
83
- "@openmrs/esm-config": "10.0.1-pre.5602",
84
- "@openmrs/esm-context": "10.0.1-pre.5602",
85
- "@openmrs/esm-emr-api": "10.0.1-pre.5602",
86
- "@openmrs/esm-error-handling": "10.0.1-pre.5602",
87
- "@openmrs/esm-extensions": "10.0.1-pre.5602",
88
- "@openmrs/esm-feature-flags": "10.0.1-pre.5602",
89
- "@openmrs/esm-globals": "10.0.1-pre.5602",
90
- "@openmrs/esm-navigation": "10.0.1-pre.5602",
91
- "@openmrs/esm-state": "10.0.1-pre.5602",
92
- "@openmrs/esm-utils": "10.0.1-pre.5602",
82
+ "@openmrs/esm-api": "10.0.1-pre.5607",
83
+ "@openmrs/esm-config": "10.0.1-pre.5607",
84
+ "@openmrs/esm-context": "10.0.1-pre.5607",
85
+ "@openmrs/esm-emr-api": "10.0.1-pre.5607",
86
+ "@openmrs/esm-error-handling": "10.0.1-pre.5607",
87
+ "@openmrs/esm-extensions": "10.0.1-pre.5607",
88
+ "@openmrs/esm-feature-flags": "10.0.1-pre.5607",
89
+ "@openmrs/esm-globals": "10.0.1-pre.5607",
90
+ "@openmrs/esm-navigation": "10.0.1-pre.5607",
91
+ "@openmrs/esm-state": "10.0.1-pre.5607",
92
+ "@openmrs/esm-utils": "10.0.1-pre.5607",
93
93
  "@swc/cli": "0.8.1",
94
94
  "@swc/core": "1.15.21",
95
95
  "@vitest/coverage-v8": "^4.1.2",
@@ -0,0 +1,70 @@
1
+ import { afterEach, beforeEach, expect, it, vi } from 'vitest';
2
+ import { act, renderHook, waitFor } from '@testing-library/react';
3
+ import { getConfig } from '@openmrs/esm-config';
4
+ import { useOpenmrsPagination } from './useOpenmrsPagination';
5
+ import { useOpenmrsFetchAll } from './useOpenmrsFetchAll';
6
+
7
+ // Exercise the source implementation rather than workspace build output or a fetcher mock.
8
+ vi.mock('@openmrs/esm-api', () => import('../../esm-api/src/openmrs-fetch'));
9
+ vi.mock('@openmrs/esm-config', () => import('@openmrs/esm-config/mock'));
10
+
11
+ const mockFetch = vi.fn<typeof fetch>();
12
+
13
+ beforeEach(() => {
14
+ window.openmrsBase = '/openmrs/';
15
+ vi.stubGlobal('location', new URL('https://frontend.example/openmrs/spa/'));
16
+ vi.stubGlobal('fetch', mockFetch);
17
+ vi.mocked(getConfig).mockResolvedValue({
18
+ redirectAuthFailure: { enabled: false, url: '', errors: [401], resolvePromise: false },
19
+ followRedirects: true,
20
+ });
21
+ mockFetch.mockImplementation(async (url) => {
22
+ const startIndex = new URL(String(url), window.location.href).searchParams.get('startIndex');
23
+ return new Response(
24
+ JSON.stringify({
25
+ results: startIndex === '1' ? ['second'] : ['first'],
26
+ totalCount: 2,
27
+ links:
28
+ startIndex === '1'
29
+ ? []
30
+ : [{ rel: 'next', uri: 'https://backend.example/openmrs/ws/rest/v1/patient?limit=1&startIndex=1' }],
31
+ }),
32
+ { headers: { 'Content-Type': 'application/json' } },
33
+ );
34
+ });
35
+ });
36
+
37
+ afterEach(() => vi.unstubAllGlobals());
38
+
39
+ it('suppresses authentication challenges on absolute URLs generated by the pagination hook', async () => {
40
+ const { result } = renderHook(() =>
41
+ useOpenmrsPagination<string>('/ws/rest/v1/patient', 1, {
42
+ swrConfig: { provider: () => new Map() },
43
+ }),
44
+ );
45
+ await waitFor(() => expect(result.current.data).toEqual(['first']));
46
+ act(() => result.current.goToNext());
47
+ await waitFor(() => expect(result.current.data).toEqual(['second']));
48
+
49
+ expect(mockFetch).toHaveBeenCalledTimes(2);
50
+ for (const [url, init] of mockFetch.mock.calls) {
51
+ expect(String(url)).toMatch(/^https:\/\/frontend.example\/openmrs\/\/ws\/rest\/v1\/patient\?/);
52
+ expect(new Headers(init?.headers).get('Disable-WWW-Authenticate')).toBe('true');
53
+ }
54
+ });
55
+
56
+ it('suppresses authentication challenges on normalized next-page links followed by fetch-all', async () => {
57
+ const { result } = renderHook(() =>
58
+ useOpenmrsFetchAll<string>('/ws/rest/v1/patient?limit=1', {
59
+ swrInfiniteConfig: { provider: () => new Map() },
60
+ }),
61
+ );
62
+ await waitFor(() => expect(result.current.data).toEqual(['first', 'second']));
63
+
64
+ expect(mockFetch.mock.calls.map(([url]) => url)).toContain(
65
+ 'https://frontend.example/openmrs/ws/rest/v1/patient?limit=1&startIndex=1',
66
+ );
67
+ for (const [, init] of mockFetch.mock.calls) {
68
+ expect(new Headers(init?.headers).get('Disable-WWW-Authenticate')).toBe('true');
69
+ }
70
+ });