Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
test: add UT's
Browse files Browse the repository at this point in the history
  • Loading branch information
wswebcreation committed Apr 27, 2019
1 parent 0a6f0e7 commit 7ac67a0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`hideRemoveElements should be able to hide elements and put them back again 1`] = `""`;

exports[`hideRemoveElements should be able to hide elements and put them back again 2`] = `""`;

exports[`hideRemoveElements should be able to hide elements and put them back again 3`] = `"hidden"`;

exports[`hideRemoveElements should be able to hide elements and put them back again 4`] = `"hidden"`;

exports[`hideRemoveElements should be able to hide elements and put them back again 5`] = `""`;

exports[`hideRemoveElements should be able to hide elements and put them back again 6`] = `""`;

exports[`hideRemoveElements should be able to remove elements and put them back again 1`] = `""`;

exports[`hideRemoveElements should be able to remove elements and put them back again 2`] = `""`;

exports[`hideRemoveElements should be able to remove elements and put them back again 3`] = `"none"`;

exports[`hideRemoveElements should be able to remove elements and put them back again 4`] = `"none"`;

exports[`hideRemoveElements should be able to remove elements and put them back again 5`] = `""`;

exports[`hideRemoveElements should be able to remove elements and put them back again 6`] = `""`;
79 changes: 79 additions & 0 deletions lib/clientSideScripts/hideRemoveElements.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import hideRemoveElements from './hideRemoveElements';

describe('hideRemoveElements', () => {
it('should be able to hide elements and put them back again', () => {
document.body.innerHTML =
'<div>' +
' <span id="id-1">Hello</span>' +
' <span id="id-2">Hello</span>' +
' <div>' +
' <span id="id-3">Hello</span>' +
' <span id="id-4">Hello</span>' +
' </div>' +
'</div>';

// Check not hidden
expect((<HTMLElement>document.querySelector('#id-1')).style.visibility).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-3')).style.visibility).toMatchSnapshot();

hideRemoveElements({
hide: [document.querySelector('#id-1'), document.querySelector('#id-3')],
remove: [],
},
true,
);

// Check hidden
expect((<HTMLElement>document.querySelector('#id-1')).style.visibility).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-3')).style.visibility).toMatchSnapshot();

hideRemoveElements({
hide: [document.querySelector('#id-1'), document.querySelector('#id-3')],
remove: [],
},
false,
);

// Check not hidden
expect((<HTMLElement>document.querySelector('#id-1')).style.visibility).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-3')).style.visibility).toMatchSnapshot();
});

it('should be able to remove elements and put them back again', () => {
document.body.innerHTML =
'<div>' +
' <span id="id-1">Hello</span>' +
' <span id="id-2">Hello</span>' +
' <div>' +
' <span id="id-3">Hello</span>' +
' <span id="id-4">Hello</span>' +
' </div>' +
'</div>';

// Check not removed
expect((<HTMLElement>document.querySelector('#id-2')).style.display).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-4')).style.display).toMatchSnapshot();

hideRemoveElements({
hide: [],
remove: [document.querySelector('#id-2'), document.querySelector('#id-4')],
},
true,
);

// Check removed
expect((<HTMLElement>document.querySelector('#id-2')).style.display).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-4')).style.display).toMatchSnapshot();

hideRemoveElements({
remove: [document.querySelector('#id-2'), document.querySelector('#id-4')],
hide: [],
},
false,
);

// Check not removed
expect((<HTMLElement>document.querySelector('#id-2')).style.display).toMatchSnapshot();
expect((<HTMLElement>document.querySelector('#id-4')).style.display).toMatchSnapshot();
});
});

0 comments on commit 7ac67a0

Please sign in to comment.