1 |
|
2 |
|
3 | var CodeGradX = require('../codegradxlib.js');
|
4 |
|
5 | describe('CodeGradX', function () {
|
6 |
|
7 | it('should be loaded', function (done) {
|
8 | expect(CodeGradX).toBeDefined();
|
9 | var state = new CodeGradX.State();
|
10 | CodeGradX.xml2html.default.markFactor = 100;
|
11 | done();
|
12 | });
|
13 |
|
14 | it("should convert p", function (done) {
|
15 | var xml = "<p>Hello</p>";
|
16 | var html = CodeGradX.xml2html(xml);
|
17 | expect(html).toMatch(/<p>Hello<\/p>/);
|
18 | done();
|
19 | });
|
20 |
|
21 | it("should convert p with attributes", function (done) {
|
22 | var xml = "<p a='b'>Hello</p>";
|
23 | var html = CodeGradX.xml2html(xml);
|
24 | expect(html).toMatch(/<p a="b">Hello<\/p>/);
|
25 | done();
|
26 | });
|
27 |
|
28 | it("should convert pre within p", function (done) {
|
29 | var xml = "<p a='b'>Hello<pre>foo()</pre> World</p>";
|
30 | var html = CodeGradX.xml2html(xml);
|
31 | expect(html).toMatch(/<p a="b">Hello<pre>foo\(\)<\/pre> World<\/p>/);
|
32 | done();
|
33 | });
|
34 |
|
35 | it("should convert warning", function (done) {
|
36 | var xml = "<p>H<warning a='b'>ell</warning></p>";
|
37 | var html = CodeGradX.xml2html(xml);
|
38 | expect(html).toMatch(/<p>H<div class="fw4ex_warning" a="b">ell<\/div><\/p>/);
|
39 | done();
|
40 | });
|
41 |
|
42 | it("should convert section", function (done) {
|
43 | var xml = "<section>H<warning a='b'>ell</warning></section>";
|
44 | var html = CodeGradX.xml2html(xml);
|
45 | expect(html).toMatch(/<div class="fw4ex_section1">H<div class="fw4ex_warning" a="b">ell<\/div><\/div>/);
|
46 | done();
|
47 | });
|
48 |
|
49 | it("should convert inner sections", function (done) {
|
50 | var xml = "<section>H<section>ell</section>o</section>";
|
51 | var html = CodeGradX.xml2html(xml);
|
52 | expect(html).toMatch(/<div class="fw4ex_section1">H<div class="fw4ex_section2">ell<\/div>o<\/div>/);
|
53 | done();
|
54 | });
|
55 |
|
56 | it("should convert mark", function (done) {
|
57 | var xml = "<section>You win <mark value='0.4'/> points</section>";
|
58 | var html = CodeGradX.xml2html(xml);
|
59 | expect(html).toMatch(/<div class="fw4ex_section1">You win <span value="0.4" class="fw4ex_mark">40<!-- 0.4 --><\/span> points<\/div>/);
|
60 | done();
|
61 | });
|
62 |
|
63 | it("should ignore FW4EX elements", function (done) {
|
64 | var xml = "<section>some <FW4EX a='b'/> thing</section>";
|
65 | var html = CodeGradX.xml2html(xml);
|
66 | expect(html).toMatch(/<div class="fw4ex_section1">some thing<\/div>/);
|
67 | done();
|
68 | });
|
69 |
|
70 | it("should convert question", function (done) {
|
71 | var xml = "<question title='two words' name='Q1'>stem</question>";
|
72 | var html = CodeGradX.xml2html(xml);
|
73 | expect(html).toMatch(/<div title="two words" name="Q1" class="fw4ex_question">stem<\/div>/);
|
74 | done();
|
75 | });
|
76 |
|
77 |
|
78 | it("should convert questions", function (done) {
|
79 | var xml = "<section><question title='two words' name='Q1'>stem</question><question name='Q2' title='other words'>other stem</question></section>";
|
80 | var html = CodeGradX.xml2html(xml);
|
81 | expect(html).toMatch(/<div class="fw4ex_section1"><div title="two words" name="Q1" class="fw4ex_question"><div class="fw4ex_question_title" data_counter="1">Q1: two words<\/div>stem<\/div><div name="Q2" title="other words" class="fw4ex_question"><div class="fw4ex_question_title" data_counter="2">Q2: other words<\/div>other stem<\/div><\/div>/);
|
82 | done();
|
83 | });
|
84 |
|
85 |
|
86 | it("should convert img1", function (done) {
|
87 | var xml = "<p><img src='/a/b' /></p>";
|
88 | var html = CodeGradX.xml2html(xml);
|
89 | expect(html).toMatch(new RegExp('<p><img src="/a/b" /></p>'));
|
90 | done();
|
91 | });
|
92 | it("should convert img2", function (done) {
|
93 | var xml = "<p><img src='./path/a/b' /></p>";
|
94 | var html = CodeGradX.xml2html(xml);
|
95 | expect(html).toMatch(new RegExp('<p><img src="./path/a/b" /></p>'));
|
96 | done();
|
97 | });
|
98 | it("should convert img3", function (done) {
|
99 | var xml = "<p><img src='path/a/b' /></p>";
|
100 | var html = CodeGradX.xml2html(xml);
|
101 | expect(html).toMatch(new RegExp('<p><img src="path/a/b" /></p>'));
|
102 | done();
|
103 | });
|
104 | it("should not convert that img1 within a stem", function (done) {
|
105 | var xml = "<p><img src='/a/b' /></p>";
|
106 | var html = CodeGradX.xml2html(xml, {
|
107 | exercise: {
|
108 | server: 'https://my.server',
|
109 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
110 | }});
|
111 | expect(html).toMatch(new RegExp('<p><img src="/a/b" /></p>'));
|
112 | done();
|
113 | });
|
114 | it("should convert img4 within a stem", function (done) {
|
115 | var xml = "<p><img src='./path/a/b' /></p>";
|
116 | var html = CodeGradX.xml2html(xml, {
|
117 | exercise: {
|
118 | server: 'https://my.server',
|
119 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
120 | }});
|
121 | expect(html).toMatch(new RegExp('<p><img src="https://my.server/exercisecontent/UUUUUUUUUUUUUUUUUUUUUU/path/a/b" /></p>'));
|
122 | done();
|
123 | });
|
124 | it("should convert img5 within a stem", function (done) {
|
125 | var xml = "<p><img src='path/a/b' /></p>";
|
126 | var html = CodeGradX.xml2html(xml, {
|
127 | exercise: {
|
128 | server: 'https://my.server',
|
129 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
130 | }});
|
131 | expect(html).toMatch(new RegExp('<p><img src="https://my.server/exercisecontent/UUUUUUUUUUUUUUUUUUUUUU/path/a/b" /></p>'));
|
132 | done();
|
133 | });
|
134 |
|
135 | it("should convert a1", function (done) {
|
136 | var xml = "<p><a src='/a/b' /></p>";
|
137 | var html = CodeGradX.xml2html(xml);
|
138 | expect(html).toMatch(new RegExp('<p><a src="/a/b" /></p>'));
|
139 | done();
|
140 | });
|
141 | it("should convert a2", function (done) {
|
142 | var xml = "<p><a src='./path/a/b' /></p>";
|
143 | var html = CodeGradX.xml2html(xml);
|
144 | expect(html).toMatch(new RegExp('<p><a src="./path/a/b" /></p>'));
|
145 | done();
|
146 | });
|
147 | it("should convert a3", function (done) {
|
148 | var xml = "<p><a src='path/a/b' /></p>";
|
149 | var html = CodeGradX.xml2html(xml);
|
150 | expect(html).toMatch(new RegExp('<p><a src="path/a/b" /></p>'));
|
151 | done();
|
152 | });
|
153 | it("should not convert that a4 within a stem", function (done) {
|
154 | var xml = "<p><a src='/a/b' /></p>";
|
155 | var html = CodeGradX.xml2html(xml, {
|
156 | exercise: {
|
157 | server: 'https://my.server',
|
158 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
159 | }});
|
160 | expect(html).toMatch(new RegExp('<p><a src="/a/b" /></p>'));
|
161 | done();
|
162 | });
|
163 | it("should convert a5 within a stem", function (done) {
|
164 | var xml = "<p><a src='./path/a/b' /></p>";
|
165 | var html = CodeGradX.xml2html(xml, {
|
166 | exercise: {
|
167 | server: 'https://my.server',
|
168 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
169 | }});
|
170 | expect(html).toMatch(new RegExp('<p><a src="https://my.server/exercisecontent/UUUUUUUUUUUUUUUUUUUUUU/path/a/b" /></p>'));
|
171 | done();
|
172 | });
|
173 | it("should convert a6 within a stem", function (done) {
|
174 | var xml = "<p><a src='path/a/b' /></p>";
|
175 | var html = CodeGradX.xml2html(xml, {
|
176 | exercise: {
|
177 | server: 'https://my.server',
|
178 | safecookie: 'UUUUUUUUUUUUUUUUUUUUUU'
|
179 | }});
|
180 | expect(html).toMatch(new RegExp('<p><a src="https://my.server/exercisecontent/UUUUUUUUUUUUUUUUUUUUUU/path/a/b" /></p>'));
|
181 | done();
|
182 | });
|
183 |
|
184 | });
|