11import React from 'react' ;
2- import { Table } from 'app/ percona/shared/components/Elements/Table/Table ' ;
2+ import { Table } from '@ percona/platform-core ' ;
33import { AGENTS_COLUMNS , NODES_COLUMNS , SERVICES_COLUMNS } from './Inventory.constants' ;
44import { InventoryDataService } from './Inventory.tools' ;
5- import { render } from '@testing-library/react' ;
5+ import { render , waitFor } from '@testing-library/react' ;
66
77jest . mock ( 'app/percona/settings/Settings.service' ) ;
88
@@ -39,20 +39,68 @@ describe('Inventory tables', () => {
3939 } ,
4040 ] ,
4141 } ;
42+ const data = InventoryDataService . getAgentModel ( response as any ) ;
4243
4344 const { container } = render (
4445 < Table
45- data = { InventoryDataService . getAgentModel ( response as any ) }
46- rowKey = { ( rec ) => rec . agent_id }
46+ data = { data }
47+ totalItems = { data . length }
48+ rowSelection
4749 columns = { AGENTS_COLUMNS }
48- loading = { false }
50+ pendingRequest = { false }
51+ showPagination
52+ pageSize = { 25 }
4953 />
5054 ) ;
5155
5256 // length is 5 because header is also tr
5357 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 5 ) ;
5458 } ) ;
5559
60+ it ( 'Agents table only first page' , async ( ) => {
61+ const response = {
62+ pmm_agent : [ { agent_id : 'pmm-server' , runs_on_node_id : 'pmm-server' , connected : true } ] ,
63+ node_exporter : new Array ( 50 ) . fill ( {
64+ agent_id : '/agent_id/262189d8-e10f-41c2-b0ae-73cc76be6968' ,
65+ pmm_agent_id : 'pmm-server' ,
66+ status : 'RUNNING' ,
67+ listen_port : 42000 ,
68+ } ) ,
69+ postgres_exporter : new Array ( 50 ) . fill ( {
70+ agent_id : '/agent_id/8b74c54e-4307-4a10-9a6f-1646215cbe07' ,
71+ pmm_agent_id : 'pmm-server' ,
72+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
73+ username : 'pmm-managed' ,
74+ status : 'RUNNING' ,
75+ listen_port : 42001 ,
76+ } ) ,
77+
78+ qan_postgresql_pgstatements_agent : new Array ( 50 ) . fill ( {
79+ agent_id : '/agent_id/ac55153c-5211-4072-a5de-59eb2a136a5c' ,
80+ pmm_agent_id : 'pmm-server' ,
81+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
82+ username : 'pmm-managed' ,
83+ status : 'RUNNING' ,
84+ } ) ,
85+ } ;
86+ const data = InventoryDataService . getAgentModel ( response as any ) ;
87+
88+ const { container } = render (
89+ < Table
90+ data = { data }
91+ totalItems = { data . length }
92+ rowSelection
93+ columns = { AGENTS_COLUMNS }
94+ pendingRequest = { false }
95+ showPagination
96+ pageSize = { 25 }
97+ />
98+ ) ;
99+
100+ // default page size is 25
101+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
102+ } ) ;
103+
56104 it ( 'Services table renders correct with right data' , ( ) => {
57105 const response = {
58106 postgresql : [
@@ -65,36 +113,92 @@ describe('Inventory tables', () => {
65113 } ,
66114 ] ,
67115 } ;
116+ const data = InventoryDataService . getServiceModel ( response as any ) ;
68117 const { container } = render (
69118 < Table
70- data = { InventoryDataService . getServiceModel ( response as any ) }
71- rowKey = { ( rec ) => rec . service_id }
119+ data = { data }
120+ totalItems = { data . length }
72121 columns = { SERVICES_COLUMNS }
73- loading = { false }
122+ pendingRequest = { false }
123+ rowSelection
124+ showPagination
125+ pageSize = { 25 }
74126 />
75127 ) ;
76128
77129 // length is 2 because header is also tr
78130 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 2 ) ;
79131 } ) ;
80132
133+ it ( 'Services table renders only first page' , async ( ) => {
134+ const response = {
135+ postgresql : new Array ( 100 ) . fill ( {
136+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
137+ service_name : 'pmm-server-postgresql' ,
138+ node_id : 'pmm-server' ,
139+ address : '127.0.0.1' ,
140+ port : 5432 ,
141+ } ) ,
142+ } ;
143+ const data = InventoryDataService . getServiceModel ( response as any ) ;
144+ const { container } = render (
145+ < Table
146+ data = { data }
147+ totalItems = { data . length }
148+ columns = { SERVICES_COLUMNS }
149+ pendingRequest = { false }
150+ rowSelection
151+ showPagination
152+ pageSize = { 25 }
153+ />
154+ ) ;
155+
156+ // default page size is 25
157+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
158+ } ) ;
159+
81160 it ( 'Nodes table renders correct with right data' , ( ) => {
82161 const response = {
83162 generic : [
84163 { node_id : 'pmm-server' , node_name : 'pmm-server' , address : '127.0.0.1' } ,
85164 { node_id : 'pmm-server2' , node_name : 'pmm-server2' , address : '127.0.0.1' } ,
86165 ] ,
87166 } ;
167+ const data = InventoryDataService . getNodeModel ( response as any ) ;
88168 const { container } = render (
89169 < Table
90- data = { InventoryDataService . getNodeModel ( response as any ) }
91- rowKey = { ( rec ) => rec . node_id }
170+ data = { data }
171+ totalItems = { data . length }
92172 columns = { NODES_COLUMNS }
93- loading = { false }
173+ pendingRequest = { false }
174+ rowSelection
175+ showPagination
176+ pageSize = { 25 }
94177 />
95178 ) ;
96179
97180 // length is 3 because header is also tr
98181 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 3 ) ;
99182 } ) ;
183+
184+ it ( 'Nodes table renders first page only' , async ( ) => {
185+ const response = {
186+ generic : new Array ( 100 ) . fill ( { node_id : 'pmm-server' , node_name : 'pmm-server' , address : '127.0.0.1' } ) ,
187+ } ;
188+ const data = InventoryDataService . getNodeModel ( response as any ) ;
189+ const { container } = render (
190+ < Table
191+ data = { data }
192+ totalItems = { data . length }
193+ columns = { NODES_COLUMNS }
194+ pendingRequest = { false }
195+ rowSelection
196+ showPagination
197+ pageSize = { 25 }
198+ />
199+ ) ;
200+
201+ // default page size is 25
202+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
203+ } ) ;
100204} ) ;
0 commit comments