User:Nardog/AutoTestcases

This script fills in the "Preview page with this template" field with the closest /testcases page that exists when editing a template or module.

For example, if you're editing "Template:Foo/bar/baz" or "Template:Foo/bar/baz/sandbox", it checks for and if any of them exist, it fills in the field with whichever comes first.
 * Template:Foo/bar/baz/testcases
 * Template:Foo/bar/testcases
 * Template:Foo/testcases

If you're editing "Module:Foo/bar" or "Module:Foo/bar/sandbox", it checks for and if any of them exist, it fills in the field with whichever comes first.
 * Module talk:Foo/bar/testcases
 * Module talk:Foo/testcases
 * Template:Foo/bar/testcases
 * Template:Foo/testcases

If you're editing "Module:Foo/testcases", it fills in the field with "Module talk:Foo/testcases" even if it doesn't exist.

If the field is not empty when the script is run, it doesn't do anything.

Installation
Add the following to your common.js or global.js:

Or you may enable the script installer in and click "Install" in the infobox on this page.