Browse Source

updating test file

pull/17054/head
Sinan997 3 years ago
committed by Mahmut Gundogdu
parent
commit
23dc05911c
  1. 9
      npm/ng-packs/packages/core/src/lib/services/internet-connection-service.ts
  2. 56
      npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts
  3. 2
      npm/ng-packs/packages/theme-shared/src/lib/components/internet-connection-status/internet-connection-status.component.ts

9
npm/ng-packs/packages/core/src/lib/services/internet-connection-service.ts

@ -6,12 +6,13 @@ import { BehaviorSubject } from 'rxjs';
providedIn: 'root',
})
export class InternetConnectionService{
protected readonly window = inject(DOCUMENT).defaultView;
protected readonly navigator = this.window.navigator;
readonly document = inject(DOCUMENT)
readonly window = this.document.defaultView;
readonly navigator = this.window.navigator;
private status$ = new BehaviorSubject<boolean>(navigator.onLine)
private status$ = new BehaviorSubject<boolean>(this.navigator.onLine)
private status = signal(navigator.onLine);
private status = signal(this.navigator.onLine);
networkStatus = computed(() => this.status())

56
npm/ng-packs/packages/core/src/lib/tests/internet-connection.service.spec.ts

@ -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';
describe('InternetConnectionService', () => {
let service: InternetConnectionService;
const internetConnectionStatus = window.navigator.onLine
let service: InternetConnectionService;
describe('Internet connection when disconnected', () => {
let mockDocument = { defaultView: {navigator: {onLine: false}, addEventListener: jest.fn()} }
beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
providers:[{provide:DOCUMENT, useValue: mockDocument}]
})
service = TestBed.inject(InternetConnectionService);
});
it('should be created', () => {
expect(service).toBeTruthy();
it('document should be created', () => {
expect(service.document).toEqual(mockDocument);
});
it('networkStatus value should be same with current internetConnectionStatus', () => {
expect(service.networkStatus()).toEqual(internetConnectionStatus)
it('signal value should be false', () => {
expect(service.networkStatus()).toEqual(false);
});
it('networkStatus$ return value should be with the current internetConnectionStatus', () => {
service.networkStatus$.subscribe(val=>{
expect(val).toEqual(internetConnectionStatus)
})
it('observable value should be false',
(done: any) => {
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();
});
});
});

2
npm/ng-packs/packages/theme-shared/src/lib/components/internet-connection-status/internet-connection-status.component.ts

@ -43,5 +43,5 @@ import { InternetConnectionService , LocalizationModule } from '@abp/ng.core';
})
export class InternetConnectionStatusComponent{
internetConnectionService = inject(InternetConnectionService);
isOnline = computed(() => this.internetConnectionService.networkStatus())
isOnline = this.internetConnectionService.networkStatus
}

Loading…
Cancel
Save