@@ -8,6 +8,8 @@ import { renderWithTheme } from 'src/utilities/testHelpers';
88
99import { ServiceURI } from './ServiceURI' ;
1010
11+ import type { DatabaseStatus } from '@linode/api-v4' ;
12+
1113const mockCredentials = {
1214 password : 'password123' ,
1315 username : 'lnroot' ,
@@ -163,11 +165,12 @@ vi.mock('@linode/queries', async () => {
163165} ) ;
164166
165167describe ( 'ServiceURI' , ( ) => {
166- it ( 'should render the service URI component and copy icon' , async ( ) => {
167- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
168- data : mockCredentials ,
169- } ) ;
168+ queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
169+ data : mockCredentials ,
170+ refetch : vi . fn ( ) ,
171+ } ) ;
170172
173+ it ( 'should render the service URI component and copy icon' , async ( ) => {
171174 const { container } = renderWithTheme (
172175 < ServiceURI database = { databaseWithNoVPC } />
173176 ) ;
@@ -188,11 +191,6 @@ describe('ServiceURI', () => {
188191 } ) ;
189192
190193 it ( 'should reveal password after clicking reveal button' , async ( ) => {
191- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
192- data : mockCredentials ,
193- refetch : vi . fn ( ) ,
194- } ) ;
195-
196194 renderWithTheme ( < ServiceURI database = { databaseWithNoVPC } /> ) ;
197195
198196 const revealPasswordBtn = screen . getByRole ( 'button' , {
@@ -208,10 +206,6 @@ describe('ServiceURI', () => {
208206 } ) ;
209207
210208 it ( 'should render general service URI if isGeneralServiceURI is true' , ( ) => {
211- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
212- data : mockCredentials ,
213- } ) ;
214-
215209 renderWithTheme (
216210 < ServiceURI database = { databaseWithNoVPC } isGeneralServiceURI />
217211 ) ;
@@ -228,10 +222,6 @@ describe('ServiceURI', () => {
228222 } ) ;
229223
230224 it ( 'should reveal general service URI password after clicking reveal button' , async ( ) => {
231- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
232- data : mockCredentials ,
233- refetch : vi . fn ( ) ,
234- } ) ;
235225 renderWithTheme (
236226 < ServiceURI database = { databaseWithNoVPC } isGeneralServiceURI />
237227 ) ;
@@ -249,10 +239,6 @@ describe('ServiceURI', () => {
249239 } ) ;
250240
251241 it ( 'should render private service URI component if there is a private-only VPC' , async ( ) => {
252- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
253- data : mockCredentials ,
254- } ) ;
255-
256242 renderWithTheme ( < ServiceURI database = { databaseWithPrivateVPC } /> ) ;
257243
258244 const revealPasswordBtn = screen . getByRole ( 'button' , {
@@ -267,10 +253,6 @@ describe('ServiceURI', () => {
267253 } ) ;
268254
269255 it ( 'should render private general service URI component if there is a private-only VPC' , async ( ) => {
270- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
271- data : mockCredentials ,
272- } ) ;
273-
274256 renderWithTheme (
275257 < ServiceURI database = { databaseWithPrivateVPC } isGeneralServiceURI />
276258 ) ;
@@ -287,10 +269,6 @@ describe('ServiceURI', () => {
287269 } ) ;
288270
289271 it ( 'should render public service URI component if there is a VPC with public access' , async ( ) => {
290- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
291- data : mockCredentials ,
292- } ) ;
293-
294272 renderWithTheme ( < ServiceURI database = { databaseWithPublicVPC } /> ) ;
295273
296274 const revealPasswordBtn = screen . getByRole ( 'button' , {
@@ -305,10 +283,6 @@ describe('ServiceURI', () => {
305283 } ) ;
306284
307285 it ( 'should render private service URI component if there is a VPC with public access and showPrivateVPC is true' , async ( ) => {
308- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
309- data : mockCredentials ,
310- } ) ;
311-
312286 renderWithTheme (
313287 < ServiceURI database = { databaseWithPublicVPC } showPrivateVPC />
314288 ) ;
@@ -325,10 +299,6 @@ describe('ServiceURI', () => {
325299 } ) ;
326300
327301 it ( 'should render general private service URI if there is a VPC with public access, isGeneralServiceURI is true, and showPrivateVPC is true' , ( ) => {
328- queryMocks . useDatabaseCredentialsQuery . mockReturnValue ( {
329- data : mockCredentials ,
330- } ) ;
331-
332302 renderWithTheme (
333303 < ServiceURI
334304 database = { databaseWithPublicVPC }
@@ -347,4 +317,23 @@ describe('ServiceURI', () => {
347317 `postgres://{click to reveal password}@${ PRIVATE_PRIMARY } :3306/defaultdb?sslmode=require`
348318 ) ;
349319 } ) ;
320+
321+ it ( 'should disable the reveal password and copy icon if the Database is suspended' , async ( ) => {
322+ const mockDatabase = {
323+ ...databaseWithNoVPC ,
324+ status : 'suspended' as DatabaseStatus ,
325+ } ;
326+
327+ const { container } = renderWithTheme (
328+ < ServiceURI database = { mockDatabase } />
329+ ) ;
330+
331+ const revealPasswordBtn = screen . getByRole ( 'button' , {
332+ name : '{click to reveal password}' ,
333+ } ) ;
334+ // eslint-disable-next-line testing-library/no-container
335+ const copyButton = container . querySelector ( '[data-qa-copy-btn]' ) ;
336+ expect ( revealPasswordBtn ) . toBeDisabled ( ) ;
337+ expect ( copyButton ) . toBeDisabled ( ) ;
338+ } ) ;
350339} ) ;
0 commit comments