go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/components/user/login_status.test.tsx (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { render, screen } from '@testing-library/react'; 16 17 import { ANONYMOUS_IDENTITY } from '@/common/api/auth_state'; 18 import { FakeContextProvider } from '@/testing_tools/fakes/fake_context_provider'; 19 20 import { LoginStatus } from './login_status'; 21 22 describe('LoginStatus', () => { 23 it('given no identity or anonymouse identity, should display login button', async () => { 24 const { rerender } = render( 25 <FakeContextProvider> 26 <LoginStatus /> 27 </FakeContextProvider>, 28 ); 29 expect(screen.getByText('Login')).toBeInTheDocument(); 30 31 rerender( 32 <FakeContextProvider> 33 <LoginStatus identity={ANONYMOUS_IDENTITY} /> 34 </FakeContextProvider>, 35 ); 36 expect(screen.getByText('Login')).toBeInTheDocument(); 37 }); 38 39 it('given an identity, should display email and logout button', async () => { 40 render( 41 <FakeContextProvider> 42 <LoginStatus 43 email="googler@google.com" 44 identity="id:123456" 45 picture="avatar_url" 46 /> 47 </FakeContextProvider>, 48 ); 49 expect(screen.getByText('googler@google.com')).toBeInTheDocument(); 50 expect(screen.getByLabelText('avatar')).toBeInTheDocument(); 51 expect(screen.getByLabelText('Logout button')).toBeInTheDocument(); 52 }); 53 });