-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathindex.spec.tsx
147 lines (124 loc) · 3.56 KB
/
index.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React from 'react';
import {
render,
screen,
cleanup,
userEvent,
} from '@mongodb-js/testing-library-compass';
import { expect } from 'chai';
import { DatabasesList, CollectionsList } from './index';
import Sinon from 'sinon';
function createDatabase(name) {
return {
_id: name,
name: name,
status: 'ready' as const,
storage_size: 0,
data_size: 0,
index_count: 0,
collectionsLength: 0,
};
}
function createCollection(name) {
return {
_id: name,
name: name,
type: 'collection' as const,
status: 'ready' as const,
document_count: 0,
document_size: 0,
avg_document_size: 0,
storage_size: 0,
free_storage_size: 0,
index_count: 0,
index_size: 0,
properties: [],
};
}
function createTimeSeries(name) {
return {
_id: name,
name: name,
type: 'timeseries' as const,
status: 'ready' as const,
document_count: 0,
document_size: 0,
avg_document_size: 0,
storage_size: 0,
free_storage_size: 0,
index_count: 0,
index_size: 0,
properties: [],
};
}
const dbs = [
createDatabase('foo'),
createDatabase('bar'),
createDatabase('buz'),
createDatabase('bat'),
];
const colls = [
createCollection('foo.foo'),
createCollection('bar.bar'),
createCollection('buz.buz'),
createTimeSeries('bat.bat'),
];
describe('databases and collections list', function () {
describe('DatabasesList', function () {
afterEach(cleanup);
it('should render databases in a list', function () {
const clickSpy = Sinon.spy();
render(
<DatabasesList
databases={dbs}
onDatabaseClick={clickSpy}
></DatabasesList>
);
expect(screen.getByTestId('database-grid')).to.exist;
expect(screen.getAllByTestId('database-grid-item')).to.have.lengthOf(4);
expect(screen.getByText('foo')).to.exist;
expect(screen.getByText('bar')).to.exist;
expect(screen.getByText('buz')).to.exist;
userEvent.click(screen.getByText('foo'));
expect(clickSpy).to.be.calledWith('foo');
});
});
describe('CollectionsList', function () {
afterEach(cleanup);
it('should render collections in a list', function () {
const clickSpy = Sinon.spy();
render(
<CollectionsList
namespace="db"
collections={colls}
onCollectionClick={clickSpy}
></CollectionsList>
);
expect(screen.getByTestId('collection-grid')).to.exist;
expect(screen.getAllByTestId('collection-grid-item')).to.have.lengthOf(4);
expect(screen.getByText('foo.foo')).to.exist;
expect(screen.getByText('bar.bar')).to.exist;
expect(screen.getByText('buz.buz')).to.exist;
userEvent.click(screen.getByText('bar.bar'));
expect(clickSpy).to.be.calledWith('bar.bar');
});
it('should not display statistics (except storage size) on timeseries collection card', function () {
render(
<CollectionsList
namespace="db"
collections={colls}
onCollectionClick={() => {}}
></CollectionsList>
);
const timeseriesCard = screen
.getByText('bat.bat')
.closest('[data-testid="collection-grid-item"]');
expect(timeseriesCard).to.exist;
expect(timeseriesCard).to.contain.text('Storage size:');
expect(timeseriesCard).to.not.contain.text('Documents:');
expect(timeseriesCard).to.not.contain.text('Avg. document size::');
expect(timeseriesCard).to.not.contain.text('Indexes:');
expect(timeseriesCard).to.not.contain.text('Total index size:');
});
});
});