// >"); var title = __re_escape(__title.en[name]); var r = new RegExp(''+text+'<\/a>$'); value_of(t).should_match(r); value_of(t).should_match(/class="/); value_of(t).should_match(/title="/); value_of(t).should_match(/href="/); if (accesskey) value_of(t).should_match(/accesskey="/); } function testing_check_button_onclick(name,func) { tests_mock.before(func); config.macros[name].onClick(); value_of(tests_mock.after(func).called).should_be(1); } describe('Macros: macro errors', { before_each : function() { __main(); }, 'missing macro should produce errortext' : function() { value_of(wikifyStatic('<>')).should_match(/errortext/); } }); describe('Macros: version macro', { before_each : function() { __main(); }, 'version macro should expand to the version string' : function() { version.major = "123"; version.minor = "456"; version.revision = "789"; version.beta = "123456789"; value_of(wikifyStatic("<>")).should_match(/^<(span|SPAN)>123.456.789 \(beta 123456789\)<\/(span|SPAN)>$/); } }); describe('Macros: today macro', { before_each : function() { __main(); }, 'today macro should return a date-shaped string [known to fail]' : function() { value_of(wikifyStatic("<>")).should_match(/^<(span|SPAN)>[A-Z][a-z]+\s[A-Z][a-z]+\s+[0-9]{1,2}\s[0-9]{2}:[0-9]{2}:[0-9]{2} 2[0-9]{3}<\/(span|SPAN)>$/); } }); describe('Macros: list macro', { before_each : function() { __main(); }, 'list all by default expands to the listTitle and an empty list' : function() { value_of(wikifyStatic("<>")).should_be('
  • ' + __title.en.all + '
'); }, 'list missing by default expands to the listTitle and an empty list' : function() { value_of(wikifyStatic("<>")).should_be('
  • ' + __title.en.missing + '
'); }, 'list orphans by default expands to the listTitle and an empty list' : function() { value_of(wikifyStatic("<>")).should_be('
  • ' + __title.en.orphans + '
'); }, 'list shadowed by default expands to the listTitle and a list of tiddlers' : function() { var pattern = new RegExp('^
  • ' + __title.en.shadowed + '
  • .*<\/li><\/ul>'); value_of(wikifyStatic("<>")).should_match(pattern); }, 'list touched by default expands to the listTitle and empty list' : function() { value_of(wikifyStatic("<>")).should_be('
    • ' + __title.en.touched + '
    '); }, 'list filter by default expands to an empty list' : function() { value_of(wikifyStatic("<>")).should_be('
      '); } }); describe('Macros: closeAll macro', { before_each : function() { __main(); }, 'closeAll macro expands to button' : function() { testing_check_button("closeAll","close all"); }, 'closeAll.onClick calls the story.closeAllTiddlers function' : function() { testing_check_button_onclick("closeAll","story.closeAllTiddlers"); } }); describe('Macros: permaview macro', { before_each : function() { __main(); }, 'permaview macro expands to button' : function() { testing_check_button("permaview","permaview"); }, 'permaview.onClick calls the story.permaView function' : function() { testing_check_button_onclick("permaview","story.permaView"); } }); describe('Macros: saveChanges macro', { before_each : function() { __main(); }, 'saveChanges macro doesn\'t expand to button when readOnly' : function() { readOnly = true; value_of(wikifyStatic("<>")).should_be(""); }, 'saveChanges macro expands to button when not readOnly' : function() { readOnly = false; testing_check_button("saveChanges","save changes","S"); }, 'saveChanges.onClick calls the saveChanges function' : function() { testing_check_button_onclick("saveChanges","saveChanges"); } }); describe('Macros: message macro', { before_each : function() { __main(); tests_mock.save('config.options.txtUserName'); }, after_each : function() { tests_mock.restore(); }, 'message with no parameters returns an empty string' : function() { value_of(wikifyStatic("<>")).should_be(''); }, 'message with returns an empty string' : function() { var username = "MyAssertedUserName"; config.options.txtUserName = username; value_of(wikifyStatic("<>")).should_be(username); }, }); describe('Macros: tagChooser macro', { before_each : function() { __main(); tests_mock.save('config.options.txtUserName'); }, after_each : function() { tests_mock.restore(); }, 'tagChooser with no parameters returns an empty string' : function() { var t = wikifyStatic("<>"); var title = __title.en.tagChooser; var text = "tags"; var r = new RegExp(''+text+'<\/a>$'); value_of(t).should_match(r); value_of(t).should_match(/tiddler="/); value_of(t).should_match(/class="/); value_of(t).should_match(/title="/); value_of(t).should_match(/href="/); } }); describe('Macros: refreshDisplay macro', { before_each : function() { __main(); }, 'refreshDisplay macro expands to button' : function() { testing_check_button("refreshDisplay","refresh"); }, 'refreshDisplay.onClick calls the refreshAll function' : function() { testing_check_button_onclick("refreshDisplay","refreshAll"); } }); describe('Macros: annotations macro', { before_each : function() { store = new TiddlyWiki(); loadShadowTiddlers(); store.saveTiddler("t","t","text"); formatter = new Formatter(config.formatters); }, 'annotations macro for a non-tiddler expands the empty string' : function() { value_of(wikifyStatic("<>")).should_be(''); }, 'annotations macro expands to empty string for tiddler not in config.annotations' : function() { value_of(wikifyStatic("<>",null,new Tiddler("temp"))).should_be(''); }, 'annotations macro expands to config.annotations defined text' : function() { var title = "This is the title text"; config.annotations.temp = title; value_of(wikifyStatic("<>",null,new Tiddler("temp"))).should_be('
      '+title+'
      '); } }); // ]]>