Skip to content

Commit

Permalink
add demo and basic tests to health-message
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemitchel committed Oct 2, 2024
1 parent 6fcdafd commit 0b5b210
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/health-message/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>&lt;health-message&gt;</title>
</head>

<body>
<h1 class="text-center">Health-Message Component Demo</h1>
<br />
<h2 class="text-center">alertClass: danger</h2>
<div id="demo-html1" style="margin: 20px;"></div>
<br />
<h2 class="text-center">alertClass: warning</h2>
<div id="demo-html2" style="margin: 20px;"></div>

<script src="../../node_modules/steal/steal.js"
data-main="@empty">
</script>

<script type="steal-module">
import HealthMessage from "~/src/health-message/"
import "~/styles/"
import "~/styles.less"

const HealthMessageComponentDanger = new HealthMessage({viewModel: {message: 'Expected Variable Type (text), found Variable Type (number)', showMessage: true, alertClass: 'danger'}})
const HealthMessageComponentWarning = new HealthMessage({viewModel: {message: 'You have no varriable assigned to the current field', showMessage: true, alertClass: 'warning'}})


const demoHtml1 = document.getElementById('demo-html1')
const demoHtml2 = document.getElementById('demo-html2')

demoHtml1.appendChild(HealthMessageComponentDanger.element)
demoHtml2.appendChild(HealthMessageComponentWarning.element)
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions src/health-message/health-message-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>

<title>Author App Tests</title>

<div id="mocha"></div>
<div id="test-area"></div>

<script type="text/javascript">
window.less = {async: true, fileSync: true};
</script>

<script src="../../node_modules/steal/steal.js"
mocha="bdd"
main="~/src/health-message/health-message-test.js"></script>
60 changes: 60 additions & 0 deletions src/health-message/health-message-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { HealthMessageVM } from './health-message'
import stache from 'can-stache'
import canViewModel from 'can-view-model'
import { assert } from 'chai'
import $ from 'jquery'

import 'steal-mocha'

describe('<health-message>', () => {
describe('viewModel', () => {
let vm
const testProps = {
showMessage: true,
alertClass: 'danger',
message: 'Danger Zone!'
}

beforeEach(() => {
vm = new HealthMessageVM(testProps)
})

it('passes simple smoke test', () => {
const expectedMessage = 'Danger Zone!'
const expectedAlertClass = 'danger'
const expectedShowMessage = true

assert.equal(vm.message, expectedMessage, 'message should show Danger Zone!')
assert.equal(vm.alertClass, expectedAlertClass, 'alertClass should be danger')
assert.equal(vm.showMessage, expectedShowMessage, 'showMessage should be true')
})
})

describe('Component', () => {
// let vm

afterEach(() => {
document.getElementById('test-area').innerHTML = ''
})

it('shows a warning level message', () => {
const render = (data) => {
const tpl = stache(`
<health-message
showMessage:raw="true"
message:raw="This is a warning message"
alertClass:raw="warning"
/>`)

document.querySelector('#test-area').appendChild(tpl(data))

return canViewModel('health-message')
}

render()

const messageEl = $('health-message')
assert.isTrue(messageEl.is(':visible'), 'should be visible')
})
})
})
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'a2jauthor/src/report/report-test'
import 'a2jauthor/legacy/a2j-legacy-tests'
import 'a2jauthor/src/utils/tests/'
import 'a2jauthor/src/vertical-navbar/vertical-navbar-test'
import 'a2jauthor/src/health-message/health-message-test'
import 'a2jauthor/src/pages-tab/components/var-picker/field/var-picker-field-test'
// import 'a2jauthor/src/templates/templates-test'
// import 'a2jauthor/src/templates/edit/edit-test'
Expand Down

0 comments on commit 0b5b210

Please sign in to comment.