From 3e01c8d9102af258502b2d6352503853109b25ea Mon Sep 17 00:00:00 2001 From: Johannes Eder Date: Fri, 2 Jul 2021 15:40:53 +0200 Subject: [PATCH] chore(auto-submit-button): implemented destroy in auto-submit-button --- frontend/src/utils/form/auto-submit-button.js | 5 +++- .../src/utils/form/auto-submit-button.spec.js | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 frontend/src/utils/form/auto-submit-button.spec.js diff --git a/frontend/src/utils/form/auto-submit-button.js b/frontend/src/utils/form/auto-submit-button.js index bf7544d30..77e942f28 100644 --- a/frontend/src/utils/form/auto-submit-button.js +++ b/frontend/src/utils/form/auto-submit-button.js @@ -9,8 +9,10 @@ const AUTO_SUBMIT_BUTTON_HIDDEN_CLASS = 'hidden'; selector: AUTO_SUBMIT_BUTTON_UTIL_SELECTOR, }) export class AutoSubmitButton { + _element; constructor(element) { + this._element = element; if (!element) { throw new Error('Auto Submit Button utility needs to be passed an element!'); } @@ -24,6 +26,7 @@ export class AutoSubmitButton { } destroy() { - // TODO + this._element.classList.remove(AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS); + this._element.classList.remove(AUTO_SUBMIT_BUTTON_HIDDEN_CLASS); } } diff --git a/frontend/src/utils/form/auto-submit-button.spec.js b/frontend/src/utils/form/auto-submit-button.spec.js new file mode 100644 index 000000000..b1436c867 --- /dev/null +++ b/frontend/src/utils/form/auto-submit-button.spec.js @@ -0,0 +1,27 @@ +import { AutoSubmitButton, AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS, AUTO_SUBMIT_BUTTON_HIDDEN_CLASS } from './auto-submit-button.js'; + +describe('Auto-submit-button', () => { + + let autoSubmitButton; + + beforeEach(() => { + const element = document.createElement('div'); + autoSubmitButton = new AutoSubmitButton(element); + }); + + it('should create', () => { + expect(autoSubmitButton).toBeTruthy(); + }); + + it('should destory auto-submit-button', () => { + autoSubmitButton.destroy(); + expect(autoSubmitButton._element.classList).not.toContain(AUTO_SUBMIT_BUTTON_INITIALIZED_CLASS); + expect(autoSubmitButton._element.classList).not.toContain(AUTO_SUBMIT_BUTTON_HIDDEN_CLASS); + }); + + it('should throw if called without an element', () => { + expect(() => { + new AutoSubmitButton(); + }).toThrow(); + }); + }); \ No newline at end of file