Adding tests package.
This commit is contained in:
parent
ba03def62c
commit
ffeeff423b
188
repository/Brea-Tests/BreaPageTest.class.st
Normal file
188
repository/Brea-Tests/BreaPageTest.class.st
Normal file
@ -0,0 +1,188 @@
|
||||
"
|
||||
A BreaPageTest is a test class for testing the behavior of BreaPage
|
||||
"
|
||||
Class {
|
||||
#name : #BreaPageTest,
|
||||
#superclass : #TestCase,
|
||||
#category : #'Brea-Tests'
|
||||
}
|
||||
|
||||
{ #category : #initialization }
|
||||
BreaPageTest >> createHTMLTemplateFile [
|
||||
| testFile contents |
|
||||
testFile := FileLocator temp / 'template.mus.html'.
|
||||
testFile ensureCreateFile.
|
||||
contents :=
|
||||
'<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{title}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{title}}</h1>
|
||||
<p>
|
||||
{{#show}} You should see me. {{/show}}
|
||||
</p>
|
||||
<p>
|
||||
{{#unhide}} You should not see me. {{/unhide}}
|
||||
</p>
|
||||
{{ contents }}
|
||||
</body>
|
||||
</html>'.
|
||||
|
||||
MarkupFile exportAsFileOn: testFile containing: contents.
|
||||
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
BreaPageTest >> createJSONFile [
|
||||
| testFile contents |
|
||||
testFile := self jsonTestFile.
|
||||
testFile ensureCreateFile.
|
||||
contents := '{ "title": "This is a test", "show": true, "unhide": false }'.
|
||||
MarkupFile exportAsFileOn: testFile containing: contents.
|
||||
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
BreaPageTest >> createMarkdownFile [
|
||||
| testFile contents |
|
||||
testFile := self markdownTestFile.
|
||||
testFile ensureCreateFile.
|
||||
contents :=
|
||||
'---
|
||||
title: This is a test
|
||||
show: true
|
||||
unhide: false
|
||||
|
||||
---
|
||||
|
||||
# Level one header
|
||||
|
||||
And paragraph contents with _emphasis_ and **strong emphasis**.'.
|
||||
|
||||
MarkupFile exportAsFileOn: testFile containing: contents.
|
||||
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
BreaPageTest >> htmlBodyContents [
|
||||
^ '<h1 id="level-one-header">Level one header</h1>
|
||||
<p>And paragraph contents with <em>emphasis</em> and <strong>strong emphasis</strong>.</p>
|
||||
'
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
BreaPageTest >> htmlOutput [
|
||||
^ '<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>This is a test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>This is a test</h1>
|
||||
<p>
|
||||
You should see me.
|
||||
</p>
|
||||
<p>
|
||||
</p>',
|
||||
self htmlBodyContents,
|
||||
'</body>
|
||||
</html>'
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
BreaPageTest >> jsonTestFile [
|
||||
^ FileLocator temp / 'test1.json'.
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
BreaPageTest >> markdownTestFile [
|
||||
^ FileLocator temp / 'test.md'.
|
||||
]
|
||||
|
||||
{ #category : #'as yet unclassified' }
|
||||
BreaPageTest >> setUp [
|
||||
"I create disposable simple files for testing purposes."
|
||||
super setUp.
|
||||
self createMarkdownFile.
|
||||
self createHTMLTemplateFile.
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testJSONMetadataExtraction [
|
||||
|
||||
| page testMetadata |
|
||||
testMetadata := {'title' -> 'This is a test' . 'show' -> true. 'unhide' -> false} asDictionary.
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test1';
|
||||
folder: FileLocator temp.
|
||||
self assert: page metadata equals: testMetadata
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testJSONPopulateMetadata [
|
||||
|
||||
| page testMetadata |
|
||||
testMetadata := {'title' -> 'This is a test' . 'show' -> true. 'unhide' -> false} asDictionary.
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test1';
|
||||
folder: FileLocator temp.
|
||||
page templateData at: 'extra' put: 'value'.
|
||||
self assert: page populateMetadata equals: (testMetadata at: 'extra' put: 'value'; yourself)
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testMarkdownContentExtraction [
|
||||
|
||||
| page |
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test';
|
||||
folder: FileLocator temp.
|
||||
self assert: page contents equals: self markdownTestFile contents.
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testMarkdownMetadataExtraction [
|
||||
|
||||
| page testMetadata |
|
||||
testMetadata := {'title' -> 'This is a test' . 'show' -> true. 'unhide' -> false} asDictionary.
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test';
|
||||
folder: FileLocator temp.
|
||||
self assert: page metadata equals: testMetadata
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testMarkdownPopulateBody [
|
||||
|
||||
| page |
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test';
|
||||
folder: FileLocator temp;
|
||||
bodyTag: 'contents'.
|
||||
page populateTaggedBody.
|
||||
self assert: (page templateData at: 'contents') equals: self htmlBodyContents.
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
BreaPageTest >> testMarkdownPopulateMetadata [
|
||||
|
||||
| page testMetadata |
|
||||
testMetadata := {'title' -> 'This is a test' . 'show' -> true. 'unhide' -> false} asDictionary.
|
||||
page := BreaPage new.
|
||||
page
|
||||
shortName: 'test';
|
||||
folder: FileLocator temp.
|
||||
page templateData at: 'extra' put: 'value'.
|
||||
self assert: page populateMetadata equals: (testMetadata at: 'extra' put: 'value'; yourself)
|
||||
]
|
1
repository/Brea-Tests/package.st
Normal file
1
repository/Brea-Tests/package.st
Normal file
@ -0,0 +1 @@
|
||||
Package { #name : #'Brea-Tests' }
|
@ -57,7 +57,7 @@ BreaFile >> folder: anObject [
|
||||
BreaFile >> metadata [
|
||||
self name ifNil: [ ^ nil ].
|
||||
(self name endsWith: '.md') ifTrue: [ ^ self contents metadata ].
|
||||
(self name endsWith: '.json') ifTrue: [ ^ self contents ].
|
||||
(self name endsWith: '.json') ifTrue: [ ^ self contents asDictionary ].
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
|
@ -165,6 +165,12 @@ BreaPage >> populateMetadata [
|
||||
^ templateData
|
||||
]
|
||||
|
||||
{ #category : #operation }
|
||||
BreaPage >> populateTaggedBody [
|
||||
self bodyTag ifNil: [ ^ self ].
|
||||
^ self populateBodyAs: self bodyTag.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
BreaPage >> shortName [
|
||||
^ shortName
|
||||
|
Loading…
Reference in New Issue
Block a user