1
1
import React from 'react'
2
2
import { cleanup , render , screen } from 'uiSrc/utils/test-utils'
3
- import { indexInfoTableDataFactory } from 'uiSrc/mocks/factories/redisearch/IndexInfoTableData.factory'
3
+ import {
4
+ indexInfoAttributeFactory ,
5
+ indexInfoFactory ,
6
+ } from 'uiSrc/mocks/factories/redisearch/IndexInfo.factory'
4
7
import {
5
8
IndexAttributesList ,
6
9
IndexAttributesListProps ,
7
10
} from './IndexAttributesList'
8
11
9
12
const renderComponent = ( props ?: Partial < IndexAttributesListProps > ) => {
10
13
const defaultProps : IndexAttributesListProps = {
11
- data : indexInfoTableDataFactory . buildList ( 3 ) ,
14
+ indexInfo : indexInfoFactory . build ( ) ,
12
15
}
13
16
14
17
return render ( < IndexAttributesList { ...defaultProps } { ...props } /> )
@@ -21,12 +24,41 @@ describe('IndexAttributesList', () => {
21
24
22
25
it ( 'should render' , ( ) => {
23
26
const props : IndexAttributesListProps = {
24
- data : [
25
- indexInfoTableDataFactory . build (
26
- { } ,
27
- { transient : { includeWeight : true , includeSeparator : true } } ,
28
- ) ,
29
- ] ,
27
+ indexInfo : indexInfoFactory . build ( ) ,
28
+ }
29
+
30
+ const { container } = renderComponent ( props )
31
+ expect ( container ) . toBeTruthy ( )
32
+
33
+ const list = screen . getByTestId ( 'index-attributes-list' )
34
+ expect ( list ) . toBeInTheDocument ( )
35
+
36
+ const table = screen . getByTestId ( 'index-attributes-list--table' )
37
+ const summaryInfo = screen . getByTestId (
38
+ 'index-attributes-list--summary-info' ,
39
+ )
40
+
41
+ expect ( table ) . toBeInTheDocument ( )
42
+ expect ( summaryInfo ) . toBeInTheDocument ( )
43
+ } )
44
+
45
+ it ( 'should render loader when index info is not provided' , ( ) => {
46
+ renderComponent ( { indexInfo : undefined } )
47
+
48
+ const loader = screen . getByTestId ( 'index-attributes-list--loader' )
49
+ expect ( loader ) . toBeInTheDocument ( )
50
+ } )
51
+
52
+ it ( 'should render index attributes in the table' , ( ) => {
53
+ const mockIndexAttribute = indexInfoAttributeFactory . build (
54
+ { } ,
55
+ { transient : { includeWeight : true , includeNoIndex : true } } ,
56
+ )
57
+
58
+ const props : IndexAttributesListProps = {
59
+ indexInfo : indexInfoFactory . build ( {
60
+ attributes : [ mockIndexAttribute ] ,
61
+ } ) ,
30
62
}
31
63
32
64
const { container } = renderComponent ( props )
@@ -36,14 +68,67 @@ describe('IndexAttributesList', () => {
36
68
expect ( list ) . toBeInTheDocument ( )
37
69
38
70
// Verify data is rendered correctly
39
- const attribute = screen . getByText ( props . data [ 0 ] . attribute )
40
- const type = screen . getByText ( props . data [ 0 ] . type )
41
- const weight = screen . getByText ( props . data [ 0 ] . weight ! )
42
- const separator = screen . getByText ( props . data [ 0 ] . separator ! )
71
+ const identifier = screen . getByText ( mockIndexAttribute . identifier )
72
+ const attribute = screen . getByText ( mockIndexAttribute . attribute )
73
+ const type = screen . getByText ( mockIndexAttribute . type )
74
+ const weight = screen . getByText ( mockIndexAttribute . WEIGHT ! )
75
+ const noIndex = screen . getByTestId ( 'index-attributes-list--noindex-icon' )
43
76
77
+ expect ( identifier ) . toBeInTheDocument ( )
44
78
expect ( attribute ) . toBeInTheDocument ( )
45
79
expect ( type ) . toBeInTheDocument ( )
46
80
expect ( weight ) . toBeInTheDocument ( )
47
- expect ( separator ) . toBeInTheDocument ( )
81
+ expect ( noIndex ) . toBeInTheDocument ( )
82
+ expect ( noIndex ) . toHaveAttribute (
83
+ 'data-attribute' ,
84
+ mockIndexAttribute . NOINDEX ?. toString ( ) ,
85
+ )
86
+ } )
87
+
88
+ it ( 'should display index summary info' , ( ) => {
89
+ const mockIndexInfo = indexInfoFactory . build ( )
90
+
91
+ const props : IndexAttributesListProps = {
92
+ indexInfo : mockIndexInfo ,
93
+ }
94
+
95
+ renderComponent ( props )
96
+
97
+ const summaryInfo = screen . getByTestId (
98
+ 'index-attributes-list--summary-info' ,
99
+ )
100
+ expect ( summaryInfo ) . toBeInTheDocument ( )
101
+
102
+ // Verify Number of documents
103
+ const numberOfDocumentLabel = screen . getByText ( / N u m b e r o f d o c s : / )
104
+ const numberOfDocumentValue = screen . getByText (
105
+ new RegExp ( mockIndexInfo . num_docs ) ,
106
+ )
107
+ expect ( numberOfDocumentLabel ) . toBeInTheDocument ( )
108
+ expect ( numberOfDocumentValue ) . toBeInTheDocument ( )
109
+
110
+ // Verify Max document ID
111
+ const maxDocumentIdLabel = screen . getByText ( / m a x / )
112
+ const maxDocumentIdValue = screen . getByText (
113
+ new RegExp ( mockIndexInfo . max_doc_id ! ) ,
114
+ )
115
+ expect ( maxDocumentIdLabel ) . toBeInTheDocument ( )
116
+ expect ( maxDocumentIdValue ) . toBeInTheDocument ( )
117
+
118
+ // Verify Number of records
119
+ const numberOfRecordsLabel = screen . getByText ( / N u m b e r o f r e c o r d s : / )
120
+ const numberOfRecordsValue = screen . getByText (
121
+ new RegExp ( mockIndexInfo . num_records ! ) ,
122
+ )
123
+ expect ( numberOfRecordsLabel ) . toBeInTheDocument ( )
124
+ expect ( numberOfRecordsValue ) . toBeInTheDocument ( )
125
+
126
+ // Verify Number of terms
127
+ const numberOfTermsLabel = screen . getByText ( / N u m b e r o f t e r m s : / )
128
+ const numberOfTermsValue = screen . getByText (
129
+ new RegExp ( mockIndexInfo . num_terms ! ) ,
130
+ )
131
+ expect ( numberOfTermsLabel ) . toBeInTheDocument ( )
132
+ expect ( numberOfTermsValue ) . toBeInTheDocument ( )
48
133
} )
49
134
} )
0 commit comments