blob: 8c83dee3ad377fb2eef69fc7af22295275bb2b0c [file]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { createSpyObj, SpyObj } from '../../../testing/mocks';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CacheComponent } from './cache.component';
import { CacheService } from '../../../api';
import { of } from 'rxjs';
import { provideTranslateTesting } from '../../../testing/i18n-testing';
import { provideNoopAnimations } from '@angular/platform-browser/animations';
describe('CacheComponent', () => {
let component: CacheComponent;
let fixture: ComponentFixture<CacheComponent>;
let serviceSpy: SpyObj<CacheService>;
beforeEach(async () => {
serviceSpy = createSpyObj(['getCaches', 'putCaches']);
serviceSpy.getCaches.mockReturnValue(
of([
{ cacheType: { id: 1, value: 'No Cache' }, enabled: false },
{ cacheType: { id: 2, value: 'Single Node' }, enabled: true },
]) as unknown as ReturnType<CacheService['getCaches']>,
);
await TestBed.configureTestingModule({
imports: [CacheComponent],
providers: [
...provideTranslateTesting(),
{ provide: CacheService, useValue: serviceSpy },
provideNoopAnimations(),
],
}).compileComponents();
fixture = TestBed.createComponent(CacheComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should select the enabled cache on load', () => {
expect(component.caches()).toHaveLength(2);
expect(component.selectedCacheType()).toBe(2);
});
it('should put the selected cache type on save', () => {
serviceSpy.putCaches.mockReturnValue(
of({}) as unknown as ReturnType<CacheService['putCaches']>,
);
component.selectedCacheType.set(1);
component.onSave();
expect(serviceSpy.putCaches).toHaveBeenCalledWith({ cacheType: 1 });
});
});