Skip to content

Commit

Permalink
test: basic tests for BodyClassManager, CSSUtils tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ala-n committed Apr 17, 2021
1 parent 5379c65 commit 4e4b859
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/modules/esl-utils/dom/body-cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class BodyClassManager {
* */
public static addCls(cls: string | null | undefined, lock: HTMLElement) {
CSSUtil.splitTokens(cls).forEach((className) => {
this.lock(className, lock);
BodyClassManager.lock(className, lock);
document.body.classList.add(className);
});
}
Expand All @@ -30,7 +30,7 @@ export abstract class BodyClassManager {
* */
public static removeCls(cls: string | null | undefined, lock: HTMLElement) {
CSSUtil.splitTokens(cls).forEach((className) => {
if (!this.unlock(className, lock)) return;
if (!BodyClassManager.unlock(className, lock)) return;
document.body.classList.remove(className);
});
}
Expand Down
20 changes: 20 additions & 0 deletions src/modules/esl-utils/dom/test/body-cls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {BodyClassManager} from '../body-cls';

describe('dom/styles tests', () => {

const list = document.body.classList;
const lock1 = document.createElement('div');
const lock2 = document.createElement('div');

test('test case', () => {
BodyClassManager.toggleClsTo('a', lock1, true);
expect(list.contains('a')).toBeTruthy();
BodyClassManager.toggleClsTo('a', lock2, true);
expect(list.contains('a')).toBeTruthy();

BodyClassManager.toggleClsTo('a', lock1, false);
expect(list.contains('a')).toBeTruthy();
BodyClassManager.toggleClsTo('a', lock2, false);
expect(list.contains('a')).toBeFalsy();
});
});
4 changes: 2 additions & 2 deletions src/modules/esl-utils/dom/test/styles.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CSSUtil} from '../styles';

describe('dom/styles helper tests', () => {
describe('CSSUtil tests', () => {
test('styles: crud simple', () => {
const el = document.createElement('div');

Expand Down Expand Up @@ -35,7 +35,7 @@ describe('dom/styles helper tests', () => {

test.each([
[''], [' '], [null], [undefined]
])('styles: safe check', (val) => {
])('add %p safe check', (val) => {
const el = document.createElement('div');
expect(el.classList.length).toBe(0);
CSSUtil.addCls(el, val);
Expand Down

0 comments on commit 4e4b859

Please sign in to comment.