forked from linode/manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseSummaryConnectionDetails.test.tsx
More file actions
154 lines (124 loc) · 4.37 KB
/
DatabaseSummaryConnectionDetails.test.tsx
File metadata and controls
154 lines (124 loc) · 4.37 KB
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
148
149
150
151
152
153
154
import { waitFor } from '@testing-library/react';
import React from 'react';
import { databaseFactory } from 'src/factories/databases';
import { renderWithTheme } from 'src/utilities/testHelpers';
import DatabaseSummaryConnectionDetails from './DatabaseSummaryConnectionDetails';
import type { Database } from '@linode/api-v4/lib/databases';
const AKMADMIN = 'akmadmin';
const POSTGRESQL = 'postgresql';
const DEFAULT_PRIMARY = 'db-mysql-default-primary.net';
const DEFAULT_STANDBY = 'db-mysql-default-standby.net';
const MYSQL = 'mysql';
const LINROOT = 'linroot';
const LEGACY_PRIMARY = 'db-mysql-legacy-primary.net';
const LEGACY_SECONDARY = 'db-mysql-legacy-secondary.net';
const queryMocks = vi.hoisted(() => ({
useDatabaseCredentialsQuery: vi.fn().mockReturnValue({}),
}));
vi.mock(import('src/queries/databases/databases'), async (importOriginal) => {
const actual = await importOriginal();
return {
...actual,
useDatabaseCredentialsQuery: queryMocks.useDatabaseCredentialsQuery,
};
});
describe('DatabaseSummaryConnectionDetails', () => {
it('should display correctly for default db', async () => {
queryMocks.useDatabaseCredentialsQuery.mockReturnValue({
data: {
password: 'abc123',
username: AKMADMIN,
},
});
const database = databaseFactory.build({
engine: POSTGRESQL,
hosts: {
primary: DEFAULT_PRIMARY,
secondary: undefined,
standby: DEFAULT_STANDBY,
},
id: 99,
platform: 'rdbms-default',
port: 22496,
ssl_connection: true,
}) as Database;
const { queryAllByText } = renderWithTheme(
<DatabaseSummaryConnectionDetails database={database} />
);
expect(queryMocks.useDatabaseCredentialsQuery).toHaveBeenCalledWith(
POSTGRESQL,
99
);
await waitFor(() => {
expect(queryAllByText('Username')).toHaveLength(1);
expect(queryAllByText(AKMADMIN)).toHaveLength(1);
expect(queryAllByText('Password')).toHaveLength(1);
expect(queryAllByText('Host')).toHaveLength(1);
expect(queryAllByText(DEFAULT_PRIMARY)).toHaveLength(1);
expect(queryAllByText('Read-only Host')).toHaveLength(1);
expect(queryAllByText(DEFAULT_STANDBY)).toHaveLength(1);
expect(queryAllByText('Port')).toHaveLength(1);
expect(queryAllByText('22496')).toHaveLength(1);
expect(queryAllByText('SSL')).toHaveLength(1);
expect(queryAllByText('ENABLED')).toHaveLength(1);
});
});
it('should display N/A for default DB with blank read-only Host field', async () => {
const database = databaseFactory.build({
engine: POSTGRESQL,
hosts: {
primary: DEFAULT_PRIMARY,
secondary: undefined,
standby: undefined,
},
id: 99,
platform: 'rdbms-default',
port: 22496,
ssl_connection: true,
});
const { queryAllByText } = renderWithTheme(
<DatabaseSummaryConnectionDetails database={database} />
);
expect(queryAllByText('N/A')).toHaveLength(1);
});
it('should display correctly for legacy db', async () => {
queryMocks.useDatabaseCredentialsQuery.mockReturnValue({
data: {
password: 'abc123',
username: LINROOT,
},
});
const database = databaseFactory.build({
engine: MYSQL,
hosts: {
primary: LEGACY_PRIMARY,
secondary: LEGACY_SECONDARY,
standby: undefined,
},
id: 22,
platform: 'rdbms-legacy',
port: 3306,
ssl_connection: true,
}) as Database;
const { queryAllByText } = renderWithTheme(
<DatabaseSummaryConnectionDetails database={database} />
);
expect(queryMocks.useDatabaseCredentialsQuery).toHaveBeenCalledWith(
MYSQL,
22
);
await waitFor(() => {
expect(queryAllByText('Username')).toHaveLength(1);
expect(queryAllByText(LINROOT)).toHaveLength(1);
expect(queryAllByText('Password')).toHaveLength(1);
expect(queryAllByText('Host')).toHaveLength(1);
expect(queryAllByText(LEGACY_PRIMARY)).toHaveLength(1);
expect(queryAllByText('Private Network Host')).toHaveLength(1);
expect(queryAllByText(LEGACY_SECONDARY)).toHaveLength(1);
expect(queryAllByText('Port')).toHaveLength(1);
expect(queryAllByText('3306')).toHaveLength(1);
expect(queryAllByText('SSL')).toHaveLength(1);
expect(queryAllByText('ENABLED')).toHaveLength(1);
});
});
});