mirror of https://github.com/abpframework/abp.git
committed by
Mahmut Gundogdu
3 changed files with 49 additions and 18 deletions
@ -1,27 +1,57 @@ |
|||||
import { TestBed } from '@angular/core/testing'; |
import { TestBed} from '@angular/core/testing'; |
||||
|
import { DOCUMENT } from '@angular/common'; |
||||
|
|
||||
import { InternetConnectionService } from '../services/internet-connection-service'; |
import { InternetConnectionService } from '../services/internet-connection-service'; |
||||
|
|
||||
describe('InternetConnectionService', () => { |
let service: InternetConnectionService; |
||||
let service: InternetConnectionService; |
|
||||
const internetConnectionStatus = window.navigator.onLine |
describe('Internet connection when disconnected', () => { |
||||
|
let mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener: jest.fn()} } |
||||
|
|
||||
beforeEach(() => { |
beforeEach(() => { |
||||
TestBed.configureTestingModule({}); |
TestBed.configureTestingModule({ |
||||
|
providers:[{provide:DOCUMENT, useValue: mockDocument}] |
||||
|
}) |
||||
service = TestBed.inject(InternetConnectionService); |
service = TestBed.inject(InternetConnectionService); |
||||
}); |
}); |
||||
|
|
||||
it('should be created', () => { |
it('document should be created', () => { |
||||
expect(service).toBeTruthy(); |
expect(service.document).toEqual(mockDocument); |
||||
}); |
}); |
||||
|
|
||||
it('networkStatus value should be same with current internetConnectionStatus', () => { |
it('signal value should be false', () => { |
||||
expect(service.networkStatus()).toEqual(internetConnectionStatus) |
expect(service.networkStatus()).toEqual(false); |
||||
}); |
}); |
||||
|
|
||||
it('networkStatus$ return value should be with the current internetConnectionStatus', () => { |
it('observable value should be false', |
||||
service.networkStatus$.subscribe(val=>{ |
(done: any) => { |
||||
expect(val).toEqual(internetConnectionStatus) |
service.networkStatus$.subscribe(value => { |
||||
}) |
expect(value).toBe(false) |
||||
|
done(); |
||||
|
}); |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|
||||
|
describe('Internet connection when connected', () => { |
||||
|
let mockDocument = { defaultView: {navigator: {onLine: true}, addEventListener: jest.fn()} } |
||||
|
|
||||
|
beforeEach(() => { |
||||
|
TestBed.configureTestingModule({ |
||||
|
providers:[{provide:DOCUMENT, useValue: mockDocument}] |
||||
|
}) |
||||
|
service = TestBed.inject(InternetConnectionService); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
it('signal value should be true', () => { |
||||
|
expect(service.networkStatus()).toEqual(true); |
||||
|
}); |
||||
|
|
||||
|
it('observable value should be true', |
||||
|
(done: any) => { |
||||
|
service.networkStatus$.subscribe(value => { |
||||
|
expect(value).toBe(true) |
||||
|
done(); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Loading…
Reference in new issue