import { HttpClientTestingModule } from '@angular/common/http/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import { FeatureTogglesService } from '~/app/shared/services/feature-toggles.service';
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
+ let featureTogglesService: FeatureTogglesService;
configureTestBed({
imports: [NgbNavModule, HttpClientTestingModule],
});
beforeEach(() => {
+ featureTogglesService = TestBed.inject(FeatureTogglesService);
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
- fixture.detectChanges();
});
it('should create', () => {
+ spyOn(featureTogglesService, 'isFeatureEnabled').and.returnValue(true);
+
+ fixture.detectChanges();
expect(component).toBeTruthy();
});
+
+ it('should call featureTogglesService.isFeatureEnabled() on initialization', () => {
+ const spy = spyOn(featureTogglesService, 'isFeatureEnabled').and.returnValue(true);
+ fixture.detectChanges();
+ expect(spy).toHaveBeenCalled();
+ expect(spy).toHaveBeenCalledWith('dashboard');
+ });
+
+ it('should set useDeprecated based on feature toggle', () => {
+ spyOn(featureTogglesService, 'isFeatureEnabled').and.returnValue(true);
+ fixture.detectChanges();
+ expect(component.useDeprecated).toBe(true);
+ });
+
+ describe('when dashboard feature is enabled (new dashboard)', () => {
+ beforeEach(() => {
+ spyOn(featureTogglesService, 'isFeatureEnabled').and.returnValue(true);
+ fixture.detectChanges();
+ });
+
+ it('should show cd-dashboard-v3 in template when dashboard feature is enabled', () => {
+ const overviewElement = fixture.debugElement.query(By.css('[data-testid="cd-overview"]'));
+ const dashboardV3Element = fixture.debugElement.query(
+ By.css('[data-testid="cd-dashboard-v3"]')
+ );
+
+ expect(overviewElement).toBeNull();
+ expect(dashboardV3Element).toBeTruthy();
+ });
+
+ it('should set useDeprecated to false when feature is enabled', () => {
+ expect(component.useDeprecated).toBe(true);
+ });
+ });
+
+ describe('when dashboard feature is disabled (old dashboard)', () => {
+ beforeEach(() => {
+ spyOn(featureTogglesService, 'isFeatureEnabled').and.returnValue(false);
+ fixture.detectChanges();
+ });
+
+ it('should show cd-overview in template when dashboard feature is disabled', () => {
+ const overviewElement = fixture.debugElement.query(By.css('[data-testid="cd-overview"]'));
+ const dashboardV3Element = fixture.debugElement.query(
+ By.css('[data-testid="cd-dashboard-v3"]')
+ );
+
+ expect(overviewElement).toBeTruthy();
+ expect(dashboardV3Element).toBeNull();
+ });
+
+ it('should set useDeprecated to true when feature is disabled', () => {
+ expect(component.useDeprecated).toBe(false);
+ });
+ });
});
--- /dev/null
+<div cdsGrid
+ [narrow]="true"
+ [condensed]="false"
+ [fullWidth]="true"
+ class="overview">
+ <div cdsRow
+ [narrow]="true"
+ class="overview-row">
+ <div cdsCol
+ [columnNumbers]="{md: 16, lg: 11}">
+ <cds-tile>Health card</cds-tile>
+ </div>
+ <div cdsCol
+ [columnNumbers]="{md: 16, lg: 5}">
+ <cds-tile>Alerts card</cds-tile>
+ </div>
+ </div>
+ <div cdsRow
+ [narrow]="true"
+ class="overview-row">
+ <div cdsCol
+ [columnNumbers]="{md: 16, lg: 11}">
+ <cds-tile>Storage card</cds-tile>
+ </div>
+ <div cdsCol
+ [columnNumbers]="{md: 16, lg: 5}">
+ <cds-tile>Docs card</cds-tile>
+ </div>
+ </div>
+ <div cdsRow>
+ <div cdsCol
+ [columnNumbers]="{md: 16, lg: 16}">
+ <cds-tile>Performance card</cds-tile>
+ </div>
+ </div>
+</div>
--- /dev/null
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { OverviewComponent } from './overview.component';
+
+describe('OverviewComponent', () => {
+ let component: OverviewComponent;
+ let fixture: ComponentFixture<OverviewComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ imports: [OverviewComponent]
+ }).compileComponents();
+
+ fixture = TestBed.createComponent(OverviewComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
# -*- coding: utf-8 -*-
from enum import Enum
-from typing import Dict, List, Optional, Set, no_type_check
+from typing import Dict, List, Optional, Set
import cherrypy
from mgr_module import CLICommand, Option
return ret, '\n'.join(msg), ''
return {'handle_command': cmd}
- @no_type_check # https://github.com/python/mypy/issues/7806
def _get_feature_from_request(self, request):
try:
return self.Controller2Feature[
return None
@ttl_cache(ttl=CACHE_TTL, maxsize=CACHE_MAX_SIZE)
- @no_type_check # https://github.com/python/mypy/issues/7806
def _is_feature_enabled(self, feature):
return self.mgr.get_module_option(self.OPTION_FMT.format(feature))