@dhis2/app-service-data 3.2.5 → 3.2.9

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.
@@ -497,6 +497,111 @@ describe('useDataQuery', () => {
497
497
  });
498
498
  });
499
499
  describe('return values: refetch', () => {
500
+ it('Should only trigger a single request when refetch is called on a lazy query with new variables', async () => {
501
+ const spy = jest.fn((type, query) => {
502
+ if (query.id === '1') {
503
+ return 42;
504
+ }
505
+
506
+ return 0;
507
+ });
508
+ const data = {
509
+ answer: spy
510
+ };
511
+ const query = {
512
+ x: {
513
+ resource: 'answer',
514
+ id: ({
515
+ id
516
+ }) => id
517
+ }
518
+ };
519
+
520
+ const wrapper = ({
521
+ children
522
+ }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
523
+ data: data
524
+ }, children);
525
+
526
+ const {
527
+ result,
528
+ waitFor
529
+ } = renderHook(() => useDataQuery(query, {
530
+ lazy: true
531
+ }), {
532
+ wrapper
533
+ });
534
+ expect(spy).not.toHaveBeenCalled();
535
+ act(() => {
536
+ result.current.refetch({
537
+ id: '1'
538
+ });
539
+ });
540
+ await waitFor(() => {
541
+ expect(result.current).toMatchObject({
542
+ loading: false,
543
+ called: true,
544
+ data: {
545
+ x: 42
546
+ }
547
+ });
548
+ });
549
+ expect(spy).toHaveBeenCalledTimes(1);
550
+ });
551
+ it('Should only trigger a single request when refetch is called on a lazy query with identical variables', async () => {
552
+ const spy = jest.fn((type, query) => {
553
+ if (query.id === '1') {
554
+ return 42;
555
+ }
556
+
557
+ return 0;
558
+ });
559
+ const data = {
560
+ answer: spy
561
+ };
562
+ const query = {
563
+ x: {
564
+ resource: 'answer',
565
+ id: ({
566
+ id
567
+ }) => id
568
+ }
569
+ };
570
+
571
+ const wrapper = ({
572
+ children
573
+ }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
574
+ data: data
575
+ }, children);
576
+
577
+ const {
578
+ result,
579
+ waitFor
580
+ } = renderHook(() => useDataQuery(query, {
581
+ lazy: true,
582
+ variables: {
583
+ id: '1'
584
+ }
585
+ }), {
586
+ wrapper
587
+ });
588
+ expect(spy).not.toHaveBeenCalled();
589
+ act(() => {
590
+ result.current.refetch({
591
+ id: '1'
592
+ });
593
+ });
594
+ await waitFor(() => {
595
+ expect(result.current).toMatchObject({
596
+ loading: false,
597
+ called: true,
598
+ data: {
599
+ x: 42
600
+ }
601
+ });
602
+ });
603
+ expect(spy).toHaveBeenCalledTimes(1);
604
+ });
500
605
  it('Should have a stable identity if the variables have not changed', async () => {
501
606
  const data = {
502
607
  answer: () => 42
@@ -1,7 +1,8 @@
1
1
  import { ResolvedResourceQuery, FetchType } from '../../../engine';
2
2
  export declare const isReplyToMessageConversation: (type: FetchType, { resource }: ResolvedResourceQuery) => boolean;
3
3
  export declare const isCreateFeedbackMessage: (type: FetchType, { resource }: ResolvedResourceQuery) => boolean;
4
- export declare const isCreateOrUpdateInterpretation: (type: FetchType, { resource, id }: ResolvedResourceQuery) => boolean;
4
+ export declare const isCreateInterpretation: (type: FetchType, { resource }: ResolvedResourceQuery) => boolean;
5
+ export declare const isUpdateInterpretation: (type: FetchType, { resource, id }: ResolvedResourceQuery) => boolean;
5
6
  export declare const isCommentOnInterpretation: (type: FetchType, { resource }: ResolvedResourceQuery) => boolean;
6
7
  export declare const isInterpretationCommentUpdate: (type: FetchType, { resource, id }: ResolvedResourceQuery) => boolean;
7
8
  export declare const isAddOrUpdateSystemOrUserSetting: (type: FetchType, { resource }: ResolvedResourceQuery) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2/app-service-data",
3
- "version": "3.2.5",
3
+ "version": "3.2.9",
4
4
  "main": "./build/cjs/index.js",
5
5
  "module": "./build/es/index.js",
6
6
  "types": "build/types/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "build/**"
23
23
  ],
24
24
  "peerDependencies": {
25
- "@dhis2/app-service-config": "3.2.5",
25
+ "@dhis2/app-service-config": "3.2.9",
26
26
  "@dhis2/cli-app-scripts": "^7.1.1",
27
27
  "prop-types": "^15.7.2",
28
28
  "react": "^16.8",