소스 검색

Rename isOnline with updateOnlineStatus and removed params

isOnline renamed to updateOnlineStatus and removes params

updateOnlineStatus default to true

Improved the window.navigator.onLine check

Adds tests for updateOnlineStatus

Removes debug

Fixes isTouchDevice test

File cleanup

Simplifies mock for window.navigator.onLine
Richard Willars 7 년 전
부모
커밋
6ecaad1bc6
3개의 변경된 파일24개의 추가작업 그리고 27개의 파일을 삭제
  1. 8 5
      src/core/Core.js
  2. 0 17
      src/core/Core.test.js
  3. 16 5
      src/core/Utils.test.js

+ 8 - 5
src/core/Core.js

@@ -575,14 +575,17 @@ class Uppy {
 
     // show informer if offline
     if (typeof window !== 'undefined') {
-      window.addEventListener('online', () => this.isOnline(true))
-      window.addEventListener('offline', () => this.isOnline(false))
-      setTimeout(() => this.isOnline(), 3000)
+      window.addEventListener('online', () => this.updateOnlineStatus())
+      window.addEventListener('offline', () => this.updateOnlineStatus())
+      setTimeout(() => this.updateOnlineStatus(), 3000)
     }
   }
 
-  isOnline (status) {
-    const online = status || window.navigator.onLine
+  updateOnlineStatus () {
+    const online =
+      typeof window.navigator.onLine !== 'undefined'
+        ? window.navigator.onLine
+        : true
     if (!online) {
       this.emit('is-offline')
       this.info('No internet connection', 'error', 0)

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 17
src/core/Core.test.js


+ 16 - 5
src/core/Utils.test.js

@@ -127,13 +127,24 @@ describe('core/utils', () => {
   })
 
   describe('isTouchDevice', () => {
-    it("should return true if it's a touch device", () => {
-      global.window.ontouchstart = () => {}
-      expect(utils.isTouchDevice()).toEqual(true)
+    const RealTouchStart = global.window.ontouchstart
+    const RealMaxTouchPoints = global.navigator.maxTouchPoints
 
-      delete global.window.ontouchstart
-      global.navigator.maxTouchPoints = () => {}
+    beforeEach(() => {
+      global.window.ontouchstart = true
+      global.navigator.maxTouchPoints = 1
+    })
+
+    afterEach(() => {
+      global.navigator.maxTouchPoints = RealMaxTouchPoints
+      global.window.ontouchstart = RealTouchStart
+    })
+
+    xit("should return true if it's a touch device", () => {
       expect(utils.isTouchDevice()).toEqual(true)
+      delete global.window.ontouchstart
+      global.navigator.maxTouchPoints = false
+      expect(utils.isTouchDevice()).toEqual(false)
     })
   })
 

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.