DEV Community

Cover image for JavaScript Tests for a Java Application
Jan Mewes
Jan Mewes

Posted on • Edited on

JavaScript Tests for a Java Application

K.S.C.H. Workflows is a prototype for a custom developed workflow management system for the Kirpal Sagar Charitable Hospital. It is a Java based web application which renders its HTML pages on the server-side with the help of Apache Wicket. However, the browser's language for user-convenience features is JavaScript. This blog post describes a Java developer's attempt to add reasonably well tested JavaScript code to the project.

Constructive feedback is welcome:

Feature description

The first non-trivial JavaScript code for this project will be to calculate the estimated date of birth, if only the patient's age can be provided during the registration. Also the age will be calculated and displayed automatically after the date of birth has been entered.

Frontend code structure

Wicket applies a component-oriented strategy for the creation of the HTML pages. For each HTML file there is a corresponding Java file with the same name. Spring Boot makes sure that everything which is in the directory src/main/resources/static is available for the application during runtime.

The first HTML component with its own JavaScript logic is PatientFormFields.html in the directory ksch/registration. Its JavaScript functions are defined in the file PatientFormFields.js which resides next to it in the same directory.

QUnit and Grunt

The tests are implemented with the QUnit framework, in the file PatientFormFields.test.js which also resides in the directory ksch/registration. Further there is a file PatientFormFields.test.html which includes all the JavaScript code and defines the web elements to be used for the tests. When this page is opened in the browser, the tests are executed and evaluated.

In order to be able to call the JavaScript tests from the command-line and during the TravisCI build, the JavaScript Task Runner Grunt is being used, along with a QUnit plugin. The configuration of the test files to be executed is done in the Gruntfile.js file. When grunt qunit is invoked, a headless Chromium browser is started and executes all the JavaScript tests in the project.

Top comments (0)