|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 19 | +import { By } from '@angular/platform-browser'; |
| 20 | +import { CustomLogoComponent } from './custom-logo.component'; |
| 21 | +import {RuntimeConfigUtil} from '../../../utils/runtime-config-util'; |
| 22 | + |
| 23 | +describe('CustomLogoComponent', () => { |
| 24 | + let component: CustomLogoComponent; |
| 25 | + let fixture: ComponentFixture<CustomLogoComponent>; |
| 26 | + |
| 27 | + const setupTest = (logoConfig: any) => { |
| 28 | + spyOn(RuntimeConfigUtil, 'getRuntimeConfig').and.returnValue({ |
| 29 | + logo: logoConfig, |
| 30 | + } as any); |
| 31 | + |
| 32 | + TestBed.configureTestingModule({ |
| 33 | + imports: [CustomLogoComponent], |
| 34 | + }).compileComponents(); |
| 35 | + |
| 36 | + fixture = TestBed.createComponent(CustomLogoComponent); |
| 37 | + component = fixture.componentInstance; |
| 38 | + fixture.detectChanges(); |
| 39 | + }; |
| 40 | + |
| 41 | + describe('with valid logo config', () => { |
| 42 | + beforeEach(() => { |
| 43 | + setupTest({ imageUrl: 'test.png', text: 'Test Logo' }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should render the logo and text', () => { |
| 47 | + const linkElement = fixture.debugElement.query(By.css('a')); |
| 48 | + const imgElement = fixture.debugElement.query(By.css('img')); |
| 49 | + |
| 50 | + expect(imgElement.nativeElement.src).toContain('test.png'); |
| 51 | + expect(linkElement.nativeElement.textContent).toContain('Test Logo'); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + describe('with invalid logo config', () => { |
| 56 | + it('should show an error if imageUrl is missing', () => { |
| 57 | + setupTest({ text: 'Test Logo' }); |
| 58 | + const errorElement = fixture.debugElement.query(By.css('div')); |
| 59 | + |
| 60 | + expect(errorElement.nativeElement.textContent).toContain( |
| 61 | + 'Invalid custom logo config' |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should show an error if text is missing', () => { |
| 66 | + setupTest({ imageUrl: 'test.png' }); |
| 67 | + const errorElement = fixture.debugElement.query(By.css('div')); |
| 68 | + |
| 69 | + expect(errorElement.nativeElement.textContent).toContain( |
| 70 | + 'Invalid custom logo config' |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should show an error if logoConfig is missing', () => { |
| 75 | + setupTest(undefined); |
| 76 | + const errorElement = fixture.debugElement.query(By.css('div')); |
| 77 | + |
| 78 | + expect(errorElement.nativeElement.textContent).toContain( |
| 79 | + 'Invalid custom logo config' |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
0 commit comments