|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2020 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import * as util from '@firebase/util'; |
| 19 | +import { expect } from 'chai'; |
| 20 | +import { restore, stub } from 'sinon'; |
| 21 | +import { Delay, _OFFLINE_DELAY_MS } from './delay'; |
| 22 | +import * as navigator from './navigator'; |
| 23 | + |
| 24 | +describe('Delay.get()', () => { |
| 25 | + const SHORT_DELAY = 30_000; |
| 26 | + const LONG_DELAY = 60_000; |
| 27 | + |
| 28 | + afterEach(restore); |
| 29 | + |
| 30 | + it('should return the short delay in browser environments', () => { |
| 31 | + const delay = new Delay(SHORT_DELAY, LONG_DELAY); |
| 32 | + expect(delay.get()).to.eq(SHORT_DELAY); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should return the long delay in Cordova environments', () => { |
| 36 | + const mock = stub(util, 'isMobileCordova'); |
| 37 | + mock.callsFake(() => true); |
| 38 | + const delay = new Delay(SHORT_DELAY, LONG_DELAY); |
| 39 | + expect(delay.get()).to.eq(LONG_DELAY); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should return the long delay in React Native environments', () => { |
| 43 | + const mock = stub(util, 'isReactNative'); |
| 44 | + mock.callsFake(() => true); |
| 45 | + const delay = new Delay(SHORT_DELAY, LONG_DELAY); |
| 46 | + expect(delay.get()).to.eq(LONG_DELAY); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return quicker when offline', () => { |
| 50 | + const mock = stub(navigator, 'isOnline'); |
| 51 | + mock.callsFake(() => false); |
| 52 | + const delay = new Delay(SHORT_DELAY, LONG_DELAY); |
| 53 | + expect(delay.get()).to.eq(_OFFLINE_DELAY_MS); |
| 54 | + }); |
| 55 | +}); |
0 commit comments