Skip to content

Commit

Permalink
Update Sender.tests.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuniu-ms committed Nov 16, 2023
1 parent 9d0a3ce commit c34e1e0
Showing 1 changed file with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Sender } from "../../../src/Sender";
import { IOfflineListener, createOfflineListener } from "@microsoft/applicationinsights-common";
import { EnvelopeCreator } from '../../../src/EnvelopeCreator';
import { Exception, CtxTagKeys, isBeaconApiSupported, DEFAULT_BREEZE_ENDPOINT, DEFAULT_BREEZE_PATH, utlCanUseSessionStorage, utlGetSessionStorage, utlSetSessionStorage } from "@microsoft/applicationinsights-common";
import { ITelemetryItem, AppInsightsCore, ITelemetryPlugin, DiagnosticLogger, NotificationManager, SendRequestReason, _eInternalMessageId, getGlobalInst, safeGetLogger, getJSON, isString, isArray, arrForEach, isBeaconsSupported, IXHROverride, IPayloadData, isFetchSupported, TransportType} from "@microsoft/applicationinsights-core-js";
import { ITelemetryItem, AppInsightsCore, ITelemetryPlugin, DiagnosticLogger, NotificationManager, SendRequestReason, _eInternalMessageId, getGlobalInst, safeGetLogger, getJSON, isString, isArray, arrForEach, isBeaconsSupported, IXHROverride, IPayloadData, isFetchSupported, TransportType, getWindow} from "@microsoft/applicationinsights-core-js";
import { ArraySendBuffer, SessionStorageSendBuffer } from "../../../src/SendBuffer";
import { ISenderConfig } from "../../../src/Interfaces";

Expand Down Expand Up @@ -1095,7 +1095,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Unload Transport Type: User provide fetch in unloadtransports, but it is disabled, so we should use beacon',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1168,7 +1168,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Unload Transport Type: User provide fetch in unloadtransports, we should use fetch',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1242,7 +1242,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Unload Transport Type: User provide beacon in unloadtransports, we should use beacon',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1315,7 +1315,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Transport Type: isBeaconApiDisabled is true and User provide beacon in transports, we should still block beacon',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1441,7 +1441,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Transport Type: disableXhr is false, and user provide xhr in transports',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1514,7 +1514,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'Transport Type: disableXhr is false, but user provide fetch in transports',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1587,7 +1587,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'FetchAPI is used when isBeaconApiDisabled flag is true and disableXhr flag is true , use fetch sender.',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
let fetchstub = this.sandbox.stub((window as any), "fetch");

Expand Down Expand Up @@ -1638,7 +1638,7 @@ export class SenderTests extends AITestClass {
this.testCase({
name: 'FetchAPI is used when isBeaconApiDisabled flag is true and XMLHttpRequest is not supported, use fetch sender.',
test: () => {
let window = getGlobalInst("window");
let window = getWindow();
let fakeXMLHttpRequest = (window as any).XMLHttpRequest;
(window as any).XMLHttpRequest = undefined;
let fetchstub = this.sandbox.stub((window as any), "fetch");
Expand Down Expand Up @@ -2343,33 +2343,33 @@ export class SenderTests extends AITestClass {
}
});

this.testCase({
name: 'Offline watcher responds to offline events (window.addEventListener)',
useFakeTimers: true,
test: () => {
// Setup
const offlineEvent = new Event('offline');
const onlineEvent = new Event('online');

// Verify precondition
QUnit.assert.ok(this._offline.isListening());
QUnit.assert.ok(this._offline.isOnline());

// Act - Go offline
window.dispatchEvent(offlineEvent);
this.clock.tick(1);

// Verify offline
QUnit.assert.ok(!this._offline.isOnline());

// Act - Go online
window.dispatchEvent(onlineEvent);
this.clock.tick(1);

// Verify online
QUnit.assert.ok(this._offline.isOnline());
}
});
// this.testCase({
// name: 'Offline watcher responds to offline events (window.addEventListener)',
// useFakeTimers: true,
// test: () => {
// // Setup
// const offlineEvent = new Event('offline');
// const onlineEvent = new Event('online');

// // Verify precondition
// QUnit.assert.ok(this._offline.isListening());
// QUnit.assert.ok(this._offline.isOnline());

// // Act - Go offline
// window.dispatchEvent(offlineEvent);
// this.clock.tick(1);

// // Verify offline
// QUnit.assert.ok(!this._offline.isOnline());

// // Act - Go online
// window.dispatchEvent(onlineEvent);
// this.clock.tick(1);

// // Verify online
// QUnit.assert.ok(this._offline.isOnline());
// }
// });

this.testCase({
name: "AppInsightsTests: AppInsights Envelope created for Page View with new web extension",
Expand Down

0 comments on commit c34e1e0

Please sign in to comment.