800ea5c6c6e163c2b56f29a264ea3cd815bce477
[mkws-moved-to-github.git] / test / widgets / Makefile
1 # Copyright (c) 2013-2014 Index Data ApS. http://indexdata.com
2
3 PHANTOMJS_TIMEOUT=30
4 PHANTOMJS=      ../bin/bomb --timeout=${PHANTOMJS_TIMEOUT} ../node_modules/phantomjs/bin/phantomjs
5 IMAGES=         ./images
6 SCREENSHOT_WIDTH_HEIGHT=        1000 1200
7 PROG=   ../phantom/screenshot.js
8 MD5=    $(shell which md5 md5sum)
9 TESTS=  koha demos mike # koha.url
10 TIMEOUT=4
11 PREFIX= test
12
13 PHANTOMJS_URL=  http://cph.koha.indexdata.com/cgi-bin/koha/opac-search.pl?q=sushi
14 PHANTOMJS_URL=  http://www.indexdata.com/
15
16 all: help
17
18 clean:
19         rm -f index-*.html
20         rm -f iframe-*.html
21         rm -f ${IMAGES}/*.png
22
23 distclean: clean
24         rm -f ${IMAGES}/*.png.tmp
25
26 test: check
27
28 screenshot:
29         file=${PREFIX}.$$(echo "${PHANTOMJS_URL}" | perl -npe 's,(\W),-,g; s/-$$//;'); \
30           ${PHANTOMJS} ${PROG} "${PHANTOMJS_URL}" ${IMAGES}/tmp.$$file.png ${SCREENSHOT_WIDTH_HEIGHT} ${TIMEOUT}; \
31           mv -f  ${IMAGES}/tmp.$$file.png  ${IMAGES}/$$file.png
32
33 screenshots: clean estimate-time iframe
34         set -e; \
35         for t in ${TESTS}; do \
36             for i in $$(cat url.$$t); do \
37                 ${MAKE} PHANTOMJS_URL="$$i" TIMEOUT=4 PREFIX=$$t screenshot & sleep 1; \
38             done; wait; \
39             ${MAKE} PREFIX=$$t index; \
40         done
41         ${MAKE} index-widgets tidy help-url
42
43 help-url:
44         @echo ""
45         @echo "Please check now: http://localhost/test/widgets/index.html"
46
47 estimate-time:
48         @wc -l url.* | tail -n1 | awk '{print "Estimeate run time: " $$1 * (1 + '${TIMEOUT}') * 0.5, "seconds" }'
49         @echo ""
50
51 index:
52         ( cd ${IMAGES}; ls -tr ${PREFIX}.*.png | perl -ne 'chomp; print qq{<h2>$$_</h2><img src="'${IMAGES}/'$$_"/><br/><br/><p/>\n}' ) > index-${PREFIX}.html
53
54 index-widgets:
55         ls -t index-*html iframe-*.html | perl -ne 'chomp; print qq{<a href="$$_">$$_</a><br/>\n}' > index.html
56
57 iframe: index-iframe-demo
58 index-iframe-demo:
59         ( egrep example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-example.html
60         ( egrep -v example.indexdata.com url.demos | perl -ne 'chomp; print qq{<h2>$$_</h2><iframe width="900px" height="600px" src="$$_"></iframe>\n}' ) > iframe-demos-other.html
61
62 tidy:
63         for i in iframe-demos*.html index*.html; do \
64             tidy -i -m $$i >/dev/null 2>&1; \
65             perl -i -npe 's,(^\s*</head>),<link type="text/css" rel="stylesheet" href="screenshots.css" /> $$1,' $$i; \
66         done
67
68 help:
69         @echo "make [ all | clean | distclean ]"
70         @echo "     [ screenshots ]"
71         @echo "     [ screenshot | index | iframe | tidy ]"
72         @echo ""
73         @echo "Examples: "
74         @echo ""
75         @echo "make TESTS=mike screenshots"
76