mirror of https://github.com/abpframework/abp.git
2 changed files with 136 additions and 4 deletions
@ -0,0 +1,128 @@ |
|||||
|
import { SpectatorDirective, createDirectiveFactory } from '@ngneat/spectator/jest'; |
||||
|
import { VisibilityDirective } from '../directives/visibility.directive'; |
||||
|
|
||||
|
describe('VisibilityDirective', () => { |
||||
|
let spectator: SpectatorDirective<VisibilityDirective>; |
||||
|
let directive: VisibilityDirective; |
||||
|
const createDirective = createDirectiveFactory({ |
||||
|
directive: VisibilityDirective, |
||||
|
}); |
||||
|
|
||||
|
describe('without mutation observer and without content', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective('<div [abpVisibility] [mutationObserverEnabled]="false"></div>'); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should be created', () => { |
||||
|
expect(directive).toBeTruthy(); |
||||
|
}); |
||||
|
|
||||
|
it('should be removed', done => { |
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('div')).toBeFalsy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('without mutation observer and with content', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective( |
||||
|
'<div [abpVisibility] [mutationObserverEnabled]="false"><p id="content">Content</p></div>', |
||||
|
); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should not removed', done => { |
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('div')).toBeTruthy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('without mutation observer and with focused element', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective( |
||||
|
'<div id="main" [abpVisibility]="container" [mutationObserverEnabled]="false"></div><div #container><p id="content">Content</p></div>', |
||||
|
); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should not removed', done => { |
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('#main')).toBeTruthy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('without content and with focused element', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective( |
||||
|
'<div id="main" [abpVisibility]="container" [mutationObserverEnabled]="false"></div><div #container></div>', |
||||
|
); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should be removed', done => { |
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('#main')).toBeFalsy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('with mutation observer and with content', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective('<div [abpVisibility]><div id="content">Content</div></div>'); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should remove the main div element when content removed', done => { |
||||
|
spectator.query('#content').remove(); |
||||
|
|
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('div')).toBeFalsy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
|
||||
|
it('should not remove the main div element', done => { |
||||
|
spectator.query('div').appendChild(document.createElement('div')); |
||||
|
|
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('div')).toBeTruthy(); |
||||
|
done(); |
||||
|
}, 100); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe('with mutation observer and with focused element', () => { |
||||
|
beforeEach(() => { |
||||
|
spectator = createDirective( |
||||
|
'<div id="main" [abpVisibility]="container"></div><div #container><p id="content">Content</p></div>', |
||||
|
); |
||||
|
directive = spectator.directive; |
||||
|
}); |
||||
|
|
||||
|
it('should remove the main div element when content removed', done => { |
||||
|
spectator.query('#content').remove(); |
||||
|
|
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('#main')).toBeFalsy(); |
||||
|
done(); |
||||
|
}, 0); |
||||
|
}); |
||||
|
|
||||
|
it('should not remove the main div element', done => { |
||||
|
spectator.query('#content').appendChild(document.createElement('div')); |
||||
|
|
||||
|
setTimeout(() => { |
||||
|
expect(spectator.query('#main')).toBeTruthy(); |
||||
|
done(); |
||||
|
}, 100); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue