2020-05-25 21:30:55 -05:00
|
|
|
import * as ko from "knockout";
|
|
|
|
import * as Constants from "../../Common/Constants";
|
|
|
|
import * as ViewModels from "../../Contracts/ViewModels";
|
|
|
|
import Explorer from "../Explorer";
|
|
|
|
import QueryTab from "./QueryTab";
|
2020-07-21 13:50:51 -05:00
|
|
|
import { View } from "@nteract/data-explorer/lib/utilities/types";
|
|
|
|
import { PartitionKey } from "../../Contracts/DataModels";
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
describe("Query Tab", () => {
|
2020-07-20 12:59:40 -05:00
|
|
|
function getNewQueryTabForContainer(container: Explorer): ViewModels.QueryTab {
|
2020-07-21 13:50:51 -05:00
|
|
|
const database = {
|
2020-05-25 21:30:55 -05:00
|
|
|
container: container,
|
|
|
|
id: ko.observable<string>("test"),
|
|
|
|
isDatabaseShared: () => false
|
2020-07-21 13:50:51 -05:00
|
|
|
} as ViewModels.Database;
|
|
|
|
const collection = {
|
2020-05-25 21:30:55 -05:00
|
|
|
container: container,
|
|
|
|
databaseId: "test",
|
|
|
|
id: ko.observable<string>("test")
|
2020-07-21 13:50:51 -05:00
|
|
|
} as ViewModels.Collection;
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
return new QueryTab({
|
|
|
|
tabKind: ViewModels.CollectionTabKind.Query,
|
|
|
|
collection: collection,
|
|
|
|
database: database,
|
|
|
|
title: "",
|
|
|
|
tabPath: "",
|
|
|
|
selfLink: "",
|
|
|
|
isActive: ko.observable<boolean>(false),
|
|
|
|
hashLocation: "",
|
2020-07-09 13:53:37 -07:00
|
|
|
onUpdateTabsButtons: (buttons: ViewModels.NavbarButtonConfig[]): void => {}
|
2020-05-25 21:30:55 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("shouldSetSystemPartitionKeyContainerPartitionKeyValueUndefined", () => {
|
2020-07-21 13:50:51 -05:00
|
|
|
const collection = {
|
|
|
|
id: ko.observable<string>("withoutsystempk"),
|
2020-05-25 21:30:55 -05:00
|
|
|
partitionKey: {
|
|
|
|
systemKey: true
|
|
|
|
}
|
2020-07-21 13:50:51 -05:00
|
|
|
} as ViewModels.Collection;
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
it("no container with system pk, should not set partition key option", () => {
|
|
|
|
const iteratorOptions = QueryTab.getIteratorOptions(collection);
|
|
|
|
expect(iteratorOptions.initialHeaders).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("isQueryMetricsEnabled()", () => {
|
2020-07-20 12:59:40 -05:00
|
|
|
let explorer: Explorer;
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-07-27 12:58:27 -05:00
|
|
|
explorer = new Explorer({ notificationsClient: null, isEmulator: false });
|
2020-05-25 21:30:55 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should be true for accounts using SQL API", () => {
|
|
|
|
explorer.defaultExperience(Constants.DefaultAccountExperience.DocumentDB.toLowerCase());
|
|
|
|
const queryTab: ViewModels.QueryTab = getNewQueryTabForContainer(explorer);
|
|
|
|
expect(queryTab.isQueryMetricsEnabled()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be false for accounts using other APIs", () => {
|
|
|
|
explorer.defaultExperience(Constants.DefaultAccountExperience.Graph.toLowerCase());
|
|
|
|
const queryTab: ViewModels.QueryTab = getNewQueryTabForContainer(explorer);
|
|
|
|
expect(queryTab.isQueryMetricsEnabled()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Save Queries command button", () => {
|
2020-07-20 12:59:40 -05:00
|
|
|
let explorer: Explorer;
|
2020-05-25 21:30:55 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-07-27 12:58:27 -05:00
|
|
|
explorer = new Explorer({ notificationsClient: null, isEmulator: false });
|
2020-05-25 21:30:55 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should be visible when using a supported API", () => {
|
|
|
|
explorer.defaultExperience(Constants.DefaultAccountExperience.DocumentDB);
|
|
|
|
const queryTab: ViewModels.QueryTab = getNewQueryTabForContainer(explorer);
|
|
|
|
expect(queryTab.saveQueryButton.visible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not be visible when using an unsupported API", () => {
|
|
|
|
explorer.defaultExperience(Constants.DefaultAccountExperience.MongoDB);
|
|
|
|
const queryTab: ViewModels.QueryTab = getNewQueryTabForContainer(explorer);
|
|
|
|
expect(queryTab.saveQueryButton.visible()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|