-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/designsystem test #40
Open
valeriesauer
wants to merge
6
commits into
develop
Choose a base branch
from
feature/designsystem-test
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7364e3
implement background image, fixes, clean-ups
valeriesauer 6844f32
implement Designsystem
valeriesauer f0ab378
implement Designsystem
valeriesauer 6c154be
small adjustments of designsystem
valeriesauer 50507da
small adjustments of designsystem
valeriesauer a756428
small adjustments of designsystem
valeriesauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface ColorPalette { | ||
name: string; | ||
colors: { | ||
icon: string; | ||
text: string; | ||
line: string; | ||
}; | ||
style: { | ||
font: string; | ||
}; | ||
} | ||
|
||
export interface ColorPalettes { | ||
'color-palettes': ColorPalette[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ColorPaletteService } from './color-palette.service'; | ||
import { ColorPalette, ColorPalettes } from './color-palette.model'; | ||
import * as data from '../assets/color-palettes.json'; | ||
import { environment } from '../environments/environment'; | ||
|
||
describe('ColorPaletteService', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This service contains not only a color palette but also other CSS configuration elements. Please rename it. |
||
let service: ColorPaletteService; | ||
const mockPalettes: ColorPalettes = (data as any).default; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(ColorPaletteService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should load color palettes on initialization', () => { | ||
spyOn(console, 'log'); | ||
service = new ColorPaletteService(); | ||
expect(console.log).toHaveBeenCalledWith('loadColorPalettes method called'); | ||
expect(service['colorPalettes']).toEqual(jasmine.objectContaining(mockPalettes['color-palettes'].reduce((acc: { [key: string]: ColorPalette }, palette: ColorPalette) => { | ||
acc[palette.name] = palette; | ||
return acc; | ||
}, {}))); | ||
expect(console.log).toHaveBeenCalledWith('Color palettes loaded successfully:', service['colorPalettes']); | ||
}); | ||
|
||
it('should set palettesLoaded$ to true after loading palettes', () => { | ||
service = new ColorPaletteService(); | ||
expect(service.getPalettesLoadedStatus().getValue()).toBe(true); | ||
}); | ||
|
||
it('should select palette specified in environment configuration', () => { | ||
service = new ColorPaletteService(); | ||
const paletteName = environment.config.COLOR_PALETTE; | ||
expect(service.getSelectedPaletteName()).toBe(paletteName); | ||
}); | ||
|
||
it('should return font style of selected palette', () => { | ||
const mockPalette: ColorPalette = mockPalettes['color-palettes'][0]; | ||
service.selectPalette(mockPalette.name); | ||
expect(service.getFontStyle()).toBe(mockPalette.style.font); | ||
}); | ||
|
||
it('should return default color if no palette is selected when getting font style', () => { | ||
expect(service.getFontStyle()).toBe('defaultColor'); | ||
}); | ||
|
||
it('should return background color of selected palette', () => { | ||
const mockPalette: ColorPalette = mockPalettes['color-palettes'][0]; | ||
service.selectPalette(mockPalette.name); | ||
expect(service.getBackgroundColor()).toBe(mockPalette.colors.background); | ||
}); | ||
|
||
it('should return default color if no palette is selected when getting background color', () => { | ||
expect(service.getBackgroundColor()).toBe('defaultColor'); | ||
}); | ||
|
||
it('should return text color of selected palette', () => { | ||
const mockPalette: ColorPalette = mockPalettes['color-palettes'][0]; | ||
service.selectPalette(mockPalette.name); | ||
expect(service.getTextColor()).toBe(mockPalette.colors.text); | ||
}); | ||
|
||
it('should return default color if no palette is selected when getting text color', () => { | ||
expect(service.getTextColor()).toBe('defaultColor'); | ||
}); | ||
|
||
it('should return line color of selected palette', () => { | ||
const mockPalette: ColorPalette = mockPalettes['color-palettes'][0]; | ||
service.selectPalette(mockPalette.name); | ||
expect(service.getLineColor()).toBe(mockPalette.colors.line); | ||
}); | ||
|
||
it('should return default color if no palette is selected when getting line color', () => { | ||
expect(service.getLineColor()).toBe('defaultColor'); | ||
}); | ||
|
||
it('should return icon color of selected palette', () => { | ||
const mockPalette: ColorPalette = mockPalettes['color-palettes'][0]; | ||
service.selectPalette(mockPalette.name); | ||
expect(service.getIconColor()).toBe(mockPalette.colors.icon); | ||
}); | ||
|
||
it('should return default color if no palette is selected when getting icon color', () => { | ||
expect(service.getIconColor()).toBe('defaultColor'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { environment } from '../environments/environment'; | ||
import { ColorPalettes, ColorPalette } from './color-palette.model'; | ||
import * as localData from '../assets/color-palettes.json'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ColorPaletteService { | ||
|
||
private colorPalettes: { [key: string]: ColorPalette } = {}; | ||
private selectedPalette: ColorPalette | null = null; | ||
private palettesLoaded$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); | ||
|
||
constructor(private http: HttpClient) { | ||
this.loadColorPalettes(); | ||
} | ||
|
||
private loadColorPalettes(): void { | ||
const paletteConfig = environment.config.COLOR_PALETTE; | ||
|
||
if (this.isUrl(paletteConfig)) { | ||
// Farbpaletten vom Server laden | ||
this.http.get<ColorPalettes>(paletteConfig).subscribe( | ||
palettes => { | ||
this.processColorPalettes(palettes); | ||
// Der Name der Farbpalette ist im URL-Parameter enthalten | ||
const url = new URL(paletteConfig); | ||
const paletteName = url.hash.substring(1); | ||
this.selectPalette(paletteName); | ||
}, | ||
error => { | ||
console.error('Fehler beim Laden der Farbpaletten vom Server', error); | ||
this.palettesLoaded$.next(false); | ||
} | ||
); | ||
} else { | ||
// Lokale Farbpaletten laden | ||
this.loadLocalColorPalettes(paletteConfig); | ||
} | ||
} | ||
|
||
private isUrl(paletteConfig: string): boolean { | ||
try { | ||
new URL(paletteConfig); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
|
||
private loadLocalColorPalettes(paletteName: string): void { | ||
console.log('loadLocalColorPalettes method called'); // Vor dem Laden der Farbpaletten | ||
const palettes: ColorPalettes = (localData as any).default; | ||
this.processColorPalettes(palettes); | ||
this.selectPalette(paletteName); | ||
} | ||
|
||
private processColorPalettes(palettes: ColorPalettes): void { | ||
palettes['color-palettes'].forEach(palette => { | ||
this.colorPalettes[palette.name] = palette; | ||
}); | ||
console.log('Color palettes loaded successfully:', this.colorPalettes); // Nach dem Laden der Farbpaletten | ||
this.palettesLoaded$.next(true); | ||
} | ||
|
||
selectPalette(paletteName: string) { | ||
this.selectedPalette = this.colorPalettes[paletteName]; | ||
} | ||
|
||
getPalettesLoadedStatus(): BehaviorSubject<boolean> { | ||
return this.palettesLoaded$; | ||
} | ||
|
||
getSelectedPaletteName(): string | null { | ||
return this.selectedPalette ? this.selectedPalette.name : null; | ||
} | ||
|
||
getFontStyle(): string { | ||
if (!this.selectedPalette) { | ||
console.error('No palette selected.'); | ||
return 'defaultColor'; | ||
} | ||
return this.selectedPalette.style.font; | ||
} | ||
|
||
getTextColor(): string { | ||
if (!this.selectedPalette) { | ||
console.error('No palette selected.'); | ||
return 'defaultColor'; | ||
} | ||
return this.selectedPalette.colors.text; | ||
} | ||
|
||
getLineColor(): string { | ||
if (!this.selectedPalette) { | ||
console.error('No palette selected.'); | ||
return 'defaultColor'; | ||
} | ||
return this.selectedPalette.colors.line; | ||
} | ||
|
||
getIconColor(): string { | ||
if (!this.selectedPalette) { | ||
console.error('No palette selected.'); | ||
return 'defaultColor'; | ||
} | ||
return this.selectedPalette.colors.icon; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this?