summaryrefslogtreecommitdiff
path: root/spec/frontend/wikis_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/wikis_spec.js')
-rw-r--r--spec/frontend/wikis_spec.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/frontend/wikis_spec.js b/spec/frontend/wikis_spec.js
index 1d17c8b0777..e5d869840aa 100644
--- a/spec/frontend/wikis_spec.js
+++ b/spec/frontend/wikis_spec.js
@@ -14,6 +14,7 @@ describe('Wikis', () => {
<option value="asciidoc">AsciiDoc</option>
<option value="org">Org</option>
</select>
+ <textarea id="wiki_content"></textarea>
<code class="js-markup-link-example">{Link title}[link:page-slug]</code>
</form>
`;
@@ -24,6 +25,10 @@ describe('Wikis', () => {
let changeFormatSelect;
let linkExample;
+ const findBeforeUnloadWarning = () => window.onbeforeunload?.();
+ const findContent = () => document.getElementById('wiki_content');
+ const findForm = () => document.querySelector('.wiki-form');
+
describe('when the wiki page is being created', () => {
const formHtmlFixture = editFormHtmlFixture({ newPage: true });
@@ -94,6 +99,27 @@ describe('Wikis', () => {
expect(linkExample.innerHTML).toBe(text);
});
+
+ it('starts with no unload warning', () => {
+ expect(findBeforeUnloadWarning()).toBeUndefined();
+ });
+
+ describe('when wiki content is updated', () => {
+ beforeEach(() => {
+ const content = findContent();
+ content.value = 'Lorem ipsum dolar sit!';
+ content.dispatchEvent(new Event('input'));
+ });
+
+ it('sets before unload warning', () => {
+ expect(findBeforeUnloadWarning()).toBe('');
+ });
+
+ it('when form submitted, unsets before unload warning', () => {
+ findForm().dispatchEvent(new Event('submit'));
+ expect(findBeforeUnloadWarning()).toBeUndefined();
+ });
+ });
});
});
});