Skip to content

Commit

Permalink
Merge pull request #63 from uosl/feature/unit-tests
Browse files Browse the repository at this point in the history
Unit tests
  • Loading branch information
heralden authored Oct 17, 2019
2 parents 38ce506 + 3ce75d6 commit 24e0724
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 72 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ out
*.iml
pom.xml
.nrepl-port
node_modules
node_modules
/.cljs_node_repl/
/.lein-repl-history
/.lsp/
/figwheel_server.log
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/.*
node_modules
bower_components
resources/public/vendor
test
tests
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: java
jdk: openjdk8

before_script:
# Install lein - required to build the project
- wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein -O /tmp/lein
- chmod +x /tmp/lein
- export PATH=$PATH:/tmp/lein
# make several attempts at downloading dependencies
- travis_retry lein deps
# check code is well formatted
- lein cljfmt check
# setup node dependencies
- npm install

script:
# Run unit tests
- lein kaocha
# ensure a minified build completes without error
- lein uberjar
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ When a table first loads it only renders the first page of the query results as
## Building

### Initial setup
Once you've checked this project, you'll need to download the css dependencies using [bower](https://bower.io/). Assuming you have bower installed already, it's just

If you want to run the unit tests, you'll need Node.js and npm. Once these have been installed, run the following.

```
bower install
npm install
```

### Quickstart
Expand All @@ -117,6 +118,7 @@ lein repl # start dev server with hot-reloading and nrepl (no clean or cs
lein deploy # build prod release and deploy to clojars
lein format # run cljfmt to fix code indentation
lein kaocha # run unit tests
```

### Compile css:
Expand Down Expand Up @@ -146,13 +148,12 @@ Wait a bit, then browse to [http://localhost:3448](http://localhost:3448).

### Run tests:

Make sure to first run `npm install` to install the dependencies required to run the unit tests. You can also add `--watch` to the command below to automatically re-run tests when saving files.

```
lein clean
lein doo phantom test once
lein kaocha
```

The above command assumes that you have [phantomjs](https://www.npmjs.com/package/phantomjs) installed. However, please note that [doo](https://github.com/bensu/doo) can be configured to run cljs.test in many other JS environments (chrome, ie, safari, opera, slimer, node, rhino, or nashorn).

## Production Build

### Deploying to Heroku
Expand Down
2 changes: 2 additions & 0 deletions bin/kaocha
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
lein kaocha "$@"
23 changes: 0 additions & 23 deletions bower.json

This file was deleted.

2 changes: 1 addition & 1 deletion devapproach.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# im-tables 3 dev approach

IM tables 3 is designed to exist standalone or embedded inside another [re-frame](https://github.com/Day8/re-frame) application such as [BlueGenes](https://github.com/intermine/redgenes), InterMine's new UI.
IM tables 3 is designed to exist standalone or embedded inside another [re-frame](https://github.com/Day8/re-frame) application such as [BlueGenes](https://github.com/intermine/bluegenes), InterMine's new UI.

From here on, we're assuming you have familiarity with re-frame.

Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@cljs-oss/module-deps": "^1.1.1"
"@cljs-oss/module-deps": "^1.1.1",
"ws": "^7.1.2"
}
}
19 changes: 13 additions & 6 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
[binaryage/oops "0.7.0"]
[inflections "0.13.2"]
[criterium "0.4.5"]
[org.intermine/imcljs "1.0.1"]]
[org.intermine/imcljs "1.0.1"]
[day8.re-frame/test "0.1.5"]]

:plugins [[lein-cljsbuild "1.1.7"]
[lein-less "1.7.5"]
[lein-ancient "0.6.15"]
[lein-pdo "0.1.1"]
[lein-cljfmt "0.6.1"]]

:cljfmt {:indents {wait-for [[:inner 0]]}}

:aliases {"dev" ["do" "clean"
["pdo"
["trampoline" "less" "auto"]
Expand All @@ -32,14 +35,17 @@
["less" "once"]
["cljsbuild" "once" "min"]]
"deploy" ["with-profile" "+uberjar" "deploy" "clojars"]
"format" ["cljfmt" "fix"]}
"format" ["cljfmt" "fix"]
"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]}

:repositories {"clojars" {:sign-releases false}}

:min-lein-version "2.8.1"

:source-paths ["src"]

:test-paths ["test/cljs"]

:clean-targets ^{:protect false} ["resources/public/js/compiled" "target"
"test/js"]

Expand All @@ -55,14 +61,15 @@
:main im-tables.core

:profiles {:dev {:dependencies [[binaryage/devtools "0.9.10"]
[day8.re-frame/re-frame-10x "0.4.3"]
[day8.re-frame/re-frame-10x "0.4.4"]
[day8.re-frame/tracing "0.5.1"]
[figwheel-sidecar "0.5.19"]
[cider/piggieback "0.4.1"]]
:plugins [[lein-figwheel "0.5.19"]
[lein-doo "0.1.8"]]}
:plugins [[lein-figwheel "0.5.19"]]}
:repl {:source-paths ["dev"]}
:uberjar {:prep-tasks ["build"]}}
:uberjar {:prep-tasks ["build"]}
:kaocha {:dependencies [[lambdaisland/kaocha "0.0-554"]
[lambdaisland/kaocha-cljs "0.0-59"]]}}

:cljsbuild {:builds [{:id "dev"
:source-paths ["src"]
Expand Down
24 changes: 8 additions & 16 deletions resources/public/index.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8'>

<link href="vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/gridlex/2.2.3/gridlex.min.css">

<script
src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/gridlex/2.2.0/gridlex.min.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/site.css" rel="stylesheet" type="text/css">
<script src="http://cdn.intermine.org/js/intermine/imjs/3.15.0/im.min.js"></script>




<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

<meta charset='utf-8'>
<meta content="width=device-width, initial-scale=1" name="viewport">


<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script>
<script src="http://cdn.intermine.org/js/intermine/imjs/3.15.0/im.min.js"></script>
</head>
<body>
<div id="app"></div>
Expand Down
12 changes: 12 additions & 0 deletions src/im_tables/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
(apply merge-with deep-merge vals)
(last vals)))

(reg-event-fx
:im-tables.main/init
;; Dispatched when the im-table is interacted with.
;; Currently this is triggered on-mouse-over.
(sandbox)
(fn [{db :db} [_ loc]]
{:db db
:dispatch-n (into [[:main/deconstruct loc]]
(map (fn [view] [:main/summarize-column loc view])
(get-in db [:response :views])))}))

(reg-event-fx
:im-tables.main/replace-all-state
(sandbox)
Expand Down Expand Up @@ -526,6 +537,7 @@

;;;;;;;;;;;;;;


(defn index-map
[results offset]
(->> results
Expand Down
7 changes: 2 additions & 5 deletions src/im_tables/views/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
static? (reagent/atom true)
model (subscribe [:assets/model location])
query (subscribe [:main/query location])
collapsed-views (subscribe [:query-response/views-collapsed-by-joins location])
views (subscribe [:query-response/views location])]
collapsed-views (subscribe [:query-response/views-collapsed-by-joins location])]
(reagent/create-class
{:reagent-render
(fn [location]
Expand All @@ -61,9 +60,7 @@
; When the mouse touches the table, set the flag to render the actual React components
{:on-mouse-over (fn []
(when (and @static? (some? @response))
(dispatch [:main/deconstruct location])
(doseq [event (map (fn [view] [:main/summarize-column location view]) @views)]
(dispatch event))
(dispatch [:im-tables.main/init location])
(reset! static? false)))}

(if @static?
Expand Down
49 changes: 44 additions & 5 deletions test/cljs/im_tables/core_test.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
(ns im-tables.core-test
(:require [cljs.test :refer-macros [deftest testing is]]
[im-tables.core :as core]))
(:require [cljs.test :refer-macros [deftest testing is use-fixtures]]
[im-tables.test-utils :as utils]
[re-frame.core :as rf]
[day8.re-frame.test :refer-macros [run-test-sync run-test-async wait-for]]
[im-tables.events]
[im-tables.subs]))

(deftest fake-test
(testing "fake description"
(is (= 1 2))))
(use-fixtures :each utils/fixtures)

(def im-config {:service {:root "beta.humanmine.org/beta"}
:query {:from "Gene"
:select ["symbol"
"secondaryIdentifier"
"dataSets.description"
"primaryIdentifier"
"organism.name"
"dataSets.name"]}
:settings {:pagination {:limit 10}
:links {:vocab {:mine "BananaMine"}
:url (fn [vocab] (str "#/reportpage/"
(:mine vocab) "/"
(:class vocab) "/"
(:id vocab)))}}})

(deftest load-im-tables
(run-test-async
(let [loc [:default]]
(rf/dispatch-sync [:im-tables/load loc im-config])
(wait-for [:main/initial-query-response]
(testing "im-table runs query"
(let [response @(rf/subscribe [:main/query-response loc])]
(is (some? response))))))))

(deftest column-summary
(run-test-async
(let [loc [:default]]
(rf/dispatch-sync [:im-tables/load loc im-config])
(wait-for [:main/initial-query-response]
(rf/dispatch-sync [:im-tables.main/init loc])
(wait-for [(utils/match-times {:main/save-column-summary 6
:main/save-decon-count 3})]
(testing "at least one non-empty column summary"
(let [summaries @(rf/subscribe [:summaries/column-summaries loc])]
(is (some (every-pred map? not-empty)
(map :response (vals summaries)))))))))))
5 changes: 0 additions & 5 deletions test/cljs/im_tables/runner.cljs

This file was deleted.

Loading

0 comments on commit 24e0724

Please sign in to comment.