Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
Back-fill tests for browse and remove duplicate invocation.
Browse files Browse the repository at this point in the history
This commit adds tests in service of eventually resolving #53. Likewise, it
removes a mistaken duplicate invocation where on call to browse would result in
two calls to browse-url.
  • Loading branch information
enocom committed Nov 28, 2019
1 parent 2ec4569 commit 5136970
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/stedi/cdk/alpha.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
(str (string/replace fqn "@aws-cdk/" "")
"-readme"))]
(format "%s/docs/%s.html" docs-prefix url-formatted-fqn)))]
(browse/browse-url
(cond
(string? obj-class-or-fqn)
(fqn->url obj-class-or-fqn)
(cond
(string? obj-class-or-fqn)
(browse/browse-url (fqn->url obj-class-or-fqn))

(jsii/jsii-primitive? obj-class-or-fqn)
(browse (jsii/fqn obj-class-or-fqn)))))))
(jsii/jsii-primitive? obj-class-or-fqn)
(browse (jsii/fqn obj-class-or-fqn))))))

(s/def ::bindings
(s/+
Expand Down
43 changes: 43 additions & 0 deletions test/stedi/cdk/alpha_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,46 @@
(is (StringParameter/grantRead
(StringParameter/fromStringParameterName s "param" "param-name")
(Function/fromFunctionArn s "fn" "function-arn"))))))

(deftest browse-test
(testing "opening documentation with no arguments"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse)
(is (= ["https://docs.aws.amazon.com/cdk/api/latest"] @spy)))))
(testing "opening module documentation with full path"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse "@aws-cdk/core")
(is (= ["https://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html"]
@spy)))))
(testing "opening module documentation for `core`"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse "core")
(is (= ["https://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html"]
@spy)))))
(testing "opening fully qualified documentation for a class"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse "@aws-cdk/core.Stack")
(is (= ["https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html"]
@spy)))))
(testing "opening documentation for a class"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse Stack)
(is (= ["https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html"]
@spy)))))
(testing "opening documentation for an instance"
(let [spy (atom [])]
(with-redefs [clojure.java.browse/browse-url
(fn [url] (swap! spy conj url))]
(cdk/browse (Stack))
(is (= ["https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html"]
@spy))))))

0 comments on commit 5136970

Please sign in to comment.