1- import { render } from '@testing-library/react' ;
1+ /* eslint-disable @typescript-eslint/no-explicit-any */
2+ import { Table } from '@percona/platform-core' ;
3+ import { render , waitFor } from '@testing-library/react' ;
24import React from 'react' ;
35
4- import { Table } from 'app/percona/shared/components/Elements/Table/Table' ;
5-
66import { AGENTS_COLUMNS , NODES_COLUMNS , SERVICES_COLUMNS } from './Inventory.constants' ;
77import { InventoryDataService } from './Inventory.tools' ;
88
9- jest . mock ( 'app/percona/settings /Settings.service' ) ;
9+ jest . mock ( 'app/percona/settingsz /Settings.service' ) ;
1010
1111// FIXME: types
1212describe ( 'Inventory tables' , ( ) => {
@@ -41,20 +41,68 @@ describe('Inventory tables', () => {
4141 } ,
4242 ] ,
4343 } ;
44+ const data = InventoryDataService . getAgentModel ( response as any ) ;
4445
4546 const { container } = render (
4647 < Table
47- data = { InventoryDataService . getAgentModel ( response as any ) }
48- rowKey = { ( rec ) => rec . agent_id }
48+ data = { data }
49+ totalItems = { data . length }
50+ rowSelection
4951 columns = { AGENTS_COLUMNS }
50- loading = { false }
52+ pendingRequest = { false }
53+ showPagination
54+ pageSize = { 25 }
5155 />
5256 ) ;
5357
5458 // length is 5 because header is also tr
5559 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 5 ) ;
5660 } ) ;
5761
62+ it ( 'Agents table only first page' , async ( ) => {
63+ const response = {
64+ pmm_agent : [ { agent_id : 'pmm-server' , runs_on_node_id : 'pmm-server' , connected : true } ] ,
65+ node_exporter : new Array ( 50 ) . fill ( {
66+ agent_id : '/agent_id/262189d8-e10f-41c2-b0ae-73cc76be6968' ,
67+ pmm_agent_id : 'pmm-server' ,
68+ status : 'RUNNING' ,
69+ listen_port : 42000 ,
70+ } ) ,
71+ postgres_exporter : new Array ( 50 ) . fill ( {
72+ agent_id : '/agent_id/8b74c54e-4307-4a10-9a6f-1646215cbe07' ,
73+ pmm_agent_id : 'pmm-server' ,
74+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
75+ username : 'pmm-managed' ,
76+ status : 'RUNNING' ,
77+ listen_port : 42001 ,
78+ } ) ,
79+
80+ qan_postgresql_pgstatements_agent : new Array ( 50 ) . fill ( {
81+ agent_id : '/agent_id/ac55153c-5211-4072-a5de-59eb2a136a5c' ,
82+ pmm_agent_id : 'pmm-server' ,
83+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
84+ username : 'pmm-managed' ,
85+ status : 'RUNNING' ,
86+ } ) ,
87+ } ;
88+ const data = InventoryDataService . getAgentModel ( response as any ) ;
89+
90+ const { container } = render (
91+ < Table
92+ data = { data }
93+ totalItems = { data . length }
94+ rowSelection
95+ columns = { AGENTS_COLUMNS }
96+ pendingRequest = { false }
97+ showPagination
98+ pageSize = { 25 }
99+ />
100+ ) ;
101+
102+ // default page size is 25
103+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
104+ } ) ;
105+
58106 it ( 'Services table renders correct with right data' , ( ) => {
59107 const response = {
60108 postgresql : [
@@ -67,36 +115,92 @@ describe('Inventory tables', () => {
67115 } ,
68116 ] ,
69117 } ;
118+ const data = InventoryDataService . getServiceModel ( response as any ) ;
70119 const { container } = render (
71120 < Table
72- data = { InventoryDataService . getServiceModel ( response as any ) }
73- rowKey = { ( rec ) => rec . service_id }
121+ data = { data }
122+ totalItems = { data . length }
74123 columns = { SERVICES_COLUMNS }
75- loading = { false }
124+ pendingRequest = { false }
125+ rowSelection
126+ showPagination
127+ pageSize = { 25 }
76128 />
77129 ) ;
78130
79131 // length is 2 because header is also tr
80132 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 2 ) ;
81133 } ) ;
82134
135+ it ( 'Services table renders only first page' , async ( ) => {
136+ const response = {
137+ postgresql : new Array ( 100 ) . fill ( {
138+ service_id : '/service_id/ab477624-4ee9-49cd-8bd4-9bf3b91628b2' ,
139+ service_name : 'pmm-server-postgresql' ,
140+ node_id : 'pmm-server' ,
141+ address : '127.0.0.1' ,
142+ port : 5432 ,
143+ } ) ,
144+ } ;
145+ const data = InventoryDataService . getServiceModel ( response as any ) ;
146+ const { container } = render (
147+ < Table
148+ data = { data }
149+ totalItems = { data . length }
150+ columns = { SERVICES_COLUMNS }
151+ pendingRequest = { false }
152+ rowSelection
153+ showPagination
154+ pageSize = { 25 }
155+ />
156+ ) ;
157+
158+ // default page size is 25
159+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
160+ } ) ;
161+
83162 it ( 'Nodes table renders correct with right data' , ( ) => {
84163 const response = {
85164 generic : [
86165 { node_id : 'pmm-server' , node_name : 'pmm-server' , address : '127.0.0.1' } ,
87166 { node_id : 'pmm-server2' , node_name : 'pmm-server2' , address : '127.0.0.1' } ,
88167 ] ,
89168 } ;
169+ const data = InventoryDataService . getNodeModel ( response as any ) ;
90170 const { container } = render (
91171 < Table
92- data = { InventoryDataService . getNodeModel ( response as any ) }
93- rowKey = { ( rec ) => rec . node_id }
172+ data = { data }
173+ totalItems = { data . length }
94174 columns = { NODES_COLUMNS }
95- loading = { false }
175+ pendingRequest = { false }
176+ rowSelection
177+ showPagination
178+ pageSize = { 25 }
96179 />
97180 ) ;
98181
99182 // length is 3 because header is also tr
100183 expect ( container . querySelectorAll ( 'tr' ) ) . toHaveLength ( 3 ) ;
101184 } ) ;
185+
186+ it ( 'Nodes table renders first page only' , async ( ) => {
187+ const response = {
188+ generic : new Array ( 100 ) . fill ( { node_id : 'pmm-server' , node_name : 'pmm-server' , address : '127.0.0.1' } ) ,
189+ } ;
190+ const data = InventoryDataService . getNodeModel ( response as any ) ;
191+ const { container } = render (
192+ < Table
193+ data = { data }
194+ totalItems = { data . length }
195+ columns = { NODES_COLUMNS }
196+ pendingRequest = { false }
197+ rowSelection
198+ showPagination
199+ pageSize = { 25 }
200+ />
201+ ) ;
202+
203+ // default page size is 25
204+ await waitFor ( ( ) => expect ( container . querySelectorAll ( 'tbody tr' ) ) . toHaveLength ( 25 ) ) ;
205+ } ) ;
102206} ) ;
0 commit comments