From 68dfa3453b17b5138ee57a39f341408c83ec0a63 Mon Sep 17 00:00:00 2001 From: Ian Sibner Date: Tue, 15 Jul 2014 20:02:31 -0400 Subject: [PATCH 01/25] Add definitions for angular-protractor 1.0.0-rc4 --- .../angular-protractor-tests.ts | 91 +- angular-protractor/angular-protractor.d.ts | 786 +++++++++------ .../legacy/angular-protractor-0.17.0-tests.ts | 244 +++++ .../legacy/angular-protractor-0.17.0.d.ts | 906 ++++++++++++++++++ 4 files changed, 1724 insertions(+), 303 deletions(-) create mode 100644 angular-protractor/legacy/angular-protractor-0.17.0-tests.ts create mode 100644 angular-protractor/legacy/angular-protractor-0.17.0.d.ts diff --git a/angular-protractor/angular-protractor-tests.ts b/angular-protractor/angular-protractor-tests.ts index 37c9e49bc..62ed46177 100644 --- a/angular-protractor/angular-protractor-tests.ts +++ b/angular-protractor/angular-protractor-tests.ts @@ -153,21 +153,36 @@ function TestProtractor() { ptor.debugger(); + var webElement: protractor.WebElement = ptor.findElement(by.css('.class')); + var promise: webdriver.promise.Promise; + promise = ptor.findElements(by.css('.class')); + promise = ptor.isElementPresent(by.css('.class')); + promise = ptor.isElementPresent(webElement); + ptor.clearMockModules(); ptor.addMockModule('name', 'script'); ptor.addMockModule('name', function() {}); + ptor.removeMockModule('name'); ptor.waitForAngular(); var elementFinder: protractor.ElementFinder; + var elementArrayFinder: protractor.ElementArrayFinder; elementFinder = ptor.element(by.id('ABC')); elementFinder = ptor.$('.class'); - var elementArrayFinder: protractor.ElementArrayFinder = ptor.$$('.class'); - - var webElement: webdriver.WebElement = ptor.wrapWebElement(new webdriver.WebElement(driver, 'id')); + elementArrayFinder = ptor.$$('.class'); var locationAbsUrl: webdriver.promise.Promise = ptor.getLocationAbsUrl(); + ptor.setLocation('webaddress.com'); + + promise = ptor.get('webaddress.com'); + promise = ptor.get('webdaddress.com', 45); + ptor.refresh(); + ptor.refresh(45); + var navigation: webdriver.WebDriverNavigation = ptor.navigate(); + ptor.pause(); + ptor.pause(8080); } function TestElement() { @@ -180,6 +195,7 @@ function TestElementFinder() { var promise: webdriver.promise.Promise; promise = elementFinder.click(); + promise = elementFinder.allowAnimations('string'); promise = elementFinder.sendKeys(protractor.Key.UP, protractor.Key.DOWN); promise = elementFinder.getTagName(); promise = elementFinder.getCssValue('display'); @@ -196,18 +212,45 @@ function TestElementFinder() { promise = elementFinder.getInnerHtml(); promise = elementFinder.isElementPresent(by.id('id')); promise = elementFinder.isElementPresent(by.js('function(a, b, c) {}'), 1, 2, 3); - promise = elementFinder.findElements(by.className('class')); - promise = elementFinder.findElements(by.js('function(a, b, c) {}'), 1, 2, 3); + promise = elementFinder.$('.class'); promise = elementFinder.$$('.class'); promise = elementFinder.evaluate('expression'); promise = elementFinder.isPresent(); var webElement: webdriver.WebElement; +} - webElement = elementFinder.$('.class'); - webElement = elementFinder.findElement(by.id('id')); - webElement = elementFinder.findElement(by.js('function(a, b, c) {}'), 1, 2, 3); - webElement = elementFinder.find(); +function TestElementArrayFinder() { + var elementArrayFinder: protractor.ElementArrayFinder = element.all(by.id('id')); + var promise: webdriver.promise.Promise; + var elementFinder: protractor.ElementFinder; + + var driverElementArray: webdriver.WebElement[] = elementArrayFinder.getWebElements(); + elementFinder = elementArrayFinder.get(42); + elementFinder = elementArrayFinder.first(); + elementFinder = elementArrayFinder.last(); + promise = elementArrayFinder.count(); + elementArrayFinder.each(function(element: protractor.ElementFinder){ + // nothing + }); + elementArrayFinder.map(function(element: protractor.ElementFinder, index: number){ + // nothing + }); + elementArrayFinder.filter(function(element: protractor.ElementFinder, index: number){ + return element.getText().then((text: string) => { + return text === "foo"; + }); + }); + elementArrayFinder.reduce(function(accumulator: string, element: protractor.ElementFinder){ + return element.getText().then((text: string) => { + return accumulator + ',' + text; + }); + }, ''); + elementArrayFinder.reduce(function(accumulator: string, element: protractor.ElementFinder, index: number, array: protractor.ElementFinder[]){ + return element.getText().then((text: string) => { + return accumulator + ',' + text; + }); + }, ''); } // This function tests the angular specific locator strategies. @@ -216,29 +259,19 @@ function TestLocatorStrategies() { var webElement: webdriver.WebElement; // Protractor Specific Locators + protractor.By.addLocator('customLocator', 'script'); + protractor.By.addLocator('customLocator2', function(){ + // nothing + }); webElement = ptor.findElement(protractor.By.binding('binding')); - webElement = ptor.findElement(protractor.By.select('select')); - webElement = ptor.findElement(protractor.By.selectedOption('selectedOptions')); - webElement = ptor.findElement(protractor.By.input('input')); + webElement = ptor.findElement(protractor.By.exactBinding('exactBinding')); webElement = ptor.findElement(protractor.By.model('model')); - webElement = ptor.findElement(protractor.By.textarea('textarea')); webElement = ptor.findElement(protractor.By.repeater('repeater')); + webElement = ptor.findElement(protractor.By.repeater('repeater').column(0)); + webElement = ptor.findElement(protractor.By.repeater('repeater').row(0)); + webElement = ptor.findElement(protractor.By.repeater('repeater').row(0).column(0)); webElement = ptor.findElement(protractor.By.buttonText('buttonText')); webElement = ptor.findElement(protractor.By.partialButtonText('partialButtonText')); -} - -// This function tests the methods that were added to the base WebElement class -function TestWebElements() { - var ptor: protractor.Protractor = protractor.getInstance(); - - var webElement: protractor.WebElement; - var promise: webdriver.promise.Promise; - - webElement = ptor.findElement(by.id('id')).$('.class'); - promise = ptor.findElement(by.id('id')).$$('.class'); - promise = ptor.findElement(by.id('id')).evaluate('something'); - - webElement = webElement.findElement(by.id('id')).$('.class'); - promise = webElement.findElement(by.id('id')).$$('.class'); - promise = webElement.findElement(by.id('id')).evaluate('something'); + webElement = ptor.findElement(protractor.By.cssContainingText('cssSelector', 'search text')); + webElement = ptor.findElement(protractor.By.options('options')); } diff --git a/angular-protractor/angular-protractor.d.ts b/angular-protractor/angular-protractor.d.ts index 3c3c0981f..81eca975e 100644 --- a/angular-protractor/angular-protractor.d.ts +++ b/angular-protractor/angular-protractor.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Angular Protractor 0.17.0 +// Type definitions for Angular Protractor 1.0.0-rc4 // Project: https://github.com/angular/protractor // Definitions by: Bill Armstrong // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -25,71 +25,7 @@ declare module protractor { class CommandName extends webdriver.CommandName {} class Key extends webdriver.Key {} class UnhandledAlertError extends webdriver.UnhandledAlertError {} - - class WebElement extends webdriver.WebElement { - /** - * Shortcut for querying the document directly with css. - * - * @param {string} selector a css selector - * @see webdriver.WebElement.findElement - * @return {!protractor.WebElement} - */ - $(selector: string): protractor.WebElement; - - /** - * Shortcut for querying the document directly with css. - * - * @param {string} selector a css selector - * @see webdriver.WebElement.findElements - * @return {!webdriver.promise.Promise} A promise that will be resolved to an - * array of the located {@link webdriver.WebElement}s. - */ - $$(selector: string): webdriver.promise.Promise; - - /** - * Evalates the input as if it were on the scope of the current element. - * @param {string} expression - * - * @return {!webdriver.promise.Promise} A promise that will resolve to the - * evaluated expression. The result will be resolved as in - * {@link webdriver.WebDriver.executeScript}. In summary - primitives will - * be resolved as is, functions will be converted to string, and elements - * will be returned as a WebElement. - */ - evaluate(expression: string): webdriver.promise.Promise; - - /** - * Schedule a command to find a descendant of this element. If the element - * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will - * be returned by the driver. Unlike other commands, this error cannot be - * suppressed. In other words, scheduling a command to find an element doubles - * as an assert that the element is present on the page. To test whether an - * element is present on the page, use {@code #isElementPresent} instead. - *

- * The search criteria for find an element may either be a - * {@code webdriver.Locator} object, or a simple JSON object whose sole key - * is one of the accepted locator strategies, as defined by - * {@code webdriver.Locator.Strategy}. For example, the following two - * statements are equivalent: - *

-         * var e1 = element.findElement(By.id('foo'));
-         * var e2 = element.findElement({id:'foo'});
-         * 
- *

- * Note that JS locator searches cannot be restricted to a subtree. All such - * searches are delegated to this instance's parent WebDriver. - * - * @param {webdriver.Locator|Object.} locator The locator - * strategy to use when searching for the element. - * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if - * using a JavaScript locator. Otherwise ignored. - * @return {protractor.WebElement} A WebElement that can be used to issue - * commands against the located element. If the element is not found, the - * element will be invalidated and all scheduled commands aborted. - */ - findElement(locator: webdriver.Locator, ...var_args: any[]): protractor.WebElement; - findElement(locator: any, ...var_args: any[]): protractor.WebElement; - } + class WebElement extends webdriver.WebElement {} module command { class Command extends webdriver.Command {} @@ -273,13 +209,160 @@ declare module protractor { } //endregion - + /** + * Use as: element(locator) + * + * The ElementFinder can be treated as a WebElement for most purposes, in + * particular, you may perform actions (i.e. click, getText) on them as you + * would a WebElement. ElementFinders extend Promise, and once an action + * is performed on an ElementFinder, the latest result from the chain can be + * accessed using then. Unlike a WebElement, an ElementFinder will wait for + * angular to settle before performing finds or actions. + * + * ElementFinder can be used to build a chain of locators that is used to find + * an element. An ElementFinder does not actually attempt to find the element + * until an action is called, which means they can be set up in helper files + * before the page is available. + * + * @param {webdriver.Locator} locator An element locator. + * @param {ElementFinder=} opt_parentElementFinder The element finder previous + * to this. (i.e. opt_parentElementFinder.element(locator) => this) + * @param {webdriver.promise.Promise} opt_actionResult The promise which + * will be retrieved with then. Resolves to the latest action result, + * or null if no action has been called. + * @param {number=} opt_index The index of the element to retrieve. null means + * retrieve the only element, while -1 means retrieve the last element + * @return {ElementFinder} + */ interface Element { - (locator: webdriver.Locator): ElementFinder; - all(locator: webdriver.Locator): ElementArrayFinder; + (locator: webdriver.Locator, + opt_parentElementFinder?: protractor.ElementFinder, + opt_actionResult?: webdriver.promise.Promise, + opt_index?: number): ElementFinder; + + /** + * ElementArrayFinder is used for operations on an array of elements (as opposed + * to a single element). + * + * @param {webdriver.Locator} locator An element locator. + * @param {ElementFinder=} opt_parentElementFinder The element finder previous to + * this. (i.e. opt_parentElementFinder.all(locator) => this) + * @return {ElementArrayFinder} + */ + all(locator: webdriver.Locator, opt_parentElementFinder?: protractor.ElementFinder): ElementArrayFinder; } interface ElementFinder { + /** + * Use as: element(locator).element(locator) + * Calls to element may be chained to find elements within a parent. + * + * @param {webdriver.Locator} locator The locator that will be used to find descendents. + * + * @return {protractor.ElementFinder} The descendent element found by the locator + */ + element(locator: webdriver.Locator): protractor.ElementFinder; + + /** + * Use as: element(locator).all(locator) + * Calls to element may be chained to find an array of elements within a parent. + * + * @param {webdriver.Locator} locator The locator that will be used to find descendents. + * + * @return {protractor.ElementArrayFinder} The descendent elements found by the locator + */ + all(locator: webdriver.Locator): protractor.ElementArrayFinder; + + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElement + * @return {!protractor.WebElement} + */ + $(selector: string): protractor.WebElement; + + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElements + * @return {!webdriver.promise.Promise} A promise that will be resolved to an + * array of the located {@link webdriver.WebElement}s. + */ + $$(selector: string): webdriver.promise.Promise; + + /** + * Use as: element(locator).isPresent() + * Determine whether the element is present on the page. + * + * @return {protractor.ElementFinder} Which resolves to whether the element is present on the page. + */ + isPresent(): webdriver.promise.Promise; + + /** + * Schedules a command to test if there is at least one descendant of this + * element that matches the given search criteria. + * + *

Note that JS locator searches cannot be restricted to a subtree of the + * DOM. All such searches are delegated to this instance's parent WebDriver. + * + * @param {webdriver.Locator|Object.} locator The locator + * strategy to use when searching for the element. + * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if + * using a JavaScript locator. Otherwise ignored. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * whether an element could be located on the page. + */ + isElementPresent(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; + isElementPresent(locator: any, ...var_args: any[]): webdriver.promise.Promise; + + /** + * Return this ElementFinder's locator. + * + * @return {webdriver.Locator} + */ + locator(): webdriver.Locator; + + /** + * Use as: element(locator).getWebElement() + * Returns the WebElement represented by this ElementFinder. + * Throws the WebDriver error if the element doesn't exist. + * If index is null, it makes sure that there is only one underlying WebElement + * described by the chain of locators and issues a warning otherwise. + * If index is not null, it retrieves the WebElement specified by the index.. + * @return {webdriver.WebElement} The WebElement represented by the ElementFinder. + */ + getWebElement(): webdriver.WebElement; + + /** + * Evalates the input as if it were on the scope of the current element. + * @param {string} expression + * + * @return {!webdriver.promise.Promise} A promise that will resolve to the + * evaluated expression. The result will be resolved as in + * {@link webdriver.WebDriver.executeScript}. In summary - primitives will + * be resolved as is, functions will be converted to string, and elements + * will be returned as a WebElement. + */ + evaluate(expression: string): webdriver.promise.Promise; + + /** + * Determine if animation is allowed on the current element. + * @param {string} value + * + * @return {ElementFinder} which resolves to whether animation is allowed. + */ + allowAnimations(value: string): webdriver.promise.Promise; + + /** + * Access the underlying actionResult of ElementFinder. Implementation allows ElementFinder to be used as a webdriver.promise.Promise. + * @param {function(webdriver.promise.Promise)} fn Function which takes the value of the underlying actionResult. + * + * @return {webdriver.promise.Promise} Promise which contains the results of evaluating fn. + */ + then(fn: IThenFunction): webdriver.promise.Promise; + /** * Schedules a command to click on this element. * @return {!webdriver.promise.Promise} A promise that will be resolved when @@ -460,113 +543,128 @@ declare module protractor { getInnerHtml(): webdriver.promise.Promise; /** - * Schedules a command to test if there is at least one descendant of this - * element that matches the given search criteria. - * - *

Note that JS locator searches cannot be restricted to a subtree of the - * DOM. All such searches are delegated to this instance's parent WebDriver. - * - * @param {webdriver.Locator|Object.} locator The locator - * strategy to use when searching for the element. - * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if - * using a JavaScript locator. Otherwise ignored. - * @return {!webdriver.promise.Promise} A promise that will be resolved with - * whether an element could be located on the page. + * @return {!webdriver.promise.Promise.} A promise + * that resolves to this element's JSON representation as defined by the + * WebDriver wire protocol. + * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol */ - isElementPresent(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; - isElementPresent(locator: any, ...var_args: any[]): webdriver.promise.Promise; - - /** - * Schedules a command to find all of the descendants of this element that match - * the given search criteria. - *

- * Note that JS locator searches cannot be restricted to a subtree. All such - * searches are delegated to this instance's parent WebDriver. - * - * @param {webdriver.Locator|Object.} locator The locator - * strategy to use when searching for the elements. - * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if - * using a JavaScript locator. Otherwise ignored. - * @return {!webdriver.promise.Promise} A promise that will be resolved with an - * array of located {@link webdriver.WebElement}s. - */ - findElements(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; - findElements(locator: any, ...var_args: any[]): webdriver.promise.Promise; - - /** - * Shortcut for querying the document directly with css. - * - * @param {string} selector a css selector - * @see webdriver.WebElement.findElement - * @return {!protractor.WebElement} - */ - $(selector: string): protractor.WebElement; - - /** - * Shortcut for querying the document directly with css. - * - * @param {string} selector a css selector - * @see webdriver.WebElement.findElements - * @return {!webdriver.promise.Promise} A promise that will be resolved to an - * array of the located {@link webdriver.WebElement}s. - */ - $$(selector: string): webdriver.promise.Promise; - - /** - * Schedule a command to find a descendant of this element. If the element - * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will - * be returned by the driver. Unlike other commands, this error cannot be - * suppressed. In other words, scheduling a command to find an element doubles - * as an assert that the element is present on the page. To test whether an - * element is present on the page, use {@code #isElementPresent} instead. - *

- * The search criteria for find an element may either be a - * {@code webdriver.Locator} object, or a simple JSON object whose sole key - * is one of the accepted locator strategies, as defined by - * {@code webdriver.Locator.Strategy}. For example, the following two - * statements are equivalent: - *

-         * var e1 = element.findElement(By.id('foo'));
-         * var e2 = element.findElement({id:'foo'});
-         * 
- *

- * Note that JS locator searches cannot be restricted to a subtree. All such - * searches are delegated to this instance's parent WebDriver. - * - * @param {webdriver.Locator|Object.} locator The locator - * strategy to use when searching for the element. - * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if - * using a JavaScript locator. Otherwise ignored. - * @return {protractor.WebElement} A WebElement that can be used to issue - * commands against the located element. If the element is not found, the - * element will be invalidated and all scheduled commands aborted. - */ - findElement(locator: webdriver.Locator, ...var_args: any[]): protractor.WebElement; - findElement(locator: any, ...var_args: any[]): protractor.WebElement; - - /** - * Evalates the input as if it were on the scope of the current element. - * @param {string} expression - * - * @return {!webdriver.promise.Promise} A promise that will resolve to the - * evaluated expression. The result will be resolved as in - * {@link webdriver.WebDriver.executeScript}. In summary - primitives will - * be resolved as is, functions will be converted to string, and elements - * will be returned as a WebElement. - */ - evaluate(expression: string): webdriver.promise.Promise; - - find(): protractor.WebElement; - - isPresent(): webdriver.promise.Promise; + toWireValue(): webdriver.promise.Promise; } - interface ElementArrayFinder{ + interface IThenFunction { + (promise: webdriver.promise.Promise): any; + } + + + interface ElementArrayFinder { + /** + * Use as: element.all(locator).getWebElements() + * Returns the array of WebElements represented by this ElementArrayFinder. + * + * @return {Array.} Array of WebElements represented by this ElementArrayFinder + */ + getWebElements(): webdriver.WebElement[]; + + /** + * Use as: element.all(locator).get(index) + * Get an element found by the locator by index. The index starts at 0. This does not actually retrieve the underlying element. + * + * @param {number} index Element index. + * + * @return {protractor.ElementFinder} Finder representing element at the given index + */ + get(index: number): protractor.ElementFinder; + + + /** + * Use as: element.all(locator).first() + * Get the first matching element for the locator. This does not actually retrieve the underlying element. + * + * @return {Protractor.ElementFinder} Finder representing the first matching element + */ + first(): protractor.ElementFinder; + + /** + * Use as: element.all(locator).last() + * Get the last matching element for the locator. This does not actually retrieve the underlying element. + * + * @return {Protractor.ElementFinder} Finder representing the last matching element + */ + last(): protractor.ElementFinder; + + /** + * Use as: element.all(locator).getWebElements() + * Returns the array of WebElements represented by this ElementArrayFinder. + * + * @return {!webdriver.promise.Promise} The array of WebElements represented by this ElementArrayFinder + */ count(): webdriver.promise.Promise; - get(index: number): protractor.WebElement; - first(): protractor.WebElement; - last(): protractor.WebElement; - then(fn: (value: any) => any): webdriver.promise.Promise; + + /** + * Use as: element.all(locator).each(eachFunction) + * Calls the input function on each ElementFinder found by the locator. + * + * @param {function(ElementFinder)} fn Input function. + */ + each(fn: IEachFunction): void; + + /** + * Use as: element.all(locator).map(mapFunction) + * Apply a map function to each element found using the locator. The callback receives the ElementFinder as the first argument and the index as a second arg. + * + * @param {function(ElementFinder, number)} mapFn Map function that will be applied to each element. + * + * @return {!webdriver.promise.Promise} A promise that resolves to an array of values returned by the map function. + */ + map(mapFn: IMapFunction): webdriver.promise.Promise; + + /** + * Use as: element.all(locator).filter(filterFn) + * Apply a filter function to each element found using the locator. Returns promise of a new array with all elements that pass the filter function. The filter function receives the ElementFinder as the first argument and the index as a second arg. + * + * @param {function(ElementFinder, number): webdriver.promise.Promise} filterFn Filter function that will test if an element should be returned. filterFn should return a promise that resolves to a boolean. + * + * @return {!webdriver.promise.Promise} A promise that resolves to an array of ElementFinders that satisfy the filter function. + */ + filter(func: IFilterFunction): webdriver.promise.Promise; + + /** + * Use as: element.all(locator).reduce(reduceFn) + * Apply a reduce function against an accumulator and every element found using the locator (from left-to-right). + * The reduce function has to reduce every element into a single value (the accumulator). + * Returns promise of the accumulator. + * The reduce function receives the accumulator, current ElementFinder, the index, and the entire array of ElementFinders, respectively. + * + * @param {function(number, ElementFinder, number, Array.): webdriver.promise.Promise} reduceFn Reduce function that reduces every element into a single value. + * @param {*} initialValue Initial value of the accumulator. + * + * @return {!webdriver.promise.Promise} A promise that resolves to the final value of the accumulator. + */ + reduce(func: IReductionFunction, initialValue: any): webdriver.promise.Promise; + } + + interface IEachFunction { + (element: protractor.ElementFinder): void; + } + + interface IMapFunction { + (element: ElementFinder, index: number): any; + } + + interface IFilterFunction { + (element: ElementFinder, index: number): webdriver.promise.Promise; + } + + interface IReductionFunction { + (accumulator: any, element: protractor.ElementFinder, index?: number, array?: protractor.ElementFinder[]): webdriver.promise.Promise; + } + + class LocatorWithColumn extends webdriver.Locator { + column(index: number): webdriver.Locator; + } + + class RepeaterLocator extends LocatorWithColumn { + row(index: number): LocatorWithColumn; } interface IProtractorLocatorStrategy extends webdriver.ILocatorStrategy { @@ -587,69 +685,160 @@ declare module protractor { * Usage: * {{status}} * var status = element(by.binding('{{status}}')); + * + * @param {string} bindingDescriptor + * @return {webdriver.Locator} */ binding(bindingDescriptor: string): webdriver.Locator; /** - * Usage: - * - * element(by.select("user")); + * Find an element by exact binding. + * + * {{ person.name }} + * + * {{person_phone|uppercase}} + * + * expect(element(by.exactBinding('person.name')).isPresent()).toBe(true); + * expect(element(by.exactBinding('person-email')).isPresent()).toBe(true); + * expect(element(by.exactBinding('person')).isPresent()).toBe(false); + * expect(element(by.exactBinding('person_phone')).isPresent()).toBe(true); + * expect(element(by.exactBinding('person_phone|uppercase')).isPresent()).toBe(true); + * expect(element(by.exactBinding('phone')).isPresent()).toBe(false); + * + * @param {string} bindingDescriptor + * @return {webdriver.Locator} */ - select(model: string): webdriver.Locator; + exactBinding(bindingDescriptor: string): webdriver.Locator; /** + * + * Find an element by ng-model expression. + * * Usage: - * - * element(by.selectedOption("user")); - */ - selectedOption(model: string): webdriver.Locator; - - /** - * @DEPRECATED - use 'model' instead. - * Usage: - * - * element(by.input('user')); - */ - input(model: string): webdriver.Locator; - - /** - * Usage: - * - * element(by.model('user')); + * + * var input = element(by.model('person.name')); + * input.sendKeys('123'); + * expect(input.getAttribute('value')).toBe('Foo123'); + * + * @param {string} model ng-model expression. + * @return {webdriver.Locator} */ model(model: string): webdriver.Locator; /** - * Usage: - * - * element(by.textarea("user")); - */ - textarea(model: string): webdriver.Locator; - - /** - * Usage: - *

- * {{cat.name}} - * {{cat.age}} - *
+ * Find a button by text. * - * // Returns the DIV for the second cat. - * var secondCat = element(by.repeater("cat in pets").row(2)); - * // Returns the SPAN for the first cat's name. - * var firstCatName = element( - * by.repeater("cat in pets").row(1).column("{{cat.name}}")); - * // Returns a promise that resolves to an array of WebElements from a column - * var ages = element( - * by.repeater("cat in pets").column("{{cat.age}}")); - * // Returns a promise that resolves to an array of WebElements containing - * // all rows of the repeater. - * var rows = element(by.repeater("cat in pets")); + * Usage: + * + * element(by.buttonText('Save')); + * + * @param {string} searchText + * @return {webdriver.Locator} */ - repeater(repeatDescriptor: string): webdriver.Locator; - buttonText(searchText: string): webdriver.Locator; + + /** + * Find a button by partial text. + * + * Usage: + * + * element(by.partialButtonText('Save')); + * + * @param {string} searchText + * @return {webdriver.Locator} + */ partialButtonText(searchText: string): webdriver.Locator; + + /** + * Find elements inside an ng-repeat. + * + * Usage: + *
+ * {{cat.name}} + * {{cat.age}} + *
+ * + *
+ * {{$index}} + *
+ *
+ *

{{book.name}}

+ *

{{book.blurb}}

+ *
+ * + * // Returns the DIV for the second cat. + * var secondCat = element(by.repeater('cat in pets').row(1)); + * + * // Returns the SPAN for the first cat's name. + * var firstCatName = element(by.repeater('cat in pets'). + * row(0).column('{{cat.name}}')); + * + * // Returns a promise that resolves to an array of WebElements from a column + * var ages = element.all( + * by.repeater('cat in pets').column('{{cat.age}}')); + * + * // Returns a promise that resolves to an array of WebElements containing + * // all top level elements repeated by the repeater. For 2 pets rows resolves + * // to an array of 2 elements. + * var rows = element.all(by.repeater('cat in pets')); + * + * // Returns a promise that resolves to an array of WebElements containing all + * // the elements with a binding to the book's name. + * var divs = element.all(by.repeater('book in library').column('book.name')); + * + * // Returns a promise that resolves to an array of WebElements containing + * // the DIVs for the second book. + * var bookInfo = element.all(by.repeater('book in library').row(1)); + * + * // Returns the H4 for the first book's name. + * var firstBookName = element(by.repeater('book in library'). + * row(0).column('{{book.name}}')); + * + * // Returns a promise that resolves to an array of WebElements containing + * // all top level elements repeated by the repeater. For 2 books divs + * // resolves to an array of 4 elements. + * var divs = element.all(by.repeater('book in library')); + */ + repeater(repeatDescriptor: string): RepeaterLocator; + + /** + * Find elements by CSS which contain a certain string. + * + * @view + * + * + * @example + * // Returns the DIV for the dog, but not cat. + * var dog = element(by.cssContainingText('.pet', 'Dog')); + * + * @param cssSelector {string} + * @param searchText {string} + * @return {webdriver.Locator} + */ + cssContainingText(cssSelector: string, searchText: string): webdriver.Locator; + + /** + * Find an element by ng-options expression. + * + * Usage: + * + * + * var allOptions = element.all(by.options('c for c in colors')); + * expect(allOptions.count()).toEqual(2); + * var firstOption = allOptions.first(); + * expect(firstOption.getText()).toEqual('red'); + * + * @param {string} optionsDescriptor ng-options expression. + * @return {webdriver.Locator} + */ + options(optionsDescriptor: string): webdriver.Locator; } var By: IProtractorLocatorStrategy; @@ -718,6 +907,43 @@ declare module protractor { //region Methods + /** + * Instruct webdriver to wait until Angular has finished rendering and has + * no outstanding $http calls before continuing. + * + * @return {!webdriver.promise.Promise} A promise that will resolve to the + * scripts return value. + */ + waitForAngular(): webdriver.promise.Promise; + + /** + * Waits for Angular to finish rendering before searching for elements. + * @see webdriver.WebDriver.findElement + * + * @param {webdriver.Locator} locator The locator used to find the element. + * @return {!webdriver.WebElement} + */ + findElement(locator: webdriver.Locator): protractor.WebElement; + + /** + * Waits for Angular to finish rendering before searching for elements. + * @see webdriver.WebDriver.findElements + * + * @param {webdriver.Locator} locator The locator used to find the elements. + * @return {!webdriver.promise.Promise} A promise that will be resolved to an + * array of the located {@link webdriver.WebElement}s. + */ + findElements(locator: webdriver.Locator): webdriver.promise.Promise; + + /** + * Tests if an element is present on the page. + * @see webdriver.WebDriver.isElementPresent + * @return {!webdriver.promise.Promise} A promise that will resolve to whether + * the element is present on the page. + */ + isElementPresent(locatorOrElement: webdriver.Locator): webdriver.promise.Promise; + isElementPresent(locatorOrElement: any): webdriver.promise.Promise; + /** * Helper function for finding elements. * @@ -739,40 +965,71 @@ declare module protractor { */ $$(cssLocator: string): ElementArrayFinder; - /** - * Instruct webdriver to wait until Angular has finished rendering and has - * no outstanding $http calls before continuing. - * - * @return {!webdriver.promise.Promise} A promise that will resolve to the - * scripts return value. - */ - waitForAngular(): webdriver.promise.Promise; - - /** - * Wrap a webdriver.WebElement with protractor specific functionality. - * - * @param {webdriver.WebElement} element - * @return {protractor.WebElement} the wrapped web element. - */ - wrapWebElement(element: webdriver.WebElement): protractor.WebElement; - /** * Add a module to load before Angular whenever Protractor.get is called. * Modules will be registered after existing modules already on the page, * so any module registered here will override preexisting modules with the same * name. * - * @param {!string} name The name of the module to load or override. - * @param {!string|Function} script The JavaScript to load the module. + * @param {string} name The name of the module to load or override. + * @param {string|Function} script The JavaScript to load the module. + * @param {...*} varArgs Any additional arguments will be provided to + * the script and may be referenced using the `arguments` object. */ - addMockModule(name: string, script: string): void; - addMockModule(name: string, script: any): void; + addMockModule(name: string, script: string, ...varArgs: any[]): void; + addMockModule(name: string, script: any, ...varArgs: any[]): void; /** * Clear the list of registered mock modules. */ clearMockModules(): void; + /** + * Remove a registered mock module. + * @param {!string} name The name of the module to remove. + */ + removeMockModule(name: string): void; + + /** + * See webdriver.WebDriver.get + * + * Navigate to the given destination and loads mock modules before + * Angular. Assumes that the page being loaded uses Angular. + * If you need to access a page which does not have Angular on load, use + * the wrapped webdriver directly. + * + * @param {string} destination Destination URL. + * @param {number=} opt_timeout Number of seconds to wait for Angular to start. + */ + get(destination: string, opt_timeout?: number): webdriver.promise.Promise; + + /** + * See webdriver.WebDriver.refresh + * + * Makes a full reload of the current page and loads mock modules before + * Angular. Assumes that the page being loaded uses Angular. + * If you need to access a page which does not have Angular on load, use + * the wrapped webdriver directly. + * + * @param {number=} opt_timeout Number of seconds to wait for Angular to start. + */ + refresh(opt_timeout?: number): void; + + /** + * Mixin navigation methods back into the navigation object so that + * they are invoked as before, i.e. driver.navigate().refresh() + */ + navigate(): webdriver.WebDriverNavigation; + + /** + * Browse to another page using in-page navigation. + * + * @param {string} url In page URL using the same syntax as $location.url() + * @returns {!webdriver.promise.Promise} A promise that will resolve once + * page has been changed. + */ + setLocation(url: string): webdriver.promise.Promise; + /** * Returns the current absolute url from AngularJS. */ @@ -799,43 +1056,14 @@ declare module protractor { debugger(): void; /** - * Schedule a command to find an element on the page. If the element cannot be - * found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will be returned - * by the driver. Unlike other commands, this error cannot be suppressed. In - * other words, scheduling a command to find an element doubles as an assert - * that the element is present on the page. To test whether an element is - * present on the page, use {@code #isElementPresent} instead. + * Beta (unstable) pause function for debugging webdriver tests. Use + * browser.pause() in your test to enter the protractor debugger from that + * point in the control flow. + * Does not require changes to the command line (no need to add 'debug'). * - *

The search criteria for find an element may either be a - * {@code webdriver.Locator} object, or a simple JSON object whose sole key - * is one of the accepted locator strategies, as defined by - * {@code webdriver.Locator.Strategy}. For example, the following two statements - * are equivalent: - *

-         * var e1 = driver.findElement(By.id('foo'));
-         * var e2 = driver.findElement({id:'foo'});
-         * 
- * - *

When running in the browser, a WebDriver cannot manipulate DOM elements - * directly; it may do so only through a {@link webdriver.WebElement} reference. - * This function may be used to generate a WebElement from a DOM element. A - * reference to the DOM element will be stored in a known location and this - * driver will attempt to retrieve it through {@link #executeScript}. If the - * element cannot be found (eg, it belongs to a different document than the - * one this instance is currently focused on), a - * {@link bot.ErrorCode.NO_SUCH_ELEMENT} error will be returned. - * - * @param {!(webdriver.Locator|Object.|Element)} locatorOrElement The - * locator strategy to use when searching for the element, or the actual - * DOM element to be located by the server. - * @param {...} var_args Arguments to pass to {@code #executeScript} if using a - * JavaScript locator. Otherwise ignored. - * @return {!protractor.WebElement} A WebElement that can be used to issue - * commands against the located element. If the element is not found, the - * element will be invalidated and all scheduled commands aborted. + * @param {=number} opt_debugPort Optional port to use for the debugging process */ - findElement(locatorOrElement: webdriver.Locator, ...var_args: any[]): protractor.WebElement; - findElement(locatorOrElement: any, ...var_args: any[]): protractor.WebElement; + pause(opt_debugPort?: number): void; //endregion } @@ -863,9 +1091,19 @@ declare module protractor { } +interface cssSelectorHelper { + (cssLocator: string): protractor.ElementFinder; +} + +interface cssArraySelectorHelper { + (cssLocator: string): protractor.ElementArrayFinder; +} + declare var browser: protractor.Protractor; declare var by: protractor.IProtractorLocatorStrategy; declare var element: protractor.Element; +declare var $: cssSelectorHelper; +declare var $$: cssArraySelectorHelper; declare module 'protractor' { export = protractor; diff --git a/angular-protractor/legacy/angular-protractor-0.17.0-tests.ts b/angular-protractor/legacy/angular-protractor-0.17.0-tests.ts new file mode 100644 index 000000000..dfd413d0e --- /dev/null +++ b/angular-protractor/legacy/angular-protractor-0.17.0-tests.ts @@ -0,0 +1,244 @@ +/// + +function TestWebDriverExports() { + var abstractBuilder: protractor.AbstractBuilder = new protractor.AbstractBuilder(); + var baseAbstractBuilder: webdriver.AbstractBuilder = abstractBuilder; + + var button: protractor.Button = new protractor.Button(); + var baseButton: webdriver.Button = button; + + var key: string = protractor.Key.ADD; + var chord: string = protractor.Key.chord(protractor.Key.NUMPAD0, protractor.Key.NUMPAD1); + + var driver: protractor.WebDriver = new protractor.Builder(). + withCapabilities(protractor.Capabilities.chrome()). + build(); + var baseDriver: webdriver.WebDriver = driver; + + var action: protractor.ActionSequence = new protractor.ActionSequence(driver); + var baseAction: webdriver.ActionSequence = action; + + var alert: protractor.Alert = new protractor.Alert(driver, 'Message'); + var baseAlert: webdriver.Alert = alert; + + var unhandledAlertError: protractor.UnhandledAlertError = new protractor.UnhandledAlertError('Message', alert); + var baseUnhandledAlertError: webdriver.UnhandledAlertError = unhandledAlertError; + + var browser: string = protractor.Browser.ANDROID; + + var builder: protractor.Builder = new protractor.Builder(); + var baseBuilder: webdriver.Builder = builder; + + var capability: string = protractor.Capability.BROWSER_NAME; + + var capabilities: protractor.Capabilities = protractor.Capabilities.chrome(); + var baseCapabilities: webdriver.Capabilities = capabilities; + + var commandName: string = protractor.CommandName.CLICK_ELEMENT; + + var command: protractor.Command = new protractor.Command(protractor.CommandName.CLICK); + var baseCommand: webdriver.Command = command; + + var eventEmitter: protractor.EventEmitter = new protractor.EventEmitter(); + var baseEventEmitter: webdriver.EventEmitter = eventEmitter; + + var firefoxDomExecutor: protractor.FirefoxDomExecutor = new protractor.FirefoxDomExecutor(); + var baseFirefoxDomExecutor: webdriver.FirefoxDomExecutor = firefoxDomExecutor; + + var webElement: protractor.WebElement = new protractor.WebElement(driver, new protractor.promise.Promise()); + var baseWebElement: webdriver.WebElement = webElement; + + var locator: protractor.Locator = new protractor.Locator('id', 'ABC'); + var baseLocator: webdriver.Locator = locator; + + var session: protractor.Session = new protractor.Session('ABC', webdriver.Capabilities.android()); + var baseSession: webdriver.Session = session; + + locator = protractor.By.name('name'); + + // logging module + + var levelName: string = protractor.logging.LevelName.ALL; + var loggingType: string = protractor.logging.Type.CLIENT; + + var level: webdriver.logging.Level = protractor.logging.Level.ALL; + + var entry: protractor.logging.Entry = new protractor.logging.Entry(protractor.logging.Level.ALL, 'Message'); + var baseEntry: webdriver.logging.Entry = entry; + + level = protractor.logging.getLevel('DEBUG'); + + protractor.logging.Preferences = { a: 123 }; + + // promise module + + var promise: protractor.promise.Promise = new protractor.promise.Promise(); + var basePromise: webdriver.promise.Promise = promise; + + var deferred: protractor.promise.Deferred = new protractor.promise.Deferred(); + var baseDeferred: webdriver.promise.Deferred = deferred; + + var flow: protractor.promise.ControlFlow = new protractor.promise.ControlFlow(); + var baseFlow: webdriver.promise.ControlFlow = flow; + + protractor.promise.asap(promise, function(value: any){ return true; }); + protractor.promise.asap(promise, function(value: any){}, function(err: any) { return 'ABC'; }); + + promise = protractor.promise.checkedNodeCall(function(err: any, value: any) { return 123; }); + + flow = protractor.promise.controlFlow(); + + promise = protractor.promise.createFlow(function(newFlow: webdriver.promise.ControlFlow) { }); + + deferred = protractor.promise.defer(function() {}); + deferred = protractor.promise.defer(function(reason?: any) {}); + + promise = protractor.promise.delayed(123); + + promise = protractor.promise.fulfilled(); + promise = protractor.promise.fulfilled({a: 123}); + + promise = protractor.promise.fullyResolved({a: 123}); + + var isPromise: boolean = protractor.promise.isPromise('ABC'); + + promise = protractor.promise.rejected({a: 123}); + + protractor.promise.setDefaultFlow(new webdriver.promise.ControlFlow()); + + promise = protractor.promise.when(promise, function(value: any) { return 123; }, function(err: Error) { return 123; }); + + // error module + + var errorCode: number = protractor.error.ErrorCode.ELEMENT_NOT_VISIBLE; + var error: protractor.error.Error = new protractor.error.Error(protractor.error.ErrorCode.ELEMENT_NOT_VISIBLE); + var baseError: webdriver.error.Error = error; + + // process module + + var isNative: boolean = protractor.process.isNative(); + var value: string; + + value = protractor.process.getEnv('name'); + value = protractor.process.getEnv('name', 'default'); + + protractor.process.setEnv('name', 'value'); + protractor.process.setEnv('name', 123); + +} + +function TestProtractor() { + var ptor: protractor.Protractor; + var driver: webdriver.WebDriver = new webdriver.Builder(). + withCapabilities(webdriver.Capabilities.chrome()). + build(); + + ptor = new protractor.Protractor(driver); + ptor = new protractor.Protractor(driver, 'baseUrl'); + ptor = new protractor.Protractor(driver, 'baseUrl', 'rootElement'); + ptor = protractor.getInstance(); + protractor.setInstance(ptor); + + ptor = protractor.wrapDriver(driver); + ptor = protractor.wrapDriver(driver, 'baseUrl'); + ptor = protractor.wrapDriver(driver, 'baseUrl', 'rootElement'); + + ptor = browser; + + driver = ptor.driver; + var baseUrl: string = ptor.baseUrl; + var rootEl: string = ptor.rootEl; + var ignoreSynchronization: boolean = ptor.ignoreSynchronization; + var params: any = ptor.params; + + ptor.debugger(); + + ptor.clearMockModules(); + ptor.addMockModule('name', 'script'); + ptor.addMockModule('name', function() {}); + ptor.waitForAngular(); + + var elementFinder: protractor.ElementFinder; + + elementFinder = ptor.element(by.id('ABC')); + elementFinder = ptor.$('.class'); + + var elementArrayFinder: protractor.ElementArrayFinder = ptor.$$('.class'); + + var webElement: webdriver.WebElement = ptor.wrapWebElement(new webdriver.WebElement(driver, 'id')); + + var locationAbsUrl: webdriver.promise.Promise = ptor.getLocationAbsUrl(); +} + +function TestElement() { + var elementFinder: protractor.ElementFinder = element(by.id('id')); + var elementArrayFinder: protractor.ElementArrayFinder = element.all(by.className('class')); +} + +function TestElementFinder() { + var elementFinder: protractor.ElementFinder = element(by.id('id')); + var promise: webdriver.promise.Promise; + + promise = elementFinder.click(); + promise = elementFinder.sendKeys(protractor.Key.UP, protractor.Key.DOWN); + promise = elementFinder.getTagName(); + promise = elementFinder.getCssValue('display'); + promise = elementFinder.getAttribute('atribute'); + promise = elementFinder.getText(); + promise = elementFinder.getSize(); + promise = elementFinder.getLocation(); + promise = elementFinder.isEnabled(); + promise = elementFinder.isSelected(); + promise = elementFinder.submit(); + promise = elementFinder.clear(); + promise = elementFinder.isDisplayed(); + promise = elementFinder.getOuterHtml(); + promise = elementFinder.getInnerHtml(); + promise = elementFinder.isElementPresent(by.id('id')); + promise = elementFinder.isElementPresent(by.js('function(a, b, c) {}'), 1, 2, 3); + promise = elementFinder.findElements(by.className('class')); + promise = elementFinder.findElements(by.js('function(a, b, c) {}'), 1, 2, 3); + promise = elementFinder.$$('.class'); + promise = elementFinder.evaluate('expression'); + promise = elementFinder.isPresent(); + + var webElement: webdriver.WebElement; + + webElement = elementFinder.$('.class'); + webElement = elementFinder.findElement(by.id('id')); + webElement = elementFinder.findElement(by.js('function(a, b, c) {}'), 1, 2, 3); + webElement = elementFinder.find(); +} + +// This function tests the angular specific locator strategies. +function TestLocatorStrategies() { + var ptor: protractor.Protractor = protractor.getInstance(); + var webElement: webdriver.WebElement; + + // Protractor Specific Locators + webElement = ptor.findElement(protractor.By.binding('binding')); + webElement = ptor.findElement(protractor.By.select('select')); + webElement = ptor.findElement(protractor.By.selectedOption('selectedOptions')); + webElement = ptor.findElement(protractor.By.input('input')); + webElement = ptor.findElement(protractor.By.model('model')); + webElement = ptor.findElement(protractor.By.textarea('textarea')); + webElement = ptor.findElement(protractor.By.repeater('repeater')); + webElement = ptor.findElement(protractor.By.buttonText('buttonText')); + webElement = ptor.findElement(protractor.By.partialButtonText('partialButtonText')); +} + +// This function tests the methods that were added to the base WebElement class +function TestWebElements() { + var ptor: protractor.Protractor = protractor.getInstance(); + + var webElement: protractor.WebElement; + var promise: webdriver.promise.Promise; + + webElement = ptor.findElement(by.id('id')).$('.class'); + promise = ptor.findElement(by.id('id')).$$('.class'); + promise = ptor.findElement(by.id('id')).evaluate('something'); + + webElement = webElement.findElement(by.id('id')).$('.class'); + promise = webElement.findElement(by.id('id')).$$('.class'); + promise = webElement.findElement(by.id('id')).evaluate('something'); +} diff --git a/angular-protractor/legacy/angular-protractor-0.17.0.d.ts b/angular-protractor/legacy/angular-protractor-0.17.0.d.ts new file mode 100644 index 000000000..38458b493 --- /dev/null +++ b/angular-protractor/legacy/angular-protractor-0.17.0.d.ts @@ -0,0 +1,906 @@ +// Type definitions for Angular Protractor 0.17.0 +// Project: https://github.com/angular/protractor +// Definitions by: Bill Armstrong +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module protractor { + //region Wrapped webdriver Items + + class AbstractBuilder extends webdriver.AbstractBuilder {} + class ActionSequence extends webdriver.ActionSequence {} + class Alert extends webdriver.Alert {} + class Builder extends webdriver.Builder {} + class Button extends webdriver.Button {} + class Capabilities extends webdriver.Capabilities {} + class Command extends webdriver.Command {} + class EventEmitter extends webdriver.EventEmitter {} + class FirefoxDomExecutor extends webdriver.FirefoxDomExecutor {} + class Locator extends webdriver.Locator {} + class Session extends webdriver.Session {} + class WebDriver extends webdriver.WebDriver {} + class Browser extends webdriver.Browser {} + class Capability extends webdriver.Capability {} + class CommandName extends webdriver.CommandName {} + class Key extends webdriver.Key {} + class UnhandledAlertError extends webdriver.UnhandledAlertError {} + + class WebElement extends webdriver.WebElement { + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElement + * @return {!protractor.WebElement} + */ + $(selector: string): protractor.WebElement; + + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElements + * @return {!webdriver.promise.Promise} A promise that will be resolved to an + * array of the located {@link webdriver.WebElement}s. + */ + $$(selector: string): webdriver.promise.Promise; + + /** + * Evalates the input as if it were on the scope of the current element. + * @param {string} expression + * + * @return {!webdriver.promise.Promise} A promise that will resolve to the + * evaluated expression. The result will be resolved as in + * {@link webdriver.WebDriver.executeScript}. In summary - primitives will + * be resolved as is, functions will be converted to string, and elements + * will be returned as a WebElement. + */ + evaluate(expression: string): webdriver.promise.Promise; + + /** + * Schedule a command to find a descendant of this element. If the element + * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will + * be returned by the driver. Unlike other commands, this error cannot be + * suppressed. In other words, scheduling a command to find an element doubles + * as an assert that the element is present on the page. To test whether an + * element is present on the page, use {@code #isElementPresent} instead. + *

+ * The search criteria for find an element may either be a + * {@code webdriver.Locator} object, or a simple JSON object whose sole key + * is one of the accepted locator strategies, as defined by + * {@code webdriver.Locator.Strategy}. For example, the following two + * statements are equivalent: + *

+         * var e1 = element.findElement(By.id('foo'));
+         * var e2 = element.findElement({id:'foo'});
+         * 
+ *

+ * Note that JS locator searches cannot be restricted to a subtree. All such + * searches are delegated to this instance's parent WebDriver. + * + * @param {webdriver.Locator|Object.} locator The locator + * strategy to use when searching for the element. + * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if + * using a JavaScript locator. Otherwise ignored. + * @return {protractor.WebElement} A WebElement that can be used to issue + * commands against the located element. If the element is not found, the + * element will be invalidated and all scheduled commands aborted. + */ + findElement(locator: webdriver.Locator, ...var_args: any[]): protractor.WebElement; + findElement(locator: any, ...var_args: any[]): protractor.WebElement; + } + + module command { + class Command extends webdriver.Command {} + class CommandName extends webdriver.CommandName {} + } + + module error { + class Error extends webdriver.error.Error {} + class ErrorCode extends webdriver.error.ErrorCode {} + } + + module events { + class EventEmitter extends webdriver.EventEmitter {} + } + + module logging { + var Preferences: any; + + class LevelName extends webdriver.logging.LevelName {} + class Type extends webdriver.logging.Type {} + class Level extends webdriver.logging.Level {} + class Entry extends webdriver.logging.Entry {} + + function getLevel(nameOrValue: string): webdriver.logging.Level; + function getLevel(nameOrValue: number): webdriver.logging.Level; + } + + module promise { + class Promise extends webdriver.promise.Promise {} + class Deferred extends webdriver.promise.Deferred {} + class ControlFlow extends webdriver.promise.ControlFlow {} + + /** + * @return {!webdriver.promise.ControlFlow} The currently active control flow. + */ + function controlFlow(): webdriver.promise.ControlFlow; + + /** + * Creates a new control flow. The provided callback will be invoked as the + * first task within the new flow, with the flow as its sole argument. Returns + * a promise that resolves to the callback result. + * @param {function(!webdriver.promise.ControlFlow)} callback The entry point + * to the newly created flow. + * @return {!webdriver.promise.Promise} A promise that resolves to the callback + * result. + */ + function createFlow(callback: (flow: webdriver.promise.ControlFlow) => any): webdriver.promise.Promise; + + /** + * Determines whether a {@code value} should be treated as a promise. + * Any object whose "then" property is a function will be considered a promise. + * + * @param {*} value The value to test. + * @return {boolean} Whether the value is a promise. + */ + function isPromise(value: any): boolean; + + /** + * Creates a promise that will be resolved at a set time in the future. + * @param {number} ms The amount of time, in milliseconds, to wait before + * resolving the promise. + * @return {!webdriver.promise.Promise} The promise. + */ + function delayed(ms: number): webdriver.promise.Promise; + + /** + * Creates a new deferred object. + * @param {Function=} opt_canceller Function to call when cancelling the + * computation of this instance's value. + * @return {!webdriver.promise.Deferred} The new deferred object. + */ + function defer(opt_canceller?: any): webdriver.promise.Deferred; + + /** + * Creates a promise that has been resolved with the given value. + * @param {*=} opt_value The resolved value. + * @return {!webdriver.promise.Promise} The resolved promise. + */ + function fulfilled(opt_value?: any): webdriver.promise.Promise; + + /** + * Creates a promise that has been rejected with the given reason. + * @param {*=} opt_reason The rejection reason; may be any value, but is + * usually an Error or a string. + * @return {!webdriver.promise.Promise} The rejected promise. + */ + function rejected(opt_reason?: any): webdriver.promise.Promise; + + /** + * Wraps a function that is assumed to be a node-style callback as its final + * argument. This callback takes two arguments: an error value (which will be + * null if the call succeeded), and the success value as the second argument. + * If the call fails, the returned promise will be rejected, otherwise it will + * be resolved with the result. + * @param {!Function} fn The function to wrap. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * result of the provided function's callback. + */ + function checkedNodeCall(fn: (error: any, value: any) => any): webdriver.promise.Promise; + + /** + * Registers an observer on a promised {@code value}, returning a new promise + * that will be resolved when the value is. If {@code value} is not a promise, + * then the return promise will be immediately resolved. + * @param {*} value The value to observe. + * @param {Function=} opt_callback The function to call when the value is + * resolved successfully. + * @param {Function=} opt_errback The function to call when the value is + * rejected. + * @return {!webdriver.promise.Promise} A new promise. + */ + function when(value: any, opt_callback?: (value: any) => any, opt_errback?: (error: any) => any): webdriver.promise.Promise; + + /** + * Invokes the appropriate callback function as soon as a promised + * {@code value} is resolved. This function is similar to + * {@code webdriver.promise.when}, except it does not return a new promise. + * @param {*} value The value to observe. + * @param {Function} callback The function to call when the value is + * resolved successfully. + * @param {Function=} opt_errback The function to call when the value is + * rejected. + */ + function asap(value: any, callback: (value: any) => any, opt_errback?: (error: any) => any): void; + + /** + * Returns a promise that will be resolved with the input value in a + * fully-resolved state. If the value is an array, each element will be fully + * resolved. Likewise, if the value is an object, all keys will be fully + * resolved. In both cases, all nested arrays and objects will also be + * fully resolved. All fields are resolved in place; the returned promise will + * resolve on {@code value} and not a copy. + * + * Warning: This function makes no checks against objects that contain + * cyclical references: + * + * var value = {}; + * value['self'] = value; + * webdriver.promise.fullyResolved(value); // Stack overflow. + * + * @param {*} value The value to fully resolve. + * @return {!webdriver.promise.Promise} A promise for a fully resolved version + * of the input value. + */ + function fullyResolved(value: any): webdriver.promise.Promise; + + /** + * Changes the default flow to use when no others are active. + * @param {!webdriver.promise.ControlFlow} flow The new default flow. + * @throws {Error} If the default flow is not currently active. + */ + function setDefaultFlow(flow: webdriver.promise.ControlFlow): void; + + } + + module process { + + /** + * Queries for a named environment variable. + * @param {string} name The name of the environment variable to look up. + * @param {string=} opt_default The default value if the named variable is not + * defined. + * @return {string} The queried environment variable. + */ + function getEnv(name: string, opt_default?: string): string; + + /** + * @return {boolean} Whether the current process is Node's native process + * object. + */ + function isNative(): boolean; + + /** + * Sets an environment value. If the new value is either null or undefined, the + * environment variable will be cleared. + * @param {string} name The value to set. + * @param {*} value The new value; will be coerced to a string. + */ + function setEnv(name: string, value: any): void; + + } + + //endregion + + interface Element { + (locator: webdriver.Locator): ElementFinder; + all(locator: webdriver.Locator): ElementArrayFinder; + } + + interface ElementFinder { + /** + * Schedules a command to click on this element. + * @return {!webdriver.promise.Promise} A promise that will be resolved when + * the click command has completed. + */ + click(): webdriver.promise.Promise; + + /** + * Schedules a command to type a sequence on the DOM element represented by this + * instance. + *

+ * Modifier keys (SHIFT, CONTROL, ALT, META) are stateful; once a modifier is + * processed in the keysequence, that key state is toggled until one of the + * following occurs: + *

+ * Note: On browsers where native keyboard events are not yet + * supported (e.g. Firefox on OS X), key events will be synthesized. Special + * punctionation keys will be synthesized according to a standard QWERTY en-us + * keyboard layout. + * + * @param {...string} var_args The sequence of keys to + * type. All arguments will be joined into a single sequence (var_args is + * permitted for convenience). + * @return {!webdriver.promise.Promise} A promise that will be resolved when all + * keys have been typed. + */ + sendKeys(...var_args: string[]): webdriver.promise.Promise; + + /** + * Schedules a command to query for the tag/node name of this element. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * element's tag name. + */ + getTagName(): webdriver.promise.Promise; + + /** + * Schedules a command to query for the computed style of the element + * represented by this instance. If the element inherits the named style from + * its parent, the parent will be queried for its value. Where possible, color + * values will be converted to their hex representation (e.g. #00ff00 instead of + * rgb(0, 255, 0)). + *

+ * Warning: the value returned will be as the browser interprets it, so + * it may be tricky to form a proper assertion. + * + * @param {string} cssStyleProperty The name of the CSS style property to look + * up. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * requested CSS value. + */ + getCssValue(cssStyleProperty: string): webdriver.promise.Promise; + + /** + * Schedules a command to query for the value of the given attribute of the + * element. Will return the current value even if it has been modified after the + * page has been loaded. More exactly, this method will return the value of the + * given attribute, unless that attribute is not present, in which case the + * value of the property with the same name is returned. If neither value is + * set, null is returned. The "style" attribute is converted as best can be to a + * text representation with a trailing semi-colon. The following are deemed to + * be "boolean" attributes and will be returned as thus: + * + *

async, autofocus, autoplay, checked, compact, complete, controls, declare, + * defaultchecked, defaultselected, defer, disabled, draggable, ended, + * formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, + * loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, + * paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, + * selected, spellcheck, truespeed, willvalidate + * + *

Finally, the following commonly mis-capitalized attribute/property names + * are evaluated as expected: + *

+ * @param {string} attributeName The name of the attribute to query. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * attribute's value. + */ + getAttribute(attributeName: string): webdriver.promise.Promise; + + /** + * Get the visible (i.e. not hidden by CSS) innerText of this element, including + * sub-elements, without any leading or trailing whitespace. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * element's visible text. + */ + getText(): webdriver.promise.Promise; + + /** + * Schedules a command to compute the size of this element's bounding box, in + * pixels. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * element's size as a {@code {width:number, height:number}} object. + */ + getSize(): webdriver.promise.Promise; + + /** + * Schedules a command to compute the location of this element in page space. + * @return {!webdriver.promise.Promise} A promise that will be resolved to the + * element's location as a {@code {x:number, y:number}} object. + */ + getLocation(): webdriver.promise.Promise; + + /** + * Schedules a command to query whether the DOM element represented by this + * instance is enabled, as dicted by the {@code disabled} attribute. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * whether this element is currently enabled. + */ + isEnabled(): webdriver.promise.Promise; + + /** + * Schedules a command to query whether this element is selected. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * whether this element is currently selected. + */ + isSelected(): webdriver.promise.Promise; + + /** + * Schedules a command to submit the form containing this element (or this + * element if it is a FORM element). This command is a no-op if the element is + * not contained in a form. + * @return {!webdriver.promise.Promise} A promise that will be resolved when + * the form has been submitted. + */ + submit(): webdriver.promise.Promise; + + /** + * Schedules a command to clear the {@code value} of this element. This command + * has no effect if the underlying DOM element is neither a text INPUT element + * nor a TEXTAREA element. + * @return {!webdriver.promise.Promise} A promise that will be resolved when + * the element has been cleared. + */ + clear(): webdriver.promise.Promise; + + /** + * Schedules a command to test whether this element is currently displayed. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * whether this element is currently visible on the page. + */ + isDisplayed(): webdriver.promise.Promise; + + /** + * Schedules a command to retrieve the outer HTML of this element. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * the element's outer HTML. + */ + getOuterHtml(): webdriver.promise.Promise; + + /** + * Schedules a command to retrieve the inner HTML of this element. + * @return {!webdriver.promise.Promise} A promise that will be resolved with the + * element's inner HTML. + */ + getInnerHtml(): webdriver.promise.Promise; + + /** + * Schedules a command to test if there is at least one descendant of this + * element that matches the given search criteria. + * + *

Note that JS locator searches cannot be restricted to a subtree of the + * DOM. All such searches are delegated to this instance's parent WebDriver. + * + * @param {webdriver.Locator|Object.} locator The locator + * strategy to use when searching for the element. + * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if + * using a JavaScript locator. Otherwise ignored. + * @return {!webdriver.promise.Promise} A promise that will be resolved with + * whether an element could be located on the page. + */ + isElementPresent(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; + isElementPresent(locator: any, ...var_args: any[]): webdriver.promise.Promise; + + /** + * Schedules a command to find all of the descendants of this element that match + * the given search criteria. + *

+ * Note that JS locator searches cannot be restricted to a subtree. All such + * searches are delegated to this instance's parent WebDriver. + * + * @param {webdriver.Locator|Object.} locator The locator + * strategy to use when searching for the elements. + * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if + * using a JavaScript locator. Otherwise ignored. + * @return {!webdriver.promise.Promise} A promise that will be resolved with an + * array of located {@link webdriver.WebElement}s. + */ + findElements(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; + findElements(locator: any, ...var_args: any[]): webdriver.promise.Promise; + + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElement + * @return {!protractor.WebElement} + */ + $(selector: string): protractor.WebElement; + + /** + * Shortcut for querying the document directly with css. + * + * @param {string} selector a css selector + * @see webdriver.WebElement.findElements + * @return {!webdriver.promise.Promise} A promise that will be resolved to an + * array of the located {@link webdriver.WebElement}s. + */ + $$(selector: string): webdriver.promise.Promise; + + /** + * Schedule a command to find a descendant of this element. If the element + * cannot be found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will + * be returned by the driver. Unlike other commands, this error cannot be + * suppressed. In other words, scheduling a command to find an element doubles + * as an assert that the element is present on the page. To test whether an + * element is present on the page, use {@code #isElementPresent} instead. + *

+ * The search criteria for find an element may either be a + * {@code webdriver.Locator} object, or a simple JSON object whose sole key + * is one of the accepted locator strategies, as defined by + * {@code webdriver.Locator.Strategy}. For example, the following two + * statements are equivalent: + *

+         * var e1 = element.findElement(By.id('foo'));
+         * var e2 = element.findElement({id:'foo'});
+         * 
+ *

+ * Note that JS locator searches cannot be restricted to a subtree. All such + * searches are delegated to this instance's parent WebDriver. + * + * @param {webdriver.Locator|Object.} locator The locator + * strategy to use when searching for the element. + * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if + * using a JavaScript locator. Otherwise ignored. + * @return {protractor.WebElement} A WebElement that can be used to issue + * commands against the located element. If the element is not found, the + * element will be invalidated and all scheduled commands aborted. + */ + findElement(locator: webdriver.Locator, ...var_args: any[]): protractor.WebElement; + findElement(locator: any, ...var_args: any[]): protractor.WebElement; + + /** + * Evalates the input as if it were on the scope of the current element. + * @param {string} expression + * + * @return {!webdriver.promise.Promise} A promise that will resolve to the + * evaluated expression. The result will be resolved as in + * {@link webdriver.WebDriver.executeScript}. In summary - primitives will + * be resolved as is, functions will be converted to string, and elements + * will be returned as a WebElement. + */ + evaluate(expression: string): webdriver.promise.Promise; + + /** + * Use as: element(locator).element(locator) + * Calls to element may be chained to find elements within a parent. + * + * @param {webdriver.Locator} The locator that will be used to find descendents. + * + * @return {protractor.ElementFinder} the descendent element found by the locator + */ + element(locator: webdriver.Locator): protractor.ElementFinder; + + /** + * Use as: element(locator).all(locator) + * Calls to element may be chained to find an array of elements within a parent. + * + * @param {webdriver.Locator} The locator that will be used to find descendents. + * + * @return {protractor.ElementArrayFinder} the descendent elements found by the locator + */ + all(locator: webdriver.Locator): protractor.ElementArrayFinder; + + find(): protractor.WebElement; + + isPresent(): webdriver.promise.Promise; + } + + interface ElementArrayFinder{ + count(): webdriver.promise.Promise; + get(index: number): protractor.WebElement; + first(): protractor.WebElement; + last(): protractor.WebElement; + then(fn: (value: any) => any): webdriver.promise.Promise; + } + + class LocatorWithColumn extends webdriver.Locator { + column(index: number): webdriver.Locator; + } + + class RepeaterLocator extends LocatorWithColumn { + row(index: number): LocatorWithColumn; + } + + interface IProtractorLocatorStrategy extends webdriver.ILocatorStrategy { + /** + * Add a locator to this instance of ProtractorBy. This locator can then be + * used with element(by.()). + * + * @param {string} name + * @param {function|string} script A script to be run in the context of + * the browser. This script will be passed an array of arguments + * that begins with the element scoping the search, and then + * contains any args passed into the locator. It should return + * an array of elements. + */ + addLocator(name: string, script: any): void; + + /** + * Usage: + * {{status}} + * var status = element(by.binding('{{status}}')); + */ + binding(bindingDescriptor: string): webdriver.Locator; + + /** + * Usage: + * + * element(by.select("user")); + */ + select(model: string): webdriver.Locator; + + /** + * Usage: + * + * element(by.selectedOption("user")); + */ + selectedOption(model: string): webdriver.Locator; + + /** + * @DEPRECATED - use 'model' instead. + * Usage: + * + * element(by.input('user')); + */ + input(model: string): webdriver.Locator; + + /** + * Usage: + * + * element(by.model('user')); + */ + model(model: string): webdriver.Locator; + + /** + * Usage: + * + * element(by.textarea("user")); + */ + textarea(model: string): webdriver.Locator; + + /** + * Usage: + *

+ * {{cat.name}} + * {{cat.age}} + *
+ * + * // Returns the DIV for the second cat. + * var secondCat = element(by.repeater("cat in pets").row(2)); + * // Returns the SPAN for the first cat's name. + * var firstCatName = element( + * by.repeater("cat in pets").row(1).column("{{cat.name}}")); + * // Returns a promise that resolves to an array of WebElements from a column + * var ages = element( + * by.repeater("cat in pets").column("{{cat.age}}")); + * // Returns a promise that resolves to an array of WebElements containing + * // all rows of the repeater. + * var rows = element(by.repeater("cat in pets")); + */ + repeater(repeatDescriptor: string): RepeaterLocator; + + buttonText(searchText: string): webdriver.Locator; + + partialButtonText(searchText: string): webdriver.Locator; + } + + var By: IProtractorLocatorStrategy; + + class Protractor extends webdriver.WebDriver { + + //region Constructors + + /** + * @param {webdriver.WebDriver} webdriver + * @param {string=} opt_baseUrl A base URL to run get requests against. + * @param {string=body} opt_rootElement Selector element that has an ng-app in + * scope. + * @constructor + */ + constructor(webdriver: webdriver.WebDriver, opt_baseUrl?: string, opt_rootElement?: string); + + //endregion + + //region Properties + + /** + * The wrapped webdriver instance. Use this to interact with pages that do + * not contain Angular (such as a log-in screen). + * + * @type {webdriver.WebDriver} + */ + driver: webdriver.WebDriver; + + /** + * All get methods will be resolved against this base URL. Relative URLs are = + * resolved the way anchor tags resolve. + * + * @type {string} + */ + baseUrl: string; + + /** + * The css selector for an element on which to find Angular. This is usually + * 'body' but if your ng-app is on a subsection of the page it may be + * a subelement. + * + * @type {string} + */ + rootEl: string; + + /** + * If true, Protractor will not attempt to synchronize with the page before + * performing actions. This can be harmful because Protractor will not wait + * until $timeouts and $http calls have been processed, which can cause + * tests to become flaky. This should be used only when necessary, such as + * when a page continuously polls an API using $timeout. + * + * @type {boolean} + */ + ignoreSynchronization: boolean; + + /** + * An object that holds custom test parameters. + * + * @type {Object} + */ + params: any; + + //endregion + + //region Methods + + /** + * Helper function for finding elements. + * + * @type {function(webdriver.Locator): ElementFinder} + */ + element(locator: webdriver.Locator): ElementFinder; + + /** + * Helper function for finding elements by css. + * + * @type {function(string): ElementFinder} + */ + $(cssLocator: string): ElementFinder; + + /** + * Helper function for finding arrays of elements by css. + * + * @type {function(string): ElementArrayFinder} + */ + $$(cssLocator: string): ElementArrayFinder; + + /** + * Instruct webdriver to wait until Angular has finished rendering and has + * no outstanding $http calls before continuing. + * + * @return {!webdriver.promise.Promise} A promise that will resolve to the + * scripts return value. + */ + waitForAngular(): webdriver.promise.Promise; + + /** + * Wrap a webdriver.WebElement with protractor specific functionality. + * + * @param {webdriver.WebElement} element + * @return {protractor.WebElement} the wrapped web element. + */ + wrapWebElement(element: webdriver.WebElement): protractor.WebElement; + + /** + * Add a module to load before Angular whenever Protractor.get is called. + * Modules will be registered after existing modules already on the page, + * so any module registered here will override preexisting modules with the same + * name. + * + * @param {!string} name The name of the module to load or override. + * @param {!string|Function} script The JavaScript to load the module. + */ + addMockModule(name: string, script: string): void; + addMockModule(name: string, script: any): void; + + /** + * Clear the list of registered mock modules. + */ + clearMockModules(): void; + + /** + * Returns the current absolute url from AngularJS. + */ + getLocationAbsUrl(): webdriver.promise.Promise; + + /** + * Pauses the test and injects some helper functions into the browser, so that + * debugging may be done in the browser console. + * + * This should be used under node in debug mode, i.e. with + * protractor debug + * + * While in the debugger, commands can be scheduled through webdriver by + * entering the repl: + * debug> repl + * Press Ctrl + C to leave rdebug repl + * > ptor.findElement(protractor.By.input('user').sendKeys('Laura')); + * > ptor.debugger(); + * debug> c + * + * This will run the sendKeys command as the next task, then re-enter the + * debugger. + */ + debugger(): void; + + /** + * Schedule a command to find an element on the page. If the element cannot be + * found, a {@code bot.ErrorCode.NO_SUCH_ELEMENT} result will be returned + * by the driver. Unlike other commands, this error cannot be suppressed. In + * other words, scheduling a command to find an element doubles as an assert + * that the element is present on the page. To test whether an element is + * present on the page, use {@code #isElementPresent} instead. + * + *

The search criteria for find an element may either be a + * {@code webdriver.Locator} object, or a simple JSON object whose sole key + * is one of the accepted locator strategies, as defined by + * {@code webdriver.Locator.Strategy}. For example, the following two statements + * are equivalent: + *

+         * var e1 = driver.findElement(By.id('foo'));
+         * var e2 = driver.findElement({id:'foo'});
+         * 
+ * + *

When running in the browser, a WebDriver cannot manipulate DOM elements + * directly; it may do so only through a {@link webdriver.WebElement} reference. + * This function may be used to generate a WebElement from a DOM element. A + * reference to the DOM element will be stored in a known location and this + * driver will attempt to retrieve it through {@link #executeScript}. If the + * element cannot be found (eg, it belongs to a different document than the + * one this instance is currently focused on), a + * {@link bot.ErrorCode.NO_SUCH_ELEMENT} error will be returned. + * + * @param {!(webdriver.Locator|Object.|Element)} locatorOrElement The + * locator strategy to use when searching for the element, or the actual + * DOM element to be located by the server. + * @param {...} var_args Arguments to pass to {@code #executeScript} if using a + * JavaScript locator. Otherwise ignored. + * @return {!protractor.WebElement} A WebElement that can be used to issue + * commands against the located element. If the element is not found, the + * element will be invalidated and all scheduled commands aborted. + */ + findElement(locatorOrElement: webdriver.Locator, ...var_args: any[]): protractor.WebElement; + findElement(locatorOrElement: any, ...var_args: any[]): protractor.WebElement; + + //endregion + } + + /** + * Create a new instance of Protractor by wrapping a webdriver instance. + * + * @param {webdriver.WebDriver} webdriver The configured webdriver instance. + * @param {string=} opt_baseUrl A URL to prepend to relative gets. + * @return {Protractor} + */ + function wrapDriver(webdriver: webdriver.WebDriver, opt_baseUrl?: string, opt_rootElement?: string): Protractor; + + /** + * Set a singleton instance of protractor. + * @param {Protractor} ptor + */ + function setInstance(ptor: Protractor): void; + + /** + * Get the singleton instance. + * @return {Protractor} + */ + function getInstance(): Protractor; + +} + +interface cssSelectorHelper { + (cssLocator: string): protractor.ElementFinder; +} + +declare var browser: protractor.Protractor; +declare var by: protractor.IProtractorLocatorStrategy; +declare var element: protractor.Element; +declare var $: cssSelectorHelper; +declare var $$: cssSelectorHelper; + +declare module 'protractor' { + export = protractor; +} From a5c374e96a57b59df69a78de61df0f4eac6c95f3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 15 Jul 2014 17:09:59 -0700 Subject: [PATCH 02/25] Fix JQueryUI Slider definitions --- jqueryui/jqueryui.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jqueryui/jqueryui.d.ts b/jqueryui/jqueryui.d.ts index 26492bf20..26e2d6cdc 100644 --- a/jqueryui/jqueryui.d.ts +++ b/jqueryui/jqueryui.d.ts @@ -609,11 +609,14 @@ declare module JQueryUI { orientation?: string; range?: any; // boolean or string step?: number; - // value?: number; - // values?: number[]; + value?: number; + values?: number[]; } interface SliderUIParams { + handle?: JQuery; + value?: number; + values?: number[]; } interface SliderEvent { From b41dc8fe9c5bb19d8bf0c1a7d5f187dccbd60c4e Mon Sep 17 00:00:00 2001 From: NewNotMoon Date: Wed, 16 Jul 2014 09:13:55 +0900 Subject: [PATCH 03/25] add jquery.pjax.falsandtru --- CONTRIBUTORS.md | 1 + jquery.pjax.falsandtru/jquery.pjax-tests.ts | 96 ++++++++++ jquery.pjax.falsandtru/jquery.pjax.d.ts | 189 ++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 jquery.pjax.falsandtru/jquery.pjax-tests.ts create mode 100644 jquery.pjax.falsandtru/jquery.pjax.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0fa132294..ef4467f22 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -164,6 +164,7 @@ All definitions files include a header with the author and editors, so at some p * [jQuery.payment](http://needim.github.io/noty/) (by [Eric J. Smith](https://github.com/ejsmith/)) * [jQuery.pickadate](https://github.com/amsul/pickadate.js) (by [Theodore Brown](https://github.com/theodorejb)) * [jQuery.pjax](https://github.com/defunkt/jquery-pjax) (by [Junle Li](https://github.com/lijunle)) +* [jQuery.pjax.falsandtru](https://github.com/falsandtru/jquery.pjax.js/) (by [NewNotMoon](https://new.not-moon.net/)) * [jQuery.pnotify](http://sciactive.github.io/pnotify/) (by [David Sichau](https://github.com/DavidSichau/)) * [jQuery.postMessage](http://benalman.com/projects/jquery-postmessage-plugin/) (by [Junle Li](https://github.com/lijunle)) * [jQuery.prettyphoto](https://github.com/scaron/prettyphoto) (by [Paul Gaske](https://github.com/pgaske)) diff --git a/jquery.pjax.falsandtru/jquery.pjax-tests.ts b/jquery.pjax.falsandtru/jquery.pjax-tests.ts new file mode 100644 index 000000000..fd8cbaecd --- /dev/null +++ b/jquery.pjax.falsandtru/jquery.pjax-tests.ts @@ -0,0 +1,96 @@ +/// +/// + +function test_pjax() { + $.pjax(); +} + +function test_pjax_selector() { + $('a').pjax(); +} + +function test_pjax_option() { + $.pjax({ + area: 'body', + load: { + head: 'base, meta, link', + css: true, + script: true + }, + cache: { click: true, submit: false, popstate: true }, + server: { query: null } + }); +} + +function test_pjax_event() { + $.pjax({ + wait: 1000 + }); + $(document).bind('pjax.request', function () { + $('div.loading').fadeIn(100); + }); + $(document).bind('pjax.render', function () { + $('div.loading').fadeOut(500); + }); +} + +function test_pjax_progressbar() { + $('body').append('

'); + $.pjax({ + area: 'div.pjax', + callbacks: { + before: function () { + $('div.loading').children().width(''); + $('div.loading').fadeIn(0); + }, + ajax: { + xhr: function () { + var xhr = jQuery.ajaxSettings.xhr(); + + $('div.loading').children().width('5%'); + if (xhr instanceof Object && 'onprogress' in xhr) { + xhr.addEventListener('progress', function (event) { + var percentage = event.total ? event.loaded / event.total : 0.4; + percentage = percentage * 90 + 5; + $('div.loading').children().width(percentage + '%'); + }, false); + xhr.addEventListener('load', function (event) { + $('div.loading').children().width('95%'); + }, false); + xhr.addEventListener('error', function (event) { + $('div.loading').children().css('background-color', '#00f'); + }, false); + } + return xhr; + } + }, + update: { + content: { + after: function () { + $('div.loading').children().width('96.25%'); + } + }, + css: { + after: function () { + $('div.loading').children().width('97.5%'); + } + }, + script: { + after: function () { + $('div.loading').children().width('98.75%'); + } + }, + render: { + after: function () { + $('div.loading').children().width('100%'); + $('div.loading').fadeOut(50); + } + } + } + }, + ajax: { timeout: 3000 }, + wait: 1000 + }); +} \ No newline at end of file diff --git a/jquery.pjax.falsandtru/jquery.pjax.d.ts b/jquery.pjax.falsandtru/jquery.pjax.d.ts new file mode 100644 index 000000000..07bc153df --- /dev/null +++ b/jquery.pjax.falsandtru/jquery.pjax.d.ts @@ -0,0 +1,189 @@ +// Type definitions for jquery.pjax.ts by falsandtru +// Project: https://github.com/falsandtru/jquery.pjax.js/ +// Definitions by: 新ゝ月 NewNotMoon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface PjaxSetting { + gns?: string; + ns?: string; + area?: any; // string, array, function( event, param, origUrl, destUrl ) + link?: string; + filter?: any; // string, function() + form?: string; + scope?: Object; + state?: any; // any, function(event, param, origUrl, destUrl ) + scrollTop?: any; // number, function( event, param, origUrl, destUrl ), null, false + scrollLeft?: any; // number, function( event, param, origUrl, destUrl ), null, false + scroll?: { + delay?: number; + record?: boolean //internal + queue?: number[] //internal + }; + ajax?: JQueryAjaxSettings; + contentType?: string; + load?: { + head?: string; + css?: boolean; + script?: boolean; + execute?: boolean; + reload?: string; + ignore?: string; + sync?: boolean; + ajax?: JQueryAjaxSettings; + rewrite?: (element: any) => any; + redirect?: boolean; + }; + interval?: number; + cache?: { + click?: boolean; + submit?: boolean; + popstate?: boolean; + get?: boolean; + post?: boolean; + page?: boolean; + size?: number; + mix?: number; + expires?: { + min?: number; + max?: number; + }; + }; + wait?: any; // number, function( event, param, origUrl, destUrl ): number + fallback?: any; // boolean, function( event, param, origUrl, destUrl ): boolean + fix?: { + location?: boolean; + history?: boolean; + scroll?: boolean; + reset?: boolean; + }; + database?: boolean; + server?: { + query?: any; // string, object + header?: { + area?: boolean; + head?: boolean; + css?: boolean; + script?: boolean; + }; + }; + callback?: (event: JQueryEventObject, param: any) => any; + callbacks?: { + before?: (event: JQueryEventObject, param: any) => any; + after?: (event: JQueryEventObject, param: any) => any; + ajax?: { + xhr?: (event: JQueryEventObject, param: any) => any; + beforeSend?: (event: JQueryEventObject, param: any, data: any, ajaxSettings: any) => any; + dataFilter?: (event: JQueryEventObject, param: any, data: any, dataType: any) => any; + success?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + error?: (event: JQueryEventObject, param: any, XMLHttpRequest: XMLHttpRequest, textStatus: string, errorThrown: any) => any; + complete?: (event: JQueryEventObject, param: any, XMLHttpRequest: XMLHttpRequest, textStatus: string) => any; + done?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + fail?: (event: JQueryEventObject, param: any, XMLHttpRequest: XMLHttpRequest, textStatus: string, errorThrown: any) => any; + always?: (event: JQueryEventObject, param: any, XMLHttpRequest: XMLHttpRequest, textStatus: string) => any; + }; + update?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + cache?: { + before?: (event: JQueryEventObject, param: any, cache: any) => any; + after?: (event: JQueryEventObject, param: any, cache: any) => any; + }; + redirect?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + url?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + title?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + head?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + content?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + scroll?: { + before?: (event: JQueryEventObject, param: any) => any; + after?: (event: JQueryEventObject, param: any) => any; + }; + css?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + script?: { + before?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + after?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + render?: { + before?: (event: JQueryEventObject, param: any) => any; + after?: (event: JQueryEventObject, param: any) => any; + }; + verify?: { + before?: (event: JQueryEventObject, param: any) => any; + after?: (event: JQueryEventObject, param: any) => any; + }; + success?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + error?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + complete?: (event: JQueryEventObject, param: any, data: any, textStatus: string, XMLHttpRequest: XMLHttpRequest) => any; + }; + param?: any; + + // internal + uuid?: string; + nss?: { + name?: string; + event?: string[]; + click?: string; + submit?: string; + popstate?: string; + scroll?: string; + data?: string; + class4html?: string; + requestHeader?: string; + }; + origLocation?: HTMLAnchorElement; + destLocation?: HTMLAnchorElement; + retry?: boolean; + speedcheck?: boolean; + disable?: boolean; + option?: any; + }; +} + +interface JQueryStatic { + pjax: { + (setting?: PjaxSetting): any; + enable(): any; + disable(): any; + click(url: string, attr: { href?: string; }): any; + click(url: HTMLAnchorElement, attr: { href?: string; }): any; + click(url: JQuery, attr: { href?: string; }): any; + click(url: any, attr: { href?: string; }): any; + submit(url: string, attr: { action?: string; method?: string; }, data: any): any; + submit(url: HTMLFormElement, attr?: { action?: string; method?: string; }, data?: any): any; + submit(url: JQuery, attr?: { action?: string; method?: string; }, data?: any): any; + submit(url: any, attr?: { action?: string; method?: string; }, data?: any): any; + follow(event: JQueryEventObject, ajax: JQueryXHR, timeStamp?: number): boolean; + setCache(): any; + setCache(url: string): any; + setCache(url: string, data: string): any; + setCache(url: string, data: string, textStatus: string, XMLHttpRequest: XMLHttpRequest): any; + getCache(): any; + getCache(url: string): any; + removeCache(url: string): any; + removeCache(): any; + clearCache(): any; + }; +} + +interface JQuery { + pjax(setting?: PjaxSetting): any; +} \ No newline at end of file From e65feae2035aa410b1462a51f5bb8fd54a57d9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E3=82=9D=E6=9C=88?= Date: Wed, 16 Jul 2014 10:08:56 +0900 Subject: [PATCH 04/25] Update jquery.pjax-tests.ts --- jquery.pjax.falsandtru/jquery.pjax-tests.ts | 61 --------------------- 1 file changed, 61 deletions(-) diff --git a/jquery.pjax.falsandtru/jquery.pjax-tests.ts b/jquery.pjax.falsandtru/jquery.pjax-tests.ts index fd8cbaecd..18eae623c 100644 --- a/jquery.pjax.falsandtru/jquery.pjax-tests.ts +++ b/jquery.pjax.falsandtru/jquery.pjax-tests.ts @@ -33,64 +33,3 @@ function test_pjax_event() { $('div.loading').fadeOut(500); }); } - -function test_pjax_progressbar() { - $('body').append(''); - $.pjax({ - area: 'div.pjax', - callbacks: { - before: function () { - $('div.loading').children().width(''); - $('div.loading').fadeIn(0); - }, - ajax: { - xhr: function () { - var xhr = jQuery.ajaxSettings.xhr(); - - $('div.loading').children().width('5%'); - if (xhr instanceof Object && 'onprogress' in xhr) { - xhr.addEventListener('progress', function (event) { - var percentage = event.total ? event.loaded / event.total : 0.4; - percentage = percentage * 90 + 5; - $('div.loading').children().width(percentage + '%'); - }, false); - xhr.addEventListener('load', function (event) { - $('div.loading').children().width('95%'); - }, false); - xhr.addEventListener('error', function (event) { - $('div.loading').children().css('background-color', '#00f'); - }, false); - } - return xhr; - } - }, - update: { - content: { - after: function () { - $('div.loading').children().width('96.25%'); - } - }, - css: { - after: function () { - $('div.loading').children().width('97.5%'); - } - }, - script: { - after: function () { - $('div.loading').children().width('98.75%'); - } - }, - render: { - after: function () { - $('div.loading').children().width('100%'); - $('div.loading').fadeOut(50); - } - } - } - }, - ajax: { timeout: 3000 }, - wait: 1000 - }); -} \ No newline at end of file From 98077b3ab84ddfbb7be526bd7adb3a116ef58db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B0=E3=82=9D=E6=9C=88?= Date: Wed, 16 Jul 2014 22:11:18 +0900 Subject: [PATCH 05/25] Update CONTRIBUTORS.md Sorry, I was writing the wrong URL. --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ef4467f22..c01d01147 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -164,7 +164,7 @@ All definitions files include a header with the author and editors, so at some p * [jQuery.payment](http://needim.github.io/noty/) (by [Eric J. Smith](https://github.com/ejsmith/)) * [jQuery.pickadate](https://github.com/amsul/pickadate.js) (by [Theodore Brown](https://github.com/theodorejb)) * [jQuery.pjax](https://github.com/defunkt/jquery-pjax) (by [Junle Li](https://github.com/lijunle)) -* [jQuery.pjax.falsandtru](https://github.com/falsandtru/jquery.pjax.js/) (by [NewNotMoon](https://new.not-moon.net/)) +* [jQuery.pjax.falsandtru](https://github.com/falsandtru/jquery.pjax.js/) (by [NewNotMoon](http://new.not-moon.net/)) * [jQuery.pnotify](http://sciactive.github.io/pnotify/) (by [David Sichau](https://github.com/DavidSichau/)) * [jQuery.postMessage](http://benalman.com/projects/jquery-postmessage-plugin/) (by [Junle Li](https://github.com/lijunle)) * [jQuery.prettyphoto](https://github.com/scaron/prettyphoto) (by [Paul Gaske](https://github.com/pgaske)) From ad8d43a73b3f5c2302abba8cb5666c8a3f7370fc Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Wed, 16 Jul 2014 23:39:39 +0400 Subject: [PATCH 06/25] Remove extra declaration of Em.Handlebars.compile in ember.d.ts --- ember/ember.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ember/ember.d.ts b/ember/ember.d.ts index bbb555e8a..2a0b35e42 100644 --- a/ember/ember.d.ts +++ b/ember/ember.d.ts @@ -2235,7 +2235,6 @@ declare module Em { var print: typeof Ember.Handlebars.print; var logger: typeof Ember.Handlebars.logger; var log: typeof Ember.Handlebars.log; - var compile: typeof Ember.Handlebars.compile; } class HashLocation extends Ember.HashLocation { } class HistoryLocation extends Ember.HistoryLocation { } From 213d8c7da7b69e6507659f96305ded3af66ffd28 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Wed, 16 Jul 2014 15:31:44 -0700 Subject: [PATCH 07/25] Adding back Backbone.$ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://backbonejs.org/#Utility-Backbone-$ Also removed `setDomLibrary` Backbone change log 0.9.9 — Dec. 13, 2012: To set what library Backbone uses for DOM manipulation and Ajax calls, use `Backbone.$ = ...` instead of `setDomLibrary`. --- backbone/backbone.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index db104f480..f23a4995a 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -359,7 +359,7 @@ declare module Backbone { // Utility function noConflict(): typeof Backbone; - function setDomLibrary(jQueryNew: any): any; + var $: JQueryStatic; } declare module "backbone" { From c743233ab0ae2955158f47f41fc231ec63dd69d0 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Wed, 16 Jul 2014 16:08:00 -0700 Subject: [PATCH 08/25] Overloads for Collection.get method --- backbone/backbone.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index f23a4995a..6b390e83e 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -170,7 +170,12 @@ declare module Backbone { add(model: TModel, options?: AddOptions): Collection; add(models: TModel[], options?: AddOptions): Collection; at(index: number): TModel; + /** + * Get a model from a collection, specified by an id, a cid, or by passing in a model. + **/ + get(id: number): TModel; get(id: string): TModel; + get(id: Model): TModel; create(attributes: any, options?: ModelSaveOptions): TModel; pluck(attribute: string): any[]; push(model: TModel, options?: AddOptions): TModel; From 06392eab9487e17a43bc251e5e2688d76e258a9a Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Wed, 16 Jul 2014 16:12:00 -0700 Subject: [PATCH 09/25] How to access attributes in a strongly-typed manner Only added comments and examples --- backbone/backbone.d.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 6b390e83e..d8bdc71c9 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -113,8 +113,23 @@ declare module Backbone { fetch(options?: ModelFetchOptions): JQueryXHR; - get(attributeName: string): any; - set(attributeName: string, value: any, options?: ModelSetOptions): Model; + /** + * For strongly-typed access to attributes, use the `get` method only privately in public getter properties. + * @example + * get name(): string { + * return super.get("name"); + * } + **/ + /*private*/ get(attributeName: string): any; + + /** + * For strongly-typed assignment of attributes, use the `set` method only privately in public setter properties. + * @example + * set name(value: string) { + * super.set("name", value); + * } + **/ + /*private*/ set(attributeName: string, value: any, options?: ModelSetOptions): Model; set(obj: any, options?: ModelSetOptions): Model; change(): any; From d205eb87269a1266e867b4e95bd85a66524e6cc0 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Wed, 16 Jul 2014 18:32:07 -0700 Subject: [PATCH 10/25] Updated collection tests and added comments --- backbone/backbone-tests.ts | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/backbone/backbone-tests.ts b/backbone/backbone-tests.ts index 6b40bb509..e3fbd6ab8 100644 --- a/backbone/backbone-tests.ts +++ b/backbone/backbone-tests.ts @@ -113,9 +113,12 @@ class EmployeeCollection extends Backbone.Collection { class Book extends Backbone.Model { title: string; author: string; + published: boolean; } class Library extends Backbone.Collection { + // This model definition is here only to test type compatibility of the model, but it + // is not necessary in working code as it is automatically inferred through generics. model: typeof Book; } @@ -123,31 +126,26 @@ class Books extends Backbone.Collection { } function test_collection() { - var books = new Library(); + var books = new Books(); - books.each(book => { - book.get("title"); - }); + var book1: Book = new Book({ title: "Title 1", author: "Mike" }); + books.add(book1); - var titles = books.map(book => { - return book.get("title"); - }); - - var publishedBooks = books.filter(book => { - return book.get("published") === true; - }); - - var alphabetical = books.sortBy((book: Book): number => { - return null; - }); - - var model: Book = new Book({title: "Test", author: "Mike"}); - books.add(model); - var model2: Book = model.collection.first(); - if (model !== model2) { + var model: Book = book1.collection.first(); + if (model !== book1) { throw new Error("Error"); } + books.each(book => + book.get("title")); + + var titles = books.map(book => + book.get("title")); + + var publishedBooks = books.filter(book => + book.get("published") === true); + + var alphabetical = books.sortBy((book: Book): number => null); } ////////// From c18eb2ad641d2bb611416eaa75b4f922f0c13c42 Mon Sep 17 00:00:00 2001 From: "Omid K. Rad" Date: Wed, 16 Jul 2014 19:42:09 -0700 Subject: [PATCH 11/25] Added test for adding object literals as models --- backbone/backbone-tests.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backbone/backbone-tests.ts b/backbone/backbone-tests.ts index e3fbd6ab8..506fd7bb6 100644 --- a/backbone/backbone-tests.ts +++ b/backbone/backbone-tests.ts @@ -131,6 +131,11 @@ function test_collection() { var book1: Book = new Book({ title: "Title 1", author: "Mike" }); books.add(book1); + // Objects can be added to collection by casting to model type. + // Compiler will check if object properties are valid for the cast. + // This gives better type checking than declaring an `any` overload. + books.add({ title: "Title 2", author: "Mikey" }); + var model: Book = book1.collection.first(); if (model !== book1) { throw new Error("Error"); From b09ee215ec421b7ed51ba44b90c8d0f5f25b3cf3 Mon Sep 17 00:00:00 2001 From: zaneli Date: Thu, 17 Jul 2014 21:21:02 +0900 Subject: [PATCH 12/25] Add definitions for ProgressJs --- CONTRIBUTORS.md | 1 + progressjs/progress-tests.ts | 36 ++++++++++++ progressjs/progress.d.ts | 103 +++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 progressjs/progress-tests.ts create mode 100644 progressjs/progress.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c01d01147..456dbc9ce 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -271,6 +271,7 @@ All definitions files include a header with the author and editors, so at some p * [Platform](https://github.com/bestiejs/platform.js) (by [Jake Hickman](https://github.com/JakeH)) * [PouchDB](http://pouchdb.com) (by [Bill Sears](https://github.com/MrBigDog2U/)) * [PreloadJS](http://www.createjs.com/#!/PreloadJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) +* [ProgressJs](http://usablica.github.io/progress.js/) (by [Shunsuke Ohtani](https://github.com/zaneli)) * [Q](https://github.com/kriskowal/q) (by Barrie Nemetchek, Andrew Gaspar) * [Q-io](https://github.com/kriskowal/q-io) (by [Bart van der Schoor](https://github.com/Bartvds)) * [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei)) diff --git a/progressjs/progress-tests.ts b/progressjs/progress-tests.ts new file mode 100644 index 000000000..e2ab62f9a --- /dev/null +++ b/progressjs/progress-tests.ts @@ -0,0 +1,36 @@ +/// + +progressJs(); //without selector, set progress-bar for whole page +progressJs("#targetElement"); //start progress-bar for element id='targetElement' + +progressJs().start(); + +progressJs().set(20); //set progress to 20% + +progressJs().start().autoIncrease(4, 500); //every 500 milliseconds, percentage + 4 + +progressJs().increase(); //increase one percent +progressJs().increase(2); //increase two percent + +progressJs().start().set(20).end(); + +progressJs().setOption("theme", "black"); +progressJs().setOption("overlayMode", true); +progressJs().setOption("considerTransition", false); + +progressJs().setOptions({ 'theme': 'black', 'overlayMode': true }); +progressJs().setOptions({ 'theme': 'black', 'overlayMode': true }); +progressJs().setOptions({ 'theme': 'black', 'overlayMode': true, 'considerTransition': false }); +progressJs().setOptions({ 'overlayMode': true }); + +progressJs().onbeforeend(function() { + alert("before end"); +}); + +progressJs().onbeforestart(function() { + alert("before start"); +}); + +progressJs().onprogress(function(targetElm, percent) { + alert("progress changed to:" + percent); +}); diff --git a/progressjs/progress.d.ts b/progressjs/progress.d.ts new file mode 100644 index 000000000..a7f9923c3 --- /dev/null +++ b/progressjs/progress.d.ts @@ -0,0 +1,103 @@ +// Type definitions for ProgressJs v0.1.0 +// Project: http://usablica.github.io/progress.js/ +// Definitions by: Shunsuke Ohtani +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface ProgressJsStatic { + + /** + * Creating an ProgressJS object. + * + * @param targetElm String (optional) Should be defined to start progress-bar for specific element. + */ + (targetElm?: string): ProgressJs; +} + +interface ProgressJs { + + /** + * Start the progress-bar for defined element(s). + */ + start(): ProgressJs; + + /** + * Set specific percentage to progress-bar. + * + * @param percent Set to specific percentage. + */ + set(percent: number): ProgressJs; + + /** + * Set an auto-increase timer for the progress-bar. + * + * @param size The size of increment when timer elapsed. + * @param millisecond Timer in milliseconds. + */ + autoIncrease(size: number, millisecond: number): ProgressJs; + + /** + * Increase the progress-bar bar specified size. Default size is 1. + * + * @param size The size of increment. + */ + increase(size?: number): ProgressJs; + + /** + * End the progress-bar and remove the elements from page. + */ + end(): ProgressJs; + + /** + * Set a single option to progressJs object. + * + * @param option Option key name. + * @param value Value of the option. + */ + setOption(option: string, value: string): ProgressJs; + setOption(option: string, value: boolean): ProgressJs; + + /** + * Set a group of options to the progressJs object. + * + * @param options Object that contains option keys with values. + */ + setOptions(options: ProgressJsOptions): ProgressJs; + + /** + * Set a callback function for before end of the progress-bar. + * + * @param providedCallback Callback function. + */ + onbeforeend(providedCallback: () => any): ProgressJs; + + /** + * Set a callback function to call before start the progress-bar. + * + * @param providedCallback Callback function. + */ + onbeforestart(providedCallback: () => any): ProgressJs; + + /** + * Set callback function to call for each change of progress-bar. + * + * @param providedCallback Callback function. + */ + onprogress(providedCallback: (targetElement: string, percent: number) => any): ProgressJs; +} + +interface ProgressJsOptions { + /** + * progress bar theme + */ + theme?: string; + /** + * overlay mode makes an overlay layer in the target element + */ + overlayMode?: boolean; + /** + * to consider CSS3 transitions in events + */ + considerTransition?: boolean; +} + +declare var progressJs: ProgressJsStatic From bc8bc17374d87764fb6338f67ac12940f0ffc0c4 Mon Sep 17 00:00:00 2001 From: Ian Sibner Date: Thu, 17 Jul 2014 11:30:43 -0400 Subject: [PATCH 13/25] Changes based on @BillArmstrong's feedback * Remove optional parameters from Element interface * Remove additional parameters from ElementFinder.isElementPresent * Add "asElementFinders_" and "then" methods to ElementArrayFinder interface --- .../angular-protractor-tests.ts | 5 +- angular-protractor/angular-protractor.d.ts | 71 +++++++++++-------- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/angular-protractor/angular-protractor-tests.ts b/angular-protractor/angular-protractor-tests.ts index 62ed46177..5ca9ecde4 100644 --- a/angular-protractor/angular-protractor-tests.ts +++ b/angular-protractor/angular-protractor-tests.ts @@ -211,7 +211,6 @@ function TestElementFinder() { promise = elementFinder.getOuterHtml(); promise = elementFinder.getInnerHtml(); promise = elementFinder.isElementPresent(by.id('id')); - promise = elementFinder.isElementPresent(by.js('function(a, b, c) {}'), 1, 2, 3); promise = elementFinder.$('.class'); promise = elementFinder.$$('.class'); promise = elementFinder.evaluate('expression'); @@ -230,6 +229,7 @@ function TestElementArrayFinder() { elementFinder = elementArrayFinder.first(); elementFinder = elementArrayFinder.last(); promise = elementArrayFinder.count(); + promise = elementArrayFinder.asElementFinders_(); elementArrayFinder.each(function(element: protractor.ElementFinder){ // nothing }); @@ -251,6 +251,9 @@ function TestElementArrayFinder() { return accumulator + ',' + text; }); }, ''); + elementArrayFinder.then(function(underlyingElementFinders: protractor.ElementFinder[]){ + //nothing + }); } // This function tests the angular specific locator strategies. diff --git a/angular-protractor/angular-protractor.d.ts b/angular-protractor/angular-protractor.d.ts index 81eca975e..2de49a0a4 100644 --- a/angular-protractor/angular-protractor.d.ts +++ b/angular-protractor/angular-protractor.d.ts @@ -225,31 +225,19 @@ declare module protractor { * before the page is available. * * @param {webdriver.Locator} locator An element locator. - * @param {ElementFinder=} opt_parentElementFinder The element finder previous - * to this. (i.e. opt_parentElementFinder.element(locator) => this) - * @param {webdriver.promise.Promise} opt_actionResult The promise which - * will be retrieved with then. Resolves to the latest action result, - * or null if no action has been called. - * @param {number=} opt_index The index of the element to retrieve. null means - * retrieve the only element, while -1 means retrieve the last element * @return {ElementFinder} */ interface Element { - (locator: webdriver.Locator, - opt_parentElementFinder?: protractor.ElementFinder, - opt_actionResult?: webdriver.promise.Promise, - opt_index?: number): ElementFinder; + (locator: webdriver.Locator): ElementFinder; /** * ElementArrayFinder is used for operations on an array of elements (as opposed * to a single element). * * @param {webdriver.Locator} locator An element locator. - * @param {ElementFinder=} opt_parentElementFinder The element finder previous to - * this. (i.e. opt_parentElementFinder.all(locator) => this) * @return {ElementArrayFinder} */ - all(locator: webdriver.Locator, opt_parentElementFinder?: protractor.ElementFinder): ElementArrayFinder; + all(locator: webdriver.Locator): ElementArrayFinder; } interface ElementFinder { @@ -301,21 +289,13 @@ declare module protractor { isPresent(): webdriver.promise.Promise; /** - * Schedules a command to test if there is at least one descendant of this - * element that matches the given search criteria. + * Override for WebElement.prototype.isElementPresent so that protractor waits + * for Angular to settle before making the check. * - *

Note that JS locator searches cannot be restricted to a subtree of the - * DOM. All such searches are delegated to this instance's parent WebDriver. - * - * @param {webdriver.Locator|Object.} locator The locator - * strategy to use when searching for the element. - * @param {...} var_args Arguments to pass to {@code WebDriver#executeScript} if - * using a JavaScript locator. Otherwise ignored. - * @return {!webdriver.promise.Promise} A promise that will be resolved with - * whether an element could be located on the page. + * @see ElementFinder.isPresent + * @return {!webdriver.promise.Promise} which resolves to whether the element is present on the page. */ - isElementPresent(locator: webdriver.Locator, ...var_args: any[]): webdriver.promise.Promise; - isElementPresent(locator: any, ...var_args: any[]): webdriver.promise.Promise; + isElementPresent(locator: webdriver.Locator): webdriver.promise.Promise; /** * Return this ElementFinder's locator. @@ -552,7 +532,7 @@ declare module protractor { } interface IThenFunction { - (promise: webdriver.promise.Promise): any; + (promiseResult: any): any; } @@ -641,6 +621,37 @@ declare module protractor { * @return {!webdriver.promise.Promise} A promise that resolves to the final value of the accumulator. */ reduce(func: IReductionFunction, initialValue: any): webdriver.promise.Promise; + + /** + * Represents the ElementArrayFinder as an array of ElementFinders. + * + * @return {!webdriver.promise.Promise} Return a promise, which resolves to a list (array) + * of ElementFinders specified by the locator. + */ + asElementFinders_(): webdriver.promise.Promise; + + + /** + * Find the elements specified by the locator. The input function is passed + * to the resulting promise, which resolves to an array of ElementFinders. + * + * Use as: element.all(locator).then(thenFunction) + *

    + *
  • First
  • + *
  • Second
  • + *
  • Third
  • + *
+ * + * element.all(by.css('.items li')).then(function(arr) { + * expect(arr.length).toEqual(3); + * }); + * + * @param {function(Array.)} fn + * + * @type {webdriver.promise.Promise} a promise which will resolve to + * an array of ElementFinders matching the locator. + */ + then(fn: IElementArrayFinderThenFunction): webdriver.promise.Promise; } interface IEachFunction { @@ -659,6 +670,10 @@ declare module protractor { (accumulator: any, element: protractor.ElementFinder, index?: number, array?: protractor.ElementFinder[]): webdriver.promise.Promise; } + interface IElementArrayFinderThenFunction { + (promiseResult: ElementFinder[]): any; + } + class LocatorWithColumn extends webdriver.Locator { column(index: number): webdriver.Locator; } From 44ace5c6602c18d5301b23c66d197bb97a086d68 Mon Sep 17 00:00:00 2001 From: Tom Hasner Date: Thu, 17 Jul 2014 18:04:10 -0400 Subject: [PATCH 14/25] added second argument "element" to $.filter --- jquery/jquery.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index 59159a188..eb6ec2e56 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -3655,7 +3655,7 @@ interface JQuery { * * @param func A function used as a test for each element in the set. this is the current DOM element. */ - filter(func: (index: number) => any): JQuery; + filter(func: (index: number, element: Element) => any): JQuery; /** * Reduce the set of matched elements to those that match the selector or pass the function's test. * From c9370c43268664be14a67f139137c8cc7affa71a Mon Sep 17 00:00:00 2001 From: Kensuke Matsuzaki Date: Fri, 18 Jul 2014 14:45:24 +0900 Subject: [PATCH 15/25] Fix jQuery BlockUI Plugin --- jquery.blockUI/jquery.blockUI-tests.ts | 14 ++++++++++++++ jquery.blockUI/jquery.blockUI.d.ts | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/jquery.blockUI/jquery.blockUI-tests.ts b/jquery.blockUI/jquery.blockUI-tests.ts index 19372976f..234340b93 100644 --- a/jquery.blockUI/jquery.blockUI-tests.ts +++ b/jquery.blockUI/jquery.blockUI-tests.ts @@ -9,3 +9,17 @@ $.blockUI(opt); $.unblockUI(); $("#test").block().unblock(); $("#test").block(opt); + +$.blockUI.defaults.css.border = '5px solid red'; +$.blockUI.defaults.fadeOut = 200; + +$.blockUI({ message: $('#domMessage') }); +$.unblockUI({ fadeOut: 200 }); + +$.blockUI({ + fadeIn: 1000, + timeout: 2000, + onBlock: function() { + alert('Page is now blocked; fadeIn complete'); + } +}); diff --git a/jquery.blockUI/jquery.blockUI.d.ts b/jquery.blockUI/jquery.blockUI.d.ts index 5b1df3f7b..259044eaf 100644 --- a/jquery.blockUI/jquery.blockUI.d.ts +++ b/jquery.blockUI/jquery.blockUI.d.ts @@ -7,7 +7,7 @@ interface JQBlockUIOptions { /** message displayed when blocking (use null for no message) */ - message?: string; + message?: any; /** title string; only used when theme == true */ title?: string; /** only used when theme == true (requires jquery-ui.js to be loaded) */ @@ -76,7 +76,7 @@ interface JQBlockUIOptions { focusInput?: boolean; /** callback method invoked when fadeIn has completed and blocking message is visible */ - onBlock?: boolean; + onBlock?: () => void; /** * callback method invoked when unblocking has completed; the callback is @@ -99,7 +99,7 @@ interface JQBlockUIOptions { interface JQBlockUIStatic { /** default options */ - default?: JQBlockUIOptions; + defaults?: JQBlockUIOptions; /** block user activity for the page */ (): void; /** @@ -113,7 +113,7 @@ interface JQueryStatic { /** block user activity for the page */ blockUI?: JQBlockUIStatic; /** unblock the page */ - unblockUI?: () => void; + unblockUI?: JQBlockUIStatic; } interface JQuery { @@ -125,5 +125,5 @@ interface JQuery { /** * unblock the element(s) */ - unblock(): JQuery; + unblock(option?: JQBlockUIOptions): JQuery; } \ No newline at end of file From e827d60b1a4f0278d5bb0022e7e5d416c642a8ae Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Sat, 19 Jul 2014 11:44:50 +0200 Subject: [PATCH 16/25] jasmine: add missing variable DEFAULT_TIMEOUT_INTERVAL --- jasmine/jasmine.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index f64a59d39..34e30cdd1 100644 --- a/jasmine/jasmine.d.ts +++ b/jasmine/jasmine.d.ts @@ -429,4 +429,5 @@ declare module jasmine { export var HtmlReporter: HtmlReporter; export var HtmlSpecFilter: HtmlSpecFilter; + export var DEFAULT_TIMEOUT_INTERVAL: number; } From 3c4d380a0fb61defc9f11ac57eb44881f5fba58a Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Sat, 19 Jul 2014 11:48:42 +0200 Subject: [PATCH 17/25] add example to jasmine-tests.ts --- jasmine/jasmine-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index 3ce5dbc5f..8a4a00e22 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -698,3 +698,5 @@ describe("Asynchronous specs", function () { }; })(); + +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; From 730cb88fb0ac988945ff4376506678eb7c0d2fb9 Mon Sep 17 00:00:00 2001 From: Sebastian Lenz Date: Sun, 20 Jul 2014 12:13:28 +0200 Subject: [PATCH 18/25] Added lunr.js definitions --- lunr/lunr-tests.ts | 44 +++ lunr/lunr.d.ts | 839 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 883 insertions(+) create mode 100644 lunr/lunr-tests.ts create mode 100644 lunr/lunr.d.ts diff --git a/lunr/lunr-tests.ts b/lunr/lunr-tests.ts new file mode 100644 index 000000000..949a53e87 --- /dev/null +++ b/lunr/lunr-tests.ts @@ -0,0 +1,44 @@ +/// + +/** + * Basic test, from http://lunrjs.com/ + */ +function basic_test() { + var index = lunr(function () { + this.field('title', {boost: 10}); + this.field('body'); + this.ref('id'); + }); + + index.add({ + id: 1, + title: 'Foo', + body: 'Foo foo foo!' + }); + + index.add({ + id: 2, + title: 'Bar', + body: 'Bar bar bar!' + }); + + index.search('foo'); +} + + +/** + * Pipeline test, from http://lunrjs.com/ + */ +function pipeline_test() { + var index = lunr(function () { + this.pipeline.add(function (token:string, tokenIndex:number, tokens:string[]):string { + // text processing in here + return token; + }); + + this.pipeline.after(lunr.stopWordFilter, function (token:string, tokenIndex:number, tokens:string[]):string { + // text processing in here + return token; + }); + }) +} \ No newline at end of file diff --git a/lunr/lunr.d.ts b/lunr/lunr.d.ts new file mode 100644 index 000000000..709e5864d --- /dev/null +++ b/lunr/lunr.d.ts @@ -0,0 +1,839 @@ +// Type definitions for lunr.js 0.5.4 +// Project: https://github.com/olivernn/lunr.js +// Definitions by: Sebastian Lenz +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** + * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.4 + * Copyright (C) 2014 Oliver Nightingale + * MIT Licensed + * @license + */ +declare module lunr +{ + var version:string; + + + /** + * A function for splitting a string into tokens ready to be inserted into the search index. + * + * @param token The token to pass through the filter + */ + function tokenizer(token:string):string; + + + /** + * lunr.stemmer is an english language stemmer, this is a JavaScript implementation of + * the PorterStemmer taken from http://tartaurs.org/~martin + * + * @param token The string to stem + */ + function stemmer(token:string):string; + + + /** + * lunr.stopWordFilter is an English language stop word list filter, any words contained + * in the list will not be passed through the filter. + * + * This is intended to be used in the Pipeline. If the token does not pass the filter then + * undefined will be returned. + * + * @param token The token to pass through the filter + */ + function stopWordFilter(token:string):string; + + module stopWordFilter { + var stopWords:SortedSet; + } + + + /** + * lunr.trimmer is a pipeline function for trimming non word characters from the beginning + * and end of tokens before they enter the index. + * + * This implementation may not work correctly for non latin characters and should either + * be removed or adapted for use with languages with non-latin characters. + * @param token The token to pass through the filter + */ + function trimmer(token:string):string; + + + /** + * lunr.EventEmitter is an event emitter for lunr. It manages adding and removing event handlers + * and triggering events and their handlers. + */ + class EventEmitter + { + /** + * Can bind a single function to many different events in one call. + * + * @param eventName The name(s) of events to bind this function to. + * @param handler The function to call when an event is fired. Binds a handler + * function to a specific event(s). + */ + addListener(eventName:string, handler:Function):void; + addListener(eventName:string, eventName2:string, handler:Function):void; + addListener(eventName:string, eventName2:string, eventName3:string, handler:Function):void; + addListener(eventName:string, eventName2:string, eventName3:string, eventName4:string, handler:Function):void; + addListener(eventName:string, eventName2:string, eventName3:string, eventName4:string, eventName5:string, handler:Function):void; + + + /** + * Removes a handler function from a specific event. + * + * @param eventName The name of the event to remove this function from. + * @param handler The function to remove from an event. + */ + removeListener(eventName:string, handler:Function):void; + + + /** + * Calls all functions bound to the given event. + * + * Additional data can be passed to the event handler as arguments to emit after the event name. + * + * @param eventName The name of the event to emit. + * @param args + */ + emit(eventName:string, ...args:any[]):void; + + + /** + * Checks whether a handler has ever been stored against an event. + * + * @param eventName The name of the event to check. + */ + hasHandler(eventName:string):boolean; + } + + + interface IPipelineFunction { + (token:string):string; + (token:string, tokenIndex:number):string; + (token:string, tokenIndex:number, tokens:string[]):string; + } + + + /** + * lunr.Pipelines maintain an ordered list of functions to be applied to all tokens in documents + * entering the search index and queries being ran against the index. + * + * An instance of lunr.Index created with the lunr shortcut will contain a pipeline with a stop + * word filter and an English language stemmer. Extra functions can be added before or after either + * of these functions or these default functions can be removed. + * + * When run the pipeline will call each function in turn, passing a token, the index of that token + * in the original list of all tokens and finally a list of all the original tokens. + * + * The output of functions in the pipeline will be passed to the next function in the pipeline. + * To exclude a token from entering the index the function should return undefined, the rest of + * the pipeline will not be called with this token. + * + * For serialisation of pipelines to work, all functions used in an instance of a pipeline should + * be registered with lunr.Pipeline. Registered functions can then be loaded. If trying to load a + * serialised pipeline that uses functions that are not registered an error will be thrown. + * + * If not planning on serialising the pipeline then registering pipeline functions is not necessary. + */ + class Pipeline + { + registeredFunctions:{[label:string]:Function}; + + + /** + * Register a function with the pipeline. + * + * Functions that are used in the pipeline should be registered if the pipeline needs to be + * serialised, or a serialised pipeline needs to be loaded. + * + * Registering a function does not add it to a pipeline, functions must still be added to instances + * of the pipeline for them to be used when running a pipeline. + * + * @param fn The function to check for. + * @param label The label to register this function with + */ + registerFunction(fn:IPipelineFunction, label:string):void; + + + /** + * Warns if the function is not registered as a Pipeline function. + * + * @param fn The function to check for. + */ + warnIfFunctionNotRegistered(fn:IPipelineFunction):void; + + + /** + * Adds new functions to the end of the pipeline. + * + * Logs a warning if the function has not been registered. + * + * @param functions Any number of functions to add to the pipeline. + */ + add(...functions:IPipelineFunction[]):void; + + + /** + * Adds a single function after a function that already exists in the pipeline. + * + * Logs a warning if the function has not been registered. + * + * @param existingFn A function that already exists in the pipeline. + * @param newFn The new function to add to the pipeline. + */ + after(existingFn:IPipelineFunction, newFn:IPipelineFunction):void; + + + /** + * Adds a single function before a function that already exists in the pipeline. + * + * Logs a warning if the function has not been registered. + * + * @param existingFn A function that already exists in the pipeline. + * @param newFn The new function to add to the pipeline. + */ + before(existingFn:IPipelineFunction, newFn:IPipelineFunction):void; + + + /** + * Removes a function from the pipeline. + * + * @param fn The function to remove from the pipeline. + */ + remove(fn:IPipelineFunction):void; + + + /** + * Runs the current list of functions that make up the pipeline against + * the passed tokens. + * + * @param tokens The tokens to run through the pipeline. + */ + run(tokens:string[]):string[]; + + + /** + * Resets the pipeline by removing any existing processors. + */ + reset():void; + + + /** + * Returns a representation of the pipeline ready for serialisation. + */ + toJSON():any; + + + /** + * Loads a previously serialised pipeline. + * + * All functions to be loaded must already be registered with lunr.Pipeline. If any function from + * the serialised data has not been registered then an error will be thrown. + * + * @param serialised The serialised pipeline to load. + */ + static load(serialised:any):Pipeline; + } + + + /** + * lunr.Vectors implement vector related operations for a series of elements. + */ + class Vector + { + list:Node; + + + /** + * Calculates the magnitude of this vector. + */ + magnitude():number; + + + /** + * Calculates the dot product of this vector and another vector. + * @param otherVector The vector to compute the dot product with. + */ + dot(otherVector:Vector):number; + + + /** + * Calculates the cosine similarity between this vector and another vector. + * + * @param otherVector The other vector to calculate the + */ + similarity(otherVector:Vector):number; + } + + + /** + * lunr.Vector.Node is a simple struct for each node in a lunr.Vector. + */ + class Node + { + /** + * The index of the node in the vector. + */ + idx:number; + + /** + * The data at this node in the vector. + */ + val:number; + + /** + * The node directly after this node in the vector. + */ + next:Node; + + + /** + * @param idx The index of the node in the vector. + * @param val The data at this node in the vector. + * @param next The node directly after this node in the vector. + */ + constructor(idx:number, val:number, next:Node); + } + + + /** + * lunr.SortedSets are used to maintain an array of unique values in a sorted order. + */ + class SortedSet + { + elements:T[]; + + length:number; + + + /** + * Inserts new items into the set in the correct position to maintain the order. + * + * @param values The objects to add to this set. + */ + add(...values:T[]):void; + + + /** + * Converts this sorted set into an array. + */ + toArray():T[]; + + + /** + * Creates a new array with the results of calling a provided function on + * every element in this sorted set. + * + * Delegates to Array.prototype.map and has the same signature. + * + * @param fn The function that is called on each element of the + * @param ctx An optional object that can be used as the context + */ + map(fn:Function, ctx:any):T[]; + + + /** + * Executes a provided function once per sorted set element. + * + * Delegates to Array.prototype.forEach and has the same signature. + * + * @param fn The function that is called on each element of the + * @param ctx An optional object that can be used as the context + */ + forEach(fn:Function, ctx:any):any; + + + /** + * Returns the index at which a given element can be found in the sorted + * set, or -1 if it is not present. + * + * @param elem The object to locate in the sorted set. + * @param start An optional index at which to start searching from + * @param end An optional index at which to stop search from within + */ + indexOf(elem:T, start?:number, end?:number):number; + + + /** + * Returns the position within the sorted set that an element should be + * inserted at to maintain the current order of the set. + * + * This function assumes that the element to search for does not already exist + * in the sorted set. + * + * @param elem - The elem to find the position for in the set + * @param start - An optional index at which to start searching from + * @param end - An optional index at which to stop search from within + */ + locationFor(elem:T, start?:number, end?:number):number; + + + /** + * Creates a new lunr.SortedSet that contains the elements in the + * intersection of this set and the passed set. + * + * @param otherSet The set to intersect with this set. + */ + intersect(otherSet:SortedSet):SortedSet; + + + /** + * Creates a new lunr.SortedSet that contains the elements in the union of this + * set and the passed set. + * + * @param otherSet The set to union with this set. + */ + union(otherSet:SortedSet):SortedSet; + + + /** + * Makes a copy of this set + */ + clone():SortedSet; + + + /** + * Returns a representation of the sorted set ready for serialisation. + */ + toJSON():any; + + + /** + * Loads a previously serialised sorted set. + * + * @param serialisedData The serialised set to load. + */ + static load(serialisedData:T[]):SortedSet; + } + + + interface IIndexField + { + /** + * The name of the field within the document that + */ + name:string; + + /** + * An optional boost that can be applied to terms in this field. + */ + boost:number; + } + + + interface IIndexSearchResult + { + ref:any; + + score:number; + } + + + /** + * lunr.Index is object that manages a search index. It contains the indexes and stores + * all the tokens and document lookups. It also provides the main user facing API for + * the library. + */ + class Index + { + eventEmitter:EventEmitter; + + documentStore:Store; + + tokenStore:TokenStore; + + corpusTokens:SortedSet; + + pipeline:Pipeline; + + _fields:IIndexField[]; + + _ref:string; + + _idfCache:{[key:string]:string}; + + + /** + * Bind a handler to events being emitted by the index. + * + * The handler can be bound to many events at the same time. + * + * @param eventName The name(s) of events to bind the function to. + * @param handler The function to call when an event is fired. Binds a handler + * function to a specific event(s). + */ + on(eventName:string, handler:Function):void; + on(eventName:string, eventName2:string, handler:Function):void; + on(eventName:string, eventName2:string, eventName3:string, handler:Function):void; + on(eventName:string, eventName2:string, eventName3:string, eventName4:string, handler:Function):void; + on(eventName:string, eventName2:string, eventName3:string, eventName4:string, eventName5:string, handler:Function):void; + + + /** + * Removes a handler from an event being emitted by the index. + * + * @param eventName The name of events to remove the function from. + * @param handler The serialised set to load. + */ + off(eventName:string, handler:Function):void; + + + /** + * Adds a field to the list of fields that will be searchable within documents in the index. + * + * An optional boost param can be passed to affect how much tokens in this field rank in + * search results, by default the boost value is 1. + * + * Fields should be added before any documents are added to the index, fields that are added + * after documents are added to the index will only apply to new documents added to the index. + * + * @param fieldName The name of the field within the document that + * @param options An optional boost that can be applied to terms in this field. + */ + field(fieldName:string, options?:{boost?:number}):Index; + + + /** + * Sets the property used to uniquely identify documents added to the index, by default this + * property is 'id'. + * + * This should only be changed before adding documents to the index, changing the ref property + * without resetting the index can lead to unexpected results. + * + * @refName The property to use to uniquely identify the + */ + ref(refName:string):Index; + + + /** + * Add a document to the index. + * + * This is the way new documents enter the index, this function will run the fields from the + * document through the index's pipeline and then add it to the index, it will then show up + * in search results. + * + * An 'add' event is emitted with the document that has been added and the index the document + * has been added to. This event can be silenced by passing false as the second argument to add. + * + * @param doc The document to add to the index. + * @param emitEvent Whether or not to emit events, default true. + */ + add(doc:any, emitEvent?:boolean):void; + + + /** + * Removes a document from the index. + * + * To make sure documents no longer show up in search results they can be removed from the + * index using this method. + * + * The document passed only needs to have the same ref property value as the document that was + * added to the index, they could be completely different objects. + * + * A 'remove' event is emitted with the document that has been removed and the index the + * document has been removed from. This event can be silenced by passing false as the second + * argument to remove. + * + * @param doc The document to remove from the index. + * @param emitEvent Whether to emit remove events, defaults to true + */ + remove(doc:any, emitEvent?:boolean):void; + + + /** + * Updates a document in the index. + * + * When a document contained within the index gets updated, fields changed, added or removed, + * to make sure it correctly matched against search queries, it should be updated in the index. + * + * This method is just a wrapper around [[remove]] and [[add]]. + * + * An 'update' event is emitted with the document that has been updated and the index. + * This event can be silenced by passing false as the second argument to update. Only an + * update event will be fired, the 'add' and 'remove' events of the underlying calls are + * silenced. + * + * @param doc The document to update in the index. + * @param emitEvent Whether to emit update events, defaults to true + */ + update(doc:any, emitEvent?:boolean):void; + + + /** + * Calculates the inverse document frequency for a token within the index. + * + * @param token The token to calculate the idf of. + */ + idf(token:string):string; + + + /** + * Searches the index using the passed query. + * + * Queries should be a string, multiple words are allowed and will lead to an AND based + * query, e.g. idx.search('foo bar') will run a search for documents containing both + * 'foo' and 'bar'. + * + * All query tokens are passed through the same pipeline that document tokens are passed + * through, so any language processing involved will be run on every query term. + * + * Each query term is expanded, so that the term 'he' might be expanded to 'hello' + * and 'help' if those terms were already included in the index. + * + * Matching documents are returned as an array of objects, each object contains the + * matching document ref, as set for this index, and the similarity score for this + * document against the query. + * + * @param query The query to search the index with. + */ + search(query:string):IIndexSearchResult[]; + + + /** + * Generates a vector containing all the tokens in the document matching the + * passed documentRef. + * + * The vector contains the tf-idf score for each token contained in the document with + * the passed documentRef. The vector will contain an element for every token in the + * indexes corpus, if the document does not contain that token the element will be 0. + * + * @param documentRef The ref to find the document with. + */ + documentVector(documentRef:string):Vector; + + + /** + * Returns a representation of the index ready for serialisation. + */ + toJSON():any; + + + /** + * Applies a plugin to the current index. + * + * A plugin is a function that is called with the index as its context. Plugins can be + * used to customise or extend the behaviour the index in some way. A plugin is just a + * function, that encapsulated the custom behaviour that should be applied to the index. + * + * The plugin function will be called with the index as its argument, additional arguments + * can also be passed when calling use. The function will be called with the index as + * its context. + * + * Example: + * + * ```javascript + * var myPlugin = function(idx, arg1, arg2) { + * // `this` is the index to be extended + * // apply any extensions etc here. + * }; + * + * var idx = lunr(function() { + * this.use(myPlugin, 'arg1', 'arg2'); + * }); + * ``` + * + * @param plugin The plugin to apply. + * @param args + */ + use(plugin:Function, ...args:any[]):void; + + + /** + * Loads a previously serialised index. + * + * Issues a warning if the index being imported was serialised by a different version + * of lunr. + * + * @param serialisedData The serialised set to load. + */ + static load(serialisedData:any):Index; + } + + + /** + * lunr.Store is a simple key-value store used for storing sets of tokens for documents + * stored in index. + */ + class Store + { + store:{[id:string]:SortedSet}; + + length:number; + + + /** + * Stores the given tokens in the store against the given id. + * + * @param id The key used to store the tokens against. + * @param tokens The tokens to store against the key. + */ + set(id:string, tokens:SortedSet):void; + + + /** + * Retrieves the tokens from the store for a given key. + * + * @param id The key to lookup and retrieve from the store. + */ + get(id:string):SortedSet; + + + /** + * Checks whether the store contains a key. + * + * @param id The id to look up in the store. + */ + has(id:string):boolean; + + + /** + * Removes the value for a key in the store. + * + * @param id The id to remove from the store. + */ + remove(id:string):void; + + + /** + * Returns a representation of the store ready for serialisation. + */ + toJSON():any; + + + /** + * Loads a previously serialised store. + * + * @param serialisedData The serialised store to load. + */ + static load(serialisedData:any):Store; + } + + + interface ITokenDocument + { + ref:number; + + tf:number; + } + + + /** + * lunr.TokenStore is used for efficient storing and lookup of the reverse index of token + * to document ref. + */ + class TokenStore + { + root:{[token:string]:TokenStore}; + + docs:{[ref:string]:ITokenDocument}; + + length:number; + + + /** + * Adds a new token doc pair to the store. + * + * By default this function starts at the root of the current store, however it can + * start at any node of any token store if required. + * + * @param token The token to store the doc under + * @param doc The doc to store against the token + * @param root An optional node at which to start looking for the + */ + add(token:string, doc:ITokenDocument, root?:TokenStore):void; + + + /** + * Checks whether this key is contained within this lunr.TokenStore. + * + * @param token The token to check for + */ + has(token:string):boolean; + + + /** + * Retrieve a node from the token store for a given token. + * + * @param token The token to get the node for. + */ + getNode(token:string):TokenStore; + + + /** + * Retrieve the documents for a node for the given token. + * + * By default this function starts at the root of the current store, however it can + * start at any node of any token store if required. + * + * @param token The token to get the documents for. + * @param root An optional node at which to start. + */ + get(token:string, root:TokenStore):{[ref:string]:ITokenDocument}; + + + count(token:string, root:TokenStore):number; + + + /** + * Remove the document identified by ref from the token in the store. + * + * @param token The token to get the documents for. + * @param ref The ref of the document to remove from this token. + */ + remove(token:string, ref:string):void; + + + /** + * Find all the possible suffixes of the passed token using tokens currently in + * the store. + * + * @param token The token to expand. + * @param memo + */ + expand(token:string, memo?:string[]):string[]; + + + /** + * Returns a representation of the token store ready for serialisation. + */ + toJSON():any; + + + /** + * Loads a previously serialised token store. + * + * @param serialisedData The serialised token store to load. + */ + static load(serialisedData:any):TokenStore; + } +} + + +/** + * Convenience function for instantiating a new lunr index and configuring it with the default + * pipeline functions and the passed config function. + * + * When using this convenience function a new index will be created with the following functions + * already in the pipeline: + * + * * lunr.StopWordFilter - filters out any stop words before they enter the index + * + * * lunr.stemmer - stems the tokens before entering the index. + * + * Example: + * + * ```javascript + * var idx = lunr(function () { + * this.field('title', 10); + * this.field('tags', 100); + * this.field('body'); + * + * this.ref('cid'); + * + * this.pipeline.add(function () { + * // some custom pipeline function + * }); + * }); + * ``` + */ +declare function lunr(config:Function):lunr.Index; \ No newline at end of file From 4227be18c1bf006da4af4f435fcdab2349f125db Mon Sep 17 00:00:00 2001 From: Steve Ognibene Date: Sun, 20 Jul 2014 09:10:21 -0400 Subject: [PATCH 19/25] Added typing for big.js library --- big.js/big.js-tests.ts | 233 +++++++++++++++++++++++++++++++++++++++++ big.js/big.js.d.ts | 200 +++++++++++++++++++++++++++++++++++ 2 files changed, 433 insertions(+) create mode 100644 big.js/big.js-tests.ts create mode 100644 big.js/big.js.d.ts diff --git a/big.js/big.js-tests.ts b/big.js/big.js-tests.ts new file mode 100644 index 000000000..6de9ee7cc --- /dev/null +++ b/big.js/big.js-tests.ts @@ -0,0 +1,233 @@ +// Type definitions for big.js +// Project: https://github.com/MikeMcl/big.js/ +// Definitions by: Steve Ognibene +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + +/* + + Tests include code from http://mikemcl.github.io/big.js/ + + Minor changes have been made such as adding variable definitions where required. + +*/ + +function constructorTests() { + var x = new Big(9) // '9' + var y = new Big(x) // '9' + var d = Big(435.345) // 'new' is optional + var e = Big('435.345') // 'new' is optional + var a = new Big('5032485723458348569331745.33434346346912144534543') + var b = new Big('4.321e+4') // '43210' + var c = new Big('-735.0918e-430') // '-7.350918e-428' +} + +function staticPropertiesTests() { + Big.DP = 40; + Big.RM = 3; + Big.RM = BigJsLibrary.RoundingMode.RoundAwayFromZero; +} + +function absTests() { + var x = new Big(-0.8); + x.abs(); // '0.8' +} + +function cmpTests() { + var x = new Big(6); + var y = new Big(5); + x.cmp(y); // 1 + y.cmp(x.minus(1)); // 0 +} + +function divTests() { + var x = new Big(355); + var y = new Big(113); + x.div(y); // '3.14159292035398230088' + Big.DP = 2; + x.div(y); // '3.14' + x.div(5); // '71' +} + +function eqTests() { + 0 === 1e-324; // true + var x = new Big(0); + x.eq('1e-324'); // false + Big(-0).eq(x); // true ( -0 === 0 ) +} + +function gtTests() { + 0.1 > 0.3 - 0.2; // true + var x = new Big(0.1); + x.gt(Big(0.3).minus(0.2)); // false + Big(0).gt(x); // false +} + +function gteTests() { + 0.3 - 0.2 >= 0.1; // false + var x = new Big(0.3).minus(0.2); + x.gte(0.1); // true + Big(1).gte(x); // true +} + +function ltTests() { + 0.3 - 0.2 < 0.1; // true + var x = new Big(0.3).minus(0.2); + x.lt(0.1); // false + Big(0).lt(x); // true +} + +function lteTests() { + 0.1 <= 0.3 - 0.2; // false + var x = new Big(0.1); + x.lte(Big(0.3).minus(0.2)); // true + Big(-1).lte(x); // true +} + +function minusTests() { + 0.3 - 0.1; // 0.19999999999999998 + var x = new Big(0.3); + x.minus(0.1); // '0.2' +} + +function modTests() { + 1 % 0.9 // 0.09999999999999998 + var x = Big(1); + x.mod(0.9) // '0.1' +} + +function plusTests() { + 0.1 + 0.2 // 0.30000000000000004 + var x = new Big(0.1) + var y = x.plus(0.2) // '0.3' + Big(0.7).plus(x).plus(y) // '1' +} + +function powTests() { + Math.pow(0.7, 2) // 0.48999999999999994 + var x = new Big(0.7) + x.pow(2) // '0.49' + Big.DP = 20 + Big(3).pow(-2) // '0.11111111111111111111' + + new Big(123.456).pow(1000).toString().length // 5099 + new Big(2).pow(1e+6) // Time taken (Node.js): 9 minutes 34 secs. +} + +function roundTests() { + var x = 123.45 + Math.round(x) // 123 + var y = new Big(x) + y.round() // '123' + y.round(2) // '123.45' + y.round(10) // '123.45' + y.round(1, 0) // '123.4' + y.round(1, 1) // '123.5' + y.round(1, 2) // '123.4' + y.round(1, 3) // '123.5' + y // '123.45' +} + +function sqrtTests() { + var x = new Big(16) + x.sqrt() // '4' + var y = new Big(3) + y.sqrt() // '1.73205080756887729353' +} + +function timesTests() { + 0.6 * 3 // 1.7999999999999998 + var x = new Big(0.6) + var y = x.times(3) // '1.8' + Big('7e+500').times(y) // '1.26e+501' +} + +function toExponentialTests() { + var x = 45.6 + var y = new Big(x) + x.toExponential() // '4.56e+1' + y.toExponential() // '4.56e+1' + x.toExponential(0) // '5e+1' + y.toExponential(0) // '5e+1' + x.toExponential(1) // '4.6e+1' + y.toExponential(1) // '4.6e+1' + x.toExponential(3) // '4.560e+1' + y.toExponential(3) // '4.560e+1' +} + +function toFixedTests() { + var x = 45.6 + var y = new Big(x) + x.toFixed() // '46' + y.toFixed() // '45.6' + y.toFixed(0) // '46' + x.toFixed(3) // '45.600' + y.toFixed(3) // '45.600' +} + +function toPrecisionTests() { + var x = 45.6 + var y = new Big(x) + x.toPrecision() // '45.6' + y.toPrecision() // '45.6' + x.toPrecision(1) // '5e+1' + y.toPrecision(1) // '5e+1' + x.toPrecision(5) // '45.600' + y.toPrecision(5) // '45.600' +} + +function toStringTests() { + var x = new Big('9.99e+20') + x.toString() // '999000000000000000000' + var y = new Big('1E21') + x.toString() // '1e+21' +} + +function valueOfTests() { + var x = new Big('177.7e+457') + x.valueOf() // '1.777e+459' +} + +function toJSONTests() { + var x = new Big('177.7e+457') + var y = new Big(235.4325) + var z = new Big('0.0098074') + var str = JSON.stringify([x, y, z]) + + var a = new Big('123').toJSON(); + + JSON.parse(str, function (k, v) { return k === '' ? v : new Big(v) }) // Returns an array of three Big numbers. +} + +function propertiesTest1() { + var x = new Big(0.123) // '0.123' + x.toExponential() // '1.23e-1' + x.c // '1,2,3' + x.e // -1 + x.s // 1 + + var y = new Number(-123.4567000e+2) // '-12345.67' + y.toExponential() // '-1.234567e+4' + var z = new Big('-123.4567000e+2') // '-12345.67' + z.toExponential() // '-1.234567e+4' + z.c // '1,2,3,4,5,6,7' + z.e // 4 + z.s // -1 +} + +function propertiesTest2() { + var x = new Big('1234.000') // '1234' + x.toExponential() // '1.234e+3' + x.c // '1,2,3,4' + x.e // 3 + + x.e = -5 + x // '0.00001234' +} + +function propertiesTest3() { + var y = new Big(-0) // '0' + y.c // '0' [0].toString() + y.e // 0 + y.s // -1 +} \ No newline at end of file diff --git a/big.js/big.js.d.ts b/big.js/big.js.d.ts new file mode 100644 index 000000000..4f6278a80 --- /dev/null +++ b/big.js/big.js.d.ts @@ -0,0 +1,200 @@ +// Type definitions for big.js +// Project: https://github.com/MikeMcl/big.js/ +// Definitions by: Steve Ognibene +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module BigJsLibrary { + + export enum RoundingMode { + RoundTowardsZero = 0, + RoundTowardsNearestAwayFromZero = 1, + RoundTowardsNearestTowardsEven = 2, + RoundAwayFromZero = 3 + } + + interface BigJS extends BigJS_Constructors { + /** The maximum number of decimal places of the results of operations involving division. + It is relevant only to the div and sqrt methods, and the pow method when the exponent is negative. + @default 40 */ + DP: number; + + /** The rounding mode used in the above operations and by round, toExponential, toFixed and toPrecision. + Default is RoundTowardsNearestAwayFromZero + @default 1 */ + RM: RoundingMode; + } + + interface BigJS_Constructors { + /** A decimal value. */ + new (value: number): BigJS; + /** A decimal value. + String values may be in exponential, as well as normal (non-exponential) notation. There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e+6. Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid. + String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9. */ + new (value: string): BigJS; + /** A decimal value. */ + new (value: BigJS): BigJS; + /** A decimal value. */ + (value: number): BigJS; + /** A decimal value. + String values may be in exponential, as well as normal (non-exponential) notation. There is no limit to the number of digits of a string value (other than that of Javascript's maximum array size), but the largest recommended exponent magnitude is 1e+6. Infinity, NaN and hexadecimal literal strings, e.g. '0xff', are not valid. + String values in octal literal form will be interpreted as decimals, e.g. '011' is 11, not 9. */ + (value: string): BigJS; + /** A decimal value. */ + (value: BigJS): BigJS; + } + + /** BigJS instance methods */ + interface BigJS extends BigJS_Constructors { + /** Returns a Big number whose value is the absolute value, i.e. the magnitude, of this Big number. */ + abs(): BigJS; + + /** Compare + @returns {Number} + 1 = If the value of this Big number is greater than the value of n + -1 = If the value of this Big number is less than the value of n + 0 = If this Big number and n have the same value */ + cmp(n: number): number; + /** Compare + @returns {Number} + 1 = If the value of this Big number is greater than the value of n + -1 = If the value of this Big number is less than the value of n + 0 = If this Big number and n have the same value */ + cmp(n: string): number; + /** Compare + @returns {Number} + 1 = If the value of this Big number is greater than the value of n + -1 = If the value of this Big number is less than the value of n + 0 = If this Big number and n have the same value */ + cmp(n: BigJS): number; + + /** Returns a Big number whose value is the value of this Big number divided by n. */ + div(n: number): BigJS; + /** Returns a Big number whose value is the value of this Big number divided by n. */ + div(n: string): BigJS; + /** Returns a Big number whose value is the value of this Big number divided by n. */ + div(n: BigJS): BigJS; + + /** Returns true if the value of this Big equals the value of n, otherwise returns false. */ + eq(n: number): boolean; + /** Returns true if the value of this Big equals the value of n, otherwise returns false. */ + eq(n: string): boolean; + /** Returns true if the value of this Big equals the value of n, otherwise returns false. */ + eq(n: BigJS): boolean; + + /** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */ + gt(n: number): boolean; + /** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */ + gt(n: string): boolean; + /** Returns true if the value of this Big is greater than the value of n, otherwise returns false. */ + gt(n: BigJS): boolean; + + /** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */ + gte(n: number): boolean; + /** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */ + gte(n: string): boolean; + /** Returns true if the value of this Big is greater than or equal to the value of n, otherwise returns false. */ + gte(n: BigJS): boolean; + + /** Returns true if the value of this Big is less than the value of n, otherwise returns false. */ + lt(n: number): boolean; + /** Returns true if the value of this Big is less than the value of n, otherwise returns false. */ + lt(n: string): boolean; + /** Returns true if the value of this Big is less than the value of n, otherwise returns false. */ + lt(n: BigJS): boolean; + + /** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */ + lte(n: number): boolean; + /** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */ + lte(n: string): boolean; + /** Returns true if the value of this Big is less than or equal to the value of n, otherwise returns false. */ + lte(n: BigJS): boolean; + + /** Returns a Big number whose value is the value of this Big number minus n. */ + minus(n: number): BigJS; + /** Returns a Big number whose value is the value of this Big number minus n. */ + minus(n: string): BigJS; + /** Returns a Big number whose value is the value of this Big number minus n. */ + minus(n: BigJS): BigJS; + + /** Returns a Big number whose value is the value of this Big number modulo n, i.e. the integer remainder of dividing this Big number by n. + The result will have the same sign as this Big number, and it will match that of Javascript's % operator (within the limits of its precision) and BigDecimal's remainder method. */ + mod(n: number): BigJS; + /** Returns a Big number whose value is the value of this Big number modulo n, i.e. the integer remainder of dividing this Big number by n. + The result will have the same sign as this Big number, and it will match that of Javascript's % operator (within the limits of its precision) and BigDecimal's remainder method. */ + mod(n: string): BigJS; + /** Returns a Big number whose value is the value of this Big number modulo n, i.e. the integer remainder of dividing this Big number by n. + The result will have the same sign as this Big number, and it will match that of Javascript's % operator (within the limits of its precision) and BigDecimal's remainder method. */ + mod(n: BigJS): BigJS; + + /** Returns a Big number whose value is the value of this Big number plus n. */ + plus(n: number): BigJS; + /** Returns a Big number whose value is the value of this Big number plus n. */ + plus(n: string): BigJS; + /** Returns a Big number whose value is the value of this Big number plus n. */ + plus(n: BigJS): BigJS; + + /** Returns a Big number whose value is the value of this Big number raised to the power exp. + If exp is negative and the result has more fraction digits than is specified by Big.DP, it will be rounded to Big.DP decimal places using rounding mode Big.RM. + @param exp integer, -1e+6 to 1e+6 inclusive */ + pow(exp: number): BigJS; + + /** Returns a Big number whose value is the value of this Big number rounded to a whole number. */ + round(): BigJS; + /** Returns a Big number whose value is the value of this Big number rounded using rounding mode rm to a maximum of dp decimal places. + @param dp Number of decimal places (0 to 1e+6 inclusive). If dp is omitted or is null or undefined, the return value is n rounded to a whole number. */ + round(dp: number): BigJS; + /** Returns a Big number whose value is the value of this Big number rounded using rounding mode rm to a maximum of dp decimal places. + @param dp Number of decimal places (0 to 1e+6 inclusive). If dp is omitted or is null or undefined, the return value is n rounded to a whole number. + @param rm Rounding mode. If rm is omitted or is null or undefined, the current Big.RM setting is used. */ + round(dp: number, rm: RoundingMode): BigJS; + + /** Returns a Big number whose value is the square root of this Big number. */ + sqrt(): BigJS; + + /** Returns a Big number whose value is the value of this Big number times n. */ + times(n: number): BigJS; + /** Returns a Big number whose value is the value of this Big number times n. */ + times(n: string): BigJS; + /** Returns a Big number whose value is the value of this Big number times n. */ + times(n: BigJS): BigJS; + + /** Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp. */ + toExponential(): string; + /** Returns a string representing the value of this Big number in exponential notation to a fixed number of decimal places dp. + @param dp Number of decimal places (0 to 1e+6 inclusive). If dp is omitted, or is null or undefined, the number of digits after the decimal point defaults to the minimum number of digits necessary to represent the value exactly. */ + toExponential(dp: number): string; + + /** Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp. */ + toFixed(): string; + /** Returns a string representing the value of this Big number in normal notation to a fixed number of decimal places dp. + @param dp Number of decimal places (0 to 1e+6 inclusive). If dp is omitted, or is null or undefined, then the return value is simply the value in normal notation. This is also unlike Number.prototype.toFixed, which returns the value to zero decimal places. */ + toFixed(dp: number): string; + + /** Returns a string representing the value of this Big number to the specified number of significant digits sd. */ + toPrecision(): string; + /** Returns a string representing the value of this Big number to the specified number of significant digits sd. + @param sd significant digits. If sd is omitted, or is null or undefined, then the return value is the same as .toString(). */ + toPrecision(sd: number /** number of significant digits (0 to 1e+6 inclusive) */): string; + + /** Returns a string representing the value of this Big number. */ + toString(): string; + + /** As toString. */ + valueOf(): string; + + /** As toString. */ + toJSON(): string; + + /** coefficient (significand) */ + c: number[]; + + /** exponent (Integer, -1e+6 to 1e+6 inclusive) */ + e: number; + + /** sign (-1 or 1) */ + s: number; + } +} + +declare var Big: BigJsLibrary.BigJS; \ No newline at end of file From 433b0cf2df9a92cc00ab22901da4f13a74a1c9dc Mon Sep 17 00:00:00 2001 From: Steve Ognibene Date: Sun, 20 Jul 2014 09:14:58 -0400 Subject: [PATCH 20/25] Added line to contributors file. --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c01d01147..4955fcbdb 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -28,6 +28,7 @@ All definitions files include a header with the author and editors, so at some p * [aws-sdk-js](https://github.com/aws/aws-sdk-js) (by [midknight41](https://github.com/midknight41)) * [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm)) +* [big.js](https://github.com/MikeMcl/big.js) (by [Steve Ognibene](https://github.com/nycdotnet)) * [BigInteger](https://github.com/peterolson/BigInteger.js) (by [Ingo Bürk](https://github.com/Airblader)) * [BigScreen](http://brad.is/coding/BigScreen/) (by [Douglas Eichelberger](https://github.com/dduugg)) * [Bluebird](https://github.com/petkaantonov/bluebird) (by [Bart van der Schoor](https://github.com/Bartvds)) From dc4d81a6bda11013ce1e1752a53a8cf00606adfd Mon Sep 17 00:00:00 2001 From: Carl de Billy Date: Sun, 20 Jul 2014 12:59:27 -0400 Subject: [PATCH 21/25] Remove useless reference to RxJS This reference is not needed and is now causing problem because the definitelyTyped for RxJS is now part of the RxJS package directly. The Nuget package will needed to be changed also. --- knockout.rx/knockout.rx.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/knockout.rx/knockout.rx.d.ts b/knockout.rx/knockout.rx.d.ts index 71d95d758..601ef5af4 100644 --- a/knockout.rx/knockout.rx.d.ts +++ b/knockout.rx/knockout.rx.d.ts @@ -4,7 +4,6 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// -/// interface KnockoutSubscribableFunctions { toObservable(event?: string): Rx.Observable; From 0692edd2381159aa004995cfd973f4d6995170f8 Mon Sep 17 00:00:00 2001 From: Carl de Billy Date: Sun, 20 Jul 2014 16:25:49 -0400 Subject: [PATCH 22/25] Revert "Remove useless reference to RxJS" This reverts commit dc4d81a6bda11013ce1e1752a53a8cf00606adfd. --- knockout.rx/knockout.rx.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/knockout.rx/knockout.rx.d.ts b/knockout.rx/knockout.rx.d.ts index 601ef5af4..71d95d758 100644 --- a/knockout.rx/knockout.rx.d.ts +++ b/knockout.rx/knockout.rx.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// interface KnockoutSubscribableFunctions { toObservable(event?: string): Rx.Observable; From a2cb953ad174cbd4431b9dc78c97251413bbe76f Mon Sep 17 00:00:00 2001 From: Carl de Billy Date: Sun, 20 Jul 2014 16:30:34 -0400 Subject: [PATCH 23/25] Removed useless reference to RxJS typing Since the typing is now part of RxJS, referencing it (which is causing a nuget package dependency) will cause a problem by having twice the save references in the samme app. --- knockout.rx/knockout.rx.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/knockout.rx/knockout.rx.d.ts b/knockout.rx/knockout.rx.d.ts index 71d95d758..4a27f3fed 100644 --- a/knockout.rx/knockout.rx.d.ts +++ b/knockout.rx/knockout.rx.d.ts @@ -4,7 +4,6 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// -/// interface KnockoutSubscribableFunctions { toObservable(event?: string): Rx.Observable; @@ -21,6 +20,8 @@ interface KnockoutComputedFunctions { } declare module Rx { + interface ISubject { } + interface Observable { toKoSubscribable(): KnockoutSubscribable; toKoObservable(initialValue?: T): KnockoutObservable; From 735c0f1d5d58cff9399035d4f70d6d30a12256c7 Mon Sep 17 00:00:00 2001 From: Basarat Syed Date: Mon, 21 Jul 2014 11:48:03 +1000 Subject: [PATCH 24/25] Added val methods - ref https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md#api --- typeahead/typeahead-tests.ts | 5 +++++ typeahead/typeahead.d.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/typeahead/typeahead-tests.ts b/typeahead/typeahead-tests.ts index 67fc8d31a..1044fe3bf 100644 --- a/typeahead/typeahead-tests.ts +++ b/typeahead/typeahead-tests.ts @@ -85,3 +85,8 @@ $('.example-countries .typeahead').typeahead({ prefetch: '../data/countries.json', limit: 10 }); + +module valueTest { + var value: string = $('foo').typeahead('val'); + $('foo').typeahead('val', value); +} \ No newline at end of file diff --git a/typeahead/typeahead.d.ts b/typeahead/typeahead.d.ts index f6f387986..bb8aaf31d 100644 --- a/typeahead/typeahead.d.ts +++ b/typeahead/typeahead.d.ts @@ -60,6 +60,17 @@ interface JQuery { * @param dataset Array of datasets */ typeahead(options: Twitter.Typeahead.Options, dataset: Twitter.Typeahead.Dataset): JQuery; + + /** + * Returns the current value of the typeahead. The value is the text the user has entered into the input element. + */ + typeahead(methodName: 'val'): string; + typeahead(methodName: string): string; + + /** + * Sets the value of the typeahead. This should be used in place of jQuery#val. + */ + typeahead(methodName: 'val', value: string): JQuery; } declare module Twitter.Typeahead { From 93116a95bb19d90999519cf863170d905c91ebfd Mon Sep 17 00:00:00 2001 From: Taylan Date: Mon, 21 Jul 2014 10:24:55 +0100 Subject: [PATCH 25/25] Update kineticjs.d.ts Updated arguments for Node.move() to match library: http://kineticjs.com/docs/Kinetic.Node.html --- kineticjs/kineticjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kineticjs/kineticjs.d.ts b/kineticjs/kineticjs.d.ts index dc9219fe2..b5d56e846 100644 --- a/kineticjs/kineticjs.d.ts +++ b/kineticjs/kineticjs.d.ts @@ -45,7 +45,7 @@ declare module Kinetic { isDraggable(): boolean; isDragging(): boolean; isListening(): boolean; - move(x: number, y: number): void; + move(change:{x: number; y: number}): void; moveDown(): void; moveTo(newContainer: IContainer): void; moveToBottom(): void;