1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { RgwTopicDetailsComponent } from './rgw-topic-details.component';
3 import { TopicDetails } from '~/app/shared/models/topic.model';
5 interface Destination {
7 push_endpoint_args: string;
8 push_endpoint_topic: string;
11 persistent_queue: string;
14 retry_sleep_duration: number;
17 const mockDestination: Destination = {
18 push_endpoint: 'http://localhost:8080',
19 push_endpoint_args: 'args',
20 push_endpoint_topic: 'topic',
21 stored_secret: 'secret',
23 persistent_queue: 'queue',
26 retry_sleep_duration: 10
29 describe('RgwTopicDetailsComponent', () => {
30 let component: RgwTopicDetailsComponent;
31 let fixture: ComponentFixture<RgwTopicDetailsComponent>;
33 beforeEach(async () => {
34 await TestBed.configureTestingModule({
35 declarations: [RgwTopicDetailsComponent]
36 }).compileComponents();
38 fixture = TestBed.createComponent(RgwTopicDetailsComponent);
39 component = fixture.componentInstance;
40 fixture.detectChanges();
43 it('should create', () => {
44 expect(component).toBeTruthy();
47 it('should parse policy string correctly', () => {
48 const mockSelection: TopicDetails = {
52 dest: mockDestination,
53 policy: '{"key": "value"}',
54 opaqueData: 'test@12345',
55 subscribed_buckets: []
58 component.selection = mockSelection;
59 component.ngOnChanges({
61 currentValue: mockSelection,
64 isFirstChange: () => true
68 expect(component.policy).toEqual({ key: 'value' });
71 it('should set policy to empty object if policy is not a string', () => {
72 const mockSelection: TopicDetails = {
76 dest: mockDestination,
78 subscribed_buckets: [],
82 component.selection = mockSelection;
83 component.ngOnChanges({
85 currentValue: mockSelection,
88 isFirstChange: () => true
92 expect(component.policy).toEqual({});