Skip to content

Commit e537ae9

Browse files
committed
#15 - Destroy flow documentation + test
1 parent 05e71fd commit e537ae9

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ Setting up Typester on your page is as easy as:
2929
```
3030
import Typester from 'typester-editor'
3131
32-
new Typester({ el: document.querySelector('[contenteditable]') }) // Where document.querySelector(...) is a single DOM element.
32+
const typesterInstance = new Typester({ el: document.querySelector('[contenteditable]') }) // Where document.querySelector(...) is a single DOM element.
33+
34+
// If you need to tear down for any reason:
35+
typesterInstance.destroy();
3336
```
3437

3538
### Configuration

test/e2e/app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
</head>
66
<body>
77
<div id='content-editable' class='content-editable' style='margin-top: 200px'></div>
8+
<a class='destroy-control'>Destroy</a>
89
<script src='/js/typester.js'></script>
910
<script>
1011
console.log('Typester')
1112
console.log(Typester);
12-
new Typester({
13+
window.typesterInstance = new Typester({
1314
el: document.getElementById('content-editable')
1415
});
1516
</script>

test/e2e/test/pages/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ var pageCommands = {
174174
}, [], function (response) {
175175
console.log(response);
176176
});
177+
return this;
178+
},
179+
180+
destroy: function () {
181+
var api = this.api;
182+
183+
api.execute(function () {
184+
try {
185+
window.typesterInstance.destroy();
186+
return 'Destroyed!';
187+
} catch (e) {
188+
return e.message;
189+
}
190+
}, [], function (response) {
191+
console.log('Destroy:');
192+
console.log(response);
193+
});
194+
177195
return this;
178196
}
179197
};

test/e2e/test/specs/core/core.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,16 @@ module.exports = {
1212
.waitForElementPresent('.typester-canvas', 1000)
1313
.assert.attributeEquals('.content-editable', 'contenteditable', 'true')
1414
.end();
15+
},
16+
17+
'Destroy': function (browser) {
18+
var page = browser.page.index();
19+
20+
page.navigate()
21+
.assert.elementPresent('.typester-toolbar')
22+
.assert.elementPresent('.typester-canvas')
23+
.destroy()
24+
.assert.elementNotPresent('.typester-toolbar')
25+
.assert.elementNotPresent('.typester-canvas');
1526
}
1627
};

0 commit comments

Comments
 (0)