From 6857ff528f944aa9ef55abd1f5533c8fc60aba23 Mon Sep 17 00:00:00 2001 From: Lisa Kim Date: Thu, 7 Nov 2024 12:04:24 -0800 Subject: [PATCH] Web: attempt state with AddApp component (#48615) --- .../src/Apps/AddApp/Manually.test.tsx | 110 ++++++++++++++++++ .../teleport/src/Apps/AddApp/Manually.tsx | 5 +- 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 web/packages/teleport/src/Apps/AddApp/Manually.test.tsx diff --git a/web/packages/teleport/src/Apps/AddApp/Manually.test.tsx b/web/packages/teleport/src/Apps/AddApp/Manually.test.tsx new file mode 100644 index 0000000000000..c7d9ca011ee1c --- /dev/null +++ b/web/packages/teleport/src/Apps/AddApp/Manually.test.tsx @@ -0,0 +1,110 @@ +/** + * Teleport + * Copyright (C) 2023 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React from 'react'; +import { render, screen } from 'design/utils/testing'; + +import { Manually } from './Manually'; + +test('loading state renders', async () => { + const token = { + id: 'token', + expiryText: '', + expiry: null, + safeName: '', + isStatic: false, + method: 'kubernetes', + roles: [], + content: '', + }; + render( + {}} + createToken={() => null} + /> + ); + + await screen.findByTestId('indicator'); + expect(screen.queryByText(/step 1/i)).not.toBeInTheDocument(); +}); + +test('success state renders', async () => { + const token = { + id: 'token', + expiryText: '', + expiry: null, + safeName: '', + isStatic: false, + method: 'kubernetes', + roles: [], + content: '', + }; + render( + {}} + createToken={() => null} + /> + ); + + expect(screen.getByText(/step 1/i)).toBeInTheDocument(); + expect(screen.getByText(/token will be valid for/i)).toBeInTheDocument(); + expect(screen.queryByText(/generate a join token/i)).not.toBeInTheDocument(); +}); + +test('failed state renders', async () => { + const token = { + id: 'token', + expiryText: '', + expiry: null, + safeName: '', + isStatic: false, + method: 'kubernetes', + roles: [], + content: '', + }; + render( + {}} + createToken={() => null} + /> + ); + + expect(screen.getByText(/step 1/i)).toBeInTheDocument(); + expect(screen.getByText(/generate a join token/i)).toBeInTheDocument(); + expect( + screen.queryByText(/token will be valid for/i) + ).not.toBeInTheDocument(); +}); diff --git a/web/packages/teleport/src/Apps/AddApp/Manually.tsx b/web/packages/teleport/src/Apps/AddApp/Manually.tsx index 95890a2817790..da48610baf801 100644 --- a/web/packages/teleport/src/Apps/AddApp/Manually.tsx +++ b/web/packages/teleport/src/Apps/AddApp/Manually.tsx @@ -69,9 +69,10 @@ export function Manually({ - Download Teleport package to your computer - {attempt.status === 'failed' ? ( + {attempt.status === 'failed' && ( - ) : ( + )} + {attempt.status === 'success' && ( )}