ABPCMS.Web/lib/push.js/push_tests.js
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
var
TEST_TITLE = 'title',
TEST_BODY = 'body',
TEST_TIMEOUT = 1000,
TEST_TIMEOUT_LONG = 50000,
TEST_TAG = 'foo',
TEST_TAG_2 = 'bar',
TEST_ICON = 'icon',
TEST_ICON_ARRAY = { x16: TEST_ICON, x32: TEST_ICON },
TEST_SW = 'customServiceWorker.js',
TEST_SW_DEFAULT = "serviceWorker.js"
NOOP = function () {}; // NO OPerator (empty function)
describe('initialization', function () {
it('should create a new instance', function () {
expect(window.Push !== undefined).toBeTruthy();
});
it('isSupported should return a boolean', function () {
expect(typeof Push.isSupported).toBe('boolean');
});
});
describe('permission', function () {
var callback; // Callback spy
beforeEach(function () {
callback = jasmine.createSpy('callback');
});
it('should have permission stored as a string constant', function () {
expect(typeof Push.Permission.get()).toBe('string');
});
it('should update permission value if permission is denied and execute callback', function (done) {
spyOn(window.Notification, 'requestPermission').and.callFake(function (cb) {
cb(Push.Permission.DENIED);
});
Push.Permission.request(NOOP, callback);
setTimeout(function () {
expect(Push.Permission.has()).toBe(false);
expect(callback).toHaveBeenCalled();
done();
}, 500);
});
it('should request permission if permission is not granted', function () {
spyOn(window.Notification, 'requestPermission').and.callFake(function (cb) {
cb(Push.Permission.DENIED);
});
Push.Permission.request();
Push.create(TEST_TITLE);
expect(window.Notification.requestPermission).toHaveBeenCalled();
});
it('should update permission value if permission is granted and execute callback', function (done) {
spyOn(window.Notification, 'requestPermission').and.callFake(function (cb) {
cb(Push.Permission.GRANTED);
后面还有 213 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
