Skip to content

Commit 37aa508

Browse files
committed
[repo] Add testse for tracker link conversions
1 parent 8555446 commit 37aa508

File tree

6 files changed

+956
-4
lines changed

6 files changed

+956
-4
lines changed

babel-test.config.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Moodle Pty Ltd.
3+
*
4+
* Moodle is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Moodle is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
module.exports = {
18+
presets: [
19+
require.resolve('@babel/preset-env'),
20+
],
21+
plugins: [
22+
['@babel/transform-runtime'],
23+
],
24+
};

babel.config.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright (c) Moodle Pty Ltd.
3+
*
4+
* Moodle is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Moodle is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
*/
117
module.exports = {
2-
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
18+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
319
};

jest.config.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) Moodle Pty Ltd.
3+
*
4+
* Moodle is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Moodle is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
module.exports = {
19+
transform: {
20+
'\\.[jt]sx?$': [
21+
'babel-jest', {
22+
configFile: './babel-test.config.js',
23+
},
24+
],
25+
},
26+
roots: [
27+
'<rootDir>/src',
28+
],
29+
};

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
},
6666
"devDependencies": {
6767
"@apidevtools/json-schema-ref-parser": "^9.0.9",
68+
"@babel/plugin-transform-runtime": "^7.18.9",
69+
"@babel/preset-env": "^7.18.9",
6870
"@docusaurus/module-type-aliases": "^2.0.0-beta.21",
6971
"@tsconfig/docusaurus": "^1.0.5",
7072
"@types/core-js": "^2.5.5",

src/remark/trackerLinks.test.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* Copyright (c) Moodle Pty Ltd.
3+
*
4+
* Moodle is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Moodle is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
const module = require('./trackerLinks');
19+
20+
describe('trackerLinks', () => {
21+
it('must be a function', () => {
22+
expect(typeof module).toBe('function');
23+
});
24+
25+
it.concurrent.each([
26+
[
27+
'Simple link in text',
28+
{
29+
type: 'paragraph',
30+
children: [
31+
{
32+
type: 'text',
33+
value: 'See MDL-12345 for more information',
34+
},
35+
],
36+
},
37+
{
38+
type: 'paragraph',
39+
children: [
40+
{
41+
type: 'text',
42+
value: 'See ',
43+
},
44+
{
45+
type: 'link',
46+
url: 'https://tracker.moodle.org/browse/MDL-12345',
47+
children: [
48+
{
49+
type: 'text',
50+
value: 'MDL-12345',
51+
},
52+
],
53+
},
54+
{
55+
type: 'text',
56+
value: ' for more information',
57+
},
58+
],
59+
},
60+
],
61+
[
62+
'Does not update existing links',
63+
{
64+
type: 'paragraph',
65+
children: [
66+
{
67+
type: 'text',
68+
value: 'Do not modify ',
69+
},
70+
{
71+
type: 'link',
72+
url: 'https://example.com',
73+
children: [{
74+
type: 'text',
75+
value: 'MDL-12345',
76+
}],
77+
}, {
78+
type: 'text',
79+
value: 'that link',
80+
},
81+
],
82+
},
83+
{
84+
type: 'paragraph',
85+
children: [
86+
{
87+
type: 'text',
88+
value: 'Do not modify ',
89+
},
90+
{
91+
type: 'link',
92+
url: 'https://example.com',
93+
children: [{
94+
type: 'text',
95+
value: 'MDL-12345',
96+
}],
97+
}, {
98+
type: 'text',
99+
value: 'that link',
100+
},
101+
],
102+
},
103+
],
104+
])('updates tracker links for testcase "%s"', async (name, input, expected) => {
105+
const transformer = module();
106+
107+
const sampleTree = {
108+
type: 'root',
109+
children: [input],
110+
};
111+
112+
await transformer(sampleTree);
113+
expect(sampleTree.children[0]).toEqual(expected);
114+
});
115+
});

0 commit comments

Comments
 (0)