172 lines
4.5 KiB
Smalltalk
172 lines
4.5 KiB
Smalltalk
"
|
|
I test the main functionality of the GrafoscopioNode class.
|
|
"
|
|
Class {
|
|
#name : #GrafoscopioNodeTest,
|
|
#superclass : #TestCase,
|
|
#category : #'Grafoscopio-Model'
|
|
}
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> dummyHtml [
|
|
| txt |
|
|
txt := '<html> <body> <img src="/web/files/pharo-logo-small.png">
|
|
<img src="https://pharo.org/web/files/pharo.png">
|
|
</body></html>'.
|
|
^ txt
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> newTestTree [
|
|
| node0 node1 node2 node3 node4 |
|
|
node0 := GrafoscopioTextNode new
|
|
created: DateAndTime now;
|
|
header: 'Arbol principal'.
|
|
node1 := GrafoscopioTextNode new
|
|
created: DateAndTime now;
|
|
header: 'Markup';
|
|
body: 'I am <b>just a node with markup</b>';
|
|
tagAs: 'text';
|
|
links: 'temp.md'.
|
|
node2 := GrafoscopioTextNode new
|
|
created: DateAndTime now ;
|
|
header: '%output Code';
|
|
tagAs: 'código';
|
|
body: '(ConfigurationOfGrafoscopio>>#version14:) sourceCode'.
|
|
node3 := GrafoscopioTextNode new
|
|
created: DateAndTime now ;
|
|
header: '%invisible';
|
|
tagAs: 'text';
|
|
body: '<i>Just testing</i>'.
|
|
node1 addNode: node3.
|
|
node4 := GrafoscopioTextNode new
|
|
created: DateAndTime now ;
|
|
header: 'Something';
|
|
tagAs: 'text';
|
|
body: '<h1>else</h1>'.
|
|
node1 addNode: node4.
|
|
node1 addNode: node2.
|
|
node0 addNode: node1.
|
|
^ node0
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testAddingChildren [
|
|
| tree nnode orig |
|
|
tree := self newTestTree.
|
|
nnode := GrafoscopioTextNode new.
|
|
orig := tree children size.
|
|
tree addNode: nnode.
|
|
self assert: tree children size equals: orig + 1.
|
|
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testDemoteNode [
|
|
| tree child1 child2 |
|
|
tree := GrafoscopioTextNode new.
|
|
child1 := GrafoscopioTextNode new.
|
|
child2 := GrafoscopioTextNode new.
|
|
tree
|
|
addNode: child1;
|
|
addNode: child2.
|
|
child2 demote.
|
|
self assert: child2 level equals: child1 level + 1
|
|
|
|
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testFindAndReplace [
|
|
| tree |
|
|
tree := GrafoscopioTextNode new.
|
|
tree body: 'I''m only a test node.'.
|
|
tree find: 'only' andReplaceWith: 'JUST'.
|
|
self assert: (tree body findString: 'JUST') > 0.
|
|
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testHasMarkdownSubtreesToExport [
|
|
"Because becomeDefaultTestTree contains at least one non empty 'links' object that
|
|
points to a relative path in the file system, ending in '.md' or '.markdown' the
|
|
result of this test is true.
|
|
Please see look #becomeDefaultTestTree message to see the details that makes this test true."
|
|
| tree |
|
|
tree := self newTestTree.
|
|
self assert: tree selectMarkupSubtreesToExport isNotEmpty equals: true.
|
|
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testInitializeIsOk [
|
|
self shouldnt: [ GrafoscopioTextNode new ] raise: Error
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testPromoteNode [
|
|
| tree child1 child2 |
|
|
tree := GrafoscopioTextNode new.
|
|
child1 := GrafoscopioTextNode new.
|
|
child2 := GrafoscopioTextNode new.
|
|
tree addNode: child1.
|
|
child1 addNode: child2.
|
|
child2 promote.
|
|
self assert: child2 level equals: child1 level
|
|
|
|
|
|
]
|
|
|
|
{ #category : #'tests-utility' }
|
|
GrafoscopioNodeTest >> testRemoveLeadingLineNumbersSized [
|
|
| copiedCode testNode |
|
|
copiedCode := '
|
|
1var tree = d3.layout.tree()
|
|
2 .sort(null)
|
|
3 .size([size.height, size.width - maxLabelLength*options.fontSize])
|
|
4 .children(function(d)
|
|
5 {
|
|
6 return (!d.contents || d.contents.length === 0) ? null : d.contents;
|
|
7 });
|
|
8
|
|
9var nodes = tree.nodes(treeData);
|
|
10var links = tree.links(nodes);
|
|
11 '.
|
|
testNode := GrafoscopioTextNode new
|
|
body: copiedCode.
|
|
testNode removeLeadingLineNumbersSized: 3.
|
|
self assert: testNode body equals: '
|
|
var tree = d3.layout.tree()
|
|
.sort(null)
|
|
.size([size.height, size.width - maxLabelLength*options.fontSize])
|
|
.children(function(d)
|
|
{
|
|
return (!d.contents || d.contents.length === 0) ? null : d.contents;
|
|
});
|
|
|
|
var nodes = tree.nodes(treeData);
|
|
var links = tree.links(nodes);
|
|
|
|
'
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testRemovingChildren [
|
|
| tree orig |
|
|
tree := self newTestTree..
|
|
orig := tree children size.
|
|
orig > 0 ifTrue: [ tree removeNode: (tree children at: 1) ].
|
|
self assert: tree children size equals: orig - 1.
|
|
|
|
]
|
|
|
|
{ #category : #tests }
|
|
GrafoscopioNodeTest >> testSanitizedLink [
|
|
| node link |
|
|
|
|
link := 'docutopia://hackbo:hackbot'.
|
|
node := GrafoscopioTextNode new links: link.
|
|
self assert: (node sanitizeDefaultLink = 'https://docutopia.tupale.co/hackbo:hackbot') equals: true
|
|
|
|
]
|