UNPKG

2.92 kBJavaScriptView Raw
1import React from 'react';
2import { render, waitFor, cleanup } from '@testing-library/react';
3import { avWebQLApi } from '@availity/api-axios';
4import PayerLogo, { getLogo } from '../PayerLogo';
5
6jest.mock('@availity/api-axios');
7
8afterEach(cleanup);
9
10describe('PayerLogo', () => {
11 test('should not render when no space or payer id', () => {
12 const { container } = render(<PayerLogo clientId="my-client-id" />);
13
14 expect(container).toMatchSnapshot();
15 });
16
17 test('should render with payer id', async () => {
18 avWebQLApi.create.mockResolvedValue({
19 data: {
20 data: {
21 configurationPagination: {
22 items: [
23 {
24 images: {
25 logo: '/static/spaces/73162546201440710195134200002269/banner.png',
26 },
27 },
28 ],
29 },
30 },
31 },
32 });
33
34 const { container } = render(
35 <PayerLogo payerId="BCBSF" clientId="my-client-id" />
36 );
37
38 await waitFor(() =>
39 container.querySelector(
40 'img[src="/static/spaces/73162546201440710195134200002269/banner.png"]'
41 )
42 );
43
44 expect(container).toMatchSnapshot();
45 });
46
47 test('should render with default when payer id returns no results', async () => {
48 avWebQLApi.create.mockResolvedValue({
49 data: {
50 data: {
51 configurationPagination: {
52 items: [],
53 },
54 },
55 },
56 });
57
58 const { container } = render(
59 <PayerLogo payerId="00681" clientId="my-client-id" />
60 );
61
62 await waitFor(() =>
63 container.querySelector(
64 'img[src="/public/apps/eligibility/images/value-add-logos/00681.gif"]'
65 )
66 );
67
68 expect(container).toMatchSnapshot();
69 });
70
71 test('should render with space id', async () => {
72 avWebQLApi.create.mockResolvedValue({
73 data: {
74 data: {
75 configurationFindOne: {
76 images: {
77 logo: '/static/spaces/73162546201441126239486200007187/banner.png',
78 },
79 },
80 },
81 },
82 });
83
84 const { container } = render(
85 <PayerLogo
86 spaceId="73162546201441126239486200007187"
87 clientId="my-client-id"
88 />
89 );
90
91 await waitFor(() =>
92 container.querySelector(
93 'img[src="/static/spaces/73162546201441126239486200007187/banner.png"]'
94 )
95 );
96
97 expect(container).toMatchSnapshot();
98 });
99
100 test('should throw error on missing clientId', async () => {
101 let message;
102 try {
103 await getLogo();
104 } catch (error) {
105 const { message: mess } = error;
106 message = mess;
107 }
108
109 expect(message).toBe('clientId is required');
110 });
111
112 test('should return error on rejected promise', async () => {
113 avWebQLApi.create.mockRejectedValue('This field was rejected');
114
115 const response = await getLogo(null, '3', 'test-client-id');
116
117 expect(response).toBe('This field was rejected');
118 });
119});