Skip to content

Tests and Optimizations

FotieMConstant edited this page Aug 12, 2020 · 6 revisions

Testing

During the testing, two stages of testing were performed. Namely manual testing and automatic Jasmine based testing

  1. During the manual testing two bugs were found:
  • The function "addItem" declaration was misspelled on call.
  • Random ID generating for todos without checking its past occurrence
  1. The Process of automatic Jasmine testing required writing additional tests to already existing ones. Based on existing test strategies new tests where added. The newly written test was to check the following.
  • should show entries on start-up
  • should show active entries
  • should show completed entries
  • should highlight "All" filter by default
  • should highlight "Active" filter when switching to active view
  • should toggle all todos to completed
  • should update the view
  • should add a new todo to the model
  • should remove an entry from the model

Note:

  • New unit tests were added immediately after the // TODO: write test line. The test was broken down into 3 parts.
  • // arrange - Setting up some data to test against
  • // act - Take action base on my data
  • // assert - Expectation of the test

Optimizations

  1. Removed unnecessary while loops in the Controller.js file (Commented out)
 //while block not necessary while title[0] is exectly equal to an empty space
   // while (title[0] === " ") {
	// 	title = title.slice(1);
   // }
      //while block not necessary while title[title.length-1] is exectly equal to an empty space
  // while (title[title.length-1] === " ") {
	// 	title = title.slice(0, -1);
   // }
  1. Modified the "for" loop in the "show" method of "template ()" in the template.js: This modification was done to reduce the usage of variables to improve performance.
	Template.prototype.show = function (data) {
		// var i, l;
		var view = '';

		for (let i = 0; i < data.length; i++) {
			var template = this.defaultTemplate;
			var completed = '';
			var checked = '';

			if (data[i].completed) {
				completed = 'completed';
				checked = 'checked';
			}

			template = template.replace('{{id}}', data[i].id);
			template = template.replace('{{title}}', escape(data[i].title));
			template = template.replace('{{completed}}', completed);
			template = template.replace('{{checked}}', checked);

			view = view + template;
		}

		return view;
	};
Clone this wiki locally