Commit 23bd9af4 authored by Shane Eckenrode's avatar Shane Eckenrode

Update style manager tests

parent 67a37a9e
Pipeline #78933 passed with stages
in 3 minutes and 54 seconds
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { inject, TestBed } from '@angular/core/testing';
import { StyleManager } from './style-manager';
import { StyleManager, STYLE_MANAGER_CONFIG } from './style-manager';
describe('StyleManager', () => {
let styleManager: StyleManager;
......@@ -8,7 +8,17 @@ describe('StyleManager', () => {
beforeEach(() =>
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [StyleManager]
providers: [
StyleManager,
{
provide: STYLE_MANAGER_CONFIG,
useValue: [
{ name: 'default', primary: '#ffffff', isDark: false, isDefault: true },
{ name: 'test', primary: '#123456', isDark: false, isDefault: false },
{ name: 'new', primary: '#000055', isDark: true, isDefault: false }
]
}
]
})
);
......@@ -27,30 +37,31 @@ describe('StyleManager', () => {
});
it('should add stylesheet to head', () => {
styleManager.setStyle('test', 'test.css');
const styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
styleManager.setCurrentTheme('test');
const styleEl = document.head.querySelector('.style-manager-theme') as HTMLLinkElement;
expect(styleEl).not.toBeNull();
expect(styleEl.href.endsWith('test.css')).toBe(true);
});
it('should change existing stylesheet', () => {
styleManager.setStyle('test', 'test.css');
const styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
styleManager.setCurrentTheme('test');
const styleEl = document.head.querySelector('.style-manager-theme') as HTMLLinkElement;
expect(styleEl).not.toBeNull();
expect(styleEl.href.endsWith('test.css')).toBe(true);
styleManager.setStyle('test', 'new.css');
expect(styleEl.href.endsWith('new.css')).toBe(true);
styleManager.setCurrentTheme('new');
const styleEl2 = document.head.querySelector('.style-manager-theme') as HTMLLinkElement;
expect(styleEl2.href.endsWith('new.css')).toBe(true);
});
it('should remove existing stylesheet', () => {
styleManager.setStyle('test', 'test.css');
let styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
it('should remove alternate stylesheet', () => {
styleManager.setCurrentTheme('test');
const styleEl = document.head.querySelector('.style-manager-theme') as HTMLLinkElement;
expect(styleEl).not.toBeNull();
expect(styleEl.href.endsWith('test.css')).toBe(true);
styleManager.removeStyle('test');
styleEl = document.head.querySelector('.style-manager-test') as HTMLLinkElement;
expect(styleEl).toBeNull();
styleManager.setCurrentTheme('default');
const styleEl2 = document.head.querySelector('.style-manager-theme') as HTMLLinkElement;
expect(styleEl2).toBeNull();
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment