diff --git a/.eslintrc b/.eslintrc index 527935d0f4d..f0599148a75 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,23 +11,19 @@ {"Ember":true, "jQuery":true, "$":true, + "QUnit":true, "RSVP":true, "Discourse":true, "Em":true, "Handlebars":true, "I18n":true, "bootbox":true, - "module":true, "moduleFor":true, "moduleForComponent":true, "Pretender":true, "sandbox":true, "controllerFor":true, "test":true, - "ok":true, - "not":true, - "expect":true, - "equal":true, "visit":true, "andThen":true, "click":true, @@ -48,12 +44,8 @@ "find":true, "sinon":true, "moment":true, - "start":true, "_":true, "alert":true, - "containsInstance":true, - "deepEqual":true, - "notEqual":true, "define":true, "require":true, "requirejs":true, diff --git a/app/assets/javascripts/discourse/routes/invites-show.js.es6 b/app/assets/javascripts/discourse/routes/invites-show.js.es6 index 9acc266ced8..10d85152580 100644 --- a/app/assets/javascripts/discourse/routes/invites-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/invites-show.js.es6 @@ -8,6 +8,8 @@ export default Discourse.Route.extend({ model(params) { if (PreloadStore.get("invite_info")) { return PreloadStore.getAndRemove("invite_info").then(json => _.merge(params, json)); + } else { + return {}; } } }); diff --git a/app/assets/javascripts/discourse/widgets/link.js.es6 b/app/assets/javascripts/discourse/widgets/link.js.es6 index 9e33999957d..4f6beef6bf2 100644 --- a/app/assets/javascripts/discourse/widgets/link.js.es6 +++ b/app/assets/javascripts/discourse/widgets/link.js.es6 @@ -11,12 +11,12 @@ export default createWidget('link', { const route = attrs.route; if (route) { const router = this.register.lookup('router:main'); - if (router && router.router) { + if (router && router._routerMicrolib) { const params = [route]; if (attrs.model) { params.push(attrs.model); } - return Discourse.getURL(router.router.generate.apply(router.router, params)); + return Discourse.getURL(router._routerMicrolib.generate.apply(router._routerMicrolib, params)); } } else { return Discourse.getURL(attrs.href); diff --git a/app/assets/javascripts/wizard/router.js.es6 b/app/assets/javascripts/wizard/router.js.es6 index ebc83ec380c..15abc15ff03 100644 --- a/app/assets/javascripts/wizard/router.js.es6 +++ b/app/assets/javascripts/wizard/router.js.es6 @@ -1,7 +1,7 @@ import getUrl from 'discourse-common/lib/get-url'; const Router = Ember.Router.extend({ - rootURL: getUrl('/wizard'), + rootURL: getUrl('/wizard/'), location: Ember.testing ? 'none': 'history' }); diff --git a/app/assets/javascripts/wizard/test/acceptance/wizard-test.js.es6 b/app/assets/javascripts/wizard/test/acceptance/wizard-test.js.es6 index fb95fa7abff..ca42183bb67 100644 --- a/app/assets/javascripts/wizard/test/acceptance/wizard-test.js.es6 +++ b/app/assets/javascripts/wizard/test/acceptance/wizard-test.js.es6 @@ -6,7 +6,7 @@ module("Acceptance: wizard", { wizard = startApp(); }, - teardown() { + afterEach() { Ember.run(wizard, 'destroy'); } }); diff --git a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 index 8e515c01c6d..cdfe0fbe159 100644 --- a/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 +++ b/app/assets/javascripts/wizard/test/components/invite-list-test.js.es6 @@ -4,7 +4,7 @@ moduleForComponent('invite-list', { integration: true }); componentTest('can add users', { template: `{{invite-list field=field}}`, - setup() { + beforeEach() { this.set('field', {}); }, diff --git a/app/assets/javascripts/wizard/test/helpers/component-test.js.es6 b/app/assets/javascripts/wizard/test/helpers/component-test.js.es6 index 0cc731b1ea0..21541d3413a 100644 --- a/app/assets/javascripts/wizard/test/helpers/component-test.js.es6 +++ b/app/assets/javascripts/wizard/test/helpers/component-test.js.es6 @@ -7,8 +7,8 @@ export function componentTest(name, opts) { test(name, function(assert) { initializer.initialize(this.registry); - if (opts.setup) { - opts.setup.call(this); + if (opts.beforeEach) { + opts.beforeEach.call(this); } andThen(() => this.render(opts.template)); diff --git a/app/assets/javascripts/wizard/test/test_helper.js b/app/assets/javascripts/wizard/test/test_helper.js index 46042a0e725..0731b301f8c 100644 --- a/app/assets/javascripts/wizard/test/test_helper.js +++ b/app/assets/javascripts/wizard/test/test_helper.js @@ -33,6 +33,7 @@ if (window.Logster) { } else { window.Logster = { enabled: false }; } +Ember.Test.adapter = window.QUnitAdapter.create(); var createPretendServer = require('wizard/test/wizard-pretender', null, null, false).default; @@ -45,6 +46,7 @@ QUnit.testDone(function() { server.shutdown(); }); + var _testApp = require('wizard/test/helpers/start-app').default(); var _buildResolver = require('discourse-common/resolver').buildResolver; window.setResolver(_buildResolver('wizard').create({ namespace: _testApp })); diff --git a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 index 427687886ab..cbf078c279a 100644 --- a/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 +++ b/plugins/discourse-details/test/javascripts/acceptance/details-button-test.js.es6 @@ -6,7 +6,7 @@ function findTextarea() { return find(".d-editor-input")[0]; } -test('details button', () => { +test('details button', (assert) => { visit("/"); click('#create-topic'); @@ -14,7 +14,7 @@ test('details button', () => { click('.popup-menu .fa-caret-right'); andThen(() => { - equal( + assert.equal( find(".d-editor-input").val(), `[details=${I18n.t("composer.details_title")}]${I18n.t("composer.details_text")}[/details]`, 'it should contain the right output' @@ -33,15 +33,15 @@ test('details button', () => { click('.popup-menu .fa-caret-right'); andThen(() => { - equal( + assert.equal( find(".d-editor-input").val(), `[details=${I18n.t("composer.details_title")}]This is my title[/details]`, 'it should contain the right selected output' ); const textarea = findTextarea(); - equal(textarea.selectionStart, 17, 'it should start highlighting at the right position'); - equal(textarea.selectionEnd, 33, 'it should end highlighting at the right position'); + assert.equal(textarea.selectionStart, 17, 'it should start highlighting at the right position'); + assert.equal(textarea.selectionEnd, 33, 'it should end highlighting at the right position'); }); fillIn('.d-editor-input', "Before some text in between After"); @@ -56,15 +56,15 @@ test('details button', () => { click('.popup-menu .fa-caret-right'); andThen(() => { - equal( + assert.equal( find(".d-editor-input").val(), `Before [details=${I18n.t("composer.details_title")}]some text in between[/details] After`, 'it should contain the right output' ); const textarea = findTextarea(); - equal(textarea.selectionStart, 24, 'it should start highlighting at the right position'); - equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position'); + assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position'); + assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position'); }); fillIn('.d-editor-input', "Before\nsome text in between\nAfter"); @@ -79,14 +79,14 @@ test('details button', () => { click('.popup-menu .fa-caret-right'); andThen(() => { - equal( + assert.equal( find(".d-editor-input").val(), `Before\n[details=${I18n.t("composer.details_title")}]some text in between[/details]\nAfter`, 'it should contain the right output' ); const textarea = findTextarea(); - equal(textarea.selectionStart, 24, 'it should start highlighting at the right position'); - equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position'); + assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position'); + assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position'); }); }); diff --git a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6 b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6 index f020474e6cb..cd490665335 100644 --- a/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6 +++ b/plugins/discourse-details/test/javascripts/lib/details-cooked-test.js.es6 @@ -13,11 +13,11 @@ const defaultOpts = buildOptions({ getURL: url => url }); -function cooked(input, expected, text) { - equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text); -}; -test("details", () => { +test("details", assert => { + const cooked = (input, expected, text) => { + assert.equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text); + }; cooked(`
Infocoucou
`, `
Info\n\n

coucou

\n\n
`, "manual HTML for details"); diff --git a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 index 66c56b24b7c..8aadbd686de 100644 --- a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 @@ -5,13 +5,13 @@ acceptance("Rendering polls", { settings: { poll_enabled: true } }); -test("Single Poll", () => { +test("Single Poll", (assert) => { server.get('/t/13.json', () => { return [ 200, { "Content-Type": "application/json" }, {"post_stream":{"posts":[{"id":19,"name":null,"username":"tgx","avatar_template":"/images/avatar.png","created_at":"2016-12-01T02:39:49.199Z","cooked":"
\n
\n
    \n
  • test
  • \n
  • haha
  • \n
\n

0voters

\n
\n
Show results
\n
\n\n
\n
\n
    \n
  • donkey
  • \n
  • kong
  • \n
\n

0voters

\n
\n
Show results
\n
","post_number":1,"post_type":1,"updated_at":"2016-12-01T02:47:18.317Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":13,"topic_slug":"this-is-a-test-topic-for-polls","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":2,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"57ddd734344eb7436d64a7d68a0df444","html":"test","votes":0},{"id":"b5b78d79ab5b5d75d4d33d8b87f5d2aa","html":"haha","votes":0}],"voters":2,"status":"open","name":"poll"},"test":{"options":[{"id":"c26ad90783b0d80936e5fdb292b7963c","html":"donkey","votes":0},{"id":"99f2b9ac452ba73b115fcf3556e6d2d4","html":"kong","votes":0}],"voters":3,"status":"open","name":"test"}}}],"stream":[19]},"timeline_lookup":[[1,0]],"id":13,"title":"This is a test topic for polls","fancy_title":"This is a test topic for polls","posts_count":1,"created_at":"2016-12-01T02:39:48.055Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2016-12-01T02:39:49.199Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-test-topic-for-polls","category_id":1,"word_count":10,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_13","draft_sequence":4,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/images/avatar.png","post_count":1}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T02:10:54.328Z","last_posted_at":"2016-11-24T02:10:54.393Z","bumped":true,"bumped_at":"2016-11-24T02:10:54.393Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/images/avatar.png"}}]},{"id":12,"title":"Some testing topic testing","fancy_title":"Some testing topic testing","slug":"some-testing-topic-testing","posts_count":4,"reply_count":0,"highest_post_number":4,"image_url":null,"created_at":"2016-11-24T08:36:08.773Z","last_posted_at":"2016-12-01T01:15:52.008Z","bumped":true,"bumped_at":"2016-12-01T01:15:52.008Z","unseen":false,"last_read_post_number":4,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":2,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}]},{"id":11,"title":"Some testing topic","fancy_title":"Some testing topic","slug":"some-testing-topic","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2016-11-24T08:35:26.758Z","last_posted_at":"2016-11-24T08:35:26.894Z","bumped":true,"bumped_at":"2016-11-24T08:35:26.894Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":0,"category_id":1,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":19,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false} - ] + ]; }); visit("/t/this-is-a-test-topic-for-polls/13"); @@ -19,19 +19,19 @@ test("Single Poll", () => { andThen(() => { const polls = find('.poll'); - equal(polls.length, 2, 'it should render the polls correctly'); - equal(find('.info-number', polls[0]).text(), '2', 'it should display the right number of votes'); - equal(find('.info-number', polls[1]).text(), '3', 'it should display the right number of votes'); + assert.equal(polls.length, 2, 'it should render the polls correctly'); + assert.equal(find('.info-number', polls[0]).text(), '2', 'it should display the right number of votes'); + assert.equal(find('.info-number', polls[1]).text(), '3', 'it should display the right number of votes'); }); }); -test("Public poll", () => { +test("Public poll", assert => { server.get('/t/12.json', () => { return [ 200, { "Content-Type": "application/json" }, {"post_stream":{"posts":[{"id":15,"name":null,"username":"tgx","avatar_template":"/images/avatar.png","created_at":"2017-01-31T08:39:06.237Z","cooked":"
\n
\n
    \n
  • 1
  • \n
  • 2
  • \n
  • 3
  • \n
\n
\n

0voters

\n

Choose up to 3 options

\n

Votes are public.

\n
\n
\n
\nVote now!Show results\n
\n
","post_number":1,"post_type":1,"updated_at":"2017-01-31T08:39:06.237Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":12,"topic_slug":"this-is-a-topic-created-for-testing","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"4d8a15e3cc35750f016ce15a43937620","html":"1","votes":29},{"id":"cd314db7dfbac2b10687b6f39abfdf41","html":"2","votes":29},{"id":"68b434ff88aeae7054e42cd05a4d9056","html":"3","votes":42}],"voters":100,"status":"open","name":"poll","type":"multiple","min":"1","max":"3","public":"true"}}}],"stream":[15]},"timeline_lookup":[[1,0]],"id":12,"title":"This is a topic created for testing","fancy_title":"This is a topic created for testing","posts_count":1,"created_at":"2017-01-31T08:39:06.094Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2017-01-31T08:39:06.237Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-topic-created-for-testing","category_id":1,"word_count":13,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_12","draft_sequence":1,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/images/avatar.png","post_count":1,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_color":null,"primary_group_flair_bg_color":null}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:53:45.363Z","last_posted_at":"2017-01-31T07:53:45.439Z","bumped":true,"bumped_at":"2017-01-31T07:53:45.439Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/images/avatar.png"}}]},{"id":11,"title":"This is a test post to try out posts","fancy_title":"This is a test post to try out posts","slug":"this-is-a-test-post-to-try-out-posts","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:55:58.407Z","last_posted_at":"2017-01-31T07:55:58.634Z","bumped":true,"bumped_at":"2017-01-31T07:55:58.634Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":15,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false,"featured_link":null} - ] + ]; }); server.get('/polls/voters.json', request => { @@ -50,13 +50,13 @@ test("Public poll", () => { andThen(() => { const polls = find('.poll'); - equal(polls.length, 1, 'it should render the poll correctly'); + assert.equal(polls.length, 1, 'it should render the poll correctly'); }); click('button.toggle-results'); andThen(() => { - equal( + assert.equal( find('.poll-voters:first li').length, 25, 'it should display the right number of voters' ); @@ -65,20 +65,20 @@ test("Public poll", () => { click('.poll-voters-toggle-expand:first a'); andThen(() => { - equal( + assert.equal( find('.poll-voters:first li').length, 50, 'it should display the right number of voters' - ) + ); }); }); -test("Public number poll", () => { +test("Public number poll", assert => { server.get('/t/13.json', () => { return [ 200, { "Content-Type": "application/json" }, {"post_stream":{"posts":[{"id":16,"name":null,"username":"tgx","avatar_template":"/images/avatar.png","created_at":"2017-01-31T09:11:11.281Z","cooked":"
\n
\n
    \n
  • 1
  • \n
  • 2
  • \n
  • 3
  • \n
  • 4
  • \n
  • 5
  • \n
  • 6
  • \n
  • 7
  • \n
  • 8
  • \n
  • 9
  • \n
  • 10
  • \n
  • 11
  • \n
  • 12
  • \n
  • 13
  • \n
  • 14
  • \n
  • 15
  • \n
  • 16
  • \n
  • 17
  • \n
  • 18
  • \n
  • 19
  • \n
  • 20
  • \n
\n
\n

0voters

\n

Votes are public.

\n
\n
\n
Show results
\n
","post_number":1,"post_type":1,"updated_at":"2017-01-31T09:11:11.281Z","reply_count":0,"reply_to_post_number":null,"quote_count":0,"avg_time":null,"incoming_link_count":0,"reads":1,"score":0,"yours":true,"topic_id":13,"topic_slug":"this-is-a-topic-for-testing-number-poll","display_username":null,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_bg_color":null,"primary_group_flair_color":null,"version":1,"can_edit":true,"can_delete":false,"can_recover":true,"can_wiki":true,"read":true,"user_title":null,"actions_summary":[{"id":3,"can_act":true},{"id":4,"can_act":true},{"id":5,"hidden":true,"can_act":true},{"id":7,"can_act":true},{"id":8,"can_act":true}],"moderator":false,"admin":true,"staff":true,"user_id":1,"hidden":false,"hidden_reason_id":null,"trust_level":4,"deleted_at":null,"user_deleted":false,"edit_reason":null,"can_view_edit_history":true,"wiki":false,"polls":{"poll":{"options":[{"id":"4d8a15e3cc35750f016ce15a43937620","html":"1","votes":2},{"id":"cd314db7dfbac2b10687b6f39abfdf41","html":"2","votes":1},{"id":"68b434ff88aeae7054e42cd05a4d9056","html":"3","votes":1},{"id":"aa2393b424f2f395abb63bf785760a3b","html":"4","votes":0},{"id":"8b2f2930cac0574c3450f5db9a6fb7f9","html":"5","votes":1},{"id":"60cad69e0cfcb3fa77a68d11d3758002","html":"6","votes":0},{"id":"9ab1070dec27185440cdabb4948a5e9a","html":"7","votes":1},{"id":"99944bf07088f815a966d585daed6a7e","html":"8","votes":3},{"id":"345a83050400d78f5fac98d381b45e23","html":"9","votes":3},{"id":"46c01f638a50d86e020f47469733b8be","html":"10","votes":3},{"id":"07f7f85b2a3809faff68a35e81a664eb","html":"11","votes":2},{"id":"b3e8c14e714910cb8dd7089f097be133","html":"12","votes":4},{"id":"b4f15431e07443c372d521e4ed131abe","html":"13","votes":2},{"id":"a77bc9a30933e5af327211db2da46e17","html":"14","votes":2},{"id":"303d7c623da1985e94a9d27d43596934","html":"15","votes":2},{"id":"4e885ead68ff4456f102843df9fbbd7f","html":"16","votes":1},{"id":"cbf6e2b72e403b12d7ee63a138f32647","html":"17","votes":2},{"id":"9364fa2d67fbd62c473165441ad69571","html":"18","votes":2},{"id":"eb8661f072794ea57baa7827cd8ffc88","html":"19","votes":1},{"id":"b373436e858c0821135f994a5ff3345f","html":"20","votes":2}],"voters":35,"status":"open","name":"poll","type":"number","min":"1","max":"20","step":"1","public":"true"}}}],"stream":[16]},"timeline_lookup":[[1,0]],"id":13,"title":"This is a topic for testing number poll","fancy_title":"This is a topic for testing number poll","posts_count":1,"created_at":"2017-01-31T09:11:11.161Z","views":1,"reply_count":0,"participant_count":1,"like_count":0,"last_posted_at":"2017-01-31T09:11:11.281Z","visible":true,"closed":false,"archived":false,"has_summary":false,"archetype":"regular","slug":"this-is-a-topic-for-testing-number-poll","category_id":1,"word_count":12,"deleted_at":null,"user_id":1,"draft":null,"draft_key":"topic_13","draft_sequence":1,"posted":true,"unpinned":null,"pinned_globally":false,"pinned":false,"pinned_at":null,"pinned_until":null,"details":{"auto_close_at":null,"auto_close_hours":null,"auto_close_based_on_last_post":false,"created_by":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"last_poster":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"},"participants":[{"id":1,"username":"tgx","avatar_template":"/images/avatar.png","post_count":1,"primary_group_name":null,"primary_group_flair_url":null,"primary_group_flair_color":null,"primary_group_flair_bg_color":null}],"suggested_topics":[{"id":8,"title":"Welcome to Discourse","fancy_title":"Welcome to Discourse","slug":"welcome-to-discourse","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:53:45.363Z","last_posted_at":"2017-01-31T07:53:45.439Z","bumped":true,"bumped_at":"2017-01-31T07:53:45.439Z","unseen":false,"pinned":true,"unpinned":null,"excerpt":"The first paragraph of this pinned topic will be visible as a welcome message to all new visitors on your homepage. It's important! \n\nEdit this into a brief description of your community: \n\n\nWho is it for?\nWhat can they …","visible":true,"closed":false,"archived":false,"bookmarked":null,"liked":null,"archetype":"regular","like_count":0,"views":0,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":-1,"username":"system","avatar_template":"/images/avatar.png"}}]},{"id":11,"title":"This is a test post to try out posts","fancy_title":"This is a test post to try out posts","slug":"this-is-a-test-post-to-try-out-posts","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T07:55:58.407Z","last_posted_at":"2017-01-31T07:55:58.634Z","bumped":true,"bumped_at":"2017-01-31T07:55:58.634Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}]},{"id":12,"title":"This is a topic created for testing","fancy_title":"This is a topic created for testing","slug":"this-is-a-topic-created-for-testing","posts_count":1,"reply_count":0,"highest_post_number":1,"image_url":null,"created_at":"2017-01-31T08:39:06.094Z","last_posted_at":"2017-01-31T08:39:06.237Z","bumped":true,"bumped_at":"2017-01-31T09:10:46.528Z","unseen":false,"last_read_post_number":1,"unread":0,"new_posts":0,"pinned":false,"unpinned":null,"visible":true,"closed":false,"archived":false,"notification_level":3,"bookmarked":false,"liked":false,"archetype":"regular","like_count":0,"views":1,"category_id":1,"featured_link":null,"posters":[{"extras":"latest single","description":"Original Poster, Most Recent Poster","user":{"id":1,"username":"tgx","avatar_template":"/images/avatar.png"}}]}],"notification_level":3,"notifications_reason_id":1,"can_move_posts":true,"can_edit":true,"can_delete":true,"can_recover":true,"can_remove_allowed_users":true,"can_invite_to":true,"can_create_post":true,"can_reply_as_new_topic":true,"can_flag_topic":true},"highest_post_number":1,"last_read_post_number":1,"last_read_post_id":16,"deleted_by":null,"has_deleted":false,"actions_summary":[{"id":4,"count":0,"hidden":false,"can_act":true},{"id":7,"count":0,"hidden":false,"can_act":true},{"id":8,"count":0,"hidden":false,"can_act":true}],"chunk_size":20,"bookmarked":false,"featured_link":null} - ] + ]; }); server.get('/polls/voters.json', request => { @@ -97,13 +97,13 @@ test("Public number poll", () => { andThen(() => { const polls = find('.poll'); - equal(polls.length, 1, 'it should render the poll correctly'); + assert.equal(polls.length, 1, 'it should render the poll correctly'); }); click('button.toggle-results'); andThen(() => { - equal( + assert.equal( find('.poll-voters:first li').length, 25, 'it should display the right number of voters' ); @@ -112,9 +112,9 @@ test("Public number poll", () => { click('.poll-voters-toggle-expand:first a'); andThen(() => { - equal( + assert.equal( find('.poll-voters:first li').length, 35, 'it should display the right number of voters' - ) + ); }); }); diff --git a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 index 61373127de8..b81d4984181 100644 --- a/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 +++ b/plugins/poll/test/javascripts/controllers/poll-ui-builder-test.js.es6 @@ -10,7 +10,7 @@ moduleFor("controller:poll-ui-builder", "controller:poll-ui-builder", { needs: ['controller:modal'] }); -test("isMultiple", function() { +test("isMultiple", function(assert) { const controller = this.subject(); controller.setProperties({ @@ -18,31 +18,31 @@ test("isMultiple", function() { pollOptionsCount: 1 }); - equal(controller.get("isMultiple"), true, "it should be true"); + assert.equal(controller.get("isMultiple"), true, "it should be true"); controller.set("pollOptionsCount", 0); - equal(controller.get("isMultiple"), false, "it should be false"); + assert.equal(controller.get("isMultiple"), false, "it should be false"); controller.setProperties({ pollType: "random", pollOptionsCount: 1 }); - equal(controller.get("isMultiple"), false, "it should be false"); + assert.equal(controller.get("isMultiple"), false, "it should be false"); }); -test("isNumber", function() { +test("isNumber", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.set("pollType", "random"); - equal(controller.get("isNumber"), false, "it should be false"); + assert.equal(controller.get("isNumber"), false, "it should be false"); controller.set("pollType", controller.get("numberPollType")); - equal(controller.get("isNumber"), true, "it should be true"); + assert.equal(controller.get("isNumber"), true, "it should be true"); }); -test("showMinMax", function() { +test("showMinMax", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; @@ -51,14 +51,14 @@ test("showMinMax", function() { isMultiple: false }); - equal(controller.get("showMinMax"), true, "it should be true"); + assert.equal(controller.get("showMinMax"), true, "it should be true"); controller.setProperties({ isNumber: false, isMultiple: true }); - equal(controller.get("showMinMax"), true, "it should be true"); + assert.equal(controller.get("showMinMax"), true, "it should be true"); controller.setProperties({ isNumber: false, @@ -66,23 +66,23 @@ test("showMinMax", function() { isRegular: true }); - equal(controller.get("showMinMax"), false, "it should be false"); + assert.equal(controller.get("showMinMax"), false, "it should be false"); }); -test("pollOptionsCount", function() { +test("pollOptionsCount", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.set("pollOptions", "1\n2\n"); - equal(controller.get("pollOptionsCount"), 2, "it should equal 2"); + assert.equal(controller.get("pollOptionsCount"), 2, "it should equal 2"); controller.set("pollOptions", ""); - equal(controller.get("pollOptionsCount"), 0, "it should equal 0"); + assert.equal(controller.get("pollOptionsCount"), 0, "it should equal 0"); }); -test("pollMinOptions", function() { +test("pollMinOptions", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; @@ -91,40 +91,40 @@ test("pollMinOptions", function() { pollOptionsCount: 1 }); - deepEqual(controller.get("pollMinOptions"), [{ name: 1, value: 1 }], "it should return the right options"); + assert.deepEqual(controller.get("pollMinOptions"), [{ name: 1, value: 1 }], "it should return the right options"); controller.set("pollOptionsCount", 2); - deepEqual(controller.get("pollMinOptions"), [ + assert.deepEqual(controller.get("pollMinOptions"), [ { name: 1, value: 1 }, { name: 2, value: 2 } ], "it should return the right options"); controller.set("isNumber", true); controller.siteSettings.poll_maximum_options = 2; - deepEqual(controller.get("pollMinOptions"), [ + assert.deepEqual(controller.get("pollMinOptions"), [ { name: 1, value: 1 }, { name: 2, value: 2 } ], "it should return the right options"); }); -test("pollMaxOptions", function() { +test("pollMaxOptions", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.setProperties({ isMultiple: true, pollOptionsCount: 1, pollMin: 1 }); - deepEqual(controller.get("pollMaxOptions"), [], "it should return the right options"); + assert.deepEqual(controller.get("pollMaxOptions"), [], "it should return the right options"); controller.set("pollOptionsCount", 2); - deepEqual(controller.get("pollMaxOptions"), [ + assert.deepEqual(controller.get("pollMaxOptions"), [ { name: 2, value: 2 } ], "it should return the right options"); controller.siteSettings.poll_maximum_options = 3; controller.setProperties({ isMultiple: false, isNumber: true, pollStep: 2, pollMin: 1 }); - deepEqual(controller.get("pollMaxOptions"), [ + assert.deepEqual(controller.get("pollMaxOptions"), [ { name: 2, value: 2 }, { name: 3, value: 3 }, { name: 4, value: 4 }, @@ -133,50 +133,50 @@ test("pollMaxOptions", function() { ], "it should return the right options"); }); -test("pollStepOptions", function() { +test("pollStepOptions", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.siteSettings.poll_maximum_options = 3; controller.set("isNumber", false); - equal(controller.get("pollStepOptions"), null, "is should return null"); + assert.equal(controller.get("pollStepOptions"), null, "is should return null"); controller.setProperties({ isNumber: true }); - deepEqual(controller.get("pollStepOptions"), [ + assert.deepEqual(controller.get("pollStepOptions"), [ { name: 1, value: 1 }, { name: 2, value: 2 }, { name: 3, value: 3 } ], "it should return the right options"); }); -test("disableInsert", function() { +test("disableInsert", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.setProperties({ isRegular: true }); - equal(controller.get("disableInsert"), true, "it should be true"); + assert.equal(controller.get("disableInsert"), true, "it should be true"); controller.setProperties({ isRegular: true, pollOptionsCount: 2 }); - equal(controller.get("disableInsert"), false, "it should be false"); + assert.equal(controller.get("disableInsert"), false, "it should be false"); controller.setProperties({ isNumber: true }); - equal(controller.get("disableInsert"), false, "it should be false"); + assert.equal(controller.get("disableInsert"), false, "it should be false"); controller.setProperties({ isNumber: false, pollOptionsCount: 3 }); - equal(controller.get("disableInsert"), false, "it should be false"); + assert.equal(controller.get("disableInsert"), false, "it should be false"); controller.setProperties({ isNumber: false, pollOptionsCount: 1 }); - equal(controller.get("disableInsert"), true, "it should be true"); + assert.equal(controller.get("disableInsert"), true, "it should be true"); }); -test("number pollOutput", function() { +test("number pollOutput", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.siteSettings.poll_maximum_options = 20; @@ -187,18 +187,18 @@ test("number pollOutput", function() { pollMin: 1 }); - equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1]\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=1]\n[/poll]", "it should return the right output"); controller.set("pollStep", 2); - equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2]\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2]\n[/poll]", "it should return the right output"); controller.set("publicPoll", true); - equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=number min=1 max=20 step=2 public=true]\n[/poll]", "it should return the right output"); }); -test("regular pollOutput", function() { +test("regular pollOutput", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.siteSettings.poll_maximum_options = 20; @@ -209,15 +209,15 @@ test("regular pollOutput", function() { pollType: controller.get("regularPollType") }); - equal(controller.get("pollOutput"), "[poll type=regular]\n* 1\n* 2\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=regular]\n* 1\n* 2\n[/poll]", "it should return the right output"); controller.set("publicPoll", "true"); - equal(controller.get("pollOutput"), "[poll type=regular public=true]\n* 1\n* 2\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=regular public=true]\n* 1\n* 2\n[/poll]", "it should return the right output"); }); -test("multiple pollOutput", function() { +test("multiple pollOutput", function(assert) { const controller = this.subject(); controller.siteSettings = Discourse.SiteSettings; controller.siteSettings.poll_maximum_options = 20; @@ -229,9 +229,9 @@ test("multiple pollOutput", function() { pollOptions: "\n\n1\n\n2" }); - equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2]\n* 1\n* 2\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2]\n* 1\n* 2\n[/poll]", "it should return the right output"); controller.set("publicPoll", "true"); - equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2 public=true]\n* 1\n* 2\n[/poll]", "it should return the right output"); + assert.equal(controller.get("pollOutput"), "[poll type=multiple min=1 max=2 public=true]\n* 1\n* 2\n[/poll]", "it should return the right output"); }); diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6 index e32c9836719..0d646199c7a 100644 --- a/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6 +++ b/plugins/poll/test/javascripts/widgets/discourse-poll-option-test.js.es6 @@ -8,7 +8,7 @@ const template = `{{mount-widget widgetTest('single, not selected', { template, - setup() { + beforeEach() { this.set('option', { id: 'opt-id' }); this.set('vote', []); }, @@ -21,7 +21,7 @@ widgetTest('single, not selected', { widgetTest('single, selected', { template, - setup() { + beforeEach() { this.set('option', { id: 'opt-id' }); this.set('vote', ['opt-id']); }, @@ -34,7 +34,7 @@ widgetTest('single, selected', { widgetTest('multi, not selected', { template, - setup() { + beforeEach() { this.setProperties({ option: { id: 'opt-id' }, isMultiple: true, @@ -50,7 +50,7 @@ widgetTest('multi, not selected', { widgetTest('multi, selected', { template, - setup() { + beforeEach() { this.setProperties({ option: { id: 'opt-id' }, isMultiple: true, diff --git a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 index f1668b11791..d289f45ae85 100644 --- a/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 +++ b/plugins/poll/test/javascripts/widgets/discourse-poll-standard-results-test.js.es6 @@ -8,7 +8,7 @@ const template = `{{mount-widget widgetTest('options in descending order', { template, - setup() { + beforeEach() { this.set('poll', Ember.Object.create({ options: [{ votes: 5 }, { votes: 4 }], voters: 9 @@ -24,7 +24,7 @@ widgetTest('options in descending order', { widgetTest('options in ascending order', { template, - setup() { + beforeEach() { this.set('poll', Ember.Object.create({ options: [{ votes: 4 }, { votes: 5 }], voters: 9 @@ -40,7 +40,7 @@ widgetTest('options in ascending order', { widgetTest('multiple options in descending order', { template, - setup() { + beforeEach() { this.set('isMultiple', true); this.set('poll', Ember.Object.create({ type: 'multiple', diff --git a/test/javascripts/acceptance/about-test.js.es6 b/test/javascripts/acceptance/about-test.js.es6 index f6547bc6466..c7ef9fb85a7 100644 --- a/test/javascripts/acceptance/about-test.js.es6 +++ b/test/javascripts/acceptance/about-test.js.es6 @@ -1,13 +1,12 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("About"); -test("viewing", () => { +QUnit.test("viewing", assert => { visit("/about"); andThen(() => { - ok($('body.about-page').length, "has body class"); - ok(exists('.about.admins .user-info'), 'has admins'); - ok(exists('.about.moderators .user-info'), 'has moderators'); - ok(exists('.about.stats tr td'), 'has stats'); + assert.ok($('body.about-page').length, "has body class"); + assert.ok(exists('.about.admins .user-info'), 'has admins'); + assert.ok(exists('.about.moderators .user-info'), 'has moderators'); + assert.ok(exists('.about.stats tr td'), 'has stats'); }); -}); - +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/account-created-test.js.es6 b/test/javascripts/acceptance/account-created-test.js.es6 index 661dc6197c3..a0fc11267ac 100644 --- a/test/javascripts/acceptance/account-created-test.js.es6 +++ b/test/javascripts/acceptance/account-created-test.js.es6 @@ -3,7 +3,7 @@ import PreloadStore from 'preload-store'; acceptance("Account Created"); -test("account created - message", assert => { +QUnit.test("account created - message", assert => { PreloadStore.store('accountCreated', { message: "Hello World", }); @@ -20,7 +20,7 @@ test("account created - message", assert => { }); }); -test("account created - resend email", assert => { +QUnit.test("account created - resend email", assert => { PreloadStore.store('accountCreated', { message: "Hello World", username: 'eviltrout', @@ -47,7 +47,7 @@ test("account created - resend email", assert => { }); -test("account created - update email - cancel", assert => { +QUnit.test("account created - update email - cancel", assert => { PreloadStore.store('accountCreated', { message: "Hello World", username: 'eviltrout', @@ -68,7 +68,7 @@ test("account created - update email - cancel", assert => { }); }); -test("account created - update email - submit", assert => { +QUnit.test("account created - update email - submit", assert => { PreloadStore.store('accountCreated', { message: "Hello World", username: 'eviltrout', @@ -94,4 +94,4 @@ test("account created - update email - submit", assert => { assert.equal(email, 'newemail@example.com'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/admin-site-text-test.js.es6 b/test/javascripts/acceptance/admin-site-text-test.js.es6 index 0cd17959c18..c20dc09f4fa 100644 --- a/test/javascripts/acceptance/admin-site-text-test.js.es6 +++ b/test/javascripts/acceptance/admin-site-text-test.js.es6 @@ -2,33 +2,33 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Admin - Site Texts", { loggedIn: true }); -test("search for a key", () => { +QUnit.test("search for a key", assert => { visit("/admin/customize/site_texts"); fillIn('.site-text-search', 'Test'); andThen(() => { - ok(exists('.site-text')); - ok(exists(".site-text:not(.overridden)")); - ok(exists('.site-text.overridden')); + assert.ok(exists('.site-text')); + assert.ok(exists(".site-text:not(.overridden)")); + assert.ok(exists('.site-text.overridden')); }); // Only show overridden click('.extra-options input'); andThen(() => { - ok(!exists(".site-text:not(.overridden)")); - ok(exists('.site-text.overridden')); + assert.ok(!exists(".site-text:not(.overridden)")); + assert.ok(exists('.site-text.overridden')); }); }); -test("edit and revert a site text by key", () => { +QUnit.test("edit and revert a site text by key", assert => { visit("/admin/customize/site_texts/site.test"); andThen(() => { - equal(find('.title h3').text(), 'site.test'); - ok(!exists('.save-messages .saved')); - ok(!exists('.save-messages .saved')); - ok(!exists('.revert-site-text')); + assert.equal(find('.title h3').text(), 'site.test'); + assert.ok(!exists('.save-messages .saved')); + assert.ok(!exists('.save-messages .saved')); + assert.ok(!exists('.revert-site-text')); }); // Change the value @@ -36,19 +36,19 @@ test("edit and revert a site text by key", () => { click(".save-changes"); andThen(() => { - ok(exists('.save-messages .saved')); - ok(exists('.revert-site-text')); + assert.ok(exists('.save-messages .saved')); + assert.ok(exists('.revert-site-text')); }); // Revert the changes click('.revert-site-text'); andThen(() => { - ok(exists('.bootbox.modal')); + assert.ok(exists('.bootbox.modal')); }); click('.bootbox.modal .btn-primary'); andThen(() => { - ok(!exists('.save-messages .saved')); - ok(!exists('.revert-site-text')); + assert.ok(!exists('.save-messages .saved')); + assert.ok(!exists('.revert-site-text')); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/admin-users-list-test.js.es6 b/test/javascripts/acceptance/admin-users-list-test.js.es6 index a391ff9b731..a6d3117e604 100644 --- a/test/javascripts/acceptance/admin-users-list-test.js.es6 +++ b/test/javascripts/acceptance/admin-users-list-test.js.es6 @@ -2,10 +2,10 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Admin - Users List", { loggedIn: true }); -test("lists users", () => { +QUnit.test("lists users", assert => { visit("/admin/users/list/active"); andThen(() => { - ok(exists('.users-list .user')); - ok(!exists('.user:eq(0) .email small'), 'escapes email'); + assert.ok(exists('.users-list .user')); + assert.ok(!exists('.user:eq(0) .email small'), 'escapes email'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/badges-test.js.es6 b/test/javascripts/acceptance/badges-test.js.es6 index ad1f00c0d53..9052efe2223 100644 --- a/test/javascripts/acceptance/badges-test.js.es6 +++ b/test/javascripts/acceptance/badges-test.js.es6 @@ -2,17 +2,17 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Badges"); -test("Visit Badge Pages", () => { +QUnit.test("Visit Badge Pages", assert => { visit("/badges"); andThen(() => { - ok($('body.badges-page').length, "has body class"); - ok(exists('.badge-groups .badge-card'), "has a list of badges"); + assert.ok($('body.badges-page').length, "has body class"); + assert.ok(exists('.badge-groups .badge-card'), "has a list of badges"); }); visit("/badges/9/autobiographer"); andThen(() => { - ok(exists('.badge-card'), "has the badge in the listing"); - ok(exists('.user-info'), "has the list of users with that badge"); - ok(!exists('.badge-card:eq(0) script')); + assert.ok(exists('.badge-card'), "has the badge in the listing"); + assert.ok(exists('.user-info'), "has the list of users with that badge"); + assert.ok(!exists('.badge-card:eq(0) script')); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/category-edit-test.js.es6 b/test/javascripts/acceptance/category-edit-test.js.es6 index 185cb7b216f..170a692c05b 100644 --- a/test/javascripts/acceptance/category-edit-test.js.es6 +++ b/test/javascripts/acceptance/category-edit-test.js.es6 @@ -6,7 +6,7 @@ acceptance("Category Edit", { settings: { email_in: true } }); -test("Can open the category modal", assert => { +QUnit.test("Can open the category modal", assert => { visit("/c/bug"); click('.edit-category'); @@ -20,7 +20,7 @@ test("Can open the category modal", assert => { }); }); -test("Change the category color", assert => { +QUnit.test("Change the category color", assert => { visit("/c/bug"); click('.edit-category'); @@ -32,7 +32,7 @@ test("Change the category color", assert => { }); }); -test("Change the topic template", assert => { +QUnit.test("Change the topic template", assert => { visit("/c/bug"); click('.edit-category'); @@ -45,7 +45,7 @@ test("Change the topic template", assert => { }); }); -test("Error Saving", assert => { +QUnit.test("Error Saving", assert => { visit("/c/bug"); click('.edit-category'); @@ -58,19 +58,19 @@ test("Error Saving", assert => { }); }); -test("Subcategory list settings", () => { +QUnit.test("Subcategory list settings", assert => { visit("/c/bug"); click('.edit-category'); click('.edit-category-settings'); andThen(() => { - ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible by default"); + assert.ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible by default"); }); click(".show-subcategory-list-field input[type=checkbox]"); andThen(() => { - ok(visible(".subcategory-list-style-field"), "subcategory list style is shown if show subcategory list is checked"); + assert.ok(visible(".subcategory-list-style-field"), "subcategory list style is shown if show subcategory list is checked"); }); click('.edit-category-general'); @@ -78,7 +78,7 @@ test("Subcategory list settings", () => { click('.edit-category-settings'); andThen(() => { - ok(!visible(".show-subcategory-list-field"), "show subcategory list isn't visible for child categories"); - ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible for child categories"); + assert.ok(!visible(".show-subcategory-list-field"), "show subcategory list isn't visible for child categories"); + assert.ok(!visible(".subcategory-list-style-field"), "subcategory list style isn't visible for child categories"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/category-hashtag-test.js.es6 b/test/javascripts/acceptance/category-hashtag-test.js.es6 index 99a0c711cd7..813578712c7 100644 --- a/test/javascripts/acceptance/category-hashtag-test.js.es6 +++ b/test/javascripts/acceptance/category-hashtag-test.js.es6 @@ -2,18 +2,18 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Category hashtag", { loggedIn: true }); -test("category hashtag is cooked properly", () => { +QUnit.test("category hashtag is cooked properly", assert => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); fillIn('.d-editor-input', "this is a category hashtag #bug"); andThen(() => { // TODO: Test that the autocomplete shows - equal(find('.d-editor-preview:visible').html().trim(), "

this is a category hashtag #bug

"); + assert.equal(find('.d-editor-preview:visible').html().trim(), "

this is a category hashtag #bug

"); }); click('#reply-control .btn.create'); andThen(() => { - equal(find('.topic-post:last .cooked p').html().trim(), "this is a category hashtag #bug"); + assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is a category hashtag #bug"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/composer-test.js.es6 b/test/javascripts/acceptance/composer-test.js.es6 index fe086a68058..b155418b78e 100644 --- a/test/javascripts/acceptance/composer-test.js.es6 +++ b/test/javascripts/acceptance/composer-test.js.es6 @@ -7,44 +7,44 @@ acceptance("Composer", { } }); -test("Tests the Composer controls", () => { +QUnit.test("Tests the Composer controls", assert => { visit("/"); andThen(() => { - ok(exists('#create-topic'), 'the create button is visible'); + assert.ok(exists('#create-topic'), 'the create button is visible'); }); click('#create-topic'); andThen(() => { - ok(exists('.d-editor-input'), 'the composer input is visible'); - ok(exists('.title-input .popup-tip.bad.hide'), 'title errors are hidden by default'); - ok(exists('.d-editor-textarea-wrapper .popup-tip.bad.hide'), 'body errors are hidden by default'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(exists('.title-input .popup-tip.bad.hide'), 'title errors are hidden by default'); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.bad.hide'), 'body errors are hidden by default'); }); click('a.toggle-preview'); andThen(() => { - ok(!exists('.d-editor-preview:visible'), "clicking the toggle hides the preview"); + assert.ok(!exists('.d-editor-preview:visible'), "clicking the toggle hides the preview"); }); click('a.toggle-preview'); andThen(() => { - ok(exists('.d-editor-preview:visible'), "clicking the toggle shows the preview again"); + assert.ok(exists('.d-editor-preview:visible'), "clicking the toggle shows the preview again"); }); click('#reply-control button.create'); andThen(() => { - ok(!exists('.title-input .popup-tip.bad.hide'), 'it shows the empty title error'); - ok(!exists('.d-editor-wrapper .popup-tip.bad.hide'), 'it shows the empty body error'); + assert.ok(!exists('.title-input .popup-tip.bad.hide'), 'it shows the empty title error'); + assert.ok(!exists('.d-editor-wrapper .popup-tip.bad.hide'), 'it shows the empty body error'); }); fillIn('#reply-title', "this is my new topic title"); andThen(() => { - ok(exists('.title-input .popup-tip.good'), 'the title is now good'); + assert.ok(exists('.title-input .popup-tip.good'), 'the title is now good'); }); fillIn('.d-editor-input', "this is the *content* of a post"); andThen(() => { - equal(find('.d-editor-preview').html().trim(), "

this is the content of a post

", "it previews content"); - ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); + assert.equal(find('.d-editor-preview').html().trim(), "

this is the content of a post

", "it previews content"); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); }); andThen(() => { @@ -64,89 +64,89 @@ test("Tests the Composer controls", () => { andThen(() => { const example = I18n.t(`composer.bold_text`); - equal(find('#reply-control .d-editor-input').val().trim(), + assert.equal(find('#reply-control .d-editor-input').val().trim(), `this is the *content* of a post**${example}**`, "it supports keyboard shortcuts"); }); click('#reply-control a.cancel'); andThen(() => { - ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); + assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); }); click('.modal-footer a:eq(1)'); andThen(() => { - ok(!exists('.bootbox.modal'), 'the confirmation can be cancelled'); + assert.ok(!exists('.bootbox.modal'), 'the confirmation can be cancelled'); }); }); -test("Create a topic with server side errors", () => { +QUnit.test("Create a topic with server side errors", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "this title triggers an error"); fillIn('.d-editor-input', "this is the *content* of a post"); click('#reply-control button.create'); andThen(() => { - ok(exists('.bootbox.modal'), 'it pops up an error message'); + assert.ok(exists('.bootbox.modal'), 'it pops up an error message'); }); click('.bootbox.modal a.btn-primary'); andThen(() => { - ok(!exists('.bootbox.modal'), 'it dismisses the error'); - ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(!exists('.bootbox.modal'), 'it dismisses the error'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); }); }); -test("Create a Topic", () => { +QUnit.test("Create a Topic", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "Internationalization Localization"); fillIn('.d-editor-input', "this is the *content* of a new topic post"); click('#reply-control button.create'); andThen(() => { - equal(currentURL(), "/t/internationalization-localization/280", "it transitions to the newly created topic URL"); + assert.equal(currentURL(), "/t/internationalization-localization/280", "it transitions to the newly created topic URL"); }); }); -test("Create an enqueued Topic", () => { +QUnit.test("Create an enqueued Topic", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "Internationalization Localization"); fillIn('.d-editor-input', "enqueue this content please"); click('#reply-control button.create'); andThen(() => { - ok(visible('#discourse-modal'), 'it pops up a modal'); - equal(currentURL(), "/", "it doesn't change routes"); + assert.ok(visible('#discourse-modal'), 'it pops up a modal'); + assert.equal(currentURL(), "/", "it doesn't change routes"); }); click('.modal-footer button'); andThen(() => { - ok(invisible('#discourse-modal'), 'the modal can be dismissed'); + assert.ok(invisible('#discourse-modal'), 'the modal can be dismissed'); }); }); -test("Create a Reply", () => { +QUnit.test("Create a Reply", assert => { visit("/t/internationalization-localization/280"); andThen(() => { - ok(!exists('article[data-post-id=12345]'), 'the post is not in the DOM'); + assert.ok(!exists('article[data-post-id=12345]'), 'the post is not in the DOM'); }); click('#topic-footer-buttons .btn.create'); andThen(() => { - ok(exists('.d-editor-input'), 'the composer input is visible'); - ok(!exists('#reply-title'), 'there is no title since this is a reply'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(!exists('#reply-title'), 'there is no title since this is a reply'); }); fillIn('.d-editor-input', 'this is the content of my reply'); click('#reply-control button.create'); andThen(() => { - equal(find('.cooked:last p').text(), 'this is the content of my reply'); + assert.equal(find('.cooked:last p').text(), 'this is the content of my reply'); }); }); -test("Posting on a different topic", (assert) => { +QUnit.test("Posting on a different topic", (assert) => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); fillIn('.d-editor-input', 'this is the content for a different topic'); @@ -167,106 +167,106 @@ test("Posting on a different topic", (assert) => { }); -test("Create an enqueued Reply", () => { +QUnit.test("Create an enqueued Reply", assert => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); andThen(() => { - ok(exists('.d-editor-input'), 'the composer input is visible'); - ok(!exists('#reply-title'), 'there is no title since this is a reply'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(!exists('#reply-title'), 'there is no title since this is a reply'); }); fillIn('.d-editor-input', 'enqueue this content please'); click('#reply-control button.create'); andThen(() => { - ok(find('.cooked:last p').text() !== 'enqueue this content please', "it doesn't insert the post"); + assert.ok(find('.cooked:last p').text() !== 'enqueue this content please', "it doesn't insert the post"); }); andThen(() => { - ok(visible('#discourse-modal'), 'it pops up a modal'); + assert.ok(visible('#discourse-modal'), 'it pops up a modal'); }); click('.modal-footer button'); andThen(() => { - ok(invisible('#discourse-modal'), 'the modal can be dismissed'); + assert.ok(invisible('#discourse-modal'), 'the modal can be dismissed'); }); }); -test("Edit the first post", () => { +QUnit.test("Edit the first post", assert => { visit("/t/internationalization-localization/280"); - ok(!exists('.topic-post:eq(0) .post-info.edits'), 'it has no edits icon at first'); + assert.ok(!exists('.topic-post:eq(0) .post-info.edits'), 'it has no edits icon at first'); click('.topic-post:eq(0) button.show-more-actions'); click('.topic-post:eq(0) button.edit'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('Any plans to support'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('Any plans to support'), 0, 'it populates the input with the post text'); }); fillIn('.d-editor-input', "This is the new text for the post"); fillIn('#reply-title', "This is the new text for the title"); click('#reply-control button.create'); andThen(() => { - ok(!exists('.d-editor-input'), 'it closes the composer'); - ok(exists('.topic-post:eq(0) .post-info.edits'), 'it has the edits icon'); - ok(find('#topic-title h1').text().indexOf('This is the new text for the title') !== -1, 'it shows the new title'); - ok(find('.topic-post:eq(0) .cooked').text().indexOf('This is the new text for the post') !== -1, 'it updates the post'); + assert.ok(!exists('.d-editor-input'), 'it closes the composer'); + assert.ok(exists('.topic-post:eq(0) .post-info.edits'), 'it has the edits icon'); + assert.ok(find('#topic-title h1').text().indexOf('This is the new text for the title') !== -1, 'it shows the new title'); + assert.ok(find('.topic-post:eq(0) .cooked').text().indexOf('This is the new text for the post') !== -1, 'it updates the post'); }); }); -test("Composer can switch between edits", () => { +QUnit.test("Composer can switch between edits", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.edit'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); }); click('.topic-post:eq(1) button.edit'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text'); }); }); -test("Composer with dirty edit can toggle to another edit", () => { +QUnit.test("Composer with dirty edit can toggle to another edit", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.edit'); fillIn('.d-editor-input', 'This is a dirty reply'); click('.topic-post:eq(1) button.edit'); andThen(() => { - ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); + assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); }); click('.modal-footer a:eq(0)'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text'); }); }); -test("Composer can toggle between edit and reply", () => { +QUnit.test("Composer can toggle between edit and reply", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.edit'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); }); click('.topic-post:eq(0) button.reply'); andThen(() => { - equal(find('.d-editor-input').val(), "", 'it clears the input'); + assert.equal(find('.d-editor-input').val(), "", 'it clears the input'); }); click('.topic-post:eq(0) button.edit'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); }); }); -test("Composer can toggle between reply and createTopic", () => { +QUnit.test("Composer can toggle between reply and createTopic", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.reply'); click('button.options'); click('.popup-menu .fa-eye-slash'); andThen(() => { - ok( + assert.ok( find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) > 0, 'it sets the post type to whisper' ); @@ -274,12 +274,12 @@ test("Composer can toggle between reply and createTopic", () => { visit("/"); andThen(() => { - ok(exists('#create-topic'), 'the create topic button is visible'); + assert.ok(exists('#create-topic'), 'the create topic button is visible'); }); click('#create-topic'); andThen(() => { - ok( + assert.ok( find('.composer-fields .whisper').text().indexOf(I18n.t("composer.whisper")) === -1, "it should reset the state of the composer's model" ); @@ -288,7 +288,7 @@ test("Composer can toggle between reply and createTopic", () => { click('button.options'); click('.popup-menu .fa-eye-slash'); andThen(() => { - ok( + assert.ok( find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) > 0, 'it sets the topic to unlisted' ); @@ -298,29 +298,29 @@ test("Composer can toggle between reply and createTopic", () => { click('.topic-post:eq(0) button.reply'); andThen(() => { - ok( + assert.ok( find('.composer-fields .whisper').text().indexOf(I18n.t("composer.unlist")) === -1, "it should reset the state of the composer's model" ); }); }); -test("Composer with dirty reply can toggle to edit", () => { +QUnit.test("Composer with dirty reply can toggle to edit", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.reply'); fillIn('.d-editor-input', 'This is a dirty reply'); click('.topic-post:eq(0) button.edit'); andThen(() => { - ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); + assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); }); click('.modal-footer a:eq(0)'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); }); }); -test("Composer draft with dirty reply can toggle to edit", () => { +QUnit.test("Composer draft with dirty reply can toggle to edit", assert => { visit("/t/this-is-a-test-topic/9"); click('.topic-post:eq(0) button.reply'); @@ -328,10 +328,10 @@ test("Composer draft with dirty reply can toggle to edit", () => { click('.toggler'); click('.topic-post:eq(0) button.edit'); andThen(() => { - ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); + assert.ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog'); }); click('.modal-footer a:eq(0)'); andThen(() => { - equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); + assert.equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/composer-topic-links-test.js.es6 b/test/javascripts/acceptance/composer-topic-links-test.js.es6 index 3876fcc5cc8..515e01f111b 100644 --- a/test/javascripts/acceptance/composer-topic-links-test.js.es6 +++ b/test/javascripts/acceptance/composer-topic-links-test.js.es6 @@ -9,58 +9,58 @@ acceptance("Composer topic featured links", { }); -test("onebox with title", () => { +QUnit.test("onebox with title", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "http://www.example.com/has-title.html"); andThen(() => { - ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); - ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); - equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); + assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); + assert.equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); }); }); -test("onebox result doesn't include a title", () => { +QUnit.test("onebox result doesn't include a title", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', 'http://www.example.com/no-title.html'); andThen(() => { - ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); - ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); - equal(find('.title-input input').val(), "http://www.example.com/no-title.html", "title is unchanged"); + assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); + assert.equal(find('.title-input input').val(), "http://www.example.com/no-title.html", "title is unchanged"); }); }); -test("no onebox result", () => { +QUnit.test("no onebox result", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "http://www.example.com/nope-onebox.html"); andThen(() => { - ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); - ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'link is pasted into body'); - equal(find('.title-input input').val(), "http://www.example.com/nope-onebox.html", "title is unchanged"); + assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'link is pasted into body'); + assert.equal(find('.title-input input').val(), "http://www.example.com/nope-onebox.html", "title is unchanged"); }); }); -test("ignore internal links", () => { +QUnit.test("ignore internal links", assert => { visit("/"); click('#create-topic'); const title = "http://" + window.location.hostname + "/internal-page.html"; fillIn('#reply-title', title); andThen(() => { - equal(find('.d-editor-preview').html().trim().indexOf('onebox'), -1, "onebox preview doesn't show"); - equal(find('.d-editor-input').val().length, 0, "link isn't put into the post"); - equal(find('.title-input input').val(), title, "title is unchanged"); + assert.equal(find('.d-editor-preview').html().trim().indexOf('onebox'), -1, "onebox preview doesn't show"); + assert.equal(find('.d-editor-input').val().length, 0, "link isn't put into the post"); + assert.equal(find('.title-input input').val(), title, "title is unchanged"); }); }); -test("link is longer than max title length", () => { +QUnit.test("link is longer than max title length", assert => { visit("/"); click('#create-topic'); fillIn('#reply-title', "http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"); andThen(() => { - ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); - ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); - equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); + assert.ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); + assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); + assert.equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/create-account-user-fields-test.js.es6 b/test/javascripts/acceptance/create-account-user-fields-test.js.es6 index 0b6fec4da4e..cb7a2fe5c56 100644 --- a/test/javascripts/acceptance/create-account-user-fields-test.js.es6 +++ b/test/javascripts/acceptance/create-account-user-fields-test.js.es6 @@ -8,14 +8,14 @@ acceptance("Create Account - User Fields", { } }); -test("create account with user fields", () => { +QUnit.test("create account with user fields", assert => { visit("/"); click("header .sign-up-button"); andThen(() => { - ok(exists('.create-account'), "it shows the create account modal"); - ok(exists('.user-field'), "it has at least one user field"); - ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first'); + assert.ok(exists('.create-account'), "it shows the create account modal"); + assert.ok(exists('.user-field'), "it has at least one user field"); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first'); }); fillIn('#new-account-name', 'Dr. Good Tuna'); @@ -24,24 +24,24 @@ test("create account with user fields", () => { fillIn('#new-account-username', 'goodtuna'); andThen(() => { - ok(exists('#username-validation.good'), 'the username validation is good'); - ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled due to lack of user fields'); + assert.ok(exists('#username-validation.good'), 'the username validation is good'); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled due to lack of user fields'); }); fillIn(".user-field input[type=text]:first", "Barky"); andThen(() => { - ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled because field is not checked'); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled because field is not checked'); }); click(".user-field input[type=checkbox]"); andThen(() => { - not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled because field is not checked'); + assert.not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled because field is not checked'); }); click(".user-field input[type=checkbox]"); andThen(() => { - ok(exists('.modal-footer .btn-primary:disabled'), 'unclicking the checkbox disables the submit'); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'unclicking the checkbox disables the submit'); }); }); diff --git a/test/javascripts/acceptance/custom-html-set-test.js.es6 b/test/javascripts/acceptance/custom-html-set-test.js.es6 index 3ae0bd63737..6b2508ebf7f 100644 --- a/test/javascripts/acceptance/custom-html-set-test.js.es6 +++ b/test/javascripts/acceptance/custom-html-set-test.js.es6 @@ -4,14 +4,14 @@ import PreloadStore from 'preload-store'; acceptance("CustomHTML set"); -test("has no custom HTML in the top", assert => { +QUnit.test("has no custom HTML in the top", assert => { visit("/static/faq"); andThen(() => { assert.ok(!exists('span.custom-html-test'), 'it has no markup'); }); }); -test("renders set HTML", assert => { +QUnit.test("renders set HTML", assert => { setCustomHTML('top', 'HTML'); visit("/static/faq"); @@ -20,11 +20,11 @@ test("renders set HTML", assert => { }); }); -test("renders preloaded HTML", assert => { +QUnit.test("renders preloaded HTML", assert => { PreloadStore.store('customHTML', {top: "monster"}); visit("/static/faq"); andThen(() => { assert.equal(find('span.cookie').text(), 'monster', 'it inserted the markup'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/custom-html-template-test.js.es6 b/test/javascripts/acceptance/custom-html-template-test.js.es6 index d125236ebbc..bb0d77c8794 100644 --- a/test/javascripts/acceptance/custom-html-template-test.js.es6 +++ b/test/javascripts/acceptance/custom-html-template-test.js.es6 @@ -1,16 +1,16 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("CustomHTML template", { - setup() { + beforeEach() { Ember.TEMPLATES['top'] = Ember.HTMLBars.compile(`TOP`); }, - teardown() { + afterEach() { delete Ember.TEMPLATES['top']; } }); -test("renders custom template", assert => { +QUnit.test("renders custom template", assert => { visit("/static/faq"); andThen(() => { assert.equal(find('span.top-span').text(), 'TOP', 'it inserted the template'); diff --git a/test/javascripts/acceptance/emoji-test.js.es6 b/test/javascripts/acceptance/emoji-test.js.es6 index dfcd95fb753..23fc2aa8046 100644 --- a/test/javascripts/acceptance/emoji-test.js.es6 +++ b/test/javascripts/acceptance/emoji-test.js.es6 @@ -2,32 +2,32 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Emoji", { loggedIn: true }); -test("emoji is cooked properly", () => { +QUnit.test("emoji is cooked properly", assert => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); fillIn('.d-editor-input', "this is an emoji :blonde_woman:"); andThen(() => { - equal(find('.d-editor-preview:visible').html().trim(), "

this is an emoji \":blonde_woman:\"

"); + assert.equal(find('.d-editor-preview:visible').html().trim(), "

this is an emoji \":blonde_woman:\"

"); }); click('#reply-control .btn.create'); andThen(() => { - equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji \":blonde_woman:\""); + assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji \":blonde_woman:\""); }); }); -test("skin toned emoji is cooked properly", () => { +QUnit.test("skin toned emoji is cooked properly", assert => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); fillIn('.d-editor-input', "this is an emoji :blonde_woman:t5:"); andThen(() => { - equal(find('.d-editor-preview:visible').html().trim(), "

this is an emoji \":blonde_woman:t5:\"

"); + assert.equal(find('.d-editor-preview:visible').html().trim(), "

this is an emoji \":blonde_woman:t5:\"

"); }); click('#reply-control .btn.create'); andThen(() => { - equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji \":blonde_woman:t5:\""); + assert.equal(find('.topic-post:last .cooked p').html().trim(), "this is an emoji \":blonde_woman:t5:\""); }); }); diff --git a/test/javascripts/acceptance/group-edit-test.js.es6 b/test/javascripts/acceptance/group-edit-test.js.es6 index 023d9c95f45..676ee7a2fc1 100644 --- a/test/javascripts/acceptance/group-edit-test.js.es6 +++ b/test/javascripts/acceptance/group-edit-test.js.es6 @@ -2,39 +2,39 @@ import { acceptance, logIn } from "helpers/qunit-helpers"; acceptance("Editing Group"); -test("Editing group", () => { +QUnit.test("Editing group", assert => { logIn(); Discourse.reset(); visit("/groups/discourse/edit"); andThen(() => { - ok(find('.group-flair-inputs').length === 1, 'it should display avatar flair inputs'); - ok(find('.group-edit-bio').length === 1, 'it should display group bio input'); - ok(find('.group-edit-full-name').length === 1, 'it should display group full name input'); - ok(find('.group-edit-public').length === 1, 'it should display group public input'); - ok(find('.group-edit-allow-membership-requests').length === 1, 'it should display group allow_membership_requets input'); - ok(find('.group-members-input .item').length === 7, 'it should display group members'); - ok(find('.group-members-input-selector').length === 1, 'it should display input to add group members'); - ok(find('.group-members-input-selector .add[disabled]').length === 1, 'add members button should be disabled'); + assert.ok(find('.group-flair-inputs').length === 1, 'it should display avatar flair inputs'); + assert.ok(find('.group-edit-bio').length === 1, 'it should display group bio input'); + assert.ok(find('.group-edit-full-name').length === 1, 'it should display group full name input'); + assert.ok(find('.group-edit-public').length === 1, 'it should display group public input'); + assert.ok(find('.group-edit-allow-membership-requests').length === 1, 'it should display group allow_membership_requets input'); + assert.ok(find('.group-members-input .item').length === 7, 'it should display group members'); + assert.ok(find('.group-members-input-selector').length === 1, 'it should display input to add group members'); + assert.ok(find('.group-members-input-selector .add[disabled]').length === 1, 'add members button should be disabled'); }); andThen(() => { - ok(find('.group-edit-allow-membership-requests[disabled]').length === 1, 'it should disable group allow_membership_request input'); + assert.ok(find('.group-edit-allow-membership-requests[disabled]').length === 1, 'it should disable group allow_membership_request input'); }); click('.group-edit-public'); click('.group-edit-allow-membership-requests'); andThen(() => { - ok(find('.group-edit-public[disabled]').length === 1, 'it should disable group public input'); + assert.ok(find('.group-edit-public[disabled]').length === 1, 'it should disable group public input'); }); }); -test("Editing group as an anonymous user", () => { +QUnit.test("Editing group as an anonymous user", assert => { visit("/groups/discourse/edit"); andThen(() => { - ok(count('.group-members tr') > 0, "it should redirect to members page for an anonymous user"); + assert.ok(count('.group-members tr') > 0, "it should redirect to members page for an anonymous user"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/group-logs-test.js.es6 b/test/javascripts/acceptance/group-logs-test.js.es6 index 58a1acb7bea..86d760cb0c2 100644 --- a/test/javascripts/acceptance/group-logs-test.js.es6 +++ b/test/javascripts/acceptance/group-logs-test.js.es6 @@ -2,7 +2,7 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Group Logs", { loggedIn: true, - setup() { + beforeEach() { const response = object => { return [ 200, @@ -26,15 +26,15 @@ acceptance("Group Logs", { } }); -test("Browsing group logs", () => { +QUnit.test("Browsing group logs", assert => { visit("/groups/snorlax/logs"); andThen(() => { - ok(find('tr.group-logs-row').length === 2, 'it should display the right number of logs'); + assert.ok(find('tr.group-logs-row').length === 2, 'it should display the right number of logs'); click(find(".group-logs-row button")[0]); }); andThen(() => { - ok(find('tr.group-logs-row').length === 1, 'it should display the right number of logs'); + assert.ok(find('tr.group-logs-row').length === 1, 'it should display the right number of logs'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/groups-test.js.es6 b/test/javascripts/acceptance/groups-test.js.es6 index baf138e76d0..0534127ea7b 100644 --- a/test/javascripts/acceptance/groups-test.js.es6 +++ b/test/javascripts/acceptance/groups-test.js.es6 @@ -2,104 +2,104 @@ import { acceptance, logIn } from "helpers/qunit-helpers"; acceptance("Groups"); -test("Browsing Groups", () => { +QUnit.test("Browsing Groups", assert => { visit("/groups"); andThen(() => { - equal(count('.groups-table-row'), 2, 'it displays visible groups'); - equal(find('.group-index-join').length, 1, 'it shows button to join group'); - equal(find('.group-index-request').length, 1, 'it shows button to request for group membership'); + assert.equal(count('.groups-table-row'), 2, 'it displays visible groups'); + assert.equal(find('.group-index-join').length, 1, 'it shows button to join group'); + assert.equal(find('.group-index-request').length, 1, 'it shows button to request for group membership'); }); click('.group-index-join'); andThen(() => { - ok(exists('.modal.login-modal'), 'it shows the login modal'); + assert.ok(exists('.modal.login-modal'), 'it shows the login modal'); }); click('.login-modal .close'); andThen(() => { - ok(invisible('.modal.login-modal'), 'it closes the login modal'); + assert.ok(invisible('.modal.login-modal'), 'it closes the login modal'); }); click('.group-index-request'); andThen(() => { - ok(exists('.modal.login-modal'), 'it shows the login modal'); + assert.ok(exists('.modal.login-modal'), 'it shows the login modal'); }); click("a[href='/groups/discourse/members']"); andThen(() => { - equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page"); + assert.equal(find('.group-info-name').text().trim(), 'Awesome Team', "it displays the group page"); }); click('.group-index-join'); andThen(() => { - ok(exists('.modal.login-modal'), 'it shows the login modal'); + assert.ok(exists('.modal.login-modal'), 'it shows the login modal'); }); }); -test("Viewing Group", () => { +QUnit.test("Viewing Group", assert => { visit("/groups/discourse"); andThen(() => { - ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair"); - ok(count('.group-members tr') > 0, "it lists group members"); + assert.ok(count('.avatar-flair .fa-adjust') === 1, "it displays the group's avatar flair"); + assert.ok(count('.group-members tr') > 0, "it lists group members"); }); click(".nav-pills li a[title='Activity']"); andThen(() => { - ok(count('.user-stream .item') > 0, "it lists stream items"); + assert.ok(count('.user-stream .item') > 0, "it lists stream items"); }); click(".group-activity-nav li a[href='/groups/discourse/activity/topics']"); andThen(() => { - ok(count('.user-stream .item') > 0, "it lists stream items"); + assert.ok(count('.user-stream .item') > 0, "it lists stream items"); }); click(".group-activity-nav li a[href='/groups/discourse/activity/mentions']"); andThen(() => { - ok(count('.user-stream .item') > 0, "it lists stream items"); + assert.ok(count('.user-stream .item') > 0, "it lists stream items"); }); andThen(() => { - equal( + assert.equal( find(".group-activity li a[href='/groups/discourse/activity/messages']").length, 0, 'it should not show messages tab if user is not a group user or admin' ); - ok(find(".nav-pills li a[title='Edit Group']").length === 0, 'it should not show messages tab if user is not admin'); - ok(find(".nav-pills li a[title='Logs']").length === 0, 'it should not show Logs tab if user is not admin'); - ok(count('.user-stream .item') > 0, "it lists stream items"); + assert.ok(find(".nav-pills li a[title='Edit Group']").length === 0, 'it should not show messages tab if user is not admin'); + assert.ok(find(".nav-pills li a[title='Logs']").length === 0, 'it should not show Logs tab if user is not admin'); + assert.ok(count('.user-stream .item') > 0, "it lists stream items"); }); }); -test("Admin Viewing Group", () => { +QUnit.test("Admin Viewing Group", assert => { logIn(); Discourse.reset(); visit("/groups/discourse"); andThen(() => { - ok(find(".nav-pills li a[title='Edit Group']").length === 1, 'it should show edit group tab if user is admin'); - ok(find(".nav-pills li a[title='Logs']").length === 1, 'it should show Logs tab if user is admin'); + assert.ok(find(".nav-pills li a[title='Edit Group']").length === 1, 'it should show edit group tab if user is admin'); + assert.ok(find(".nav-pills li a[title='Logs']").length === 1, 'it should show Logs tab if user is admin'); - equal(find('.group-info-name').text(), 'Awesome Team', 'it should display the group name'); + assert.equal(find('.group-info-name').text(), 'Awesome Team', 'it should display the group name'); }); click(".nav-pills li a[title='Activity']"); andThen(() => { - equal( + assert.equal( find(".group-activity li a[href='/groups/discourse/activity/messages']").length, 1, 'it should show messages tab if user is admin' ); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/invite-accept-test.js.es6 b/test/javascripts/acceptance/invite-accept-test.js.es6 index f89d5329bc0..697948e69de 100644 --- a/test/javascripts/acceptance/invite-accept-test.js.es6 +++ b/test/javascripts/acceptance/invite-accept-test.js.es6 @@ -7,7 +7,7 @@ acceptance("Invite Accept", { } }); -test("Invite Acceptance Page", () => { +QUnit.test("Invite Acceptance Page", assert => { PreloadStore.store('invite_info', { invited_by: {"id":123,"username":"neil","avatar_template":"/user_avatar/localhost/neil/{size}/25_1.png","name":"Neil Lalonde","title":"team"}, email: "invited@asdf.com", @@ -16,35 +16,35 @@ test("Invite Acceptance Page", () => { visit("/invites/myvalidinvitetoken"); andThen(() => { - ok(exists("#new-account-username"), "shows the username input"); - equal(find("#new-account-username").val(), "invited", "username is prefilled"); - ok(exists("#new-account-name"), "shows the name input"); - ok(exists("#new-account-password"), "shows the password input"); - ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because name is not filled'); + assert.ok(exists("#new-account-username"), "shows the username input"); + assert.equal(find("#new-account-username").val(), "invited", "username is prefilled"); + assert.ok(exists("#new-account-name"), "shows the name input"); + assert.ok(exists("#new-account-password"), "shows the password input"); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because name is not filled'); }); fillIn("#new-account-name", 'John Doe'); andThen(() => { - not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled'); + assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled'); }); fillIn("#new-account-username", 'a'); andThen(() => { - ok(exists(".username-input .bad"), "username is not valid"); - ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); + assert.ok(exists(".username-input .bad"), "username is not valid"); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); }); fillIn("#new-account-password", 'aaa'); andThen(() => { - ok(exists(".password-input .bad"), "password is not valid"); - ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); + assert.ok(exists(".password-input .bad"), "password is not valid"); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); }); fillIn("#new-account-username", 'validname'); fillIn("#new-account-password", 'secur3ty4Y0uAndMe'); andThen(() => { - ok(exists(".username-input .good"), "username is valid"); - ok(exists(".password-input .good"), "password is valid"); - not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled'); + assert.ok(exists(".username-input .good"), "username is valid"); + assert.ok(exists(".password-input .good"), "password is valid"); + assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled'); }); }); diff --git a/test/javascripts/acceptance/invite-show-user-fields-test.js.es6 b/test/javascripts/acceptance/invite-show-user-fields-test.js.es6 index bf4893a0e5c..823a5113ce4 100644 --- a/test/javascripts/acceptance/invite-show-user-fields-test.js.es6 +++ b/test/javascripts/acceptance/invite-show-user-fields-test.js.es6 @@ -8,12 +8,12 @@ acceptance("Accept Invite - User Fields", { } }); -test("accept invite with user fields", () => { +QUnit.test("accept invite with user fields", assert => { visit("/invites/myvalidinvitetoken"); andThen(() => { - ok(exists(".invites-show"), "shows the accept invite page"); - ok(exists('.user-field'), "it has at least one user field"); - ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); + assert.ok(exists(".invites-show"), "shows the accept invite page"); + assert.ok(exists('.user-field'), "it has at least one user field"); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled'); }); fillIn("#new-account-name", 'John Doe'); @@ -21,24 +21,24 @@ test("accept invite with user fields", () => { fillIn("#new-account-password", 'secur3ty4Y0uAndMe'); andThen(() => { - ok(exists(".username-input .good"), "username is valid"); - ok(exists('.invites-show .btn-primary:disabled'), 'submit is still disabled due to lack of user fields'); + assert.ok(exists(".username-input .good"), "username is valid"); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is still disabled due to lack of user fields'); }); fillIn(".user-field input[type=text]:first", "Barky"); andThen(() => { - ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because field is not checked'); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because field is not checked'); }); click(".user-field input[type=checkbox]"); andThen(() => { - not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled because field is checked'); + assert.not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled because field is checked'); }); click(".user-field input[type=checkbox]"); andThen(() => { - ok(exists('.invites-show .btn-primary:disabled'), 'unclicking the checkbox disables the submit'); + assert.ok(exists('.invites-show .btn-primary:disabled'), 'unclicking the checkbox disables the submit'); }); }); diff --git a/test/javascripts/acceptance/login-required-test.js.es6 b/test/javascripts/acceptance/login-required-test.js.es6 index 4bbec697a41..6153b12f22a 100644 --- a/test/javascripts/acceptance/login-required-test.js.es6 +++ b/test/javascripts/acceptance/login-required-test.js.es6 @@ -6,24 +6,24 @@ acceptance("Login Required", { } }); -test("redirect", () => { +QUnit.test("redirect", assert => { visit('/latest'); andThen(() => { - equal(currentPath(), "login", "it redirects them to login"); + assert.equal(currentPath(), "login", "it redirects them to login"); }); click('#site-logo'); andThen(() => { - equal(currentPath(), "login", "clicking the logo keeps them on login"); + assert.equal(currentPath(), "login", "clicking the logo keeps them on login"); }); click('header .login-button'); andThen(() => { - ok(exists('.login-modal'), "they can still access the login modal"); + assert.ok(exists('.login-modal'), "they can still access the login modal"); }); click('.modal-header .close'); andThen(() => { - ok(invisible('.login-modal'), "it closes the login modal"); + assert.ok(invisible('.login-modal'), "it closes the login modal"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/mobile-discovery-test.js.es6 b/test/javascripts/acceptance/mobile-discovery-test.js.es6 index 4d0198bffe7..564c5b4ec1f 100644 --- a/test/javascripts/acceptance/mobile-discovery-test.js.es6 +++ b/test/javascripts/acceptance/mobile-discovery-test.js.es6 @@ -1,15 +1,15 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Topic Discovery - Mobile", { mobileView: true }); -test("Visit Discovery Pages", () => { +QUnit.test("Visit Discovery Pages", assert => { visit("/"); andThen(() => { - ok(exists(".topic-list"), "The list of topics was rendered"); - ok(exists('.topic-list .topic-list-item'), "has topics"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists('.topic-list .topic-list-item'), "has topics"); }); visit("/categories"); andThen(() => { - ok(exists('.category'), "has a list of categories"); + assert.ok(exists('.category'), "has a list of categories"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/mobile-sign-in-test.js.es6 b/test/javascripts/acceptance/mobile-sign-in-test.js.es6 index 80831091317..34c03ec7d83 100644 --- a/test/javascripts/acceptance/mobile-sign-in-test.js.es6 +++ b/test/javascripts/acceptance/mobile-sign-in-test.js.es6 @@ -2,10 +2,10 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Signing In - Mobile", { mobileView: true }); -test("sign in", () => { +QUnit.test("sign in", assert => { visit("/"); click("header .login-button"); andThen(() => { - ok(exists('#login-form'), "it shows the login modal"); + assert.ok(exists('#login-form'), "it shows the login modal"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/mobile-users-test.js.es6 b/test/javascripts/acceptance/mobile-users-test.js.es6 index 8cc2cb9da1b..70d5f2a0c52 100644 --- a/test/javascripts/acceptance/mobile-users-test.js.es6 +++ b/test/javascripts/acceptance/mobile-users-test.js.es6 @@ -2,9 +2,9 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User Directory - Mobile", { mobileView: true }); -test("Visit Page", () => { +QUnit.test("Visit Page", assert => { visit("/users"); andThen(() => { - ok(exists('.directory .user'), "has a list of users"); + assert.ok(exists('.directory .user'), "has a list of users"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/modal-test.js.es6 b/test/javascripts/acceptance/modal-test.js.es6 index e3f0986f01b..1a570f222d7 100644 --- a/test/javascripts/acceptance/modal-test.js.es6 +++ b/test/javascripts/acceptance/modal-test.js.es6 @@ -1,30 +1,30 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Modal"); -test("modal", () => { +QUnit.test("modal", assert => { visit('/'); andThen(() => { - ok(find('#discourse-modal:visible').length === 0, 'there is no modal at first'); + assert.ok(find('#discourse-modal:visible').length === 0, 'there is no modal at first'); }); click('.login-button'); andThen(() => { - ok(find('#discourse-modal:visible').length === 1, 'modal should appear'); + assert.ok(find('#discourse-modal:visible').length === 1, 'modal should appear'); }); click('.modal-outer-container'); andThen(() => { - ok(find('#discourse-modal:visible').length === 0, 'modal should disappear when you click outside'); + assert.ok(find('#discourse-modal:visible').length === 0, 'modal should disappear when you click outside'); }); click('.login-button'); andThen(() => { - ok(find('#discourse-modal:visible').length === 1, 'modal should reappear'); + assert.ok(find('#discourse-modal:visible').length === 1, 'modal should reappear'); }); keyEvent('#main-outlet', 'keydown', 27); andThen(() => { - ok(find('#discourse-modal:visible').length === 0, 'ESC should close the modal'); + assert.ok(find('#discourse-modal:visible').length === 0, 'ESC should close the modal'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/password-reset-test.js.es6 b/test/javascripts/acceptance/password-reset-test.js.es6 index c8eaf488a2d..4706b88c29b 100644 --- a/test/javascripts/acceptance/password-reset-test.js.es6 +++ b/test/javascripts/acceptance/password-reset-test.js.es6 @@ -3,7 +3,7 @@ import PreloadStore from 'preload-store'; import { parsePostData } from "helpers/create-pretender"; acceptance("Password Reset", { - setup() { + beforeEach() { const response = (object) => { return [ 200, @@ -27,36 +27,35 @@ acceptance("Password Reset", { } }); -test("Password Reset Page", () => { +QUnit.test("Password Reset Page", assert => { PreloadStore.store('password_reset', {is_developer: false}); visit("/u/password-reset/myvalidtoken"); andThen(() => { - ok(exists(".password-reset input"), "shows the input"); + assert.ok(exists(".password-reset input"), "shows the input"); }); fillIn('.password-reset input', 'perf3ctly5ecur3'); andThen(() => { - ok(exists(".password-reset .tip.good"), "input looks good"); + assert.ok(exists(".password-reset .tip.good"), "input looks good"); }); fillIn('.password-reset input', '123'); andThen(() => { - ok(exists(".password-reset .tip.bad"), "input is not valid"); - ok(find(".password-reset .tip.bad").html().indexOf(I18n.t('user.password.too_short')) > -1, "password too short"); + assert.ok(exists(".password-reset .tip.bad"), "input is not valid"); + assert.ok(find(".password-reset .tip.bad").html().indexOf(I18n.t('user.password.too_short')) > -1, "password too short"); }); fillIn('.password-reset input', 'jonesyAlienSlayer'); click('.password-reset form button'); andThen(() => { - ok(exists(".password-reset .tip.bad"), "input is not valid"); - ok(find(".password-reset .tip.bad").html().indexOf("is the name of your cat") > -1, "server validation error message shows"); + assert.ok(exists(".password-reset .tip.bad"), "input is not valid"); + assert.ok(find(".password-reset .tip.bad").html().indexOf("is the name of your cat") > -1, "server validation error message shows"); }); fillIn('.password-reset input', 'perf3ctly5ecur3'); click('.password-reset form button'); andThen(() => { - ok(!exists(".password-reset form"), "form is gone"); + assert.ok(!exists(".password-reset form"), "form is gone"); }); -}); - +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 index 60a85e3cc77..b7a371d1e32 100644 --- a/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 @@ -3,7 +3,7 @@ import { extraConnectorClass } from 'discourse/lib/plugin-connectors'; const PREFIX = "javascripts/single-test/connectors"; acceptance("Plugin Outlet - Connector Class", { - setup() { + beforeEach() { extraConnectorClass('user-profile-primary/hello', { actions: { sayHello() { @@ -28,13 +28,13 @@ acceptance("Plugin Outlet - Connector Class", { ); }, - teardown() { + afterEach() { delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`]; delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`]; } }); -test("Renders a template into the outlet", assert => { +QUnit.test("Renders a template into the outlet", assert => { visit("/u/eviltrout"); andThen(() => { assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names'); @@ -44,4 +44,4 @@ test("Renders a template into the outlet", assert => { andThen(() => { assert.equal(find('.hello-result').text(), 'hello!', 'actions delegate properly'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 index b74b46395be..3f4722d7576 100644 --- a/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 @@ -5,20 +5,20 @@ const HELLO = 'javascripts/multi-test/connectors/user-profile-primary/hello'; const GOODBYE = 'javascripts/multi-test/connectors/user-profile-primary/goodbye'; acceptance("Plugin Outlet - Multi Template", { - setup() { + beforeEach() { clearCache(); Ember.TEMPLATES[HELLO] = Ember.HTMLBars.compile(`Hello`); Ember.TEMPLATES[GOODBYE] = Ember.HTMLBars.compile(`Goodbye`); }, - teardown() { + afterEach() { delete Ember.TEMPLATES[HELLO]; delete Ember.TEMPLATES[GOODBYE]; clearCache(); } }); -test("Renders a template into the outlet", assert => { +QUnit.test("Renders a template into the outlet", assert => { visit("/u/eviltrout"); andThen(() => { assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names'); @@ -26,4 +26,4 @@ test("Renders a template into the outlet", assert => { assert.equal(find('.hello-span').text(), 'Hello', 'it renders into the outlet'); assert.equal(find('.bye-span').text(), 'Goodbye', 'it renders into the outlet'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 index 63a05b36296..48ae7ba07c2 100644 --- a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 @@ -2,21 +2,21 @@ import { acceptance } from "helpers/qunit-helpers"; const CONNECTOR = 'javascripts/single-test/connectors/user-profile-primary/hello'; acceptance("Plugin Outlet - Single Template", { - setup() { + beforeEach() { Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile( `{{model.username}}` ); }, - teardown() { + afterEach() { delete Ember.TEMPLATES[CONNECTOR]; } }); -test("Renders a template into the outlet", assert => { +QUnit.test("Renders a template into the outlet", assert => { visit("/u/eviltrout"); andThen(() => { assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names'); assert.equal(find('.hello-username').text(), 'eviltrout', 'it renders into the outlet'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/preferences-test.js.es6 b/test/javascripts/acceptance/preferences-test.js.es6 index ccd2aff7b41..e4607f5bcf1 100644 --- a/test/javascripts/acceptance/preferences-test.js.es6 +++ b/test/javascripts/acceptance/preferences-test.js.es6 @@ -1,20 +1,20 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User Preferences", { loggedIn: true }); -test("update some fields", () => { +QUnit.test("update some fields", assert => { visit("/u/eviltrout/preferences"); andThen(() => { - ok($('body.user-preferences-page').length, "has the body class"); - equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab"); - ok(exists('.user-preferences'), 'it shows the preferences'); + assert.ok($('body.user-preferences-page').length, "has the body class"); + assert.equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab"); + assert.ok(exists('.user-preferences'), 'it shows the preferences'); }); const savePreferences = () => { click('.save-user'); - ok(!exists('.saved-user'), "it hasn't been saved yet"); + assert.ok(!exists('.saved-user'), "it hasn't been saved yet"); andThen(() => { - ok(exists('.saved-user'), 'it displays the saved message'); + assert.ok(exists('.saved-user'), 'it displays the saved message'); }); }; @@ -37,39 +37,39 @@ test("update some fields", () => { fillIn('.category-controls .category-selector', 'faq'); savePreferences(); - ok(!exists('.preferences-nav .nav-tags a'), "tags tab isn't there when tags are disabled"); + assert.ok(!exists('.preferences-nav .nav-tags a'), "tags tab isn't there when tags are disabled"); // Error: Unhandled request in test environment: /themes/assets/10d71596-7e4e-4dc0-b368-faa3b6f1ce6d?_=1493833562388 (GET) // click(".preferences-nav .nav-interface a"); // click('.control-group.other input[type=checkbox]:first'); // savePreferences(); - ok(!exists('.preferences-nav .nav-apps a'), "apps tab isn't there when you have no authorized apps"); + assert.ok(!exists('.preferences-nav .nav-apps a'), "apps tab isn't there when you have no authorized apps"); }); -test("username", () => { +QUnit.test("username", assert => { visit("/u/eviltrout/preferences/username"); andThen(() => { - ok(exists("#change_username"), "it has the input element"); + assert.ok(exists("#change_username"), "it has the input element"); }); }); -test("about me", () => { +QUnit.test("about me", assert => { visit("/u/eviltrout/preferences/about-me"); andThen(() => { - ok(exists(".raw-bio"), "it has the input element"); + assert.ok(exists(".raw-bio"), "it has the input element"); }); }); -test("email", () => { +QUnit.test("email", assert => { visit("/u/eviltrout/preferences/email"); andThen(() => { - ok(exists("#change-email"), "it has the input element"); + assert.ok(exists("#change-email"), "it has the input element"); }); fillIn("#change-email", 'invalidemail'); andThen(() => { - equal(find('.tip.bad').text().trim(), I18n.t('user.email.invalid'), 'it should display invalid email tip'); + assert.equal(find('.tip.bad').text().trim(), I18n.t('user.email.invalid'), 'it should display invalid email tip'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/raw-plugin-outlet-test.js.es6 b/test/javascripts/acceptance/raw-plugin-outlet-test.js.es6 index e21de0a31ec..5303d53cfe2 100644 --- a/test/javascripts/acceptance/raw-plugin-outlet-test.js.es6 +++ b/test/javascripts/acceptance/raw-plugin-outlet-test.js.es6 @@ -2,21 +2,21 @@ import { acceptance } from "helpers/qunit-helpers"; const CONNECTOR = 'javascripts/raw-test/connectors/topic-list-before-status/lala'; acceptance("Raw Plugin Outlet", { - setup() { + beforeEach() { Discourse.RAW_TEMPLATES[CONNECTOR] = Handlebars.compile( `{{context.topic.id}}` ); }, - teardown() { + afterEach() { delete Discourse.RAW_TEMPLATES[CONNECTOR]; } }); -test("Renders the raw plugin outlet", assert => { +QUnit.test("Renders the raw plugin outlet", assert => { visit("/"); andThen(() => { assert.ok(find('.topic-lala').length > 0, 'it renders the outlet'); assert.equal(find('.topic-lala:eq(0)').text(), '11557', 'it has the topic id'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/search-full-test.js.es6 b/test/javascripts/acceptance/search-full-test.js.es6 index d8050d72f4c..b978f8879d5 100644 --- a/test/javascripts/acceptance/search-full-test.js.es6 +++ b/test/javascripts/acceptance/search-full-test.js.es6 @@ -1,7 +1,7 @@ import { acceptance, waitFor } from "helpers/qunit-helpers"; acceptance("Search - Full Page", { settings: {tagging_enabled: true}, - setup() { + beforeEach() { const response = (object) => { return [ 200, @@ -39,12 +39,12 @@ acceptance("Search - Full Page", { } }); -test("perform various searches", assert => { +QUnit.test("perform various searches", assert => { visit("/search"); andThen(() => { - ok($('body.search-page').length, "has body class"); - ok(exists('.search-container'), "has container class"); + assert.ok($('body.search-page').length, "has body class"); + assert.ok(exists('.search-container'), "has container class"); assert.ok(find('input.search').length > 0); assert.ok(find('.fps-topic').length === 0); }); @@ -60,7 +60,7 @@ test("perform various searches", assert => { andThen(() => assert.ok(find('.fps-topic').length === 1, 'has one post')); }); -test("open advanced search", assert => { +QUnit.test("open advanced search", assert => { visit("/search"); andThen(() => assert.ok(exists('.search .search-advanced'), 'shows advanced search panel')); @@ -95,7 +95,7 @@ test("open advanced search", assert => { // }); // }); -test("escape search term", (assert) => { +QUnit.test("escape search term", (assert) => { visit("/search"); fillIn('.search input.full-page-search', '@gmail.com'); click('.search-advanced-btn'); @@ -105,7 +105,7 @@ test("escape search term", (assert) => { }); }); -test("update username through advanced search ui", assert => { +QUnit.test("update username through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -114,7 +114,7 @@ test("update username through advanced search ui", assert => { keyEvent('.search-advanced-options .user-selector', 'keydown', 8); andThen(() => { - waitFor(() => { + waitFor(assert, () => { assert.ok(visible('.search-advanced-options .autocomplete'), '"autocomplete" popup is visible'); assert.ok(exists('.search-advanced-options .autocomplete ul li a span.username:contains("admin")'), '"autocomplete" popup has an entry for "admin"'); @@ -128,7 +128,7 @@ test("update username through advanced search ui", assert => { }); }); -test("update category through advanced search ui", assert => { +QUnit.test("update category through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -209,7 +209,7 @@ test("update category through advanced search ui", assert => { // }); // }); -test("update in:likes filter through advanced search ui", assert => { +QUnit.test("update in:likes filter through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -221,7 +221,7 @@ test("update in:likes filter through advanced search ui", assert => { }); }); -test("update in:private filter through advanced search ui", assert => { +QUnit.test("update in:private filter through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -233,7 +233,7 @@ test("update in:private filter through advanced search ui", assert => { }); }); -test("update in:seen filter through advanced search ui", assert => { +QUnit.test("update in:seen filter through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -248,7 +248,7 @@ test("update in:seen filter through advanced search ui", assert => { }); }); -test("update in filter through advanced search ui", assert => { +QUnit.test("update in filter through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -261,7 +261,7 @@ test("update in filter through advanced search ui", assert => { }); }); -test("update status through advanced search ui", assert => { +QUnit.test("update status through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -274,7 +274,7 @@ test("update status through advanced search ui", assert => { }); }); -test("update post time through advanced search ui", assert => { +QUnit.test("update post time through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -289,7 +289,7 @@ test("update post time through advanced search ui", assert => { }); }); -test("update min post count through advanced search ui", assert => { +QUnit.test("update min post count through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); @@ -301,7 +301,7 @@ test("update min post count through advanced search ui", assert => { }); }); -test("validate advanced search when initially empty", assert => { +QUnit.test("validate advanced search when initially empty", assert => { visit("/search?expanded=true"); click('.search-advanced-options .in-likes'); diff --git a/test/javascripts/acceptance/search-test.js.es6 b/test/javascripts/acceptance/search-test.js.es6 index b80552708bc..475c164137f 100644 --- a/test/javascripts/acceptance/search-test.js.es6 +++ b/test/javascripts/acceptance/search-test.js.es6 @@ -1,7 +1,7 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Search"); -test("search", (assert) => { +QUnit.test("search", (assert) => { visit("/"); click('#search-button'); @@ -25,29 +25,29 @@ test("search", (assert) => { }); }); -test("search scope checkbox", () => { +QUnit.test("search scope checkbox", assert => { visit("/c/bug"); click('#search-button'); andThen(() => { - ok(exists('.search-context input:checked'), 'scope to category checkbox is checked'); + assert.ok(exists('.search-context input:checked'), 'scope to category checkbox is checked'); }); click('#search-button'); visit("/t/internationalization-localization/280"); click('#search-button'); andThen(() => { - not(exists('.search-context input:checked'), 'scope to topic checkbox is not checked'); + assert.not(exists('.search-context input:checked'), 'scope to topic checkbox is not checked'); }); click('#search-button'); visit("/u/eviltrout"); click('#search-button'); andThen(() => { - ok(exists('.search-context input:checked'), 'scope to user checkbox is checked'); + assert.ok(exists('.search-context input:checked'), 'scope to user checkbox is checked'); }); }); -test("Search with context", assert => { +QUnit.test("Search with context", assert => { visit("/t/internationalization-localization/280/1"); click('#search-button'); @@ -72,4 +72,4 @@ test("Search with context", assert => { andThen(() => { assert.ok(!$('.search-context input[type=checkbox]').is(":checked")); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/sign-in-test.js.es6 b/test/javascripts/acceptance/sign-in-test.js.es6 index 21403770ba6..12d77228a59 100644 --- a/test/javascripts/acceptance/sign-in-test.js.es6 +++ b/test/javascripts/acceptance/sign-in-test.js.es6 @@ -1,11 +1,11 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Signing In"); -test("sign in", () => { +QUnit.test("sign in", assert => { visit("/"); click("header .login-button"); andThen(() => { - ok(exists('.login-modal'), "it shows the login modal"); + assert.ok(exists('.login-modal'), "it shows the login modal"); }); // Test invalid password first @@ -13,48 +13,48 @@ test("sign in", () => { fillIn('#login-account-password', 'incorrect'); click('.modal-footer .btn-primary'); andThen(() => { - ok(exists('#modal-alert:visible'), 'it displays the login error'); - not(exists('.modal-footer .btn-primary:disabled'), "enables the login button"); + assert.ok(exists('#modal-alert:visible'), 'it displays the login error'); + assert.not(exists('.modal-footer .btn-primary:disabled'), "enables the login button"); }); // Use the correct password fillIn('#login-account-password', 'correct'); click('.modal-footer .btn-primary'); andThen(() => { - ok(exists('.modal-footer .btn-primary:disabled'), "disables the login button"); + assert.ok(exists('.modal-footer .btn-primary:disabled'), "disables the login button"); }); }); -test("sign in - not activated", () => { +QUnit.test("sign in - not activated", assert => { visit("/"); andThen(() => { click("header .login-button"); andThen(() => { - ok(exists('.login-modal'), "it shows the login modal"); + assert.ok(exists('.login-modal'), "it shows the login modal"); }); fillIn('#login-account-name', 'eviltrout'); fillIn('#login-account-password', 'not-activated'); click('.modal-footer .btn-primary'); andThen(() => { - equal(find('.modal-body b').text(), 'eviltrout@example.com'); - ok(!exists('.modal-body small'), 'it escapes the email address'); + assert.equal(find('.modal-body b').text(), 'eviltrout@example.com'); + assert.ok(!exists('.modal-body small'), 'it escapes the email address'); }); click('.modal-footer button.resend'); andThen(() => { - equal(find('.modal-body b').text(), 'current@example.com'); - ok(!exists('.modal-body small'), 'it escapes the email address'); + assert.equal(find('.modal-body b').text(), 'current@example.com'); + assert.ok(!exists('.modal-body small'), 'it escapes the email address'); }); }); }); -test("sign in - not activated - edit email", () => { +QUnit.test("sign in - not activated - edit email", assert => { visit("/"); andThen(() => { click("header .login-button"); andThen(() => { - ok(exists('.login-modal'), "it shows the login modal"); + assert.ok(exists('.login-modal'), "it shows the login modal"); }); fillIn('#login-account-name', 'eviltrout'); @@ -62,27 +62,27 @@ test("sign in - not activated - edit email", () => { click('.modal-footer .btn-primary'); click('.modal-footer button.edit-email'); andThen(() => { - equal(find('.activate-new-email').val(), 'current@example.com'); - equal(find('.modal-footer .btn-primary:disabled').length, 1, "must change email"); + assert.equal(find('.activate-new-email').val(), 'current@example.com'); + assert.equal(find('.modal-footer .btn-primary:disabled').length, 1, "must change email"); }); fillIn('.activate-new-email', 'different@example.com'); andThen(() => { - equal(find('.modal-footer .btn-primary:disabled').length, 0); + assert.equal(find('.modal-footer .btn-primary:disabled').length, 0); }); click(".modal-footer .btn-primary"); andThen(() => { - equal(find('.modal-body b').text(), 'different@example.com'); + assert.equal(find('.modal-body b').text(), 'different@example.com'); }); }); }); -test("create account", () => { +QUnit.test("create account", assert => { visit("/"); click("header .sign-up-button"); andThen(() => { - ok(exists('.create-account'), "it shows the create account modal"); - ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first'); + assert.ok(exists('.create-account'), "it shows the create account modal"); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first'); }); fillIn('#new-account-name', 'Dr. Good Tuna'); @@ -92,18 +92,18 @@ test("create account", () => { fillIn('#new-account-email', 'good.tuna@test.com'); fillIn('#new-account-username', 'taken'); andThen(() => { - ok(exists('#username-validation.bad'), 'the username validation is bad'); - ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled'); + assert.ok(exists('#username-validation.bad'), 'the username validation is bad'); + assert.ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled'); }); fillIn('#new-account-username', 'goodtuna'); andThen(() => { - ok(exists('#username-validation.good'), 'the username validation is good'); - not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled'); + assert.ok(exists('#username-validation.good'), 'the username validation is good'); + assert.not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled'); }); click('.modal-footer .btn-primary'); andThen(() => { - ok(exists('.modal-footer .btn-primary:disabled'), "create account is disabled"); + assert.ok(exists('.modal-footer .btn-primary:disabled'), "create account is disabled"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/static-test.js.es6 b/test/javascripts/acceptance/static-test.js.es6 index 26bc4e594bc..97592dbd4a9 100644 --- a/test/javascripts/acceptance/static-test.js.es6 +++ b/test/javascripts/acceptance/static-test.js.es6 @@ -1,33 +1,33 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Static"); -test("Static Pages", () => { +QUnit.test("Static Pages", assert => { visit("/faq"); andThen(() => { - ok($('body.static-faq').length, "has the body class"); - ok(exists(".body-page"), "The content is present"); + assert.ok($('body.static-faq').length, "has the body class"); + assert.ok(exists(".body-page"), "The content is present"); }); visit("/guidelines"); andThen(() => { - ok($('body.static-guidelines').length, "has the body class"); - ok(exists(".body-page"), "The content is present"); + assert.ok($('body.static-guidelines').length, "has the body class"); + assert.ok(exists(".body-page"), "The content is present"); }); visit("/tos"); andThen(() => { - ok($('body.static-tos').length, "has the body class"); - ok(exists(".body-page"), "The content is present"); + assert.ok($('body.static-tos').length, "has the body class"); + assert.ok(exists(".body-page"), "The content is present"); }); visit("/privacy"); andThen(() => { - ok($('body.static-privacy').length, "has the body class"); - ok(exists(".body-page"), "The content is present"); + assert.ok($('body.static-privacy').length, "has the body class"); + assert.ok(exists(".body-page"), "The content is present"); }); visit("/login"); andThen(() => { - equal(currentPath(), "discovery.latest", "it redirects them to latest unless `login_required`"); + assert.equal(currentPath(), "discovery.latest", "it redirects them to latest unless `login_required`"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/tag-hashtag-test.js.es6 b/test/javascripts/acceptance/tag-hashtag-test.js.es6 index e20c0afade6..559b9ff9269 100644 --- a/test/javascripts/acceptance/tag-hashtag-test.js.es6 +++ b/test/javascripts/acceptance/tag-hashtag-test.js.es6 @@ -3,7 +3,7 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Tag Hashtag", { loggedIn: true, settings: { tagging_enabled: true }, - setup() { + beforeEach() { const response = (object) => { return [ 200, @@ -26,18 +26,18 @@ acceptance("Tag Hashtag", { } }); -test("tag is cooked properly", () => { +QUnit.test("tag is cooked properly", assert => { visit("/t/internationalization-localization/280"); click('#topic-footer-buttons .btn.create'); fillIn('.d-editor-input', "this is a tag hashtag #monkey::tag"); andThen(() => { // TODO: Test that the autocomplete shows - equal(find('.d-editor-preview:visible').html().trim(), "

this is a tag hashtag #monkey

"); + assert.equal(find('.d-editor-preview:visible').html().trim(), "

this is a tag hashtag #monkey

"); }); click('#reply-control .btn.create'); andThen(() => { - equal(find('.topic-post:last .cooked').html().trim(), "

this is a tag hashtag #monkey

"); + assert.equal(find('.topic-post:last .cooked').html().trim(), "

this is a tag hashtag #monkey

"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/tags-test.js.es6 b/test/javascripts/acceptance/tags-test.js.es6 index c24cbee8d18..ca7a745a94c 100644 --- a/test/javascripts/acceptance/tags-test.js.es6 +++ b/test/javascripts/acceptance/tags-test.js.es6 @@ -1,11 +1,11 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Tags", { loggedIn: true }); -test("list the tags", () => { +QUnit.test("list the tags", assert => { visit("/tags"); andThen(() => { - ok($('body.tags-page').length, "has the body class"); - ok(exists('.tag-eviltrout'), "shows the evil trout tag"); + assert.ok($('body.tags-page').length, "has the body class"); + assert.ok(exists('.tag-eviltrout'), "shows the evil trout tag"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/topic-anonymous-test.js.es6 b/test/javascripts/acceptance/topic-anonymous-test.js.es6 index 831968a21c3..f077e99fca3 100644 --- a/test/javascripts/acceptance/topic-anonymous-test.js.es6 +++ b/test/javascripts/acceptance/topic-anonymous-test.js.es6 @@ -1,22 +1,22 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Topic - Anonymous"); -test("Enter a Topic", () => { +QUnit.test("Enter a Topic", assert => { visit("/t/internationalization-localization/280/1"); andThen(() => { - ok(exists("#topic"), "The topic was rendered"); - ok(exists("#topic .cooked"), "The topic has cooked posts"); + assert.ok(exists("#topic"), "The topic was rendered"); + assert.ok(exists("#topic .cooked"), "The topic has cooked posts"); }); }); -test("Enter without an id", () => { +QUnit.test("Enter without an id", assert => { visit("/t/internationalization-localization"); andThen(() => { - ok(exists("#topic"), "The topic was rendered"); + assert.ok(exists("#topic"), "The topic was rendered"); }); }); -test("Enter a 404 topic", assert => { +QUnit.test("Enter a 404 topic", assert => { visit("/t/not-found/404"); andThen(() => { assert.ok(!exists("#topic"), "The topic was not rendered"); @@ -24,7 +24,7 @@ test("Enter a 404 topic", assert => { }); }); -test("Enter without access", assert => { +QUnit.test("Enter without access", assert => { visit("/t/i-dont-have-access/403"); andThen(() => { assert.ok(!exists("#topic"), "The topic was not rendered"); @@ -32,10 +32,10 @@ test("Enter without access", assert => { }); }); -test("Enter with 500 errors", assert => { +QUnit.test("Enter with 500 errors", assert => { visit("/t/throws-error/500"); andThen(() => { assert.ok(!exists("#topic"), "The topic was not rendered"); assert.ok(exists(".topic-error"), "An error message is displayed"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/topic-discovery-test.js.es6 b/test/javascripts/acceptance/topic-discovery-test.js.es6 index c0767e82829..458c3471a03 100644 --- a/test/javascripts/acceptance/topic-discovery-test.js.es6 +++ b/test/javascripts/acceptance/topic-discovery-test.js.es6 @@ -1,46 +1,46 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Topic Discovery"); -test("Visit Discovery Pages", () => { +QUnit.test("Visit Discovery Pages", assert => { visit("/"); andThen(() => { - ok($('body.navigation-topics').length, "has the default navigation"); - ok(exists(".topic-list"), "The list of topics was rendered"); - ok(exists('.topic-list .topic-list-item'), "has topics"); + assert.ok($('body.navigation-topics').length, "has the default navigation"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists('.topic-list .topic-list-item'), "has topics"); }); visit("/c/bug"); andThen(() => { - ok(exists(".topic-list"), "The list of topics was rendered"); - ok(exists('.topic-list .topic-list-item'), "has topics"); - ok(!exists('.category-list'), "doesn't render subcategories"); - ok($('body.category-bug').length, "has a custom css class for the category id on the body"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists('.topic-list .topic-list-item'), "has topics"); + assert.ok(!exists('.category-list'), "doesn't render subcategories"); + assert.ok($('body.category-bug').length, "has a custom css class for the category id on the body"); }); visit("/categories"); andThen(() => { - ok($('body.navigation-categories').length, "has the body class"); - ok($('body.category-bug').length === 0, "removes the custom category class"); - ok(exists('.category'), "has a list of categories"); - ok($('body.categories-list').length, "has a custom class to indicate categories"); + assert.ok($('body.navigation-categories').length, "has the body class"); + assert.ok($('body.category-bug').length === 0, "removes the custom category class"); + assert.ok(exists('.category'), "has a list of categories"); + assert.ok($('body.categories-list').length, "has a custom class to indicate categories"); }); visit("/top"); andThen(() => { - ok($('body.categories-list').length === 0, "removes the `categories-list` class"); - ok(exists('.topic-list .topic-list-item'), "has topics"); + assert.ok($('body.categories-list').length === 0, "removes the `categories-list` class"); + assert.ok(exists('.topic-list .topic-list-item'), "has topics"); }); visit("/c/feature"); andThen(() => { - ok(exists(".topic-list"), "The list of topics was rendered"); - ok(exists(".category-boxes"), "The list of subcategories were rendered with box style"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists(".category-boxes"), "The list of subcategories were rendered with box style"); }); visit("/c/dev"); andThen(() => { - ok(exists(".topic-list"), "The list of topics was rendered"); - ok(exists(".category-boxes-with-topics"), "The list of subcategories were rendered with box-with-featured-topics style"); - ok(exists(".category-boxes-with-topics .featured-topics"), "The featured topics are there too"); + assert.ok(exists(".topic-list"), "The list of topics was rendered"); + assert.ok(exists(".category-boxes-with-topics"), "The list of subcategories were rendered with box-with-featured-topics style"); + assert.ok(exists(".category-boxes-with-topics .featured-topics"), "The featured topics are there too"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/topic-notifications-button-test.js.es6 b/test/javascripts/acceptance/topic-notifications-button-test.js.es6 index 4689b86bb09..bb1c314a1c0 100644 --- a/test/javascripts/acceptance/topic-notifications-button-test.js.es6 +++ b/test/javascripts/acceptance/topic-notifications-button-test.js.es6 @@ -1,7 +1,7 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Topic Notifications button", { loggedIn: true, - setup() { + beforeEach() { const response = object => { return [ 200, @@ -16,13 +16,13 @@ acceptance("Topic Notifications button", { } }); -test("Updating topic notification level", () => { +QUnit.test("Updating topic notification level", assert => { visit("/t/internationalization-localization/280"); const notificationOptions = "#topic-footer-buttons .notification-options"; andThen(() => { - ok( + assert.ok( exists(`${notificationOptions} .tracking`), "it should display the notification options button in the topic's footer" ); @@ -32,7 +32,7 @@ test("Updating topic notification level", () => { click(`${notificationOptions} .dropdown-menu .watching`); andThen(() => { - ok( + assert.ok( exists(`${notificationOptions} .watching`), "it should display the right notification level" ); @@ -44,4 +44,4 @@ test("Updating topic notification level", () => { // 'it should display the right notification level in topic timeline' // ); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6 index a3b85778ce6..08b54bfd519 100644 --- a/test/javascripts/acceptance/topic-test.js.es6 +++ b/test/javascripts/acceptance/topic-test.js.es6 @@ -1,20 +1,20 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Topic", { loggedIn: true }); -test("Share Popup", () => { +QUnit.test("Share Popup", assert => { visit("/t/internationalization-localization/280"); andThen(() => { - ok(!exists('#share-link.visible'), 'it is not visible'); + assert.ok(!exists('#share-link.visible'), 'it is not visible'); }); click("button[data-share-url]"); andThen(() => { - ok(exists('#share-link.visible'), 'it shows the popup'); + assert.ok(exists('#share-link.visible'), 'it shows the popup'); }); click('#share-link .close-share'); andThen(() => { - ok(!exists('#share-link.visible'), 'it closes the popup'); + assert.ok(!exists('#share-link.visible'), 'it closes the popup'); }); // TODO tgxworld This fails on Travis but we need to push the security fix out @@ -30,23 +30,23 @@ test("Share Popup", () => { // }); }); -test("Showing and hiding the edit controls", () => { +QUnit.test("Showing and hiding the edit controls", assert => { visit("/t/internationalization-localization/280"); click('#topic-title .fa-pencil'); andThen(() => { - ok(exists('#edit-title'), 'it shows the editing controls'); + assert.ok(exists('#edit-title'), 'it shows the editing controls'); }); fillIn('#edit-title', 'this is the new title'); click('#topic-title .cancel-edit'); andThen(() => { - ok(!exists('#edit-title'), 'it hides the editing controls'); + assert.ok(!exists('#edit-title'), 'it hides the editing controls'); }); }); -test("Updating the topic title and category", () => { +QUnit.test("Updating the topic title and category", assert => { visit("/t/internationalization-localization/280"); click('#topic-title .fa-pencil'); @@ -56,12 +56,12 @@ test("Updating the topic title and category", () => { click('#topic-title .submit-edit'); andThen(() => { - equal(find('#topic-title .badge-category').text(), 'faq', 'it displays the new category'); - equal(find('.fancy-title').text().trim(), 'this is the new title', 'it displays the new title'); + assert.equal(find('#topic-title .badge-category').text(), 'faq', 'it displays the new category'); + assert.equal(find('.fancy-title').text().trim(), 'this is the new title', 'it displays the new title'); }); }); -test("Marking a topic as wiki", () => { +QUnit.test("Marking a topic as wiki", assert => { server.put('/posts/398/wiki', () => { // eslint-disable-line no-undef return [ 200, @@ -73,7 +73,7 @@ test("Marking a topic as wiki", () => { visit("/t/internationalization-localization/280"); andThen(() => { - ok(find('a.wiki').length === 0, 'it does not show the wiki icon'); + assert.ok(find('a.wiki').length === 0, 'it does not show the wiki icon'); }); click('.topic-post:eq(0) button.show-more-actions'); @@ -81,39 +81,39 @@ test("Marking a topic as wiki", () => { click('.btn.wiki'); andThen(() => { - ok(find('a.wiki').length === 1, 'it shows the wiki icon'); + assert.ok(find('a.wiki').length === 1, 'it shows the wiki icon'); }); }); -test("Reply as new topic", () => { +QUnit.test("Reply as new topic", assert => { visit("/t/internationalization-localization/280"); click("button.share:eq(0)"); click(".reply-as-new-topic a"); andThen(() => { - ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); - equal( + assert.equal( find('.d-editor-input').val().trim(), `Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):`, "it fills composer with the ring string" ); - equal( + assert.equal( find('.category-combobox').select2('data').text, "feature", "it fills category selector with the right category" ); }); }); -test("Reply as new message", () => { +QUnit.test("Reply as new message", assert => { visit("/t/pm-for-testing/12"); click("button.share:eq(0)"); click(".reply-as-new-topic a"); andThen(() => { - ok(exists('.d-editor-input'), 'the composer input is visible'); + assert.ok(exists('.d-editor-input'), 'the composer input is visible'); - equal( + assert.equal( find('.d-editor-input').val().trim(), `Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):`, "it fills composer with the ring string" @@ -121,24 +121,24 @@ test("Reply as new message", () => { const targets = find('.item span', '.composer-fields'); - equal( + assert.equal( $(targets[0]).text(), "someguy", "it fills up the composer with the right user to start the PM to" ); - equal( + assert.equal( $(targets[1]).text(), "test", "it fills up the composer with the right user to start the PM to" ); - equal( + assert.equal( $(targets[2]).text(), "Group", "it fills up the composer with the right group to start the PM to" ); }); }); -test("Updating the topic title with emojis", () => { +QUnit.test("Updating the topic title with emojis", assert => { visit("/t/internationalization-localization/280"); click('#topic-title .fa-pencil'); @@ -147,6 +147,6 @@ test("Updating the topic title with emojis", () => { click('#topic-title .submit-edit'); andThen(() => { - equal(find('.fancy-title').html().trim(), 'emojis title \"bike\" \"blonde_woman:t6\"', 'it displays the new title with emojis'); + assert.equal(find('.fancy-title').html().trim(), 'emojis title \"bike\" \"blonde_woman:t6\"', 'it displays the new title with emojis'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/unknown-test.js.es6 b/test/javascripts/acceptance/unknown-test.js.es6 index 148d8d2eefd..541df10e1f0 100644 --- a/test/javascripts/acceptance/unknown-test.js.es6 +++ b/test/javascripts/acceptance/unknown-test.js.es6 @@ -1,10 +1,10 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Unknown"); -test("Unknown URL", () => { - expect(1); +QUnit.test("Unknown URL", assert => { + assert.expect(1); visit("/url-that-doesn't-exist"); andThen(() => { - ok(exists(".page-not-found"), "The not found content is present"); + assert.ok(exists(".page-not-found"), "The not found content is present"); }); }); diff --git a/test/javascripts/acceptance/user-anonymous-test.js.es6 b/test/javascripts/acceptance/user-anonymous-test.js.es6 index ae9b7c149f4..91f3c62c758 100644 --- a/test/javascripts/acceptance/user-anonymous-test.js.es6 +++ b/test/javascripts/acceptance/user-anonymous-test.js.es6 @@ -1,54 +1,54 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User Anonymous"); -export function hasStream() { +function hasStream(assert) { andThen(() => { - ok(exists('.user-main .about'), 'it has the about section'); - ok(count('.user-stream .item') > 0, 'it has stream items'); + assert.ok(exists('.user-main .about'), 'it has the about section'); + assert.ok(count('.user-stream .item') > 0, 'it has stream items'); }); } -function hasTopicList() { +function hasTopicList(assert) { andThen(() => { - equal(count('.user-stream .item'), 0, "has no stream displayed"); - ok(count('.topic-list tr') > 0, 'it has a topic list'); + assert.equal(count('.user-stream .item'), 0, "has no stream displayed"); + assert.ok(count('.topic-list tr') > 0, 'it has a topic list'); }); } -test("Root URL", () => { +QUnit.test("Root URL", assert => { visit("/u/eviltrout"); andThen(() => { - ok($('body.user-summary-page').length, "has the body class"); - equal(currentPath(), 'user.summary', "it defaults to summary"); + assert.ok($('body.user-summary-page').length, "has the body class"); + assert.equal(currentPath(), 'user.summary', "it defaults to summary"); }); }); -test("Filters", () => { +QUnit.test("Filters", assert => { visit("/u/eviltrout/activity"); andThen(() => { - ok($('body.user-activity-page').length, "has the body class"); + assert.ok($('body.user-activity-page').length, "has the body class"); }); - hasStream(); + hasStream(assert); visit("/u/eviltrout/activity/topics"); - hasTopicList(); + hasTopicList(assert); visit("/u/eviltrout/activity/replies"); - hasStream(); + hasStream(assert); }); -test("Badges", () => { +QUnit.test("Badges", assert => { visit("/u/eviltrout/badges"); andThen(() => { - ok($('body.user-badges-page').length, "has the body class"); - ok(exists(".user-badges-list .badge-card"), "shows a badge"); + assert.ok($('body.user-badges-page').length, "has the body class"); + assert.ok(exists(".user-badges-list .badge-card"), "shows a badge"); }); }); -test("Restricted Routes", () => { +QUnit.test("Restricted Routes", assert => { visit("/u/eviltrout/preferences"); andThen(() => { - equal(currentURL(), '/u/eviltrout/activity', "it redirects from preferences"); + assert.equal(currentURL(), '/u/eviltrout/activity', "it redirects from preferences"); }); }); diff --git a/test/javascripts/acceptance/user-card-test.js.es6 b/test/javascripts/acceptance/user-card-test.js.es6 index 4a4d7288bfd..e19d96836b7 100644 --- a/test/javascripts/acceptance/user-card-test.js.es6 +++ b/test/javascripts/acceptance/user-card-test.js.es6 @@ -1,14 +1,14 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User Card"); -test("card", () => { +QUnit.test("card", assert => { visit('/'); - ok(invisible('#user-card'), 'user card is invisible by default'); + assert.ok(invisible('#user-card'), 'user card is invisible by default'); click('a[data-user-card=eviltrout]:first'); andThen(() => { - ok(visible('#user-card'), 'card should appear'); + assert.ok(visible('#user-card'), 'card should appear'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/user-test.js.es6 b/test/javascripts/acceptance/user-test.js.es6 index 84269cbe08c..22759a7ee7e 100644 --- a/test/javascripts/acceptance/user-test.js.es6 +++ b/test/javascripts/acceptance/user-test.js.es6 @@ -2,32 +2,32 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User", {loggedIn: true}); -test("Invites", () => { +QUnit.test("Invites", assert => { visit("/u/eviltrout/invited/pending"); andThen(() => { - ok($('body.user-invites-page').length, "has the body class"); + assert.ok($('body.user-invites-page').length, "has the body class"); }); }); -test("Messages", () => { +QUnit.test("Messages", assert => { visit("/u/eviltrout/messages"); andThen(() => { - ok($('body.user-messages-page').length, "has the body class"); + assert.ok($('body.user-messages-page').length, "has the body class"); }); }); -test("Notifications", () => { +QUnit.test("Notifications", assert => { visit("/u/eviltrout/notifications"); andThen(() => { - ok($('body.user-notifications-page').length, "has the body class"); + assert.ok($('body.user-notifications-page').length, "has the body class"); }); }); -test("Root URL - Viewing Self", () => { +QUnit.test("Root URL - Viewing Self", assert => { visit("/u/eviltrout"); andThen(() => { - ok($('body.user-activity-page').length, "has the body class"); - equal(currentPath(), 'user.userActivity.index', "it defaults to activity"); - ok(exists('.container.viewing-self'), "has the viewing-self class"); + assert.ok($('body.user-activity-page').length, "has the body class"); + assert.equal(currentPath(), 'user.userActivity.index', "it defaults to activity"); + assert.ok(exists('.container.viewing-self'), "has the viewing-self class"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/acceptance/users-test.js.es6 b/test/javascripts/acceptance/users-test.js.es6 index eb89741d252..427225a774e 100644 --- a/test/javascripts/acceptance/users-test.js.es6 +++ b/test/javascripts/acceptance/users-test.js.es6 @@ -1,17 +1,17 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("User Directory"); -test("Visit Page", function() { +QUnit.test("Visit Page", assert => { visit("/users"); andThen(() => { - ok($('body.users-page').length, "has the body class"); - ok(exists('.directory table tr'), "has a list of users"); + assert.ok($('body.users-page').length, "has the body class"); + assert.ok(exists('.directory table tr'), "has a list of users"); }); }); -test("Visit All Time", function() { +QUnit.test("Visit All Time", assert => { visit("/users?period=all"); andThen(() => { - ok(exists('.time-read'), "has time read column"); + assert.ok(exists('.time-read'), "has time read column"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/admin/controllers/admin-customize-themes-test.js.es6 b/test/javascripts/admin/controllers/admin-customize-themes-test.js.es6 index 2c70b5b12fc..41468970937 100644 --- a/test/javascripts/admin/controllers/admin-customize-themes-test.js.es6 +++ b/test/javascripts/admin/controllers/admin-customize-themes-test.js.es6 @@ -2,13 +2,13 @@ import { mapRoutes } from 'discourse/mapping-router'; import Theme from 'admin/models/theme'; moduleFor('controller:admin-customize-themes', { - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, needs: ['controller:adminUser'] }); -test("can list sorted themes", function() { +QUnit.test("can list sorted themes", function(assert) { const defaultTheme = Theme.create({id: 2, 'default': true, name: 'default'}); const userTheme = Theme.create({id: 3, 'user_selectable': true, name: 'name'}); @@ -23,7 +23,7 @@ test("can list sorted themes", function() { }); - deepEqual(controller.get('sortedThemes').map(t=>t.get('name')), [ + assert.deepEqual(controller.get('sortedThemes').map(t=>t.get('name')), [ defaultTheme, userTheme, strayTheme1, diff --git a/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 b/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 index f58845ecfc0..112ef64d041 100644 --- a/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 +++ b/test/javascripts/admin/controllers/admin-user-badges-test.js.es6 @@ -2,13 +2,13 @@ import Badge from 'discourse/models/badge'; import { mapRoutes } from 'discourse/mapping-router'; moduleFor('controller:admin-user-badges', { - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, needs: ['controller:adminUser'] }); -test("grantableBadges", function() { +QUnit.test("grantableBadges", function(assert) { const badgeFirst = Badge.create({id: 3, name: "A Badge", enabled: true}); const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true}); const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true}); @@ -20,6 +20,6 @@ test("grantableBadges", function() { }); - not(badgeNames.includes(badgeDisabled), "excludes disabled badges"); - deepEqual(badgeNames, sortedNames, "sorts badges by name"); + assert.not(badgeNames.includes(badgeDisabled), "excludes disabled badges"); + assert.deepEqual(badgeNames, sortedNames, "sorts badges by name"); }); diff --git a/test/javascripts/admin/models/admin-user-test.js.es6 b/test/javascripts/admin/models/admin-user-test.js.es6 index e735ec9456c..161a8be373b 100644 --- a/test/javascripts/admin/models/admin-user-test.js.es6 +++ b/test/javascripts/admin/models/admin-user-test.js.es6 @@ -1,20 +1,19 @@ -import { blank, present } from 'helpers/qunit-helpers'; import AdminUser from 'admin/models/admin-user'; import ApiKey from 'admin/models/api-key'; -module("model:admin-user"); +QUnit.module("model:admin-user"); -test('generate key', function(assert) { +QUnit.test('generate key', function(assert) { assert.expect(2); var adminUser = AdminUser.create({id: 333}); assert.ok(!adminUser.get('api_key'), 'it has no api key by default'); return adminUser.generateApiKey().then(function() { - present(adminUser.get('api_key'), 'it has an api_key now'); + assert.present(adminUser.get('api_key'), 'it has an api_key now'); }); }); -test('revoke key', function(assert) { +QUnit.test('revoke key', function(assert) { assert.expect(2); var apiKey = ApiKey.create({id: 1234, key: 'asdfasdf'}), @@ -22,6 +21,6 @@ test('revoke key', function(assert) { assert.equal(adminUser.get('api_key'), apiKey, 'it has the api key in the beginning'); return adminUser.revokeApiKey().then(function() { - blank(adminUser.get('api_key'), 'it cleared the api_key'); + assert.blank(adminUser.get('api_key'), 'it cleared the api_key'); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/admin/models/theme-test.js.es6 b/test/javascripts/admin/models/theme-test.js.es6 index 88d9d62947e..4a16c584c85 100644 --- a/test/javascripts/admin/models/theme-test.js.es6 +++ b/test/javascripts/admin/models/theme-test.js.es6 @@ -1,8 +1,8 @@ import Theme from 'admin/models/theme'; -module("model:theme"); +QUnit.module("model:theme"); -test('can add an upload correctly', function(assert) { +QUnit.test('can add an upload correctly', function(assert) { let theme = Theme.create(); assert.equal(theme.get("uploads.length"), 0, "uploads should be an empty array"); @@ -14,4 +14,4 @@ test('can add an upload correctly', function(assert) { assert.equal(fields[0].type_id, 2, 'expecting type id to be set'); assert.equal(theme.get("uploads.length"), 1, "expecting an upload"); -}); +}); \ No newline at end of file diff --git a/test/javascripts/components/ace-editor-test.js.es6 b/test/javascripts/components/ace-editor-test.js.es6 index 76aa436ff3a..4a05e6f83e2 100644 --- a/test/javascripts/components/ace-editor-test.js.es6 +++ b/test/javascripts/components/ace-editor-test.js.es6 @@ -5,7 +5,7 @@ moduleForComponent('ace-editor', {integration: true}); componentTest('css editor', { template: '{{ace-editor mode="css"}}', test(assert) { - expect(1); + assert.expect(1); assert.ok(this.$('.ace_editor').length, 'it renders the ace editor'); } }); @@ -13,7 +13,7 @@ componentTest('css editor', { componentTest('html editor', { template: '{{ace-editor mode="html" content="wat"}}', test(assert) { - expect(1); + assert.expect(1); assert.ok(this.$('.ace_editor').length, 'it renders the ace editor'); } }); diff --git a/test/javascripts/components/combo-box-test.js.es6 b/test/javascripts/components/combo-box-test.js.es6 index 39232362ffb..285d817e3a7 100644 --- a/test/javascripts/components/combo-box-test.js.es6 +++ b/test/javascripts/components/combo-box-test.js.es6 @@ -3,7 +3,7 @@ moduleForComponent('combo-box', {integration: true}); componentTest('with objects', { template: '{{combo-box content=items value=value}}', - setup() { + beforeEach() { this.set('items', [{id: 1, name: 'hello'}, {id: 2, name: 'world'}]); }, @@ -17,7 +17,7 @@ componentTest('with objects', { componentTest('with objects and valueAttribute', { template: '{{combo-box content=items valueAttribute="value"}}', - setup() { + beforeEach() { this.set('items', [{value: 0, name: 'hello'}, {value: 1, name: 'world'}]); }, @@ -30,7 +30,7 @@ componentTest('with objects and valueAttribute', { componentTest('with an array', { template: '{{combo-box content=items value=value}}', - setup() { + beforeEach() { this.set('items', ['evil', 'trout', 'hat']); }, @@ -44,7 +44,7 @@ componentTest('with an array', { componentTest('with none', { template: '{{combo-box content=items none="test.none" value=value}}', - setup() { + beforeEach() { I18n.translations[I18n.locale].js.test = {none: 'none'}; this.set('items', ['evil', 'trout', 'hat']); }, @@ -59,7 +59,7 @@ componentTest('with none', { componentTest('with Object none', { template: '{{combo-box content=items none=none value=value selected="something"}}', - setup() { + beforeEach() { this.set('none', { id: 'something', name: 'none' }); this.set('items', ['evil', 'trout', 'hat']); }, diff --git a/test/javascripts/components/d-editor-test.js.es6 b/test/javascripts/components/d-editor-test.js.es6 index cddd81828d7..99bf4616ec6 100644 --- a/test/javascripts/components/d-editor-test.js.es6 +++ b/test/javascripts/components/d-editor-test.js.es6 @@ -31,7 +31,7 @@ componentTest('preview sanitizes HTML', { componentTest('updating the value refreshes the preview', { template: '{{d-editor value=value}}', - setup() { + beforeEach() { this.set('value', 'evil trout'); }, @@ -52,7 +52,7 @@ function jumpEnd(textarea) { function testCase(title, testFunc) { componentTest(title, { template: '{{d-editor value=value}}', - setup() { + beforeEach() { this.set('value', 'hello world.'); }, test(assert) { @@ -65,7 +65,7 @@ function testCase(title, testFunc) { function composerTestCase(title, testFunc) { componentTest(title, { template: '{{d-editor value=value composerEvents=true}}', - setup() { + beforeEach() { this.set('value', 'hello world.'); }, test(assert) { @@ -269,7 +269,7 @@ testCase('link modal (link with description)', function(assert) { componentTest('advanced code', { template: '{{d-editor value=value}}', - setup() { + beforeEach() { this.siteSettings.code_formatting_style = '4-spaces-indent'; this.set('value', ` @@ -304,7 +304,7 @@ function xyz(x, y, z) { componentTest('code button', { template: '{{d-editor value=value}}', - setup() { + beforeEach() { this.siteSettings.code_formatting_style = '4-spaces-indent'; }, @@ -406,7 +406,7 @@ third line` componentTest('code fences', { template: '{{d-editor value=value}}', - setup() { + beforeEach() { this.set('value', ''); }, @@ -740,7 +740,7 @@ testCase(`doesn't jump to bottom with long text`, function(assert, textarea) { componentTest('emoji', { template: '{{d-editor value=value}}', - setup() { + beforeEach() { // Test adding a custom button withPluginApi('0.1', api => { api.onToolbarCreate(toolbar => { diff --git a/test/javascripts/components/group-membership-button-test.js.es6 b/test/javascripts/components/group-membership-button-test.js.es6 index 930b7270b4f..9f404c151b5 100644 --- a/test/javascripts/components/group-membership-button-test.js.es6 +++ b/test/javascripts/components/group-membership-button-test.js.es6 @@ -1,48 +1,48 @@ moduleFor('component:group-membership-button'); -test('canJoinGroup', function() { +QUnit.test('canJoinGroup', function(assert) { this.subject().setProperties({ model: { public: false } }); - equal(this.subject().get("canJoinGroup"), false, "non public group cannot be joined"); + assert.equal(this.subject().get("canJoinGroup"), false, "non public group cannot be joined"); this.subject().set("model.public", true); - equal(this.subject().get("canJoinGroup"), true, "public group can be joined"); + assert.equal(this.subject().get("canJoinGroup"), true, "public group can be joined"); this.subject().setProperties({ currentUser: null, model: { public: true } }); - equal(this.subject().get("canJoinGroup"), true, "can't join group when not logged in"); + assert.equal(this.subject().get("canJoinGroup"), true, "can't join group when not logged in"); }); -test('userIsGroupUser', function() { +QUnit.test('userIsGroupUser', function(assert) { this.subject().setProperties({ model: { is_group_user: true } }); - equal(this.subject().get('userIsGroupUser'), true); + assert.equal(this.subject().get('userIsGroupUser'), true); this.subject().set('model.is_group_user', false); - equal(this.subject().get('userIsGroupUser'), false); + assert.equal(this.subject().get('userIsGroupUser'), false); this.subject().setProperties({ model: { id: 1 }, groupUserIds: [1] }); - equal(this.subject().get('userIsGroupUser'), true); + assert.equal(this.subject().get('userIsGroupUser'), true); this.subject().set('groupUserIds', [3]); - equal(this.subject().get('userIsGroupUser'), false); + assert.equal(this.subject().get('userIsGroupUser'), false); this.subject().set('groupUserIds', undefined); - equal(this.subject().get('userIsGroupUser'), false); + assert.equal(this.subject().get('userIsGroupUser'), false); this.subject().setProperties({ groupUserIds: [1, 3], model: { id: 1, is_group_user: false } }); - equal(this.subject().get('userIsGroupUser'), false); + assert.equal(this.subject().get('userIsGroupUser'), false); }); diff --git a/test/javascripts/components/keyboard-shortcuts-test.js.es6 b/test/javascripts/components/keyboard-shortcuts-test.js.es6 index 745a8f3c246..642f35d5432 100644 --- a/test/javascripts/components/keyboard-shortcuts-test.js.es6 +++ b/test/javascripts/components/keyboard-shortcuts-test.js.es6 @@ -3,8 +3,8 @@ import DiscourseURL from 'discourse/lib/url'; var testMouseTrap; import KeyboardShortcuts from 'discourse/lib/keyboard-shortcuts'; -module("lib:keyboard-shortcuts", { - setup: function() { +QUnit.module("lib:keyboard-shortcuts", { + beforeEach() { var _bindings = {}; testMouseTrap = { @@ -62,7 +62,7 @@ module("lib:keyboard-shortcuts", { ].join("\n")); }, - teardown: function() { + afterEach() { $("#qunit-scratch").html(""); } }); @@ -72,11 +72,11 @@ var pathBindings = KeyboardShortcuts.PATH_BINDINGS; _.each(pathBindings, function(path, binding) { var testName = binding + " goes to " + path; - test(testName, function() { + test(testName, function(assert) { KeyboardShortcuts.bindEvents(testMouseTrap); testMouseTrap.trigger(binding); - ok(DiscourseURL.routeTo.calledWith(path)); + assert.ok(DiscourseURL.routeTo.calledWith(path)); }); }); @@ -87,10 +87,10 @@ _.each(clickBindings, function(selector, binding) { var testName = binding + " clicks on " + selector; - test(testName, function() { + test(testName, function(assert) { KeyboardShortcuts.bindEvents(testMouseTrap); $(selector).on("click", function() { - ok(true, selector + " was clicked"); + assert.ok(true, selector + " was clicked"); }); _.each(bindings, function(b) { @@ -104,9 +104,9 @@ var functionBindings = KeyboardShortcuts.FUNCTION_BINDINGS; _.each(functionBindings, function(func, binding) { var testName = binding + " calls " + func; - test(testName, function() { + test(testName, function(assert) { sandbox.stub(KeyboardShortcuts, func, function() { - ok(true, func + " is called when " + binding + " is triggered"); + assert.ok(true, func + " is called when " + binding + " is triggered"); }); KeyboardShortcuts.bindEvents(testMouseTrap); @@ -114,40 +114,40 @@ _.each(functionBindings, function(func, binding) { }); }); -test("selectDown calls _moveSelection with 1", function() { +QUnit.test("selectDown calls _moveSelection with 1", assert => { var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection'); KeyboardShortcuts.selectDown(); - ok(spy.calledWith(1), "_moveSelection is called with 1"); + assert.ok(spy.calledWith(1), "_moveSelection is called with 1"); }); -test("selectUp calls _moveSelection with -1", function() { +QUnit.test("selectUp calls _moveSelection with -1", assert => { var spy = sandbox.spy(KeyboardShortcuts, '_moveSelection'); KeyboardShortcuts.selectUp(); - ok(spy.calledWith(-1), "_moveSelection is called with -1"); + assert.ok(spy.calledWith(-1), "_moveSelection is called with -1"); }); -test("goBack calls history.back", function() { +QUnit.test("goBack calls history.back", assert => { var called = false; sandbox.stub(history, 'back', function() { called = true; }); KeyboardShortcuts.goBack(); - ok(called, "history.back is called"); + assert.ok(called, "history.back is called"); }); -test("nextSection calls _changeSection with 1", function() { +QUnit.test("nextSection calls _changeSection with 1", assert => { var spy = sandbox.spy(KeyboardShortcuts, '_changeSection'); KeyboardShortcuts.nextSection(); - ok(spy.calledWith(1), "_changeSection is called with 1"); + assert.ok(spy.calledWith(1), "_changeSection is called with 1"); }); -test("prevSection calls _changeSection with -1", function() { +QUnit.test("prevSection calls _changeSection with -1", assert => { var spy = sandbox.spy(KeyboardShortcuts, '_changeSection'); KeyboardShortcuts.prevSection(); - ok(spy.calledWith(-1), "_changeSection is called with -1"); + assert.ok(spy.calledWith(-1), "_changeSection is called with -1"); }); diff --git a/test/javascripts/components/text-field-test.js.es6 b/test/javascripts/components/text-field-test.js.es6 index 81b0660052b..e18662c2ab9 100644 --- a/test/javascripts/components/text-field-test.js.es6 +++ b/test/javascripts/components/text-field-test.js.es6 @@ -13,7 +13,7 @@ componentTest("renders correctly with no properties set", { componentTest("support a placeholder", { template: `{{text-field placeholderKey="placeholder.i18n.key"}}`, - setup() { + beforeEach() { sandbox.stub(I18n, "t").returnsArg(0); }, diff --git a/test/javascripts/components/value-list-test.js.es6 b/test/javascripts/components/value-list-test.js.es6 index 7bb9599eece..feefcbea079 100644 --- a/test/javascripts/components/value-list-test.js.es6 +++ b/test/javascripts/components/value-list-test.js.es6 @@ -30,7 +30,7 @@ componentTest('functionality', { componentTest('with string delimited values', { template: '{{value-list values=valueString}}', - setup() { + beforeEach() { this.set('valueString', "hello\nworld"); }, @@ -49,7 +49,7 @@ componentTest('with string delimited values', { componentTest('with array values', { template: '{{value-list values=valueArray inputType="array"}}', - setup() { + beforeEach() { this.set('valueArray', ['abc', 'def']); }, diff --git a/test/javascripts/controllers/admin-group-test.js.es6 b/test/javascripts/controllers/admin-group-test.js.es6 index e80e50d6f3c..c8b747fc5f9 100644 --- a/test/javascripts/controllers/admin-group-test.js.es6 +++ b/test/javascripts/controllers/admin-group-test.js.es6 @@ -1,33 +1,35 @@ -moduleFor("controller:admin-group"); +moduleFor("controller:admin-group", { + needs: ['controller:adminGroupsType'] +}); -test("disablePublicSetting", function() { +QUnit.test("disablePublicSetting", function(assert) { this.subject().setProperties({ model: { visible: false, allow_membership_requests: false } }); - equal(this.subject().get("disablePublicSetting"), true, "it should disable setting"); + assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting"); this.subject().set("model.visible", true); - equal(this.subject().get("disablePublicSetting"), false, "it should enable setting"); + assert.equal(this.subject().get("disablePublicSetting"), false, "it should enable setting"); this.subject().set("model.allow_membership_requests", true); - equal(this.subject().get("disablePublicSetting"), true, "it should disable setting"); + assert.equal(this.subject().get("disablePublicSetting"), true, "it should disable setting"); }); -test("disableMembershipRequestSetting", function() { +QUnit.test("disableMembershipRequestSetting", function(assert) { this.subject().setProperties({ model: { visible: false, public: false, canEveryoneMention: true } }); - equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting"); + assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disable setting"); this.subject().set("model.visible", true); - equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting"); + assert.equal(this.subject().get("disableMembershipRequestSetting"), false, "it should enable setting"); this.subject().set("model.public", true); - equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting"); + assert.equal(this.subject().get("disableMembershipRequestSetting"), true, "it should disalbe setting"); }); diff --git a/test/javascripts/controllers/avatar-selector-test.js.es6 b/test/javascripts/controllers/avatar-selector-test.js.es6 index 00514303f48..ce26c62163f 100644 --- a/test/javascripts/controllers/avatar-selector-test.js.es6 +++ b/test/javascripts/controllers/avatar-selector-test.js.es6 @@ -1,13 +1,13 @@ import { mapRoutes } from 'discourse/mapping-router'; moduleFor("controller:avatar-selector", "controller:avatar-selector", { - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, needs: ['controller:modal'] }); -test("avatarTemplate", function() { +QUnit.test("avatarTemplate", function(assert) { const avatarSelectorController = this.subject(); avatarSelectorController.setProperties({ @@ -17,11 +17,11 @@ test("avatarTemplate", function() { custom_avatar_upload_id: 3 }); - equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default"); + assert.equal(avatarSelectorController.get("selectedUploadId"), 1, "we are using system by default"); avatarSelectorController.set('selected', 'gravatar'); - equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set"); + assert.equal(avatarSelectorController.get("selectedUploadId"), 2, "we are using gravatar when set"); avatarSelectorController.set("selected", "custom"); - equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set"); + assert.equal(avatarSelectorController.get("selectedUploadId"), 3, "we are using custom when set"); }); diff --git a/test/javascripts/controllers/create-account-test.js.es6 b/test/javascripts/controllers/create-account-test.js.es6 index 11a9045a136..f5604d8169b 100644 --- a/test/javascripts/controllers/create-account-test.js.es6 +++ b/test/javascripts/controllers/create-account-test.js.es6 @@ -1,20 +1,20 @@ import { mapRoutes } from 'discourse/mapping-router'; moduleFor("controller:create-account", "controller:create-account", { - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, needs: ['controller:modal', 'controller:login'] }); -test('basicUsernameValidation', function() { +QUnit.test('basicUsernameValidation', function(assert) { var subject = this.subject; var testInvalidUsername = function(username, expectedReason) { var controller = subject({ siteSettings: Discourse.SiteSettings }); controller.set('accountUsername', username); - equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username); - equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason); + assert.equal(controller.get('basicUsernameValidation.failed'), true, 'username should be invalid: ' + username); + assert.equal(controller.get('basicUsernameValidation.reason'), expectedReason, 'username validation reason: ' + username + ', ' + expectedReason); }; testInvalidUsername('', undefined); @@ -24,11 +24,11 @@ test('basicUsernameValidation', function() { var controller = subject({ siteSettings: Discourse.SiteSettings }); controller.set('accountUsername', 'porkchops'); controller.set('prefilledUsername', 'porkchops'); - equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid'); - equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid'); + assert.equal(controller.get('basicUsernameValidation.ok'), true, 'Prefilled username is valid'); + assert.equal(controller.get('basicUsernameValidation.reason'), I18n.t('user.username.prefilled'), 'Prefilled username is valid'); }); -test('passwordValidation', function() { +QUnit.test('passwordValidation', function(assert) { var subject = this.subject; var controller = subject({ siteSettings: Discourse.SiteSettings }); @@ -38,14 +38,14 @@ test('passwordValidation', function() { controller.set('prefilledUsername', 'porkchops'); controller.set('accountPassword', 'b4fcdae11f9167'); - equal(controller.get('passwordValidation.ok'), true, 'Password is ok'); - equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid'); + assert.equal(controller.get('passwordValidation.ok'), true, 'Password is ok'); + assert.equal(controller.get('passwordValidation.reason'), I18n.t('user.password.ok'), 'Password is valid'); var testInvalidPassword = function(password, expectedReason) { var c = subject({ siteSettings: Discourse.SiteSettings }); c.set('accountPassword', password); - equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password); - equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason); + assert.equal(c.get('passwordValidation.failed'), true, 'password should be invalid: ' + password); + assert.equal(c.get('passwordValidation.reason'), expectedReason, 'password validation reason: ' + password + ', ' + expectedReason); }; testInvalidPassword('', undefined); diff --git a/test/javascripts/controllers/flag-test.js.es6 b/test/javascripts/controllers/flag-test.js.es6 index 90368082457..0d4b49e16b3 100644 --- a/test/javascripts/controllers/flag-test.js.es6 +++ b/test/javascripts/controllers/flag-test.js.es6 @@ -18,13 +18,13 @@ var buildAdminUser = function(args) { }; moduleFor("controller:flag", "controller:flag", { - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, needs: ['controller:modal'] }); -test("canDeleteSpammer not staff", function(){ +QUnit.test("canDeleteSpammer not staff", function(assert) { const store = createStore(); var flagController = this.subject({ model: buildPost() }); @@ -32,44 +32,44 @@ test("canDeleteSpammer not staff", function(){ const spamFlag = store.createRecord('post-action-type', {name_key: 'spam'}); flagController.set('selected', spamFlag); - equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff'); + assert.equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff'); }); -var canDeleteSpammer = function(flagController, postActionType, expected, testName) { +var canDeleteSpammer = function(assert, flagController, postActionType, expected, testName) { const store = createStore(); const flag = store.createRecord('post-action-type', {name_key: postActionType}); flagController.set('selected', flag); - equal(flagController.get('canDeleteSpammer'), expected, testName); + assert.equal(flagController.get('canDeleteSpammer'), expected, testName); }; -test("canDeleteSpammer spam not selected", function(){ +QUnit.test("canDeleteSpammer spam not selected", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); var flagController = this.subject({ model: buildPost() }); flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true})); - canDeleteSpammer(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic'); - canDeleteSpammer(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate'); - canDeleteSpammer(flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user'); - canDeleteSpammer(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators'); + canDeleteSpammer(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic'); + canDeleteSpammer(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate'); + canDeleteSpammer(assert, flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user'); + canDeleteSpammer(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators'); }); -test("canDeleteSpammer spam selected", function(){ +QUnit.test("canDeleteSpammer spam selected", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); var flagController = this.subject({ model: buildPost() }); flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true})); - canDeleteSpammer(flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted'); + canDeleteSpammer(assert, flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted'); flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: true})); - canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted'); + canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted'); flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: false})); - canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted'); + canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted'); flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: false})); - canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted'); + canDeleteSpammer(assert, flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted'); }); -test("canSendWarning not staff", function(){ +QUnit.test("canSendWarning not staff", function(assert) { const store = createStore(); var flagController = this.subject({ model: buildPost() }); @@ -77,28 +77,28 @@ test("canSendWarning not staff", function(){ const notifyUserFlag = store.createRecord('post-action-type', {name_key: 'notify_user'}); flagController.set('selected', notifyUserFlag); - equal(flagController.get('canSendWarning'), false, 'false if current user is not staff'); + assert.equal(flagController.get('canSendWarning'), false, 'false if current user is not staff'); }); -var canSendWarning = function(flagController, postActionType, expected, testName) { +var canSendWarning = function(assert, flagController, postActionType, expected, testName) { const store = createStore(); const flag = store.createRecord('post-action-type', {name_key: postActionType}); flagController.set('selected', flag); - equal(flagController.get('canSendWarning'), expected, testName); + assert.equal(flagController.get('canSendWarning'), expected, testName); }; -test("canSendWarning notify_user not selected", function(){ +QUnit.test("canSendWarning notify_user not selected", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); var flagController = this.subject({ model: buildPost() }); - canSendWarning(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic'); - canSendWarning(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate'); - canSendWarning(flagController, 'spam', false, 'false if current user is staff, but selected is spam'); - canSendWarning(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators'); + canSendWarning(assert, flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic'); + canSendWarning(assert, flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate'); + canSendWarning(assert, flagController, 'spam', false, 'false if current user is staff, but selected is spam'); + canSendWarning(assert, flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators'); }); -test("canSendWarning notify_user selected", function(){ +QUnit.test("canSendWarning notify_user selected", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true); var flagController = this.subject({ model: buildPost() }); - canSendWarning(flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user'); + canSendWarning(assert, flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user'); }); diff --git a/test/javascripts/controllers/group-test.js.es6 b/test/javascripts/controllers/group-test.js.es6 index 822b14dd424..a5defd2d14a 100644 --- a/test/javascripts/controllers/group-test.js.es6 +++ b/test/javascripts/controllers/group-test.js.es6 @@ -1,19 +1,21 @@ -moduleFor("controller:group"); +moduleFor("controller:group", { + needs: ['controller:application'] +}); -test("canEditGroup", function() { +QUnit.test("canEditGroup", function(assert) { const GroupController = this.subject(); GroupController.setProperties({ model: { is_group_owner: true, automatic: true } }); - equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited"); + assert.equal(GroupController.get("canEditGroup"), false, "automatic groups cannot be edited"); GroupController.set("model.automatic", false); - equal(GroupController.get("canEditGroup"), true, "owners can edit groups"); + assert.equal(GroupController.get("canEditGroup"), true, "owners can edit groups"); GroupController.set("model.is_group_owner", false); - equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups"); + assert.equal(GroupController.get("canEditGroup"), false, "normal users cannot edit groups"); }); diff --git a/test/javascripts/controllers/history-test.js.es6 b/test/javascripts/controllers/history-test.js.es6 index fc8bbe1f5c0..11fe31a27e2 100644 --- a/test/javascripts/controllers/history-test.js.es6 +++ b/test/javascripts/controllers/history-test.js.es6 @@ -1,27 +1,27 @@ moduleFor("controller:history"); -test("displayEdit", function() { +QUnit.test("displayEdit", function(assert) { const HistoryController = this.subject(); HistoryController.setProperties({ model: { last_revision: 3, current_revision: 3, can_edit: false } }); - equal( + assert.equal( HistoryController.get("displayEdit"), false, "it should not display edit button when user cannot edit the post" ); HistoryController.set("model.can_edit", true); - equal( + assert.equal( HistoryController.get("displayEdit"), true, "it should display edit button when user can edit the post" ); HistoryController.set("model.current_revision", 2); - equal( + assert.equal( HistoryController.get("displayEdit"), false, "it should only display the edit button on the latest revision" ); diff --git a/test/javascripts/controllers/topic-test.js.es6 b/test/javascripts/controllers/topic-test.js.es6 index a8e3609e34b..1ae8080bc4e 100644 --- a/test/javascripts/controllers/topic-test.js.es6 +++ b/test/javascripts/controllers/topic-test.js.es6 @@ -1,9 +1,8 @@ -import { blank, present } from 'helpers/qunit-helpers'; import { mapRoutes } from 'discourse/mapping-router'; moduleFor('controller:topic', 'controller:topic', { needs: ['controller:modal', 'controller:composer', 'controller:application'], - setup() { + beforeEach() { this.registry.register('router:main', mapRoutes()); }, }); @@ -23,27 +22,27 @@ var buildTopic = function() { }; -test("editingMode", function() { +QUnit.test("editingMode", function(assert) { var topic = buildTopic(), topicController = this.subject({model: topic}); - ok(!topicController.get('editingTopic'), "we are not editing by default"); + assert.ok(!topicController.get('editingTopic'), "we are not editing by default"); topicController.set('model.details.can_edit', false); topicController.send('editTopic'); - ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit"); + assert.ok(!topicController.get('editingTopic'), "calling editTopic doesn't enable editing unless the user can edit"); topicController.set('model.details.can_edit', true); topicController.send('editTopic'); - ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit"); - equal(topicController.get('buffered.title'), topic.get('title')); - equal(topicController.get('buffered.category_id'), topic.get('category_id')); + assert.ok(topicController.get('editingTopic'), "calling editTopic enables editing if the user can edit"); + assert.equal(topicController.get('buffered.title'), topic.get('title')); + assert.equal(topicController.get('buffered.category_id'), topic.get('category_id')); topicController.send('cancelEditingTopic'); - ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value"); + assert.ok(!topicController.get('editingTopic'), "cancelling edit mode reverts the property value"); }); -test("toggledSelectedPost", function() { +QUnit.test("toggledSelectedPost", function(assert) { var tc = this.subject({ model: buildTopic() }), post = Discourse.Post.create({id: 123, post_number: 2}), postStream = tc.get('model.postStream'); @@ -51,38 +50,38 @@ test("toggledSelectedPost", function() { postStream.appendPost(post); postStream.appendPost(Discourse.Post.create({id: 124, post_number: 3})); - blank(tc.get('selectedPosts'), "there are no selected posts by default"); - equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0"); - ok(!tc.postSelected(post), "the post is not selected by default"); + assert.blank(tc.get('selectedPosts'), "there are no selected posts by default"); + assert.equal(tc.get('selectedPostsCount'), 0, "there is a selected post count of 0"); + assert.ok(!tc.postSelected(post), "the post is not selected by default"); tc.send('toggledSelectedPost', post); - present(tc.get('selectedPosts'), "there is a selectedPosts collection"); - equal(tc.get('selectedPostsCount'), 1, "there is a selected post now"); - ok(tc.postSelected(post), "the post is now selected"); + assert.present(tc.get('selectedPosts'), "there is a selectedPosts collection"); + assert.equal(tc.get('selectedPostsCount'), 1, "there is a selected post now"); + assert.ok(tc.postSelected(post), "the post is now selected"); tc.send('toggledSelectedPost', post); - ok(!tc.postSelected(post), "the post is no longer selected"); + assert.ok(!tc.postSelected(post), "the post is no longer selected"); }); -test("selectAll", function() { +QUnit.test("selectAll", function(assert) { var tc = this.subject({model: buildTopic(), appEvents: AppEvents.create()}), post = Discourse.Post.create({id: 123, post_number: 2}), postStream = tc.get('model.postStream'); postStream.appendPost(post); - ok(!tc.postSelected(post), "the post is not selected by default"); + assert.ok(!tc.postSelected(post), "the post is not selected by default"); tc.send('selectAll'); - ok(tc.postSelected(post), "the post is now selected"); - ok(tc.get('allPostsSelected'), "all posts are selected"); + assert.ok(tc.postSelected(post), "the post is now selected"); + assert.ok(tc.get('allPostsSelected'), "all posts are selected"); tc.send('deselectAll'); - ok(!tc.postSelected(post), "the post is deselected again"); - ok(!tc.get('allPostsSelected'), "all posts are not selected"); + assert.ok(!tc.postSelected(post), "the post is deselected again"); + assert.ok(!tc.get('allPostsSelected'), "all posts are not selected"); }); -test("Automating setting of allPostsSelected", function() { +QUnit.test("Automating setting of allPostsSelected", function(assert) { var topic = buildTopic(), tc = this.subject({model: topic}), post = Discourse.Post.create({id: 123, post_number: 2}), @@ -90,39 +89,38 @@ test("Automating setting of allPostsSelected", function() { topic.set('posts_count', 1); postStream.appendPost(post); - ok(!tc.get('allPostsSelected'), "all posts are not selected by default"); + assert.ok(!tc.get('allPostsSelected'), "all posts are not selected by default"); tc.send('toggledSelectedPost', post); - ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post"); + assert.ok(tc.get('allPostsSelected'), "all posts are selected if we select the only post"); tc.send('toggledSelectedPost', post); - ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected"); + assert.ok(!tc.get('allPostsSelected'), "the posts are no longer automatically selected"); }); -test("Select Replies when present", function() { +QUnit.test("Select Replies when present", function(assert) { var topic = buildTopic(), tc = this.subject({ model: topic, appEvents: AppEvents.create() }), p1 = Discourse.Post.create({id: 1, post_number: 1, reply_count: 1}), p2 = Discourse.Post.create({id: 2, post_number: 2}), p3 = Discourse.Post.create({id: 2, post_number: 3, reply_to_post_number: 1}); - ok(!tc.postSelected(p3), "replies are not selected by default"); + assert.ok(!tc.postSelected(p3), "replies are not selected by default"); tc.send('toggledSelectedPostReplies', p1); - ok(tc.postSelected(p1), "it selects the post"); - ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply"); - ok(tc.postSelected(p3), "it selects a post that is a reply"); - equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two"); + assert.ok(tc.postSelected(p1), "it selects the post"); + assert.ok(!tc.postSelected(p2), "it doesn't select a post that's not a reply"); + assert.ok(tc.postSelected(p3), "it selects a post that is a reply"); + assert.equal(tc.get('selectedPostsCount'), 2, "it has a selected posts count of two"); // If we deselected the post whose replies are selected... tc.send('toggledSelectedPost', p1); - ok(!tc.postSelected(p1), "it deselects the post"); - ok(!tc.postSelected(p3), "it deselects the replies too"); + assert.ok(!tc.postSelected(p1), "it deselects the post"); + assert.ok(!tc.postSelected(p3), "it deselects the replies too"); // If we deselect a reply, it should deselect the parent's replies selected attribute. Weird but what else would make sense? tc.send('toggledSelectedPostReplies', p1); tc.send('toggledSelectedPost', p3); - ok(tc.postSelected(p1), "the post stays selected"); - ok(!tc.postSelected(p3), "it deselects the replies too"); + assert.ok(tc.postSelected(p1), "the post stays selected"); + assert.ok(!tc.postSelected(p3), "it deselects the replies too"); }); - diff --git a/test/javascripts/ember/resolver-test.js.es6 b/test/javascripts/ember/resolver-test.js.es6 index 648729d6bd3..85424065ecf 100644 --- a/test/javascripts/ember/resolver-test.js.es6 +++ b/test/javascripts/ember/resolver-test.js.es6 @@ -3,10 +3,10 @@ import { setResolverOption, buildResolver } from 'discourse-common/resolver'; let originalTemplates; let resolver; -function lookupTemplate(name, expectedTemplate, message) { +function lookupTemplate(assert, name, expectedTemplate, message) { var parseName = resolver.parseName(name); var result = resolver.resolveTemplate(parseName); - equal(result, expectedTemplate, message); + assert.equal(result, expectedTemplate, message); } function setTemplates(lookupTemplateStrings) { @@ -17,20 +17,20 @@ function setTemplates(lookupTemplateStrings) { const DiscourseResolver = buildResolver('discourse'); -module("lib:resolver", { - setup: function() { +QUnit.module("lib:resolver", { + beforeEach() { originalTemplates = Ember.TEMPLATES; Ember.TEMPLATES = {}; resolver = DiscourseResolver.create(); }, - teardown: function() { + afterEach() { Ember.TEMPLATES = originalTemplates; } }); -test("finds templates in top level dir", function() { +QUnit.test("finds templates in top level dir", assert => { setTemplates([ "foobar", "fooBar", @@ -38,24 +38,24 @@ test("finds templates in top level dir", function() { "foo.bar" ]); - lookupTemplate("template:foobar", "foobar", "by lowcased name"); - lookupTemplate("template:fooBar", "fooBar", "by camel cased name"); - lookupTemplate("template:foo_bar", "foo_bar", "by underscored name"); - lookupTemplate("template:foo.bar", "foo.bar", "by dotted name"); + lookupTemplate(assert, "template:foobar", "foobar", "by lowcased name"); + lookupTemplate(assert, "template:fooBar", "fooBar", "by camel cased name"); + lookupTemplate(assert, "template:foo_bar", "foo_bar", "by underscored name"); + lookupTemplate(assert, "template:foo.bar", "foo.bar", "by dotted name"); }); -test("finds templates in first-level subdir", function() { +QUnit.test("finds templates in first-level subdir", assert => { setTemplates([ "foo/bar_baz" ]); - lookupTemplate("template:foo/bar_baz", "foo/bar_baz", "with subdir defined by slash"); - lookupTemplate("template:foo.bar_baz", "foo/bar_baz", "with subdir defined by dot"); - lookupTemplate("template:fooBarBaz", "foo/bar_baz", "with subdir defined by first camel case and the rest of camel cases converted to underscores"); - lookupTemplate("template:foo_bar_baz", "foo/bar_baz", "with subdir defined by first underscore"); + lookupTemplate(assert, "template:foo/bar_baz", "foo/bar_baz", "with subdir defined by slash"); + lookupTemplate(assert, "template:foo.bar_baz", "foo/bar_baz", "with subdir defined by dot"); + lookupTemplate(assert, "template:fooBarBaz", "foo/bar_baz", "with subdir defined by first camel case and the rest of camel cases converted to underscores"); + lookupTemplate(assert, "template:foo_bar_baz", "foo/bar_baz", "with subdir defined by first underscore"); }); -test("resolves precedence between overlapping top level dir and first level subdir templates", function() { +QUnit.test("resolves precedence between overlapping top level dir and first level subdir templates", assert => { setTemplates([ "fooBar", "foo_bar", @@ -63,28 +63,28 @@ test("resolves precedence between overlapping top level dir and first level subd "foo/bar" ]); - lookupTemplate("template:foo.bar", "foo/bar", "preferring first level subdir for dotted name"); - lookupTemplate("template:fooBar", "fooBar", "preferring top level dir for camel cased name"); - lookupTemplate("template:foo_bar", "foo_bar", "preferring top level dir for underscored name"); + lookupTemplate(assert, "template:foo.bar", "foo/bar", "preferring first level subdir for dotted name"); + lookupTemplate(assert, "template:fooBar", "fooBar", "preferring top level dir for camel cased name"); + lookupTemplate(assert, "template:foo_bar", "foo_bar", "preferring top level dir for underscored name"); }); -test("finds templates in subdir deeper than one level", function() { +QUnit.test("finds templates in subdir deeper than one level", assert => { setTemplates([ "foo/bar/baz/qux" ]); - lookupTemplate("template:foo/bar/baz/qux", "foo/bar/baz/qux", "for subdirs defined by slashes"); - lookupTemplate("template:foo.bar.baz.qux", "foo/bar/baz/qux", "for subdirs defined by dots"); - lookupTemplate("template:foo/bar/bazQux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one camel case"); - lookupTemplate("template:foo/bar/baz_qux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one underscore"); + lookupTemplate(assert, "template:foo/bar/baz/qux", "foo/bar/baz/qux", "for subdirs defined by slashes"); + lookupTemplate(assert, "template:foo.bar.baz.qux", "foo/bar/baz/qux", "for subdirs defined by dots"); + lookupTemplate(assert, "template:foo/bar/bazQux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one camel case"); + lookupTemplate(assert, "template:foo/bar/baz_qux", "foo/bar/baz/qux", "for subdirs defined by slashes plus one underscore"); - lookupTemplate("template:fooBarBazQux", undefined, "but not for subdirs defined by more than one camel case"); - lookupTemplate("template:foo_bar_baz_qux", undefined, "but not for subdirs defined by more than one underscore"); - lookupTemplate("template:foo.bar.bazQux", undefined, "but not for subdirs defined by dots plus one camel case"); - lookupTemplate("template:foo.bar.baz_qux", undefined, "but not for subdirs defined by dots plus one underscore"); + lookupTemplate(assert, "template:fooBarBazQux", undefined, "but not for subdirs defined by more than one camel case"); + lookupTemplate(assert, "template:foo_bar_baz_qux", undefined, "but not for subdirs defined by more than one underscore"); + lookupTemplate(assert, "template:foo.bar.bazQux", undefined, "but not for subdirs defined by dots plus one camel case"); + lookupTemplate(assert, "template:foo.bar.baz_qux", undefined, "but not for subdirs defined by dots plus one underscore"); }); -test("resolves mobile templates to 'mobile/' namespace", function() { +QUnit.test("resolves mobile templates to 'mobile/' namespace", assert => { setTemplates([ "mobile/foo", "bar", @@ -94,12 +94,12 @@ test("resolves mobile templates to 'mobile/' namespace", function() { setResolverOption('mobileView', true); - lookupTemplate("template:foo", "mobile/foo", "finding mobile version even if normal one is not present"); - lookupTemplate("template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present"); - lookupTemplate("template:baz", "baz", "falling back to a normal version when mobile version is not present"); + lookupTemplate(assert, "template:foo", "mobile/foo", "finding mobile version even if normal one is not present"); + lookupTemplate(assert, "template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present"); + lookupTemplate(assert, "template:baz", "baz", "falling back to a normal version when mobile version is not present"); }); -test("resolves plugin templates to 'javascripts/' namespace", function() { +QUnit.test("resolves plugin templates to 'javascripts/' namespace", assert => { setTemplates([ "javascripts/foo", "bar", @@ -107,12 +107,12 @@ test("resolves plugin templates to 'javascripts/' namespace", function() { "baz" ]); - lookupTemplate("template:foo", "javascripts/foo", "finding plugin version even if normal one is not present"); - lookupTemplate("template:bar", "javascripts/bar", "preferring plugin version when both versions are present"); - lookupTemplate("template:baz", "baz", "falling back to a normal version when plugin version is not present"); + lookupTemplate(assert, "template:foo", "javascripts/foo", "finding plugin version even if normal one is not present"); + lookupTemplate(assert, "template:bar", "javascripts/bar", "preferring plugin version when both versions are present"); + lookupTemplate(assert, "template:baz", "baz", "falling back to a normal version when plugin version is not present"); }); -test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", function() { +QUnit.test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", assert => { setTemplates([ "admin/templates/foo", "adminBar", @@ -121,20 +121,20 @@ test("resolves templates with 'admin' prefix to 'admin/templates/' namespace", f "admin/templates/bar" ]); - lookupTemplate("template:adminFoo", "admin/templates/foo", "when prefix is separated by camel case"); - lookupTemplate("template:admin_foo", "admin/templates/foo", "when prefix is separated by underscore"); - lookupTemplate("template:admin.foo", "admin/templates/foo", "when prefix is separated by dot"); + lookupTemplate(assert, "template:adminFoo", "admin/templates/foo", "when prefix is separated by camel case"); + lookupTemplate(assert, "template:admin_foo", "admin/templates/foo", "when prefix is separated by underscore"); + lookupTemplate(assert, "template:admin.foo", "admin/templates/foo", "when prefix is separated by dot"); - lookupTemplate("template:adminfoo", undefined, "but not when prefix is not separated in any way"); - lookupTemplate("template:adminBar", "adminBar", "but not when template with the exact camel cased name exists"); - lookupTemplate("template:admin_bar", "admin_bar", "but not when template with the exact underscored name exists"); - lookupTemplate("template:admin.bar", "admin.bar", "but not when template with the exact dotted name exists"); + lookupTemplate(assert, "template:adminfoo", undefined, "but not when prefix is not separated in any way"); + lookupTemplate(assert, "template:adminBar", "adminBar", "but not when template with the exact camel cased name exists"); + lookupTemplate(assert, "template:admin_bar", "admin_bar", "but not when template with the exact underscored name exists"); + lookupTemplate(assert, "template:admin.bar", "admin.bar", "but not when template with the exact dotted name exists"); }); -test("returns 'not_found' template when template name cannot be resolved", function() { +QUnit.test("returns 'not_found' template when template name cannot be resolved", assert => { setTemplates([ "not_found" ]); - lookupTemplate("template:foo/bar/baz", "not_found", ""); + lookupTemplate(assert, "template:foo/bar/baz", "not_found", ""); }); diff --git a/test/javascripts/helpers/assertions.js b/test/javascripts/helpers/assertions.js index 66b6fc8f846..4e6b53b5d16 100644 --- a/test/javascripts/helpers/assertions.js +++ b/test/javascripts/helpers/assertions.js @@ -8,14 +8,6 @@ function count(selector) { return find(selector).length; } -function containsInstance(collection, klass, text) { - ok(klass.detectInstance(_.first(collection)), text); -} - -function not(state, message) { - ok(!state, message); -} - function visible(selector) { return find(selector + ":visible").length > 0; } diff --git a/test/javascripts/helpers/component-test.js.es6 b/test/javascripts/helpers/component-test.js.es6 index 341c106b33a..4154a461219 100644 --- a/test/javascripts/helpers/component-test.js.es6 +++ b/test/javascripts/helpers/component-test.js.es6 @@ -35,8 +35,8 @@ export default function(name, opts) { this.registry.register('store:main', store, { instantiate: false }); - if (opts.setup) { - opts.setup.call(this, store); + if (opts.beforeEach) { + opts.beforeEach.call(this, store); } andThen(() => { diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 85d171a37f0..bfa32ba4af4 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -379,4 +379,4 @@ export default function() { server.checkPassthrough = request => request.requestHeaders['Discourse-Script']; return server; -} +} \ No newline at end of file diff --git a/test/javascripts/helpers/create-store.js.es6 b/test/javascripts/helpers/create-store.js.es6 index 9ad8d169c51..a1ab5351a81 100644 --- a/test/javascripts/helpers/create-store.js.es6 +++ b/test/javascripts/helpers/create-store.js.es6 @@ -11,8 +11,11 @@ export default function() { register: { lookup(type) { if (type === "adapter:rest") { - this._restAdapter = this._restAdapter || RestAdapter.create({ container: this }); - return (this._restAdapter); + if (!this._restAdapter) { + this._restAdapter = RestAdapter.create({ owner: this }); + // this._restAdapter.container = this; + } + return this._restAdapter; } if (type === "key-value-store:main") { this._kvs = this._kvs || new KeyValueStore(); @@ -34,5 +37,4 @@ export default function() { }, } }); -} - +} \ No newline at end of file diff --git a/test/javascripts/helpers/parse-html.js.es6 b/test/javascripts/helpers/parse-html.js.es6 index c9469fa6b9f..0d3bab90d56 100644 --- a/test/javascripts/helpers/parse-html.js.es6 +++ b/test/javascripts/helpers/parse-html.js.es6 @@ -5,4 +5,4 @@ export default function parseHTML(rawHtml) { parser.parseComplete(rawHtml); return builder.dom; -} +} \ No newline at end of file diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index bb296f0d776..2640e806b34 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -1,4 +1,4 @@ -/* global asyncTest, fixtures */ +/* global QUnit, fixtures */ import sessionFixtures from 'fixtures/session-fixtures'; import siteFixtures from 'fixtures/site-fixtures'; @@ -41,7 +41,7 @@ $.fn.modal = AcceptanceModal; function acceptance(name, options) { module("Acceptance: " + name, { - setup() { + beforeEach() { resetMobile(); // For now don't do scrolling stuff in Test Mode @@ -50,8 +50,8 @@ function acceptance(name, options) { resetExtraClasses(); const siteJson = siteFixtures['site.json'].site; if (options) { - if (options.setup) { - options.setup.call(this); + if (options.beforeEach) { + options.beforeEach.call(this); } if (options.mobileView) { @@ -77,9 +77,9 @@ function acceptance(name, options) { Discourse.reset(); }, - teardown() { - if (options && options.teardown) { - options.teardown.call(this); + afterEach() { + if (options && options.afterEach) { + options.afterEach.call(this); } flushMap(); Discourse.User.resetCurrent(); @@ -102,10 +102,11 @@ function controllerFor(controller, model) { } function asyncTestDiscourse(text, func) { - asyncTest(text, function () { - var self = this; - Ember.run(function () { - func.call(self); + QUnit.test(text, function(assert) { + const done = assert.async(); + Ember.run(() => { + func.call(this, assert); + done(); }); }); } @@ -117,20 +118,46 @@ function fixture(selector) { return $("#qunit-fixture"); } -function present(obj, text) { - ok(!Ember.isEmpty(obj), text); -} +QUnit.assert.not = function(actual, message) { + this.pushResult({ + result: !actual, + actual, + expected: !actual, + message + }); +}; -function blank(obj, text) { - ok(Ember.isEmpty(obj), text); -} +QUnit.assert.blank = function(actual, message) { + this.pushResult({ + result: Ember.isEmpty(actual), + actual, + message + }); +}; -function waitFor(callback, timeout) { +QUnit.assert.present = function(actual, message) { + this.pushResult({ + result: !Ember.isEmpty(actual), + actual, + message + }); +}; + +QUnit.assert.containsInstance = function(collection, klass, message) { + const result = klass.detectInstance(_.first(collection)); + this.pushResult({ + result, + message + }); +}; + +function waitFor(assert, callback, timeout) { timeout = timeout || 500; - stop(); + + const done = assert.async(); Ember.run.later(() => { callback(); - start(); + done(); }, timeout); } @@ -140,6 +167,4 @@ export { acceptance, fixture, logIn, currentUser, - blank, - present, waitFor }; diff --git a/test/javascripts/helpers/site.js.es6 b/test/javascripts/helpers/site.js.es6 index d8ab85a4861..a477be1859c 100644 --- a/test/javascripts/helpers/site.js.es6 +++ b/test/javascripts/helpers/site.js.es6 @@ -1,4 +1,4 @@ import PreloadStore from 'preload-store'; /*jshint maxlen:10000000 */ -PreloadStore.store("site",{"default_archetype":"regular","notification_types":{"mentioned":1,"replied":2,"quoted":3,"edited":4,"liked":5,"private_message":6,"invited_to_private_message":7,"invitee_accepted":8,"posted":9,"moved_post":10},"post_types":{"regular":1,"moderator_action":2},"groups":[{"id":0,"name":"everyone"},{"id":1,"name":"admins"},{"id":2,"name":"moderators"},{"id":3,"name":"staff"},{"id":10,"name":"trust_level_0"},{"id":11,"name":"trust_level_1"},{"id":12,"name":"trust_level_2"},{"id":13,"name":"trust_level_3"},{"id":14,"name":"trust_level_4"},{"id":20,"name":"ubuntu"},{"id":21,"name":"test"}],"filters":["latest","unread","new","starred","read","posted"],"periods":["yearly","monthly","weekly","daily"],"top_menu_items":["latest","unread","new","starred","read","posted","category","categories","top"],"anonymous_top_menu_items":["latest","category","categories","top"],"uncategorized_category_id":17,"categories":[{"id":5,"name":"extensibility","color":"FE8432","text_color":"FFFFFF","slug":"extensibility","topic_count":102,"description":"Topics about extending the functionality of Discourse with plugins, themes, add-ons, or other mechanisms for extensibility. ","topic_url":"/t/category-definition-for-extensibility/28","hotness":5.0,"read_restricted":false,"permission":null},{"id":7,"name":"dev","color":"000","text_color":"FFFFFF","slug":"dev","topic_count":284,"description":"This category is for topics related to hacking on Discourse: submitting pull requests, configuring development environments, coding conventions, and so forth.","topic_url":"/t/category-definition-for-dev/1026","hotness":5.0,"read_restricted":false,"permission":null},{"id":1,"name":"bug","color":"e9dd00","text_color":"000000","slug":"bug","topic_count":660,"description":"Bug reports on Discourse. Do be sure to search prior to submitting bugs. Include repro steps, and only describe one bug per topic please.","topic_url":"/t/category-definition-for-bug/2","hotness":5.0,"read_restricted":false,"permission":null},{"id":8,"name":"hosting","color":"74CCED","text_color":"FFFFFF","slug":"hosting","topic_count":69,"description":"Topics about hosting Discourse, either on your own servers, in the cloud, or with specific hosting services.","topic_url":"/t/category-definition-for-hosting/2626","hotness":5.0,"read_restricted":false,"permission":null},{"id":6,"name":"support","color":"b99","text_color":"FFFFFF","slug":"support","topic_count":782,"description":"Support on configuring, using, and installing Discourse. Not for software development related topics, but for admins and end users configuring and using Discourse.","topic_url":"/t/category-definition-for-support/389","hotness":5.0,"read_restricted":false,"permission":null},{"id":2,"name":"feature","color":"0E76BD","text_color":"FFFFFF","slug":"feature","topic_count":727,"description":"Discussion about features or potential features of Discourse: how they work, why they work, etc.","topic_url":"/t/category-definition-for-feature/11","hotness":5.0,"read_restricted":false,"permission":null},{"id":13,"name":"blog","color":"ED207B","text_color":"FFFFFF","slug":"blog","topic_count":14,"description":"Discussion topics generated from the official Discourse Blog. These topics are linked from the bottom of each blog entry where the blog comments would normally be.","topic_url":"/t/category-definition-for-blog/5250","hotness":5.0,"read_restricted":false,"permission":null},{"id":12,"name":"discourse hub","color":"b2c79f","text_color":"FFFFFF","slug":"discourse-hub","topic_count":4,"description":"Topics about current or future Discourse Hub functionality at discourse.org including nickname registration, global user pages, and the site directory.","topic_url":"/t/category-definition-for-discourse-hub/3038","hotness":5.0,"read_restricted":false,"permission":null},{"id":11,"name":"login","color":"edb400","text_color":"FFFFFF","slug":"login","topic_count":27,"description":"Topics about logging in to Discourse, using any standard third party provider (Twitter, Facebook, Google), traditional username and password, or with a custom plugin.","topic_url":"/t/category-definition-for-login/2828","hotness":5.0,"read_restricted":false,"permission":null},{"id":3,"name":"meta","color":"aaa","text_color":"FFFFFF","slug":"meta","topic_count":79,"description":"Discussion about meta.discourse.org itself, the organization of this forum about Discourse, how it works, and how we can improve this site.","topic_url":"/t/category-definition-for-meta/24","hotness":5.0,"read_restricted":false,"permission":null},{"id":10,"name":"howto","color":"76923C","text_color":"FFFFFF","slug":"howto","topic_count":58,"description":"Tutorial topics that describe how to set up, configure, or install Discourse using a specific platform or environment. Topics in this category may only be created by trust level 2 and up. ","topic_url":"/t/category-definition-for-howto/2629","hotness":5.0,"read_restricted":false,"permission":null},{"id":14,"name":"marketplace","color":"8C6238","text_color":"FFFFFF","slug":"marketplace","topic_count":24,"description":"About commercial Discourse related stuff: jobs or paid gigs, plugins, themes, hosting, etc.","topic_url":"/t/category-definition-for-marketplace/5425","hotness":5.0,"read_restricted":false,"permission":null},{"id":17,"name":"uncategorized","color":"AB9364","text_color":"FFFFFF","slug":"uncategorized","topic_count":229,"description":"","topic_url":null,"hotness":5.0,"read_restricted":false,"permission":null},{"id":9,"name":"ux","color":"5F497A","text_color":"FFFFFF","slug":"ux","topic_count":184,"description":"Discussion about the user interface of Discourse, how features are presented to the user in the client, including language and UI elements.","topic_url":"/t/category-definition-for-ux/2628","hotness":5.0,"read_restricted":false,"permission":null},{"id":4,"name":"faq","color":"33b","text_color":"FFFFFF","slug":"faq","topic_count":49,"description":"Topics that come up very often when discussing Discourse will eventually be classified into this Frequently Asked Questions category. Should only be added to popular topics.","topic_url":"/t/category-definition-for-faq/25","hotness":5.0,"read_restricted":false,"permission":null}],"post_action_types":[{"name_key":"bookmark","name":"Bookmark","description":"Bookmark this post","long_form":"bookmarked this post","is_flag":false,"icon":null,"id":1,"is_custom_flag":false},{"name_key":"like","name":"Like","description":"Like this post","long_form":"liked this","is_flag":false,"icon":"heart","id":2,"is_custom_flag":false},{"name_key":"off_topic","name":"Off-Topic","description":"This post is radically off-topic in the current conversation, and should probably be moved to a different topic. If this is a topic, perhaps it does not belong here.","long_form":"flagged this as off-topic","is_flag":true,"icon":null,"id":3,"is_custom_flag":false},{"name_key":"inappropriate","name":"Inappropriate","description":"This post contains content that a reasonable person would consider offensive, abusive, or a violation of our community guidelines<\/a>.","long_form":"flagged this as inappropriate","is_flag":true,"icon":null,"id":4,"is_custom_flag":false},{"name_key":"vote","name":"Vote","description":"Vote for this post","long_form":"voted for this post","is_flag":false,"icon":null,"id":5,"is_custom_flag":false},{"name_key":"spam","name":"Spam","description":"This post is an advertisement. It is not useful or relevant to the current conversation, but promotional in nature.","long_form":"flagged this as spam","is_flag":true,"icon":null,"id":8,"is_custom_flag":false},{"name_key":"notify_user","name":"Notify {{username}}","description":"This post contains something I want to talk to this person directly and privately about.","long_form":"notified user","is_flag":true,"icon":null,"id":6,"is_custom_flag":true},{"name_key":"notify_moderators","name":"Notify moderators","description":"This post requires general moderator attention based on the FAQ<\/a>, TOS<\/a>, or for another reason not listed above.","long_form":"notified moderators","is_flag":true,"icon":null,"id":7,"is_custom_flag":true}],"trust_levels":[{"id":0,"name":"new user"},{"id":1,"name":"basic user"},{"id":2,"name":"member"},{"id":3,"name":"regular"},{"id":4,"name":"leader"}],"archetypes":[{"id":"regular","name":"Regular Topic","options":[]}]}); +PreloadStore.store("site",{"default_archetype":"regular","notification_types":{"mentioned":1,"replied":2,"quoted":3,"edited":4,"liked":5,"private_message":6,"invited_to_private_message":7,"invitee_accepted":8,"posted":9,"moved_post":10},"post_types":{"regular":1,"moderator_action":2},"groups":[{"id":0,"name":"everyone"},{"id":1,"name":"admins"},{"id":2,"name":"moderators"},{"id":3,"name":"staff"},{"id":10,"name":"trust_level_0"},{"id":11,"name":"trust_level_1"},{"id":12,"name":"trust_level_2"},{"id":13,"name":"trust_level_3"},{"id":14,"name":"trust_level_4"},{"id":20,"name":"ubuntu"},{"id":21,"name":"test"}],"filters":["latest","unread","new","starred","read","posted"],"periods":["yearly","monthly","weekly","daily"],"top_menu_items":["latest","unread","new","starred","read","posted","category","categories","top"],"anonymous_top_menu_items":["latest","category","categories","top"],"uncategorized_category_id":17,"categories":[{"id":5,"name":"extensibility","color":"FE8432","text_color":"FFFFFF","slug":"extensibility","topic_count":102,"description":"Topics about extending the functionality of Discourse with plugins, themes, add-ons, or other mechanisms for extensibility. ","topic_url":"/t/category-definition-for-extensibility/28","hotness":5.0,"read_restricted":false,"permission":null},{"id":7,"name":"dev","color":"000","text_color":"FFFFFF","slug":"dev","topic_count":284,"description":"This category is for topics related to hacking on Discourse: submitting pull requests, configuring development environments, coding conventions, and so forth.","topic_url":"/t/category-definition-for-dev/1026","hotness":5.0,"read_restricted":false,"permission":null},{"id":1,"name":"bug","color":"e9dd00","text_color":"000000","slug":"bug","topic_count":660,"description":"Bug reports on Discourse. Do be sure to search prior to submitting bugs. Include repro steps, and only describe one bug per topic please.","topic_url":"/t/category-definition-for-bug/2","hotness":5.0,"read_restricted":false,"permission":null},{"id":8,"name":"hosting","color":"74CCED","text_color":"FFFFFF","slug":"hosting","topic_count":69,"description":"Topics about hosting Discourse, either on your own servers, in the cloud, or with specific hosting services.","topic_url":"/t/category-definition-for-hosting/2626","hotness":5.0,"read_restricted":false,"permission":null},{"id":6,"name":"support","color":"b99","text_color":"FFFFFF","slug":"support","topic_count":782,"description":"Support on configuring, using, and installing Discourse. Not for software development related topics, but for admins and end users configuring and using Discourse.","topic_url":"/t/category-definition-for-support/389","hotness":5.0,"read_restricted":false,"permission":null},{"id":2,"name":"feature","color":"0E76BD","text_color":"FFFFFF","slug":"feature","topic_count":727,"description":"Discussion about features or potential features of Discourse: how they work, why they work, etc.","topic_url":"/t/category-definition-for-feature/11","hotness":5.0,"read_restricted":false,"permission":null},{"id":13,"name":"blog","color":"ED207B","text_color":"FFFFFF","slug":"blog","topic_count":14,"description":"Discussion topics generated from the official Discourse Blog. These topics are linked from the bottom of each blog entry where the blog comments would normally be.","topic_url":"/t/category-definition-for-blog/5250","hotness":5.0,"read_restricted":false,"permission":null},{"id":12,"name":"discourse hub","color":"b2c79f","text_color":"FFFFFF","slug":"discourse-hub","topic_count":4,"description":"Topics about current or future Discourse Hub functionality at discourse.org including nickname registration, global user pages, and the site directory.","topic_url":"/t/category-definition-for-discourse-hub/3038","hotness":5.0,"read_restricted":false,"permission":null},{"id":11,"name":"login","color":"edb400","text_color":"FFFFFF","slug":"login","topic_count":27,"description":"Topics about logging in to Discourse, using any standard third party provider (Twitter, Facebook, Google), traditional username and password, or with a custom plugin.","topic_url":"/t/category-definition-for-login/2828","hotness":5.0,"read_restricted":false,"permission":null},{"id":3,"name":"meta","color":"aaa","text_color":"FFFFFF","slug":"meta","topic_count":79,"description":"Discussion about meta.discourse.org itself, the organization of this forum about Discourse, how it works, and how we can improve this site.","topic_url":"/t/category-definition-for-meta/24","hotness":5.0,"read_restricted":false,"permission":null},{"id":10,"name":"howto","color":"76923C","text_color":"FFFFFF","slug":"howto","topic_count":58,"description":"Tutorial topics that describe how to set up, configure, or install Discourse using a specific platform or environment. Topics in this category may only be created by trust level 2 and up. ","topic_url":"/t/category-definition-for-howto/2629","hotness":5.0,"read_restricted":false,"permission":null},{"id":14,"name":"marketplace","color":"8C6238","text_color":"FFFFFF","slug":"marketplace","topic_count":24,"description":"About commercial Discourse related stuff: jobs or paid gigs, plugins, themes, hosting, etc.","topic_url":"/t/category-definition-for-marketplace/5425","hotness":5.0,"read_restricted":false,"permission":null},{"id":17,"name":"uncategorized","color":"AB9364","text_color":"FFFFFF","slug":"uncategorized","topic_count":229,"description":"","topic_url":null,"hotness":5.0,"read_restricted":false,"permission":null},{"id":9,"name":"ux","color":"5F497A","text_color":"FFFFFF","slug":"ux","topic_count":184,"description":"Discussion about the user interface of Discourse, how features are presented to the user in the client, including language and UI elements.","topic_url":"/t/category-definition-for-ux/2628","hotness":5.0,"read_restricted":false,"permission":null},{"id":4,"name":"faq","color":"33b","text_color":"FFFFFF","slug":"faq","topic_count":49,"description":"Topics that come up very often when discussing Discourse will eventually be classified into this Frequently Asked Questions category. Should only be added to popular topics.","topic_url":"/t/category-definition-for-faq/25","hotness":5.0,"read_restricted":false,"permission":null}],"post_action_types":[{"name_key":"bookmark","name":"Bookmark","description":"Bookmark this post","long_form":"bookmarked this post","is_flag":false,"icon":null,"id":1,"is_custom_flag":false},{"name_key":"like","name":"Like","description":"Like this post","long_form":"liked this","is_flag":false,"icon":"heart","id":2,"is_custom_flag":false},{"name_key":"off_topic","name":"Off-Topic","description":"This post is radically off-topic in the current conversation, and should probably be moved to a different topic. If this is a topic, perhaps it does not belong here.","long_form":"flagged this as off-topic","is_flag":true,"icon":null,"id":3,"is_custom_flag":false},{"name_key":"inappropriate","name":"Inappropriate","description":"This post contains content that a reasonable person would consider offensive, abusive, or a violation of our community guidelines<\/a>.","long_form":"flagged this as inappropriate","is_flag":true,"icon":null,"id":4,"is_custom_flag":false},{"name_key":"vote","name":"Vote","description":"Vote for this post","long_form":"voted for this post","is_flag":false,"icon":null,"id":5,"is_custom_flag":false},{"name_key":"spam","name":"Spam","description":"This post is an advertisement. It is not useful or relevant to the current conversation, but promotional in nature.","long_form":"flagged this as spam","is_flag":true,"icon":null,"id":8,"is_custom_flag":false},{"name_key":"notify_user","name":"Notify {{username}}","description":"This post contains something I want to talk to this person directly and privately about.","long_form":"notified user","is_flag":true,"icon":null,"id":6,"is_custom_flag":true},{"name_key":"notify_moderators","name":"Notify moderators","description":"This post requires general moderator attention based on the FAQ<\/a>, TOS<\/a>, or for another reason not listed above.","long_form":"notified moderators","is_flag":true,"icon":null,"id":7,"is_custom_flag":true}],"trust_levels":[{"id":0,"name":"new user"},{"id":1,"name":"basic user"},{"id":2,"name":"member"},{"id":3,"name":"regular"},{"id":4,"name":"leader"}],"archetypes":[{"id":"regular","name":"Regular Topic","options":[]}]}); \ No newline at end of file diff --git a/test/javascripts/helpers/store-pretender.js.es6 b/test/javascripts/helpers/store-pretender.js.es6 index de7ff6b27c8..c47dec3ab93 100644 --- a/test/javascripts/helpers/store-pretender.js.es6 +++ b/test/javascripts/helpers/store-pretender.js.es6 @@ -76,4 +76,4 @@ export default function(helpers) { }); this.delete('/widgets/:widget_id', success); -}; +}; \ No newline at end of file diff --git a/test/javascripts/helpers/widget-test.js.es6 b/test/javascripts/helpers/widget-test.js.es6 index d30170ff1db..15e43cbe32e 100644 --- a/test/javascripts/helpers/widget-test.js.es6 +++ b/test/javascripts/helpers/widget-test.js.es6 @@ -6,4 +6,4 @@ export function moduleForWidget(name) { export function widgetTest(name, opts) { return componentTest(name, opts); -} +} \ No newline at end of file diff --git a/test/javascripts/initializers/localization-test.js.es6 b/test/javascripts/initializers/localization-test.js.es6 index 4f6e0670e52..45f60724a52 100644 --- a/test/javascripts/initializers/localization-test.js.es6 +++ b/test/javascripts/initializers/localization-test.js.es6 @@ -1,11 +1,11 @@ import PreloadStore from 'preload-store'; import LocalizationInitializer from 'discourse/initializers/localization'; -module("initializer:localization", { +QUnit.module("initializer:localization", { _locale: I18n.locale, _translations: I18n.translations, - setup() { + beforeEach() { I18n.locale = "fr"; I18n.translations = { @@ -28,16 +28,16 @@ module("initializer:localization", { }; }, - teardown() { + afterEach() { I18n.locale = this._locale; I18n.translations = this._translations; } }); -test("translation overrides", function() { +QUnit.test("translation overrides", assert => { PreloadStore.store('translationOverrides', {"js.composer.reply":"WAT","js.topic.reply.help":"foobar"}); LocalizationInitializer.initialize(this.registry); - equal(I18n.t("composer.reply"), "WAT", "overrides existing translation in current locale"); - equal(I18n.t("topic.reply.help"), "foobar", "overrides translation in default locale"); -}); + assert.equal(I18n.t("composer.reply"), "WAT", "overrides existing translation in current locale"); + assert.equal(I18n.t("topic.reply.help"), "foobar", "overrides translation in default locale"); +}); \ No newline at end of file diff --git a/test/javascripts/lib/category-badge-test.js.es6 b/test/javascripts/lib/category-badge-test.js.es6 index 385d478c6ad..ffd837a5e61 100644 --- a/test/javascripts/lib/category-badge-test.js.es6 +++ b/test/javascripts/lib/category-badge-test.js.es6 @@ -1,16 +1,15 @@ import createStore from 'helpers/create-store'; -import { blank, present } from 'helpers/qunit-helpers'; -module("lib:category-link"); +QUnit.module("lib:category-link"); import parseHTML from 'helpers/parse-html'; import { categoryBadgeHTML } from "discourse/helpers/category-link"; -test("categoryBadge without a category", function() { - blank(categoryBadgeHTML(), "it returns no HTML"); +QUnit.test("categoryBadge without a category", assert => { + assert.blank(categoryBadgeHTML(), "it returns no HTML"); }); -test("Regular categoryBadge", function() { +QUnit.test("Regular categoryBadge", assert => { const store = createStore(); const category = store.createRecord('category', { name: 'hello', @@ -21,28 +20,28 @@ test("Regular categoryBadge", function() { }); const tag = parseHTML(categoryBadgeHTML(category))[0]; - equal(tag.name, 'a', 'it creates a `a` wrapper tag'); - equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class'); + assert.equal(tag.name, 'a', 'it creates a `a` wrapper tag'); + assert.equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class'); const label = tag.children[1]; - equal(label.attributes.title, 'cool description', 'it has the correct title'); + assert.equal(label.attributes.title, 'cool description', 'it has the correct title'); - equal(label.children[0].data, 'hello', 'it has the category name'); + assert.equal(label.children[0].data, 'hello', 'it has the category name'); }); -test("undefined color", function() { +QUnit.test("undefined color", assert => { const store = createStore(); const noColor = store.createRecord('category', { name: 'hello', id: 123 }); const tag = parseHTML(categoryBadgeHTML(noColor))[0]; - blank(tag.attributes.style, "it has no color style because there are no colors"); + assert.blank(tag.attributes.style, "it has no color style because there are no colors"); }); -test("allowUncategorized", function() { +QUnit.test("allowUncategorized", assert => { const store = createStore(); const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345}); sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345); - blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default"); - present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML"); -}); + assert.blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default"); + assert.present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML"); +}); \ No newline at end of file diff --git a/test/javascripts/lib/click-track-edit-history-test.js.es6 b/test/javascripts/lib/click-track-edit-history-test.js.es6 index 4350ab6d22b..bf0c6abad94 100644 --- a/test/javascripts/lib/click-track-edit-history-test.js.es6 +++ b/test/javascripts/lib/click-track-edit-history-test.js.es6 @@ -1,4 +1,3 @@ -import { blank } from 'helpers/qunit-helpers'; import DiscourseURL from "discourse/lib/url"; import ClickTrack from "discourse/lib/click-track"; @@ -6,8 +5,8 @@ var windowOpen, win, redirectTo; -module("lib:click-track-edit-history", { - setup: function() { +QUnit.module("lib:click-track-edit-history", { + beforeEach() { // Prevent any of these tests from navigating away win = {focus: function() { } }; @@ -56,56 +55,57 @@ var generateClickEventOn = function(selector) { return $.Event("click", { currentTarget: fixture(selector)[0] }); }; -test("does not track clicks on lightboxes", function() { +QUnit.test("does not track clicks on lightboxes", assert => { var clickEvent = generateClickEventOn('.lightbox'); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); -test("it calls preventDefault when clicking on an a", function() { +QUnit.test("it calls preventDefault when clicking on an a", assert => { var clickEvent = generateClickEventOn('a'); sandbox.stub(clickEvent, "preventDefault"); track(clickEvent); - ok(clickEvent.preventDefault.calledOnce); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(clickEvent.preventDefault.calledOnce); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("does not track clicks when forcibly disabled", function() { - ok(track(generateClickEventOn('.no-track-link'))); +QUnit.test("does not track clicks when forcibly disabled", assert => { + assert.ok(track(generateClickEventOn('.no-track-link'))); }); -test("does not track clicks on back buttons", function() { - ok(track(generateClickEventOn('.back'))); +QUnit.test("does not track clicks on back buttons", assert => { + assert.ok(track(generateClickEventOn('.back'))); }); -test("does not track clicks on quote buttons", function() { - ok(track(generateClickEventOn('.quote-other-topic'))); +QUnit.test("does not track clicks on quote buttons", assert => { + assert.ok(track(generateClickEventOn('.quote-other-topic'))); }); -test("does not track clicks on category badges", () => { - ok(track(generateClickEventOn('.hashtag'))); +QUnit.test("does not track clicks on category badges", assert => { + assert.ok(track(generateClickEventOn('.hashtag'))); }); -test("removes the href and put it as a data attribute", function() { +QUnit.test("removes the href and put it as a data attribute", assert => { track(generateClickEventOn('a')); var $link = fixture('a').first(); - ok($link.hasClass('no-href')); - equal($link.data('href'), 'http://www.google.com'); - blank($link.attr('href')); - ok($link.data('auto-route')); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok($link.hasClass('no-href')); + assert.equal($link.data('href'), 'http://www.google.com'); + assert.blank($link.attr('href')); + assert.ok($link.data('auto-route')); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -asyncTestDiscourse("restores the href after a while", function() { - expect(1); +asyncTestDiscourse("restores the href after a while", function(assert) { + assert.expect(1); track(generateClickEventOn('a')); + const done = assert.async(); setTimeout(function() { - start(); - equal(fixture('a').attr('href'), "http://www.google.com"); + done(); + assert.equal(fixture('a').attr('href'), "http://www.google.com"); }, 75); }); @@ -115,32 +115,32 @@ var trackRightClick = function(target) { return track(clickEvent); }; -test("right clicks change the href", function() { - ok(trackRightClick('a')); - equal(fixture('a').first().prop('href'), "http://www.google.com/"); +QUnit.test("right clicks change the href", assert => { + assert.ok(trackRightClick('a')); + assert.equal(fixture('a').first().prop('href'), "http://www.google.com/"); }); -test("right clicks are tracked", function() { +QUnit.test("right clicks are tracked", assert => { Discourse.SiteSettings.track_external_right_clicks = true; trackRightClick('a'); - equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); + assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); }); -test("preventDefault is not called for right clicks", function() { +QUnit.test("preventDefault is not called for right clicks", assert => { var clickEvent = generateClickEventOn('a'); clickEvent.which = 3; sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); var testOpenInANewTab = function(description, clickEventModifier) { - test(description, function() { + test(description, function(assert) { var clickEvent = generateClickEventOn('a'); clickEventModifier(clickEvent); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); }; @@ -160,31 +160,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent) clickEvent.button = 2; }); -test("tracks via AJAX if we're on the same site", function() { +QUnit.test("tracks via AJAX if we're on the same site", assert => { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('#same-site'))); - ok(DiscourseURL.routeTo.calledOnce); + assert.ok(!track(generateClickEventOn('#same-site'))); + assert.ok(DiscourseURL.routeTo.calledOnce); }); -test("does not track via AJAX for attachments", function() { +QUnit.test("does not track via AJAX for attachments", assert => { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('.attachment'))); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(!track(generateClickEventOn('.attachment'))); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", assert => { var clickEvent = generateClickEventOn('a'); sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true); - ok(!track(clickEvent)); - ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); + assert.ok(!track(clickEvent)); + assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", assert => { var clickEvent = generateClickEventOn('a'); - ok(!track(clickEvent)); - ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); + assert.ok(!track(clickEvent)); + assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); }); diff --git a/test/javascripts/lib/click-track-profile-page-test.js.es6 b/test/javascripts/lib/click-track-profile-page-test.js.es6 index bc0b46e5595..9e91d6ea709 100644 --- a/test/javascripts/lib/click-track-profile-page-test.js.es6 +++ b/test/javascripts/lib/click-track-profile-page-test.js.es6 @@ -1,4 +1,3 @@ -import { blank } from 'helpers/qunit-helpers'; import DiscourseURL from "discourse/lib/url"; import ClickTrack from "discourse/lib/click-track"; @@ -6,8 +5,8 @@ var windowOpen, win, redirectTo; -module("lib:click-track-profile-page", { - setup: function() { +QUnit.module("lib:click-track-profile-page", { + beforeEach() { // Prevent any of these tests from navigating away win = {focus: function() { } }; @@ -50,56 +49,57 @@ var generateClickEventOn = function(selector) { return $.Event("click", { currentTarget: fixture(selector)[0] }); }; -test("does not track clicks on lightboxes", function() { +QUnit.test("does not track clicks on lightboxes", assert => { var clickEvent = generateClickEventOn('.lightbox'); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); -test("it calls preventDefault when clicking on an a", function() { +QUnit.test("it calls preventDefault when clicking on an a", assert => { var clickEvent = generateClickEventOn('a'); sandbox.stub(clickEvent, "preventDefault"); track(clickEvent); - ok(clickEvent.preventDefault.calledOnce); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(clickEvent.preventDefault.calledOnce); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("does not track clicks when forcibly disabled", function() { - ok(track(generateClickEventOn('.no-track-link'))); +QUnit.test("does not track clicks when forcibly disabled", assert => { + assert.ok(track(generateClickEventOn('.no-track-link'))); }); -test("does not track clicks on back buttons", function() { - ok(track(generateClickEventOn('.back'))); +QUnit.test("does not track clicks on back buttons", assert => { + assert.ok(track(generateClickEventOn('.back'))); }); -test("does not track clicks on quote buttons", function() { - ok(track(generateClickEventOn('.quote-other-topic'))); +QUnit.test("does not track clicks on quote buttons", assert => { + assert.ok(track(generateClickEventOn('.quote-other-topic'))); }); -test("does not track clicks on category badges", () => { - ok(track(generateClickEventOn('.hashtag'))); +QUnit.test("does not track clicks on category badges", assert => { + assert.ok(track(generateClickEventOn('.hashtag'))); }); -test("removes the href and put it as a data attribute", function() { +QUnit.test("removes the href and put it as a data attribute", assert => { track(generateClickEventOn('a')); var $link = fixture('a').first(); - ok($link.hasClass('no-href')); - equal($link.data('href'), 'http://www.google.com'); - blank($link.attr('href')); - ok($link.data('auto-route')); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok($link.hasClass('no-href')); + assert.equal($link.data('href'), 'http://www.google.com'); + assert.blank($link.attr('href')); + assert.ok($link.data('auto-route')); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -asyncTestDiscourse("restores the href after a while", function() { - expect(1); +asyncTestDiscourse("restores the href after a while", function(assert) { + assert.expect(1); track(generateClickEventOn('a')); + const done = assert.async(); setTimeout(function() { - start(); - equal(fixture('a').attr('href'), "http://www.google.com"); + done(); + assert.equal(fixture('a').attr('href'), "http://www.google.com"); }, 75); }); @@ -109,38 +109,38 @@ var trackRightClick = function(target) { return track(clickEvent); }; -test("right clicks change the href", function() { - ok(trackRightClick('a')); - equal(fixture('a').first().prop('href'), "http://www.google.com/"); +QUnit.test("right clicks change the href", assert => { + assert.ok(trackRightClick('a')); + assert.equal(fixture('a').first().prop('href'), "http://www.google.com/"); }); -test("right clicks are tracked", function() { +QUnit.test("right clicks are tracked", assert => { Discourse.SiteSettings.track_external_right_clicks = true; trackRightClick('a'); - equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); + assert.equal(fixture('.first a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); }); -test("right clicks are tracked for second excerpt", function() { +QUnit.test("right clicks are tracked for second excerpt", assert => { Discourse.SiteSettings.track_external_right_clicks = true; trackRightClick('.second a'); - equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"); + assert.equal(fixture('.second a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331"); }); -test("preventDefault is not called for right clicks", function() { +QUnit.test("preventDefault is not called for right clicks", assert => { var clickEvent = generateClickEventOn('a'); clickEvent.which = 3; sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); var testOpenInANewTab = function(description, clickEventModifier) { - test(description, function() { + test(description, function(assert) { var clickEvent = generateClickEventOn('a'); clickEventModifier(clickEvent); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); }; @@ -160,44 +160,44 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent) clickEvent.button = 2; }); -test("tracks via AJAX if we're on the same site", function() { +QUnit.test("tracks via AJAX if we're on the same site", assert => { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('#same-site'))); - ok(DiscourseURL.routeTo.calledOnce); + assert.ok(!track(generateClickEventOn('#same-site'))); + assert.ok(DiscourseURL.routeTo.calledOnce); }); -test("does not track via AJAX for attachments", function() { +QUnit.test("does not track via AJAX for attachments", assert => { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('.attachment'))); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(!track(generateClickEventOn('.attachment'))); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", assert => { var clickEvent = generateClickEventOn('a'); sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true); - ok(!track(clickEvent)); - ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); + assert.ok(!track(clickEvent)); + assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); }); -test("tracks custom urls on second excerpt when opening in another window", function() { +QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => { var clickEvent = generateClickEventOn('.second a'); sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true); - ok(!track(clickEvent)); - ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank')); + assert.ok(!track(clickEvent)); + assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331', '_blank')); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", assert => { var clickEvent = generateClickEventOn('a'); - ok(!track(clickEvent)); - ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); + assert.ok(!track(clickEvent)); + assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); }); -test("tracks custom urls on second excerpt when opening in another window", function() { +QUnit.test("tracks custom urls on second excerpt when opening in another window", assert => { var clickEvent = generateClickEventOn('.second a'); - ok(!track(clickEvent)); - ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331')); + assert.ok(!track(clickEvent)); + assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=24&topic_id=7331')); }); diff --git a/test/javascripts/lib/click-track-test.js.es6 b/test/javascripts/lib/click-track-test.js.es6 index cb05ba7e565..5f33e03374b 100644 --- a/test/javascripts/lib/click-track-test.js.es6 +++ b/test/javascripts/lib/click-track-test.js.es6 @@ -1,4 +1,3 @@ -import { blank } from 'helpers/qunit-helpers'; import DiscourseURL from "discourse/lib/url"; import ClickTrack from "discourse/lib/click-track"; @@ -6,8 +5,8 @@ var windowOpen, win, redirectTo; -module("lib:click-track", { - setup: function() { +QUnit.module("lib:click-track", { + beforeEach() { // Prevent any of these tests from navigating away win = {focus: function() { } }; redirectTo = sandbox.stub(DiscourseURL, "redirectTo"); @@ -47,87 +46,88 @@ var generateClickEventOn = function(selector) { return $.Event("click", { currentTarget: fixture(selector)[0] }); }; -test("does not track clicks on lightboxes", function() { +QUnit.test("does not track clicks on lightboxes", function(assert) { var clickEvent = generateClickEventOn('.lightbox'); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); -test("it calls preventDefault when clicking on an a", function() { +QUnit.test("it calls preventDefault when clicking on an a", function(assert) { var clickEvent = generateClickEventOn('a'); sandbox.stub(clickEvent, "preventDefault"); track(clickEvent); - ok(clickEvent.preventDefault.calledOnce); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(clickEvent.preventDefault.calledOnce); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("does not track clicks when forcibly disabled", function() { - ok(track(generateClickEventOn('.no-track-link'))); +QUnit.test("does not track clicks when forcibly disabled", function(assert) { + assert.ok(track(generateClickEventOn('.no-track-link'))); }); -test("does not track clicks on back buttons", function() { - ok(track(generateClickEventOn('.back'))); +QUnit.test("does not track clicks on back buttons", function(assert) { + assert.ok(track(generateClickEventOn('.back'))); }); -test("does not track clicks in quotes", function() { - ok(track(generateClickEventOn('.inside-quote'))); +QUnit.test("does not track clicks in quotes", function(assert) { + assert.ok(track(generateClickEventOn('.inside-quote'))); }); -test("does not track clicks on quote buttons", function() { - ok(track(generateClickEventOn('.quote-other-topic'))); +QUnit.test("does not track clicks on quote buttons", function(assert) { + assert.ok(track(generateClickEventOn('.quote-other-topic'))); }); -test("does not track clicks on category badges", () => { - ok(track(generateClickEventOn('.hashtag'))); +QUnit.test("does not track clicks on category badges", assert => { + assert.ok(track(generateClickEventOn('.hashtag'))); }); -test("does not track clicks on mailto", function() { - ok(track(generateClickEventOn('.mailto'))); +QUnit.test("does not track clicks on mailto", function(assert) { + assert.ok(track(generateClickEventOn('.mailto'))); }); -test("removes the href and put it as a data attribute", function() { +QUnit.test("removes the href and put it as a data attribute", function(assert) { track(generateClickEventOn('a')); var $link = fixture('a').first(); - ok($link.hasClass('no-href')); - equal($link.data('href'), 'http://www.google.com'); - blank($link.attr('href')); - ok($link.data('auto-route')); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok($link.hasClass('no-href')); + assert.equal($link.data('href'), 'http://www.google.com'); + assert.blank($link.attr('href')); + assert.ok($link.data('auto-route')); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -asyncTestDiscourse("restores the href after a while", function() { - expect(1); +asyncTestDiscourse("restores the href after a while", function(assert) { + assert.expect(1); track(generateClickEventOn('a')); + const done = assert.async(); setTimeout(function() { - start(); - equal(fixture('a').attr('href'), "http://www.google.com"); + done(); + assert.equal(fixture('a').attr('href'), "http://www.google.com"); }, 75); }); -var badgeClickCount = function(id, expected) { +var badgeClickCount = function(assert, id, expected) { track(generateClickEventOn('#' + id)); var $badge = $('span.badge', fixture('#' + id).first()); - equal(parseInt($badge.html(), 10), expected); + assert.equal(parseInt($badge.html(), 10), expected); }; -test("does not update badge clicks on my own link", function() { +QUnit.test("does not update badge clicks on my own link", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(314); - badgeClickCount('with-badge', 1); + badgeClickCount(assert, 'with-badge', 1); }); -test("does not update badge clicks in my own post", function() { +QUnit.test("does not update badge clicks in my own post", function(assert) { sandbox.stub(Discourse.User, 'currentProp').withArgs('id').returns(3141); - badgeClickCount('with-badge-but-not-mine', 1); + badgeClickCount(assert, 'with-badge-but-not-mine', 1); }); -test("updates badge counts correctly", function() { - badgeClickCount('inside-onebox', 1); - badgeClickCount('inside-onebox-forced', 2); - badgeClickCount('with-badge', 2); +QUnit.test("updates badge counts correctly", function(assert) { + badgeClickCount(assert, 'inside-onebox', 1); + badgeClickCount(assert, 'inside-onebox-forced', 2); + badgeClickCount(assert, 'with-badge', 2); }); var trackRightClick = function() { @@ -136,32 +136,32 @@ var trackRightClick = function() { return track(clickEvent); }; -test("right clicks change the href", function() { - ok(trackRightClick()); - equal(fixture('a').first().prop('href'), "http://www.google.com/"); +QUnit.test("right clicks change the href", function(assert) { + assert.ok(trackRightClick()); + assert.equal(fixture('a').first().prop('href'), "http://www.google.com/"); }); -test("right clicks are tracked", function() { +QUnit.test("right clicks are tracked", function(assert) { Discourse.SiteSettings.track_external_right_clicks = true; trackRightClick(); - equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); + assert.equal(fixture('a').first().attr('href'), "/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337"); }); -test("preventDefault is not called for right clicks", function() { +QUnit.test("preventDefault is not called for right clicks", function(assert) { var clickEvent = generateClickEventOn('a'); clickEvent.which = 3; sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); var testOpenInANewTab = function(description, clickEventModifier) { - test(description, function() { + test(description, function(assert) { var clickEvent = generateClickEventOn('a'); clickEventModifier(clickEvent); sandbox.stub(clickEvent, "preventDefault"); - ok(track(clickEvent)); - ok(!clickEvent.preventDefault.calledOnce); + assert.ok(track(clickEvent)); + assert.ok(!clickEvent.preventDefault.calledOnce); }); }; @@ -181,31 +181,31 @@ testOpenInANewTab("it opens in a new tab on middle click", function(clickEvent) clickEvent.button = 2; }); -test("tracks via AJAX if we're on the same site", function() { +QUnit.test("tracks via AJAX if we're on the same site", function(assert) { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('#same-site'))); - ok(DiscourseURL.routeTo.calledOnce); + assert.ok(!track(generateClickEventOn('#same-site'))); + assert.ok(DiscourseURL.routeTo.calledOnce); }); -test("does not track via AJAX for attachments", function() { +QUnit.test("does not track via AJAX for attachments", function(assert) { sandbox.stub(DiscourseURL, "routeTo"); sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com"); - ok(!track(generateClickEventOn('.attachment'))); - ok(DiscourseURL.redirectTo.calledOnce); + assert.ok(!track(generateClickEventOn('.attachment'))); + assert.ok(DiscourseURL.redirectTo.calledOnce); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", function(assert) { var clickEvent = generateClickEventOn('a'); sandbox.stub(Discourse.User, "currentProp").withArgs('external_links_in_new_tab').returns(true); - ok(!track(clickEvent)); - ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); + assert.ok(!track(clickEvent)); + assert.ok(windowOpen.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337', '_blank')); }); -test("tracks custom urls when opening in another window", function() { +QUnit.test("tracks custom urls when opening in another window", function(assert) { var clickEvent = generateClickEventOn('a'); - ok(!track(clickEvent)); - ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); + assert.ok(!track(clickEvent)); + assert.ok(redirectTo.calledWith('/clicks/track?url=http%3A%2F%2Fwww.google.com&post_id=42&topic_id=1337')); }); diff --git a/test/javascripts/lib/computed-test.js.es6 b/test/javascripts/lib/computed-test.js.es6 index 658f35e6757..5c29a3adba0 100644 --- a/test/javascripts/lib/computed-test.js.es6 +++ b/test/javascripts/lib/computed-test.js.es6 @@ -1,29 +1,29 @@ import { setting, propertyEqual, propertyNotEqual, fmt, i18n, url } from 'discourse/lib/computed'; -module("lib:computed", { - setup: function() { +QUnit.module("lib:computed", { + beforeEach() { sandbox.stub(I18n, "t", function(scope) { return "%@ translated: " + scope; }); }, - teardown: function() { + afterEach() { I18n.t.restore(); } }); -test("setting", function() { +QUnit.test("setting", assert => { var t = Em.Object.extend({ vehicle: setting('vehicle'), missingProp: setting('madeUpThing') }).create(); Discourse.SiteSettings.vehicle = "airplane"; - equal(t.get('vehicle'), "airplane", "it has the value of the site setting"); - ok(!t.get('missingProp'), "it is falsy when the site setting is not defined"); + assert.equal(t.get('vehicle'), "airplane", "it has the value of the site setting"); + assert.ok(!t.get('missingProp'), "it is falsy when the site setting is not defined"); }); -test("propertyEqual", function() { +QUnit.test("propertyEqual", assert => { var t = Em.Object.extend({ same: propertyEqual('cookies', 'biscuits') }).create({ @@ -31,12 +31,12 @@ test("propertyEqual", function() { biscuits: 10 }); - ok(t.get('same'), "it is true when the properties are the same"); + assert.ok(t.get('same'), "it is true when the properties are the same"); t.set('biscuits', 9); - ok(!t.get('same'), "it isn't true when one property is different"); + assert.ok(!t.get('same'), "it isn't true when one property is different"); }); -test("propertyNotEqual", function() { +QUnit.test("propertyNotEqual", assert => { var t = Em.Object.extend({ diff: propertyNotEqual('cookies', 'biscuits') }).create({ @@ -44,13 +44,13 @@ test("propertyNotEqual", function() { biscuits: 10 }); - ok(!t.get('diff'), "it isn't true when the properties are the same"); + assert.ok(!t.get('diff'), "it isn't true when the properties are the same"); t.set('biscuits', 9); - ok(t.get('diff'), "it is true when one property is different"); + assert.ok(t.get('diff'), "it is true when one property is different"); }); -test("fmt", function() { +QUnit.test("fmt", assert => { var t = Em.Object.extend({ exclaimyUsername: fmt('username', "!!! %@ !!!"), multiple: fmt('username', 'mood', "%@ is %@") @@ -59,17 +59,17 @@ test("fmt", function() { mood: "happy" }); - equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string"); - equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings"); + assert.equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string"); + assert.equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings"); t.set('username', 'codinghorror'); - equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties"); + assert.equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties"); t.set('mood', 'ecstatic'); - equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property"); + assert.equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property"); }); -test("i18n", function() { +QUnit.test("i18n", assert => { var t = Em.Object.extend({ exclaimyUsername: i18n('username', "!!! %@ !!!"), multiple: i18n('username', 'mood', "%@ is %@") @@ -78,17 +78,17 @@ test("i18n", function() { mood: "happy" }); - equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates"); - equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates"); + assert.equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates"); + assert.equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates"); t.set('username', 'codinghorror'); - equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties"); + assert.equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties"); t.set('mood', 'ecstatic'); - equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property"); + assert.equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property"); }); -test("url", function() { +QUnit.test("url", assert => { var t, testClass; testClass = Em.Object.extend({ @@ -96,9 +96,9 @@ test("url", function() { }); t = testClass.create({ username: 'eviltrout' }); - equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix"); + assert.equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix"); Discourse.BaseUri = "/prefixed"; t = testClass.create({ username: 'eviltrout' }); - equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix"); + assert.equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix"); }); diff --git a/test/javascripts/lib/discourse-test.js.es6 b/test/javascripts/lib/discourse-test.js.es6 index a6547741238..4bafe429abb 100644 --- a/test/javascripts/lib/discourse-test.js.es6 +++ b/test/javascripts/lib/discourse-test.js.es6 @@ -1,7 +1,7 @@ -module("lib:discourse"); +QUnit.module("lib:discourse"); -test("getURL on subfolder install", function() { +QUnit.test("getURL on subfolder install", assert => { Discourse.BaseUri = "/forum"; - equal(Discourse.getURL("/"), "/forum/", "root url has subfolder"); - equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder"); -}); + assert.equal(Discourse.getURL("/"), "/forum/", "root url has subfolder"); + assert.equal(Discourse.getURL("/u/neil"), "/forum/u/neil", "relative url has subfolder"); +}); \ No newline at end of file diff --git a/test/javascripts/lib/emoji-test.js.es6 b/test/javascripts/lib/emoji-test.js.es6 index a9293235371..8512b9f05ce 100644 --- a/test/javascripts/lib/emoji-test.js.es6 +++ b/test/javascripts/lib/emoji-test.js.es6 @@ -1,13 +1,13 @@ import { emojiSearch, IMAGE_VERSION as v } from 'pretty-text/emoji'; import { emojiUnescape } from 'discourse/lib/text'; -module('lib:emoji'); +QUnit.module('lib:emoji'); -function testUnescape(input, expected, description) { - equal(emojiUnescape(input), expected, description); -}; +QUnit.test("emojiUnescape", assert => { + const testUnescape = (input, expected, description) => { + assert.equal(emojiUnescape(input), expected, description); + }; -test("emojiUnescape", () => { testUnescape("Not emoji :O) :frog) :smile)", "Not emoji :O) :frog) :smile)", "title without emoji"); testUnescape("Not emoji :frog :smile", "Not emoji :frog :smile", "end colon is not optional"); testUnescape("emoticons :)", `emoticons slight_smile`, "emoticons are still supported"); @@ -24,11 +24,11 @@ test("emojiUnescape", () => { }); -test("Emoji search", () => { +QUnit.test("Emoji search", assert => { // able to find an alias - equal(emojiSearch("+1").length, 1); + assert.equal(emojiSearch("+1").length, 1); // able to find middle of line search - equal(emojiSearch("check", {maxResults: 3}).length, 3); + assert.equal(emojiSearch("check", {maxResults: 3}).length, 3); }); diff --git a/test/javascripts/lib/formatter-test.js.es6 b/test/javascripts/lib/formatter-test.js.es6 index 31be0668ad8..9e929e1853e 100644 --- a/test/javascripts/lib/formatter-test.js.es6 +++ b/test/javascripts/lib/formatter-test.js.es6 @@ -2,12 +2,12 @@ var clock; import { relativeAge, autoUpdatingRelativeAge, updateRelativeAge, breakUp, number, longDate } from 'discourse/lib/formatter'; -module("lib:formatter", { - setup: function() { +QUnit.module("lib:formatter", { + beforeEach() { clock = sinon.useFakeTimers(new Date(2012,11,31,12,0).getTime()); }, - teardown: function() { + afterEach() { clock.restore(); } }); @@ -34,7 +34,7 @@ var shortDate = function(days){ return moment().subtract(days, 'days').format('MMM D'); }; -test("formating medium length dates", function() { +QUnit.test("formating medium length dates", assert => { format = "medium"; var strip = function(html){ @@ -46,133 +46,133 @@ test("formating medium length dates", function() { }; leaveAgo = true; - equal(strip(formatMins(1.4)), "1 min ago"); - equal(strip(formatMins(2)), "2 mins ago"); - equal(strip(formatMins(55)), "55 mins ago"); - equal(strip(formatMins(56)), "1 hour ago"); - equal(strip(formatHours(4)), "4 hours ago"); - equal(strip(formatHours(22)), "22 hours ago"); - equal(strip(formatHours(23)), "23 hours ago"); - equal(strip(formatHours(23.5)), "1 day ago"); - equal(strip(formatDays(4.85)), "4 days ago"); + assert.equal(strip(formatMins(1.4)), "1 min ago"); + assert.equal(strip(formatMins(2)), "2 mins ago"); + assert.equal(strip(formatMins(55)), "55 mins ago"); + assert.equal(strip(formatMins(56)), "1 hour ago"); + assert.equal(strip(formatHours(4)), "4 hours ago"); + assert.equal(strip(formatHours(22)), "22 hours ago"); + assert.equal(strip(formatHours(23)), "23 hours ago"); + assert.equal(strip(formatHours(23.5)), "1 day ago"); + assert.equal(strip(formatDays(4.85)), "4 days ago"); leaveAgo = false; - equal(strip(formatMins(0)), "just now"); - equal(strip(formatMins(1.4)), "1 min"); - equal(strip(formatMins(2)), "2 mins"); - equal(strip(formatMins(55)), "55 mins"); - equal(strip(formatMins(56)), "1 hour"); - equal(strip(formatHours(4)), "4 hours"); - equal(strip(formatHours(22)), "22 hours"); - equal(strip(formatHours(23)), "23 hours"); - equal(strip(formatHours(23.5)), "1 day"); - equal(strip(formatDays(4.85)), "4 days"); + assert.equal(strip(formatMins(0)), "just now"); + assert.equal(strip(formatMins(1.4)), "1 min"); + assert.equal(strip(formatMins(2)), "2 mins"); + assert.equal(strip(formatMins(55)), "55 mins"); + assert.equal(strip(formatMins(56)), "1 hour"); + assert.equal(strip(formatHours(4)), "4 hours"); + assert.equal(strip(formatHours(22)), "22 hours"); + assert.equal(strip(formatHours(23)), "23 hours"); + assert.equal(strip(formatHours(23.5)), "1 day"); + assert.equal(strip(formatDays(4.85)), "4 days"); - equal(strip(formatDays(6)), shortDate(6)); - equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23 - equal(strip(formatDays(500)), shortDateYear(500)); + assert.equal(strip(formatDays(6)), shortDate(6)); + assert.equal(strip(formatDays(100)), shortDate(100)); // eg: Jan 23 + assert.equal(strip(formatDays(500)), shortDateYear(500)); - equal($(formatDays(0)).attr("title"), longDate(new Date())); - equal($(formatDays(0)).attr("class"), "date"); + assert.equal($(formatDays(0)).attr("title"), longDate(new Date())); + assert.equal($(formatDays(0)).attr("class"), "date"); clock.restore(); clock = sinon.useFakeTimers(new Date(2012,0,9,12,0).getTime()); // Jan 9, 2012 - equal(strip(formatDays(8)), shortDate(8)); - equal(strip(formatDays(10)), shortDateYear(10)); + assert.equal(strip(formatDays(8)), shortDate(8)); + assert.equal(strip(formatDays(10)), shortDateYear(10)); }); -test("formating tiny dates", function() { +QUnit.test("formating tiny dates", assert => { var shortDateYear = function(days){ return moment().subtract(days, 'days').format("MMM 'YY"); }; format = "tiny"; - equal(formatMins(0), "1m"); - equal(formatMins(1), "1m"); - equal(formatMins(2), "2m"); - equal(formatMins(60), "1h"); - equal(formatHours(4), "4h"); - equal(formatHours(23), "23h"); - equal(formatHours(23.5), "1d"); - equal(formatDays(1), "1d"); - equal(formatDays(14), "14d"); - equal(formatDays(15), shortDate(15)); - equal(formatDays(92), shortDate(92)); - equal(formatDays(364), shortDate(364)); - equal(formatDays(365), shortDate(365)); - equal(formatDays(366), shortDateYear(366)); // leap year - equal(formatDays(500), shortDateYear(500)); - equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year + assert.equal(formatMins(0), "1m"); + assert.equal(formatMins(1), "1m"); + assert.equal(formatMins(2), "2m"); + assert.equal(formatMins(60), "1h"); + assert.equal(formatHours(4), "4h"); + assert.equal(formatHours(23), "23h"); + assert.equal(formatHours(23.5), "1d"); + assert.equal(formatDays(1), "1d"); + assert.equal(formatDays(14), "14d"); + assert.equal(formatDays(15), shortDate(15)); + assert.equal(formatDays(92), shortDate(92)); + assert.equal(formatDays(364), shortDate(364)); + assert.equal(formatDays(365), shortDate(365)); + assert.equal(formatDays(366), shortDateYear(366)); // leap year + assert.equal(formatDays(500), shortDateYear(500)); + assert.equal(formatDays(365*2 + 1), shortDateYear(365*2 + 1)); // one leap year var originalValue = Discourse.SiteSettings.relative_date_duration; Discourse.SiteSettings.relative_date_duration = 7; - equal(formatDays(7), "7d"); - equal(formatDays(8), shortDate(8)); + assert.equal(formatDays(7), "7d"); + assert.equal(formatDays(8), shortDate(8)); Discourse.SiteSettings.relative_date_duration = 1; - equal(formatDays(1), "1d"); - equal(formatDays(2), shortDate(2)); + assert.equal(formatDays(1), "1d"); + assert.equal(formatDays(2), shortDate(2)); Discourse.SiteSettings.relative_date_duration = 0; - equal(formatMins(0), "1m"); - equal(formatMins(1), "1m"); - equal(formatMins(2), "2m"); - equal(formatMins(60), "1h"); - equal(formatDays(1), shortDate(1)); - equal(formatDays(2), shortDate(2)); - equal(formatDays(366), shortDateYear(366)); + assert.equal(formatMins(0), "1m"); + assert.equal(formatMins(1), "1m"); + assert.equal(formatMins(2), "2m"); + assert.equal(formatMins(60), "1h"); + assert.equal(formatDays(1), shortDate(1)); + assert.equal(formatDays(2), shortDate(2)); + assert.equal(formatDays(366), shortDateYear(366)); Discourse.SiteSettings.relative_date_duration = null; - equal(formatDays(1), '1d'); - equal(formatDays(14), '14d'); - equal(formatDays(15), shortDate(15)); + assert.equal(formatDays(1), '1d'); + assert.equal(formatDays(14), '14d'); + assert.equal(formatDays(15), shortDate(15)); Discourse.SiteSettings.relative_date_duration = 14; clock.restore(); clock = sinon.useFakeTimers(new Date(2012,0,12,12,0).getTime()); // Jan 12, 2012 - equal(formatDays(11), "11d"); - equal(formatDays(14), "14d"); - equal(formatDays(15), shortDateYear(15)); - equal(formatDays(366), shortDateYear(366)); + assert.equal(formatDays(11), "11d"); + assert.equal(formatDays(14), "14d"); + assert.equal(formatDays(15), shortDateYear(15)); + assert.equal(formatDays(366), shortDateYear(366)); clock.restore(); clock = sinon.useFakeTimers(new Date(2012,0,20,12,0).getTime()); // Jan 20, 2012 - equal(formatDays(14), "14d"); - equal(formatDays(15), shortDate(15)); - equal(formatDays(20), shortDateYear(20)); + assert.equal(formatDays(14), "14d"); + assert.equal(formatDays(15), shortDate(15)); + assert.equal(formatDays(20), shortDateYear(20)); Discourse.SiteSettings.relative_date_duration = originalValue; }); -test("autoUpdatingRelativeAge", function() { +QUnit.test("autoUpdatingRelativeAge", assert => { var d = moment().subtract(1, 'day').toDate(); var $elem = $(autoUpdatingRelativeAge(d)); - equal($elem.data('format'), "tiny"); - equal($elem.data('time'), d.getTime()); - equal($elem.attr('title'), undefined); + assert.equal($elem.data('format'), "tiny"); + assert.equal($elem.data('time'), d.getTime()); + assert.equal($elem.attr('title'), undefined); $elem = $(autoUpdatingRelativeAge(d, {title: true})); - equal($elem.attr('title'), longDate(d)); + assert.equal($elem.attr('title'), longDate(d)); $elem = $(autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true})); - equal($elem.data('format'), "medium-with-ago"); - equal($elem.data('time'), d.getTime()); - equal($elem.attr('title'), longDate(d)); - equal($elem.html(), '1 day ago'); + assert.equal($elem.data('format'), "medium-with-ago"); + assert.equal($elem.data('time'), d.getTime()); + assert.equal($elem.attr('title'), longDate(d)); + assert.equal($elem.html(), '1 day ago'); $elem = $(autoUpdatingRelativeAge(d,{format: 'medium'})); - equal($elem.data('format'), "medium"); - equal($elem.data('time'), d.getTime()); - equal($elem.attr('title'), undefined); - equal($elem.html(), '1 day'); + assert.equal($elem.data('format'), "medium"); + assert.equal($elem.data('time'), d.getTime()); + assert.equal($elem.attr('title'), undefined); + assert.equal($elem.html(), '1 day'); }); -test("updateRelativeAge", function(){ +QUnit.test("updateRelativeAge", assert =>{ var d = new Date(); var $elem = $(autoUpdatingRelativeAge(d)); @@ -180,7 +180,7 @@ test("updateRelativeAge", function(){ updateRelativeAge($elem); - equal($elem.html(), "2m"); + assert.equal($elem.html(), "2m"); d = new Date(); $elem = $(autoUpdatingRelativeAge(d, {format: 'medium', leaveAgo: true})); @@ -188,27 +188,27 @@ test("updateRelativeAge", function(){ updateRelativeAge($elem); - equal($elem.html(), "2 mins ago"); + assert.equal($elem.html(), "2 mins ago"); }); -test("breakUp", function(){ +QUnit.test("breakUp", assert =>{ var b = function(s,hint){ return breakUp(s,hint); }; - equal(b("hello"), "hello"); - equal(b("helloworld"), "helloworld"); - equal(b("HeMans11"), "He​Mans​11"); - equal(b("he_man"), "he_​man"); - equal(b("he11111"), "he​11111"); - equal(b("HRCBob"), "HRC​Bob"); - equal(b("bobmarleytoo","Bob Marley Too"), "bob​marley​too"); + assert.equal(b("hello"), "hello"); + assert.equal(b("helloworld"), "helloworld"); + assert.equal(b("HeMans11"), "He​Mans​11"); + assert.equal(b("he_man"), "he_​man"); + assert.equal(b("he11111"), "he​11111"); + assert.equal(b("HRCBob"), "HRC​Bob"); + assert.equal(b("bobmarleytoo","Bob Marley Too"), "bob​marley​too"); }); -test("number", function() { - equal(number(123), "123", "it returns a string version of the number"); - equal(number("123"), "123", "it works with a string command"); - equal(number(NaN), "0", "it returns 0 for NaN"); - equal(number(3333), "3.3k", "it abbreviates thousands"); - equal(number(2499999), "2.5M", "it abbreviates millions"); -}); +QUnit.test("number", assert => { + assert.equal(number(123), "123", "it returns a string version of the number"); + assert.equal(number("123"), "123", "it works with a string command"); + assert.equal(number(NaN), "0", "it returns 0 for NaN"); + assert.equal(number(3333), "3.3k", "it abbreviates thousands"); + assert.equal(number(2499999), "2.5M", "it abbreviates millions"); +}); \ No newline at end of file diff --git a/test/javascripts/lib/i18n-test.js.es6 b/test/javascripts/lib/i18n-test.js.es6 index 9fbfa7beacc..314c4cc6938 100644 --- a/test/javascripts/lib/i18n-test.js.es6 +++ b/test/javascripts/lib/i18n-test.js.es6 @@ -1,8 +1,8 @@ -module("lib:i18n", { +QUnit.module("lib:i18n", { _locale: I18n.locale, _translations: I18n.translations, - setup() { + beforeEach() { I18n.locale = "fr"; I18n.translations = { @@ -54,42 +54,42 @@ module("lib:i18n", { }; }, - teardown() { + afterEach() { I18n.locale = this._locale; I18n.translations = this._translations; } }); -test("defaults", function() { - equal(I18n.defaultLocale, "en", "it has English as default locale"); - ok(I18n.pluralizationRules["en"], "it has English pluralizer"); +QUnit.test("defaults", assert => { + assert.equal(I18n.defaultLocale, "en", "it has English as default locale"); + assert.ok(I18n.pluralizationRules["en"], "it has English pluralizer"); }); -test("translations", function() { - equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist"); - equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations"); - equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale"); - equal(I18n.t("hello.universe"), "", "allows empty strings"); +QUnit.test("translations", assert => { + assert.equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist"); + assert.equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations"); + assert.equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale"); + assert.equal(I18n.t("hello.universe"), "", "allows empty strings"); }); -test("extra translations", function() { +QUnit.test("extra translations", assert => { I18n.extras = [{ "admin": { "title": "Discourse Admin" }}]; - equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists"); + assert.equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists"); }); -test("pluralizations", function() { - equal(I18n.t("character_count", { count: 0 }), "0 ZERO"); - equal(I18n.t("character_count", { count: 1 }), "1 ONE"); - equal(I18n.t("character_count", { count: 2 }), "2 TWO"); - equal(I18n.t("character_count", { count: 3 }), "3 FEW"); - equal(I18n.t("character_count", { count: 10 }), "10 MANY"); - equal(I18n.t("character_count", { count: 100 }), "100 OTHER"); +QUnit.test("pluralizations", assert => { + assert.equal(I18n.t("character_count", { count: 0 }), "0 ZERO"); + assert.equal(I18n.t("character_count", { count: 1 }), "1 ONE"); + assert.equal(I18n.t("character_count", { count: 2 }), "2 TWO"); + assert.equal(I18n.t("character_count", { count: 3 }), "3 FEW"); + assert.equal(I18n.t("character_count", { count: 10 }), "10 MANY"); + assert.equal(I18n.t("character_count", { count: 100 }), "100 OTHER"); - equal(I18n.t("word_count", { count: 0 }), "0 words"); - equal(I18n.t("word_count", { count: 1 }), "1 word"); - equal(I18n.t("word_count", { count: 2 }), "2 words"); - equal(I18n.t("word_count", { count: 3 }), "3 words"); - equal(I18n.t("word_count", { count: 10 }), "10 words"); - equal(I18n.t("word_count", { count: 100 }), "100 words"); -}); + assert.equal(I18n.t("word_count", { count: 0 }), "0 words"); + assert.equal(I18n.t("word_count", { count: 1 }), "1 word"); + assert.equal(I18n.t("word_count", { count: 2 }), "2 words"); + assert.equal(I18n.t("word_count", { count: 3 }), "3 words"); + assert.equal(I18n.t("word_count", { count: 10 }), "10 words"); + assert.equal(I18n.t("word_count", { count: 100 }), "100 words"); +}); \ No newline at end of file diff --git a/test/javascripts/lib/key-value-store-test.js.es6 b/test/javascripts/lib/key-value-store-test.js.es6 index 8f1b0ae4003..1bbafcc5cbc 100644 --- a/test/javascripts/lib/key-value-store-test.js.es6 +++ b/test/javascripts/lib/key-value-store-test.js.es6 @@ -1,18 +1,18 @@ import KeyValueStore from "discourse/lib/key-value-store"; -module("lib:key-value-store"); +QUnit.module("lib:key-value-store"); -test("it's able to get the result back from the store", (assert) => { +QUnit.test("it's able to get the result back from the store", (assert) => { const store = new KeyValueStore("_test"); store.set({ key: "bob", value: "uncle" }); assert.equal(store.get("bob"), "uncle"); }); -test("is able to nuke the store", (assert) => { +QUnit.test("is able to nuke the store", (assert) => { const store = new KeyValueStore("_test"); store.set({ key: "bob1", value: "uncle" }); store.abandonLocal(); localStorage.a = 1; assert.equal(store.get("bob1"), void 0); assert.equal(localStorage.a, "1"); -}); +}); \ No newline at end of file diff --git a/test/javascripts/lib/preload-store-test.js.es6 b/test/javascripts/lib/preload-store-test.js.es6 index 391ac3d2f1e..26f8d04059c 100644 --- a/test/javascripts/lib/preload-store-test.js.es6 +++ b/test/javascripts/lib/preload-store-test.js.es6 @@ -1,74 +1,78 @@ -import { blank } from 'helpers/qunit-helpers'; import PreloadStore from 'preload-store'; -module("preload-store", { - setup() { +QUnit.module("preload-store", { + beforeEach() { PreloadStore.store('bane', 'evil'); } }); -test("get", function() { - blank(PreloadStore.get('joker'), "returns blank for a missing key"); - equal(PreloadStore.get('bane'), 'evil', "returns the value for that key"); +QUnit.test("get", assert => { + assert.blank(PreloadStore.get('joker'), "returns blank for a missing key"); + assert.equal(PreloadStore.get('bane'), 'evil', "returns the value for that key"); }); -test("remove", function() { +QUnit.test("remove", assert => { PreloadStore.remove('bane'); - blank(PreloadStore.get('bane'), "removes the value if the key exists"); + assert.blank(PreloadStore.get('bane'), "removes the value if the key exists"); }); -asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function() { - expect(1); +asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function(assert) { + assert.expect(1); + const done = assert.async(); PreloadStore.getAndRemove('joker').then(function(result) { - blank(result); - start(); + assert.blank(result); + done(); }); }); -asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function() { - expect(1); +asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function(assert) { + assert.expect(1); - var finder = function() { return 'batdance'; }; + const done = assert.async(); + const finder = function() { return 'batdance'; }; PreloadStore.getAndRemove('joker', finder).then(function(result) { - equal(result, 'batdance'); - start(); + assert.equal(result, 'batdance'); + done(); }); }); -asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function() { - expect(1); +asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function(assert) { + assert.expect(1); - var finder = function() { + const finder = function() { return new Ember.RSVP.Promise(function(resolve) { resolve('hahahah'); }); }; + const done = assert.async(); PreloadStore.getAndRemove('joker', finder).then(function(result) { - equal(result, 'hahahah'); - start(); + assert.equal(result, 'hahahah'); + done(); }); }); -asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function() { - expect(1); +asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function(assert) { + assert.expect(1); - var finder = function() { + const finder = function() { return new Ember.RSVP.Promise(function(resolve, reject) { reject('error'); }); }; + const done = assert.async(); PreloadStore.getAndRemove('joker', finder).then(null, function(result) { - equal(result, 'error'); - start(); + assert.equal(result, 'error'); + done(); }); }); -asyncTestDiscourse("returns a promise that resolves to 'evil'", function() { - expect(1); +asyncTestDiscourse("returns a promise that resolves to 'evil'", function(assert) { + assert.expect(1); + const done = assert.async(); PreloadStore.getAndRemove('bane').then(function(result) { - equal(result, 'evil'); - start(); + assert.equal(result, 'evil'); + done(); }); }); diff --git a/test/javascripts/lib/pretty-text-test.js.es6 b/test/javascripts/lib/pretty-text-test.js.es6 index 72c1adf30b9..558c105e3fd 100644 --- a/test/javascripts/lib/pretty-text-test.js.es6 +++ b/test/javascripts/lib/pretty-text-test.js.es6 @@ -3,7 +3,7 @@ import Post from 'discourse/models/post'; import { default as PrettyText, buildOptions } from 'pretty-text/pretty-text'; import { IMAGE_VERSION as v} from 'pretty-text/emoji'; -module("lib:pretty-text"); +QUnit.module("lib:pretty-text"); const defaultOpts = buildOptions({ siteSettings: { @@ -17,602 +17,614 @@ const defaultOpts = buildOptions({ getURL: url => url }); -function cooked(input, expected, text) { - equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text); +QUnit.assert.cooked = function(input, expected, message) { + const actual = new PrettyText(defaultOpts).cook(input); + this.pushResult({ + result: actual === expected.replace(/\/>/g, ">"), + actual, + expected, + message + }); }; -function cookedOptions(input, opts, expected, text) { - equal(new PrettyText(_.merge({}, defaultOpts, opts)).cook(input), expected, text); +QUnit.assert.cookedOptions = function(input, opts, expected, message) { + const actual = new PrettyText(_.merge({}, defaultOpts, opts)).cook(input); + this.pushResult({ + result: actual === expected, + actual, + expected, + message + }); }; -function cookedPara(input, expected, text) { - cooked(input, `

${expected}

`, text); +QUnit.assert.cookedPara = function(input, expected, message) { + QUnit.assert.cooked(input, `

${expected}

`, message); }; -test("buildOptions", () => { - ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled'); - ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled'); +QUnit.test("buildOptions", assert => { + assert.ok(buildOptions({ siteSettings: { allow_html_tables: true } }).features.table, 'tables enabled'); + assert.ok(!buildOptions({ siteSettings: { allow_html_tables: false } }).features.table, 'tables disabled'); - ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled'); - ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled'); + assert.ok(buildOptions({ siteSettings: { enable_emoji: true } }).features.emoji, 'emoji enabled'); + assert.ok(!buildOptions({ siteSettings: { enable_emoji: false } }).features.emoji, 'emoji disabled'); }); -test("basic cooking", function() { - cooked("hello", "

hello

", "surrounds text with paragraphs"); - cooked("**evil**", "

evil

", "it bolds text."); - cooked("__bold__", "

bold

", "it bolds text."); - cooked("*trout*", "

trout

", "it italicizes text."); - cooked("_trout_", "

trout

", "it italicizes text."); - cooked("***hello***", "

hello

", "it can do bold and italics at once."); - cooked("word_with_underscores", "

word_with_underscores

", "it doesn't do intraword italics"); - cooked("common/_special_font_face.html.erb", "

common/_special_font_face.html.erb

", "it doesn't intraword with a slash"); - cooked("hello \\*evil\\*", "

hello *evil*

", "it supports escaping of asterisks"); - cooked("hello \\_evil\\_", "

hello _evil_

", "it supports escaping of italics"); - cooked("brussels sprouts are *awful*.", "

brussels sprouts are awful.

", "it doesn't swallow periods."); +QUnit.test("basic cooking", assert => { + assert.cooked("hello", "

hello

", "surrounds text with paragraphs"); + assert.cooked("**evil**", "

evil

", "it bolds text."); + assert.cooked("__bold__", "

bold

", "it bolds text."); + assert.cooked("*trout*", "

trout

", "it italicizes text."); + assert.cooked("_trout_", "

trout

", "it italicizes text."); + assert.cooked("***hello***", "

hello

", "it can do bold and italics at once."); + assert.cooked("word_with_underscores", "

word_with_underscores

", "it doesn't do intraword italics"); + assert.cooked("common/_special_font_face.html.erb", "

common/_special_font_face.html.erb

", "it doesn't intraword with a slash"); + assert.cooked("hello \\*evil\\*", "

hello *evil*

", "it supports escaping of asterisks"); + assert.cooked("hello \\_evil\\_", "

hello _evil_

", "it supports escaping of italics"); + assert.cooked("brussels sprouts are *awful*.", "

brussels sprouts are awful.

", "it doesn't swallow periods."); }); -test("Nested bold and italics", function() { - cooked("*this is italic **with some bold** inside*", "

this is italic with some bold inside

", "it handles nested bold in italics"); +QUnit.test("Nested bold and italics", assert => { + assert.cooked("*this is italic **with some bold** inside*", "

this is italic with some bold inside

", "it handles nested bold in italics"); }); -test("Traditional Line Breaks", function() { +QUnit.test("Traditional Line Breaks", assert => { const input = "1\n2\n3"; - cooked(input, "

1
2
3

", "automatically handles trivial newlines"); + assert.cooked(input, "

1
2
3

", "automatically handles trivial newlines"); const result = new PrettyText({ traditionalMarkdownLinebreaks: true }).cook(input); - equal(result, "

1\n2\n3

"); + assert.equal(result, "

1\n2\n3

"); }); -test("Unbalanced underscores", function() { - cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "

evil_trout hello_

"); +QUnit.test("Unbalanced underscores", assert => { + assert.cooked("[evil_trout][1] hello_\n\n[1]: http://eviltrout.com", "

evil_trout hello_

"); }); -test("Line Breaks", function() { - cooked("[] first choice\n[] second choice", +QUnit.test("Line Breaks", assert => { + assert.cooked("[] first choice\n[] second choice", "

[] first choice
[] second choice

", "it handles new lines correctly with [] options"); - cooked("
evil
\ntrout", + assert.cooked("
evil
\ntrout", "
evil
\n\n

trout

", "it doesn't insert
after blockquotes"); - cooked("leading
evil
\ntrout", + assert.cooked("leading
evil
\ntrout", "leading
evil
\n\n

trout

", "it doesn't insert
after blockquotes with leading text"); }); -test("Paragraphs for HTML", function() { - cooked("
hello world
", "
hello world
", "it doesn't surround
with paragraphs"); - cooked("

hello world

", "

hello world

", "it doesn't surround

with paragraphs"); - cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); - cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); +QUnit.test("Paragraphs for HTML", assert => { + assert.cooked("
hello world
", "
hello world
", "it doesn't surround
with paragraphs"); + assert.cooked("

hello world

", "

hello world

", "it doesn't surround

with paragraphs"); + assert.cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); + assert.cooked("hello world", "

hello world

", "it surrounds inline html tags with paragraphs"); }); -test("Links", function() { +QUnit.test("Links", assert => { - cooked("EvilTrout: http://eviltrout.com", + assert.cooked("EvilTrout: http://eviltrout.com", '

EvilTrout: http://eviltrout.com

', "autolinks a URL"); - cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A", + assert.cooked("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A", '

Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A

', "allows links to contain query params"); - cooked("Derpy: http://derp.com?__test=1", + assert.cooked("Derpy: http://derp.com?__test=1", '

Derpy: http://derp.com?__test=1

', "works with double underscores in urls"); - cooked("Derpy: http://derp.com?_test_=1", + assert.cooked("Derpy: http://derp.com?_test_=1", '

Derpy: http://derp.com?_test_=1

', "works with underscores in urls"); - cooked("Atwood: www.codinghorror.com", + assert.cooked("Atwood: www.codinghorror.com", '

Atwood: www.codinghorror.com

', "autolinks something that begins with www"); - cooked("Atwood: http://www.codinghorror.com", + assert.cooked("Atwood: http://www.codinghorror.com", '

Atwood: http://www.codinghorror.com

', "autolinks a URL with http://www"); - cooked("EvilTrout: http://eviltrout.com hello", + assert.cooked("EvilTrout: http://eviltrout.com hello", '

EvilTrout: http://eviltrout.com hello

', "autolinks with trailing text"); - cooked("here is [an example](http://twitter.com)", + assert.cooked("here is [an example](http://twitter.com)", '

here is an example

', "supports markdown style links"); - cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)", + assert.cooked("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)", '

Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)

', "autolinks a URL with parentheses (like Wikipedia)"); - cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200", + assert.cooked("Here's a tweet:\nhttps://twitter.com/evil_trout/status/345954894420787200", "

Here's a tweet:
https://twitter.com/evil_trout/status/345954894420787200

", "It doesn't strip the new line."); - cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity
next line.", + assert.cooked("1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity
next line.", "
  1. View @eviltrout's profile here: http://meta.discourse.org/u/eviltrout/activity
    next line.
", "allows autolinking within a list without inserting a paragraph."); - cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references"); + assert.cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references"); - cooked("[]: http://eviltrout.com", "

[]: http://eviltrout.com

", "It doesn't accept empty link references"); + assert.cooked("[]: http://eviltrout.com", "

[]: http://eviltrout.com

", "It doesn't accept empty link references"); - cooked("[b]label[/b]: description", "

label: description

", "It doesn't accept BBCode as link references"); + assert.cooked("[b]label[/b]: description", "

label: description

", "It doesn't accept BBCode as link references"); - cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369", + assert.cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369", "

http://discourse.org and " + "http://discourse.org/another_url and " + "http://www.imdb.com/name/nm2225369

", 'allows multiple links on one line'); - cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com", + assert.cooked("* [Evil Trout][1]\n [1]: http://eviltrout.com", "", "allows markdown link references in a list"); - cooked("User [MOD]: Hello!", + assert.cooked("User [MOD]: Hello!", "

User [MOD]: Hello!

", "It does not consider references that are obviously not URLs"); - cooked("http://eviltrout.com", "

http://eviltrout.com

", "Links within HTML tags"); + assert.cooked("http://eviltrout.com", "

http://eviltrout.com

", "Links within HTML tags"); - cooked("[http://google.com ... wat](http://discourse.org)", + assert.cooked("[http://google.com ... wat](http://discourse.org)", "

http://google.com ... wat

", "it supports links within links"); - cooked("[http://google.com](http://discourse.org)", + assert.cooked("[http://google.com](http://discourse.org)", "

http://google.com

", "it supports markdown links where the name and link match"); - cooked("[Link](http://www.example.com) (with an outer \"description\")", + assert.cooked("[Link](http://www.example.com) (with an outer \"description\")", "

Link (with an outer \"description\")

", "it doesn't consume closing parens as part of the url"); - cooked("A link inside parentheses (http://www.example.com)", + assert.cooked("A link inside parentheses (http://www.example.com)", "

A link inside parentheses (http://www.example.com)

", "it auto-links a url within parentheses"); - cooked("[ul][1]\n\n[1]: http://eviltrout.com", + assert.cooked("[ul][1]\n\n[1]: http://eviltrout.com", "

ul

", "it can use `ul` as a link name"); }); -test("simple quotes", function() { - cooked("> nice!", "

nice!

", "it supports simple quotes"); - cooked(" > nice!", "

nice!

", "it allows quotes with preceding spaces"); - cooked("> level 1\n> > level 2", +QUnit.test("simple quotes", assert => { + assert.cooked("> nice!", "

nice!

", "it supports simple quotes"); + assert.cooked(" > nice!", "

nice!

", "it allows quotes with preceding spaces"); + assert.cooked("> level 1\n> > level 2", "

level 1

level 2

", "it allows nesting of blockquotes"); - cooked("> level 1\n> > level 2", + assert.cooked("> level 1\n> > level 2", "

level 1

level 2

", "it allows nesting of blockquotes with spaces"); - cooked("- hello\n\n > world\n > eviltrout", + assert.cooked("- hello\n\n > world\n > eviltrout", "
  • hello
\n\n

world
eviltrout

", "it allows quotes within a list."); - cooked("-

eviltrout

", + assert.cooked("-

eviltrout

", "
  • eviltrout

", "it allows paragraphs within a list."); - cooked(" > indent 1\n > indent 2", "

indent 1
indent 2

", "allow multiple spaces to indent"); + assert.cooked(" > indent 1\n > indent 2", "

indent 1
indent 2

", "allow multiple spaces to indent"); }); -test("Quotes", function() { +QUnit.test("Quotes", assert => { - cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]", + assert.cookedOptions("[quote=\"eviltrout, post: 1\"]\na quote\n\nsecond line\n\nthird line[/quote]", { topicId: 2 }, "", "works with multiple lines"); - cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", + assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function(name) { return "" + name; }, sanitize: true }, "

1

\n\n\n\n

2

", "handles quotes properly"); - cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", + assert.cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function() { } }, "

1

\n\n\n\n

2

", "includes no avatar if none is found"); - cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`, + assert.cooked(`[quote]\na\n\n[quote]\nb\n[/quote]\n[/quote]`, "

", "handles nested quotes properly"); }); -test("Mentions", function() { +QUnit.test("Mentions", assert => { const alwaysTrue = { mentionLookup: (function() { return "user"; }) }; - cookedOptions("Hello @sam", alwaysTrue, + assert.cookedOptions("Hello @sam", alwaysTrue, "

Hello @sam

", "translates mentions to links"); - cooked("[@codinghorror](https://twitter.com/codinghorror)", + assert.cooked("[@codinghorror](https://twitter.com/codinghorror)", "

@codinghorror

", "it doesn't do mentions within links"); - cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue, + assert.cookedOptions("[@codinghorror](https://twitter.com/codinghorror)", alwaysTrue, "

@codinghorror

", "it doesn't do link mentions within links"); - cooked("Hello @EvilTrout", + assert.cooked("Hello @EvilTrout", "

Hello @EvilTrout

", "adds a mention class"); - cooked("robin@email.host", + assert.cooked("robin@email.host", "

robin@email.host

", "won't add mention class to an email address"); - cooked("hanzo55@yahoo.com", + assert.cooked("hanzo55@yahoo.com", "

hanzo55@yahoo.com

", "won't be affected by email addresses that have a number before the @ symbol"); - cooked("@EvilTrout yo", + assert.cooked("@EvilTrout yo", "

@EvilTrout yo

", "it handles mentions at the beginning of a string"); - cooked("yo\n@EvilTrout", + assert.cooked("yo\n@EvilTrout", "

yo
@EvilTrout

", "it handles mentions at the beginning of a new line"); - cooked("`evil` @EvilTrout `trout`", + assert.cooked("`evil` @EvilTrout `trout`", "

evil @EvilTrout trout

", "deals correctly with multiple blocks"); - cooked("```\na @test\n```", + assert.cooked("```\na @test\n```", "

a @test

", "should not do mentions within a code block."); - cooked("> foo bar baz @eviltrout", + assert.cooked("> foo bar baz @eviltrout", "

foo bar baz @eviltrout

", "handles mentions in simple quotes"); - cooked("> foo bar baz @eviltrout ohmagerd\nlook at this", + assert.cooked("> foo bar baz @eviltrout ohmagerd\nlook at this", "

foo bar baz @eviltrout ohmagerd
look at this

", "does mentions properly with trailing text within a simple quote"); - cooked("`code` is okay before @mention", + assert.cooked("`code` is okay before @mention", "

code is okay before @mention

", "Does not mention in an inline code block"); - cooked("@mention is okay before `code`", + assert.cooked("@mention is okay before `code`", "

@mention is okay before code

", "Does not mention in an inline code block"); - cooked("don't `@mention`", + assert.cooked("don't `@mention`", "

don't @mention

", "Does not mention in an inline code block"); - cooked("Yes `@this` should be code @eviltrout", + assert.cooked("Yes `@this` should be code @eviltrout", "

Yes @this should be code @eviltrout

", "Does not mention in an inline code block"); - cooked("@eviltrout and `@eviltrout`", + assert.cooked("@eviltrout and `@eviltrout`", "

@eviltrout and @eviltrout

", "you can have a mention in an inline code block following a real mention."); - cooked("1. this is a list\n\n2. this is an @eviltrout mention\n", + assert.cooked("1. this is a list\n\n2. this is an @eviltrout mention\n", "
  1. this is a list

  2. this is an @eviltrout mention

", "it mentions properly in a list."); - cooked("Hello @foo/@bar", + assert.cooked("Hello @foo/@bar", "

Hello @foo/@bar

", "handles mentions separated by a slash."); - cookedOptions("@eviltrout", alwaysTrue, + assert.cookedOptions("@eviltrout", alwaysTrue, "

@eviltrout

", "it doesn't onebox mentions"); - cookedOptions("a @sam c", alwaysTrue, + assert.cookedOptions("a @sam c", alwaysTrue, "

a @sam c

", "it allows mentions within HTML tags"); }); -test("Category hashtags", () => { +QUnit.test("Category hashtags", assert => { const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) }; - cookedOptions("Check out #category-hashtag", alwaysTrue, + assert.cookedOptions("Check out #category-hashtag", alwaysTrue, "

Check out #category-hashtag

", "it translates category hashtag into links"); - cooked("Check out #category-hashtag", + assert.cooked("Check out #category-hashtag", "

Check out #category-hashtag

", "it does not translate category hashtag into links if it is not a valid category hashtag"); - cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue, + assert.cookedOptions("[#category-hashtag](http://www.test.com)", alwaysTrue, "

#category-hashtag

", "it does not translate category hashtag within links"); - cooked("```\n# #category-hashtag\n```", + assert.cooked("```\n# #category-hashtag\n```", "

# #category-hashtag

", "it does not translate category hashtags to links in code blocks"); - cooked("># #category-hashtag\n", + assert.cooked("># #category-hashtag\n", "

#category-hashtag

", "it handles category hashtags in simple quotes"); - cooked("# #category-hashtag", + assert.cooked("# #category-hashtag", "

#category-hashtag

", "it works within ATX-style headers"); - cooked("don't `#category-hashtag`", + assert.cooked("don't `#category-hashtag`", "

don't #category-hashtag

", "it does not mention in an inline code block"); - cooked("test #hashtag1/#hashtag2", + assert.cooked("test #hashtag1/#hashtag2", "

test #hashtag1/#hashtag2

", "it does not convert category hashtag not bounded by spaces"); - cooked("#category-hashtag", + assert.cooked("#category-hashtag", "

#category-hashtag

", "it works between HTML tags"); }); -test("Heading", function() { - cooked("**Bold**\n----------", "

Bold

", "It will bold the heading"); +QUnit.test("Heading", assert => { + assert.cooked("**Bold**\n----------", "

Bold

", "It will bold the heading"); }); -test("bold and italics", function() { - cooked("a \"**hello**\"", "

a \"hello\"

", "bolds in quotes"); - cooked("(**hello**)", "

(hello)

", "bolds in parens"); - cooked("**hello**\nworld", "

hello
world

", "allows newline after bold"); - cooked("**hello**\n**world**", "

hello
world

", "newline between two bolds"); - cooked("**a*_b**", "

a*_b

", "allows for characters within bold"); - cooked("** hello**", "

** hello**

", "does not bold on a space boundary"); - cooked("**hello **", "

**hello **

", "does not bold on a space boundary"); - cooked("你**hello**", "

你**hello**

", "does not bold chinese intra word"); - cooked("**你hello**", "

你hello

", "allows bolded chinese"); +QUnit.test("bold and italics", assert => { + assert.cooked("a \"**hello**\"", "

a \"hello\"

", "bolds in quotes"); + assert.cooked("(**hello**)", "

(hello)

", "bolds in parens"); + assert.cooked("**hello**\nworld", "

hello
world

", "allows newline after bold"); + assert.cooked("**hello**\n**world**", "

hello
world

", "newline between two bolds"); + assert.cooked("**a*_b**", "

a*_b

", "allows for characters within bold"); + assert.cooked("** hello**", "

** hello**

", "does not bold on a space boundary"); + assert.cooked("**hello **", "

**hello **

", "does not bold on a space boundary"); + assert.cooked("你**hello**", "

你**hello**

", "does not bold chinese intra word"); + assert.cooked("**你hello**", "

你hello

", "allows bolded chinese"); }); -test("Escaping", function() { - cooked("*\\*laughs\\**", "

*laughs*

", "allows escaping strong"); - cooked("*\\_laughs\\_*", "

_laughs_

", "allows escaping em"); +QUnit.test("Escaping", assert => { + assert.cooked("*\\*laughs\\**", "

*laughs*

", "allows escaping strong"); + assert.cooked("*\\_laughs\\_*", "

_laughs_

", "allows escaping em"); }); -test("New Lines", function() { +QUnit.test("New Lines", assert => { // Note: This behavior was discussed and we determined it does not make sense to do this // unless you're using traditional line breaks - cooked("_abc\ndef_", "

_abc
def_

", "it does not allow markup to span new lines"); - cooked("_abc\n\ndef_", "

_abc

\n\n

def_

", "it does not allow markup to span new paragraphs"); + assert.cooked("_abc\ndef_", "

_abc
def_

", "it does not allow markup to span new lines"); + assert.cooked("_abc\n\ndef_", "

_abc

\n\n

def_

", "it does not allow markup to span new paragraphs"); }); -test("Oneboxing", function() { +QUnit.test("Oneboxing", assert => { function matches(input, regexp) { return new PrettyText(defaultOpts).cook(input).match(regexp); }; - ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/), + assert.ok(!matches("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org", /onebox/), "doesn't onebox a link within a list"); - ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line"); - ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links"); - ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text"); + assert.ok(matches("http://test.com", /onebox/), "adds a onebox class to a link on its own line"); + assert.ok(matches("http://test.com\nhttp://test2.com", /onebox[\s\S]+onebox/m), "supports multiple links"); + assert.ok(!matches("http://test.com bob", /onebox/), "doesn't onebox links that have trailing text"); - ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed"); - ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)", + assert.ok(!matches("[Tom Cruise](http://www.tomcruise.com/)", "onebox"), "Markdown links with labels are not oneboxed"); + assert.ok(matches("[http://www.tomcruise.com/](http://www.tomcruise.com/)", "onebox"), "Markdown links where the label is the same as the url are oneboxed"); - cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street", + assert.cooked("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street", "

http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street

", "works with links that have underscores in them"); }); -test("links with full urls", function() { - cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com", +QUnit.test("links with full urls", assert => { + assert.cooked("[http://eviltrout.com][1] is a url\n\n[1]: http://eviltrout.com", "

http://eviltrout.com is a url

", "it supports links that are full URLs"); }); -test("Code Blocks", function() { +QUnit.test("Code Blocks", assert => { - cooked("
\nhello\n
\n", + assert.cooked("
\nhello\n
\n", "

hello

", "pre blocks don't include extra lines"); - cooked("```\na\nb\nc\n\nd\n```", + assert.cooked("```\na\nb\nc\n\nd\n```", "

a\nb\nc\n\nd

", "it treats new lines properly"); - cooked("```\ntest\n```", + assert.cooked("```\ntest\n```", "

test

", "it supports basic code blocks"); - cooked("```json\n{hello: 'world'}\n```\ntrailing", + assert.cooked("```json\n{hello: 'world'}\n```\ntrailing", "

{hello: 'world'}

\n\n

trailing

", "It does not truncate text after a code block."); - cooked("```json\nline 1\n\nline 2\n\n\nline3\n```", + assert.cooked("```json\nline 1\n\nline 2\n\n\nline3\n```", "

line 1\n\nline 2\n\n\nline3

", "it maintains new lines inside a code block."); - cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```", + assert.cooked("hello\nworld\n```json\nline 1\n\nline 2\n\n\nline3\n```", "

hello
world

\n\n

line 1\n\nline 2\n\n\nline3

", "it maintains new lines inside a code block with leading content."); - cooked("```ruby\n
hello
\n```", + assert.cooked("```ruby\n
hello
\n```", "

<header>hello</header>

", "it escapes code in the code block"); - cooked("```text\ntext\n```", + assert.cooked("```text\ntext\n```", "

text

", "handles text by adding nohighlight"); - cooked("```ruby\n# cool\n```", + assert.cooked("```ruby\n# cool\n```", "

# cool

", "it supports changing the language"); - cooked(" ```\n hello\n ```", + assert.cooked(" ```\n hello\n ```", "
```\nhello\n```
", "only detect ``` at the beginning of lines"); - cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```", + assert.cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```", "

def self.parse(text)\n\n  text\nend

", "it allows leading spaces on lines in a code block."); - cooked("```ruby\nhello `eviltrout`\n```", + assert.cooked("```ruby\nhello `eviltrout`\n```", "

hello `eviltrout`

", "it allows code with backticks in it"); - cooked("```eviltrout\nhello\n```", + assert.cooked("```eviltrout\nhello\n```", "

hello

", "it doesn't not whitelist all classes"); - cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `` a bug.[/quote]\n```", + assert.cooked("```\n[quote=\"sam, post:1, topic:9441, full:true\"]This is `` a bug.[/quote]\n```", "

[quote="sam, post:1, topic:9441, full:true"]This is `<not>` a bug.[/quote]

", "it allows code with backticks in it"); - cooked(" hello\n
test
", + assert.cooked(" hello\n
test
", "
hello
\n\n
test
", "it allows an indented code block to by followed by a `
`"); - cooked("``` foo bar ```", + assert.cooked("``` foo bar ```", "

foo bar

", "it tolerates misuse of code block tags as inline code"); - cooked("```\nline1\n```\n```\nline2\n\nline3\n```", + assert.cooked("```\nline1\n```\n```\nline2\n\nline3\n```", "

line1

\n\n

line2\n\nline3

", "it does not consume next block's trailing newlines"); - cooked("
test
", + assert.cooked("
test
", "
<pre>test</pre>
", "it does not parse other block types in markdown code blocks"); - cooked(" [quote]test[/quote]", + assert.cooked(" [quote]test[/quote]", "
[quote]test[/quote]
", "it does not parse other block types in markdown code blocks"); - cooked("## a\nb\n```\nc\n```", + assert.cooked("## a\nb\n```\nc\n```", "

a

\n\n

c

", "it handles headings with code blocks after them."); }); -test("URLs in BBCode tags", function() { +QUnit.test("URLs in BBCode tags", assert => { - cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]", + assert.cooked("[img]http://eviltrout.com/eviltrout.png[/img][img]http://samsaffron.com/samsaffron.png[/img]", "

", "images are properly parsed"); - cooked("[url]http://discourse.org[/url]", + assert.cooked("[url]http://discourse.org[/url]", "

http://discourse.org

", "links are properly parsed"); - cooked("[url=http://discourse.org]discourse[/url]", + assert.cooked("[url=http://discourse.org]discourse[/url]", "

discourse

", "named links are properly parsed"); }); -test("images", function() { - cooked("[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)", +QUnit.test("images", assert => { + assert.cooked("[![folksy logo](http://folksy.com/images/folksy-colour.png)](http://folksy.com/)", "

\"folksy

", "It allows images with links around them"); - cooked("\"Red", + assert.cooked("\"Red", "

\"Red

", "It allows data images"); }); -test("censoring", function() { - cooked("aw shucks, golly gee whiz.", +QUnit.test("censoring", assert => { + assert.cooked("aw shucks, golly gee whiz.", "

aw ■■■■■■, golly gee ■■■■.

", "it censors words in the Site Settings"); - cooked("you are a whizzard! I love cheesewhiz. Whiz.", + assert.cooked("you are a whizzard! I love cheesewhiz. Whiz.", "

you are a whizzard! I love cheesewhiz. ■■■■.

", "it doesn't censor words unless they have boundaries."); - cooked("you are a whizzer! I love cheesewhiz. Whiz.", + assert.cooked("you are a whizzer! I love cheesewhiz. Whiz.", "

you are a ■■■■■■■! I love cheesewhiz. ■■■■.

", "it censors words even if previous partial matches exist."); - cooked("The link still works. [whiz](http://www.whiz.com)", + assert.cooked("The link still works. [whiz](http://www.whiz.com)", "

The link still works. ■■■■

", "it won't break links by censoring them."); - cooked("Call techapj the computer whiz at 555-555-1234 for free help.", + assert.cooked("Call techapj the computer whiz at 555-555-1234 for free help.", "

Call ■■■■■■■ the computer ■■■■ at 555-■■■■■■■■ for free help.

", "uses both censored words and patterns from site settings"); - cooked("I have a pen, I have an a**le", + assert.cooked("I have a pen, I have an a**le", "

I have a pen, I have an ■■■■■

", "it escapes regexp chars"); }); -test("code blocks/spans hoisting", function() { - cooked("```\n\n some code\n```", +QUnit.test("code blocks/spans hoisting", assert => { + assert.cooked("```\n\n some code\n```", "

    some code

", "it works when nesting standard markdown code blocks within a fenced code block"); - cooked("`$&`", + assert.cooked("`$&`", "

$&

", "it works even when hoisting special replacement patterns"); }); -test('basic bbcode', function() { - cookedPara("[b]strong[/b]", "strong", "bolds text"); - cookedPara("[i]emphasis[/i]", "emphasis", "italics text"); - cookedPara("[u]underlined[/u]", "underlined", "underlines text"); - cookedPara("[s]strikethrough[/s]", "strikethrough", "strikes-through text"); - cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images"); - cookedPara("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title"); - cookedPara("[b]evil [i]trout[/i][/b]", +QUnit.test('basic bbcode', assert => { + assert.cookedPara("[b]strong[/b]", "strong", "bolds text"); + assert.cookedPara("[i]emphasis[/i]", "emphasis", "italics text"); + assert.cookedPara("[u]underlined[/u]", "underlined", "underlines text"); + assert.cookedPara("[s]strikethrough[/s]", "strikethrough", "strikes-through text"); + assert.cookedPara("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images"); + assert.cookedPara("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title"); + assert.cookedPara("[b]evil [i]trout[/i][/b]", "evil trout", "allows embedding of tags"); - cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "eviltrout@mailinator.com", "supports upper case bbcode"); - cookedPara("[b]strong [b]stronger[/b][/b]", "strong stronger", "accepts nested bbcode tags"); + assert.cookedPara("[EMAIL]eviltrout@mailinator.com[/EMAIL]", "eviltrout@mailinator.com", "supports upper case bbcode"); + assert.cookedPara("[b]strong [b]stronger[/b][/b]", "strong stronger", "accepts nested bbcode tags"); }); -test('urls', function() { - cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url"); - cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a"); - cookedPara("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without parameter"); - cookedPara("[url=http://example.com]example[/url]", "example", "supports [url] with given href"); - cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]", +QUnit.test('urls', assert => { + assert.cookedPara("[url]not a url[/url]", "not a url", "supports [url] that isn't a url"); + assert.cookedPara("[url]abc.com[/url]", "abc.com", "no error when a url has no protocol and begins with a"); + assert.cookedPara("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without parameter"); + assert.cookedPara("[url=http://example.com]example[/url]", "example", "supports [url] with given href"); + assert.cookedPara("[url=http://www.example.com][img]http://example.com/logo.png[/img][/url]", "", "supports [url] with an embedded [img]"); }); -test('invalid bbcode', function() { +QUnit.test('invalid bbcode', assert => { const result = new PrettyText({ lookupAvatar: false }).cook("[code]I am not closed\n\nThis text exists."); - equal(result, "

[code]I am not closed

\n\n

This text exists.

", "does not raise an error with an open bbcode tag."); + assert.equal(result, "

[code]I am not closed

\n\n

This text exists.

", "does not raise an error with an open bbcode tag."); }); -test('code', function() { - cookedPara("[code]\nx++\n[/code]", "
x++
", "makes code into pre"); - cookedPara("[code]\nx++\ny++\nz++\n[/code]", "
x++\ny++\nz++
", "makes code into pre"); - cookedPara("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block'); - cookedPara("[code]\n s[/code]", +QUnit.test('code', assert => { + assert.cookedPara("[code]\nx++\n[/code]", "
x++
", "makes code into pre"); + assert.cookedPara("[code]\nx++\ny++\nz++\n[/code]", "
x++\ny++\nz++
", "makes code into pre"); + assert.cookedPara("[code]abc\n#def\n[/code]", '
abc\n#def
', 'it handles headings in a [code] block'); + assert.cookedPara("[code]\n s[/code]", "
   s
", "it doesn't trim leading whitespace"); }); -test('lists', function() { - cookedPara("[ul][li]option one[/li][/ul]", "
  • option one
", "creates an ul"); - cookedPara("[ol][li]option one[/li][/ol]", "
  1. option one
", "creates an ol"); - cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "
  • option one
  • option two
", "suppresses empty lines in lists"); +QUnit.test('lists', assert => { + assert.cookedPara("[ul][li]option one[/li][/ul]", "
  • option one
", "creates an ul"); + assert.cookedPara("[ol][li]option one[/li][/ol]", "
  1. option one
", "creates an ol"); + assert.cookedPara("[ul]\n[li]option one[/li]\n[li]option two[/li]\n[/ul]", "
  • option one
  • option two
", "suppresses empty lines in lists"); }); -test('tags with arguments', function() { - cookedPara("[url=http://bettercallsaul.com]better call![/url]", "better call!", "supports [url] with a title"); - cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "evil trout", "supports [email] with a title"); - cookedPara("[u][i]abc[/i][/u]", "abc", "can nest tags"); - cookedPara("[b]first[/b] [b]second[/b]", "first second", "can bold two things on the same line"); +QUnit.test('tags with arguments', assert => { + assert.cookedPara("[url=http://bettercallsaul.com]better call![/url]", "better call!", "supports [url] with a title"); + assert.cookedPara("[email=eviltrout@mailinator.com]evil trout[/email]", "evil trout", "supports [email] with a title"); + assert.cookedPara("[u][i]abc[/i][/u]", "abc", "can nest tags"); + assert.cookedPara("[b]first[/b] [b]second[/b]", "first second", "can bold two things on the same line"); }); -test("quotes", function() { +QUnit.test("quotes", assert => { const post = Post.create({ cooked: "

lorem ipsum

", username: "eviltrout", @@ -621,7 +633,7 @@ test("quotes", function() { }); function formatQuote(val, expected, text) { - equal(Quote.build(post, val), expected, text); + assert.equal(Quote.build(post, val), expected, text); }; formatQuote(undefined, "", "empty string for undefined content"); @@ -646,80 +658,80 @@ test("quotes", function() { "[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n", "it escapes the contents of the quote"); - cookedPara("[quote]test[/quote]", + assert.cookedPara("[quote]test[/quote]", "", "it supports quotes without params"); - cookedPara("[quote]\n*test*\n[/quote]", + assert.cookedPara("[quote]\n*test*\n[/quote]", "", "it doesn't insert a new line for italics"); - cookedPara("[quote=,script='a'>
"), "
"); - equal(pt.sanitize("

hello

"), "

hello

"); - equal(pt.sanitize("<3 <3"), "<3 <3"); - equal(pt.sanitize("<_<"), "<_<"); + assert.equal(pt.sanitize("bug"), "bug"); + assert.equal(pt.sanitize("
"), "
"); + assert.equal(pt.sanitize("

hello

"), "

hello

"); + assert.equal(pt.sanitize("<3 <3"), "<3 <3"); + assert.equal(pt.sanitize("<_<"), "<_<"); cooked("hello", "

hello

", "it sanitizes while cooking"); cooked("disney reddit", @@ -32,11 +32,11 @@ test("sanitize", function() { "", "it allows iframe to OpenStreetMap"); - equal(pt.sanitize(""), "hullo"); - equal(pt.sanitize(""), "press me!"); - equal(pt.sanitize("draw me!"), "draw me!"); - equal(pt.sanitize("hello"), "hello"); - equal(pt.sanitize("highlight"), "highlight"); + assert.equal(pt.sanitize(""), "hullo"); + assert.equal(pt.sanitize(""), "press me!"); + assert.equal(pt.sanitize("draw me!"), "draw me!"); + assert.equal(pt.sanitize("hello"), "hello"); + assert.equal(pt.sanitize("highlight"), "highlight"); cooked("[the answer](javascript:alert(42))", "

the answer

", "it prevents XSS"); @@ -60,26 +60,26 @@ test("sanitize", function() { cooked(`
RTL text
`, `
RTL text
`); }); -test("ids on headings", () => { +QUnit.test("ids on headings", assert => { const pt = new PrettyText(buildOptions({ siteSettings: {} })); - equal(pt.sanitize("

Test Heading

"), "

Test Heading

"); - equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); - equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); - equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); - equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); - equal(pt.sanitize(`
Test Heading
`), `
Test Heading
`); - equal(pt.sanitize(`
Test Heading
`), `
Test Heading
`); + assert.equal(pt.sanitize("

Test Heading

"), "

Test Heading

"); + assert.equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); + assert.equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); + assert.equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); + assert.equal(pt.sanitize(`

Test Heading

`), `

Test Heading

`); + assert.equal(pt.sanitize(`
Test Heading
`), `
Test Heading
`); + assert.equal(pt.sanitize(`
Test Heading
`), `
Test Heading
`); }); -test("urlAllowed", () => { - const allowed = (url, msg) => equal(hrefAllowed(url), url, msg); +QUnit.test("urlAllowed", assert => { + const allowed = (url, msg) => assert.equal(hrefAllowed(url), url, msg); allowed("/foo/bar.html", "allows relative urls"); allowed("http://eviltrout.com/evil/trout", "allows full urls"); allowed("https://eviltrout.com/evil/trout", "allows https urls"); allowed("//eviltrout.com/evil/trout", "allows protocol relative urls"); - equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"), + assert.equal(hrefAllowed("http://google.com/test'onmouseover=alert('XSS!');//.swf"), "http://google.com/test%27onmouseover=alert(%27XSS!%27);//.swf", "escape single quotes"); }); diff --git a/test/javascripts/lib/url-test.js.es6 b/test/javascripts/lib/url-test.js.es6 index dd938b5d0c4..71a95467a70 100644 --- a/test/javascripts/lib/url-test.js.es6 +++ b/test/javascripts/lib/url-test.js.es6 @@ -1,40 +1,40 @@ import { default as DiscourseURL, userPath } from 'discourse/lib/url'; -module("lib:url"); +QUnit.module("lib:url"); -test("isInternal with a HTTP url", function() { +QUnit.test("isInternal with a HTTP url", assert => { sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com"); - not(DiscourseURL.isInternal(null), "a blank URL is not internal"); - ok(DiscourseURL.isInternal("/test"), "relative URLs are internal"); - ok(DiscourseURL.isInternal("//eviltrout.com"), "a url on the same host is internal (protocol-less)"); - ok(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host is internal"); - ok(DiscourseURL.isInternal("https://eviltrout.com/moustache"), "a url on a HTTPS of the same host is internal"); - not(DiscourseURL.isInternal("//twitter.com.com"), "a different host is not internal (protocol-less)"); - not(DiscourseURL.isInternal("http://twitter.com"), "a different host is not internal"); + assert.not(DiscourseURL.isInternal(null), "a blank URL is not internal"); + assert.ok(DiscourseURL.isInternal("/test"), "relative URLs are internal"); + assert.ok(DiscourseURL.isInternal("//eviltrout.com"), "a url on the same host is internal (protocol-less)"); + assert.ok(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host is internal"); + assert.ok(DiscourseURL.isInternal("https://eviltrout.com/moustache"), "a url on a HTTPS of the same host is internal"); + assert.not(DiscourseURL.isInternal("//twitter.com.com"), "a different host is not internal (protocol-less)"); + assert.not(DiscourseURL.isInternal("http://twitter.com"), "a different host is not internal"); }); -test("isInternal with a HTTPS url", function() { +QUnit.test("isInternal with a HTTPS url", assert => { sandbox.stub(DiscourseURL, "origin").returns("https://eviltrout.com"); - ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls"); + assert.ok(DiscourseURL.isInternal("http://eviltrout.com/monocle"), "HTTPS urls match HTTP urls"); }); -test("isInternal on subfolder install", function() { +QUnit.test("isInternal on subfolder install", assert => { sandbox.stub(DiscourseURL, "origin").returns("http://eviltrout.com/forum"); - not(DiscourseURL.isInternal("http://eviltrout.com"), "the host root is not internal"); - not(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host but on a different folder is not internal"); - ok(DiscourseURL.isInternal("http://eviltrout.com/forum/moustache"), "a url on the same host and on the same folder is internal"); + assert.not(DiscourseURL.isInternal("http://eviltrout.com"), "the host root is not internal"); + assert.not(DiscourseURL.isInternal("http://eviltrout.com/tophat"), "a url on the same host but on a different folder is not internal"); + assert.ok(DiscourseURL.isInternal("http://eviltrout.com/forum/moustache"), "a url on the same host and on the same folder is internal"); }); -test("userPath", assert => { +QUnit.test("userPath", assert => { assert.equal(userPath(), '/u'); assert.equal(userPath('eviltrout'), '/u/eviltrout'); assert.equal(userPath('hp.json'), '/u/hp.json'); }); -test("userPath with BaseUri", assert => { +QUnit.test("userPath with BaseUri", assert => { Discourse.BaseUri = "/forum"; assert.equal(userPath(), '/forum/u'); assert.equal(userPath('eviltrout'), '/forum/u/eviltrout'); assert.equal(userPath('hp.json'), '/forum/u/hp.json'); -}); +}); \ No newline at end of file diff --git a/test/javascripts/lib/user-search-test.js.es6 b/test/javascripts/lib/user-search-test.js.es6 index fba45e9ff73..9cdb8302216 100644 --- a/test/javascripts/lib/user-search-test.js.es6 +++ b/test/javascripts/lib/user-search-test.js.es6 @@ -1,7 +1,7 @@ import userSearch from 'discourse/lib/user-search'; -module("lib:user-search", { - setup() { +QUnit.module("lib:user-search", { + beforeEach() { const response = (object) => { return [ 200, @@ -57,8 +57,8 @@ module("lib:user-search", { } }); -test("it places groups unconditionally for exact match", function() { +QUnit.test("it places groups unconditionally for exact match", assert => { return userSearch({term: 'Team'}).then((results)=>{ - equal(results[results.length-1]["name"], "team"); + assert.equal(results[results.length-1]["name"], "team"); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/lib/utilities-test.js.es6 b/test/javascripts/lib/utilities-test.js.es6 index 7c4e000bbe8..e8a3a8c93f0 100644 --- a/test/javascripts/lib/utilities-test.js.es6 +++ b/test/javascripts/lib/utilities-test.js.es6 @@ -1,5 +1,4 @@ /* global Int8Array:true */ -import { blank } from 'helpers/qunit-helpers'; import { emailValid, extractDomainFromUrl, @@ -17,68 +16,68 @@ import { setCaretPosition } from 'discourse/lib/utilities'; -module("lib:utilities"); +QUnit.module("lib:utilities"); -test("emailValid", function() { - ok(emailValid('Bob@example.com'), "allows upper case in the first part of emails"); - ok(emailValid('bob@EXAMPLE.com'), "allows upper case in the email domain"); +QUnit.test("emailValid", assert => { + assert.ok(emailValid('Bob@example.com'), "allows upper case in the first part of emails"); + assert.ok(emailValid('bob@EXAMPLE.com'), "allows upper case in the email domain"); }); -test("extractDomainFromUrl", function() { - equal(extractDomainFromUrl('http://meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain name from url"); - equal(extractDomainFromUrl('meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain regardless of scheme presence"); - equal(extractDomainFromUrl('http://192.168.0.1:443/random'), '192.168.0.1', "works for IP address"); - equal(extractDomainFromUrl('http://localhost:443/random'), 'localhost', "works for localhost"); +QUnit.test("extractDomainFromUrl", assert => { + assert.equal(extractDomainFromUrl('http://meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain name from url"); + assert.equal(extractDomainFromUrl('meta.discourse.org:443/random'), 'meta.discourse.org', "extract domain regardless of scheme presence"); + assert.equal(extractDomainFromUrl('http://192.168.0.1:443/random'), '192.168.0.1', "works for IP address"); + assert.equal(extractDomainFromUrl('http://localhost:443/random'), 'localhost', "works for localhost"); }); var validUpload = validateUploadedFiles; -test("validateUploadedFiles", function() { - not(validUpload(null), "no files are invalid"); - not(validUpload(undefined), "undefined files are invalid"); - not(validUpload([]), "empty array of files is invalid"); +QUnit.test("validateUploadedFiles", assert => { + assert.not(validUpload(null), "no files are invalid"); + assert.not(validUpload(undefined), "undefined files are invalid"); + assert.not(validUpload([]), "empty array of files is invalid"); }); -test("uploading one file", function() { +QUnit.test("uploading one file", assert => { sandbox.stub(bootbox, "alert"); - not(validUpload([1, 2])); - ok(bootbox.alert.calledWith(I18n.t('post.errors.too_many_uploads'))); + assert.not(validUpload([1, 2])); + assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.too_many_uploads'))); }); -test("new user cannot upload images", function() { +QUnit.test("new user cannot upload images", assert => { Discourse.SiteSettings.newuser_max_images = 0; Discourse.User.resetCurrent(Discourse.User.create()); sandbox.stub(bootbox, "alert"); - not(validUpload([{name: "image.png"}]), 'the upload is not valid'); - ok(bootbox.alert.calledWith(I18n.t('post.errors.image_upload_not_allowed_for_new_user')), 'the alert is called'); + assert.not(validUpload([{name: "image.png"}]), 'the upload is not valid'); + assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.image_upload_not_allowed_for_new_user')), 'the alert is called'); }); -test("new user cannot upload attachments", function() { +QUnit.test("new user cannot upload attachments", assert => { Discourse.SiteSettings.newuser_max_attachments = 0; sandbox.stub(bootbox, "alert"); Discourse.User.resetCurrent(Discourse.User.create()); - not(validUpload([{name: "roman.txt"}])); - ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user'))); + assert.not(validUpload([{name: "roman.txt"}])); + assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user'))); }); -test("ensures an authorized upload", function() { +QUnit.test("ensures an authorized upload", assert => { sandbox.stub(bootbox, "alert"); - not(validUpload([{ name: "unauthorized.html" }])); - ok(bootbox.alert.calledWith(I18n.t('post.errors.upload_not_authorized', { authorized_extensions: authorizedExtensions() }))); + assert.not(validUpload([{ name: "unauthorized.html" }])); + assert.ok(bootbox.alert.calledWith(I18n.t('post.errors.upload_not_authorized', { authorized_extensions: authorizedExtensions() }))); }); -test("staff can upload anything in PM", function() { +QUnit.test("staff can upload anything in PM", assert => { const files = [{ name: "some.docx" }]; Discourse.SiteSettings.authorized_extensions = "jpeg"; Discourse.User.resetCurrent(Discourse.User.create({ moderator: true })); sandbox.stub(bootbox, "alert"); - not(validUpload(files)); - ok(validUpload(files, { isPrivateMessage: true, allowStaffToUploadAnyFileInPm: true })); + assert.not(validUpload(files)); + assert.ok(validUpload(files, { isPrivateMessage: true, allowStaffToUploadAnyFileInPm: true })); }); var imageSize = 10 * 1024; @@ -94,19 +93,19 @@ var dummyBlob = function() { } }; -test("allows valid uploads to go through", function() { +QUnit.test("allows valid uploads to go through", assert => { Discourse.User.resetCurrent(Discourse.User.create()); Discourse.User.currentProp("trust_level", 1); sandbox.stub(bootbox, "alert"); // image var image = { name: "image.png", size: imageSize }; - ok(validUpload([image])); + assert.ok(validUpload([image])); // pasted image var pastedImage = dummyBlob(); - ok(validUpload([pastedImage])); + assert.ok(validUpload([pastedImage])); - not(bootbox.alert.calledOnce); + assert.not(bootbox.alert.calledOnce); }); var testUploadMarkdown = function(filename) { @@ -119,27 +118,27 @@ var testUploadMarkdown = function(filename) { }); }; -test("getUploadMarkdown", function() { - ok(testUploadMarkdown("lolcat.gif") === ''); - ok(testUploadMarkdown("important.txt") === 'important.txt (42 Bytes)\n'); +QUnit.test("getUploadMarkdown", assert => { + assert.ok(testUploadMarkdown("lolcat.gif") === ''); + assert.ok(testUploadMarkdown("important.txt") === 'important.txt (42 Bytes)\n'); }); -test("isAnImage", function() { +QUnit.test("isAnImage", assert => { _.each(["png", "jpg", "jpeg", "bmp", "gif", "tif", "tiff", "ico"], function(extension) { var image = "image." + extension; - ok(isAnImage(image), image + " is recognized as an image"); - ok(isAnImage("http://foo.bar/path/to/" + image), image + " is recognized as an image"); + assert.ok(isAnImage(image), image + " is recognized as an image"); + assert.ok(isAnImage("http://foo.bar/path/to/" + image), image + " is recognized as an image"); }); - not(isAnImage("file.txt")); - not(isAnImage("http://foo.bar/path/to/file.txt")); - not(isAnImage("")); + assert.not(isAnImage("file.txt")); + assert.not(isAnImage("http://foo.bar/path/to/file.txt")); + assert.not(isAnImage("")); }); -test("avatarUrl", function() { +QUnit.test("avatarUrl", assert => { var rawSize = getRawSize; - blank(avatarUrl('', 'tiny'), "no template returns blank"); - equal(avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url"); - equal(avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size"); + assert.blank(avatarUrl('', 'tiny'), "no template returns blank"); + assert.equal(avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url"); + assert.equal(avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size"); }); var setDevicePixelRatio = function(value) { @@ -150,64 +149,64 @@ var setDevicePixelRatio = function(value) { } }; -test("avatarImg", function() { +QUnit.test("avatarImg", assert => { var oldRatio = window.devicePixelRatio; setDevicePixelRatio(2); var avatarTemplate = "/path/to/avatar/{size}.png"; - equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}), + assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}), "", "it returns the avatar html"); - equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}), + assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}), "", "it adds a title if supplied"); - equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}), + assert.equal(avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}), "", "it adds extra classes if supplied"); - blank(avatarImg({avatarTemplate: "", size: 'tiny'}), + assert.blank(avatarImg({avatarTemplate: "", size: 'tiny'}), "it doesn't render avatars for invalid avatar template"); setDevicePixelRatio(oldRatio); }); -test("allowsImages", function() { +QUnit.test("allowsImages", assert => { Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif"; - ok(allowsImages(), "works"); + assert.ok(allowsImages(), "works"); Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif"; - ok(allowsImages(), "works with old extensions syntax"); + assert.ok(allowsImages(), "works with old extensions syntax"); Discourse.SiteSettings.authorized_extensions = "txt|pdf|*"; - ok(allowsImages(), "images are allowed when all extensions are allowed"); + assert.ok(allowsImages(), "images are allowed when all extensions are allowed"); Discourse.SiteSettings.authorized_extensions = "json|jpg|pdf|txt"; - ok(allowsImages(), "images are allowed when at least one extension is an image extension"); + assert.ok(allowsImages(), "images are allowed when at least one extension is an image extension"); }); -test("allowsAttachments", function() { +QUnit.test("allowsAttachments", assert => { Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif"; - not(allowsAttachments(), "no attachments allowed by default"); + assert.not(allowsAttachments(), "no attachments allowed by default"); Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|*"; - ok(allowsAttachments(), "attachments are allowed when all extensions are allowed"); + assert.ok(allowsAttachments(), "attachments are allowed when all extensions are allowed"); Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|pdf"; - ok(allowsAttachments(), "attachments are allowed when at least one extension is not an image extension"); + assert.ok(allowsAttachments(), "attachments are allowed when at least one extension is not an image extension"); Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif|.pdf"; - ok(allowsAttachments(), "works with old extensions syntax"); + assert.ok(allowsAttachments(), "works with old extensions syntax"); }); -test("defaultHomepage", function() { +QUnit.test("defaultHomepage", assert => { Discourse.SiteSettings.top_menu = "latest|top|hot"; - equal(defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting"); + assert.equal(defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting"); }); -test("caretRowCol", () => { +QUnit.test("caretRowCol", assert => { var textarea = document.createElement('textarea'); const content = document.createTextNode("01234\n56789\n012345"); textarea.appendChild(content); @@ -217,8 +216,8 @@ test("caretRowCol", () => { setCaretPosition(textarea, setCaretPos); const result = caretRowCol(textarea); - equal(result.rowNum, expectedRowNum, "returns the right row of the caret"); - equal(result.colNum, expectedColNum, "returns the right col of the caret"); + assert.equal(result.rowNum, expectedRowNum, "returns the right row of the caret"); + assert.equal(result.colNum, expectedColNum, "returns the right col of the caret"); }; assertResult(0, 1, 0); @@ -228,4 +227,4 @@ test("caretRowCol", () => { assertResult(14, 3, 2); document.body.removeChild(textarea); -}); +}); \ No newline at end of file diff --git a/test/javascripts/mdtest/mdtest.js.es6.erb b/test/javascripts/mdtest/mdtest.js.es6.erb index 92047e74130..870d556a415 100644 --- a/test/javascripts/mdtest/mdtest.js.es6.erb +++ b/test/javascripts/mdtest/mdtest.js.es6.erb @@ -37,7 +37,7 @@ function sanitizer(result, whiteLister) { return result; } -function md(input, expected, text, settings) { +function md(assert, input, expected, text, settings) { const opts = buildOptions({ siteSettings: settings||{} }); opts.traditionalMarkdownLinebreaks = true; @@ -50,16 +50,12 @@ function md(input, expected, text, settings) { const same = (result === expected) || (resultNorm === expectedNorm); if (same) { - ok(same, text); + assert.ok(same, text); } else { - equal(resultNorm, expectedNorm, text); + assert.equal(resultNorm, expectedNorm, text); } }; -test("first", function(){ - equal(1, 1, "cool") -}); - <% def mdtest_suite result = "" @@ -70,7 +66,7 @@ test("first", function(){ text = File.read(f) html = File.read("#{filename_no_ext}.xhtml"); - result << "test(\"#{filename}\", function() { md(#{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n" + result << "test(\"#{filename}\", function(assert) { md(assert, #{text.to_json}, #{html.to_json}, 'passes MDTest'); });\n" end result end @@ -78,10 +74,10 @@ test("first", function(){ <%= mdtest_suite %> -test("whitelisted url scheme", function() { - md("[Steam URL Scheme](steam://store/452530)", '

Steam URL Scheme

', 'whitelists the steam url', {allowed_href_schemes: "macappstore|steam"}); +test("whitelisted url scheme", function(assert) { + md(assert, "[Steam URL Scheme](steam://store/452530)", '

Steam URL Scheme

', 'whitelists the steam url', {allowed_href_schemes: "macappstore|steam"}); }); -test("forbidden url scheme", function() { - md("[Steam URL Scheme](steam://store/452530)", '

Steam URL Scheme

', 'removes the href', {allowed_href_schemes: "macappstore|itunes"}); +test("forbidden url scheme", function(assert) { + md(assert, "[Steam URL Scheme](steam://store/452530)", '

Steam URL Scheme

', 'removes the href', {allowed_href_schemes: "macappstore|itunes"}); }); diff --git a/test/javascripts/mixins/selected-posts-count-test.js.es6 b/test/javascripts/mixins/selected-posts-count-test.js.es6 index c6233a52a30..182ad85de2d 100644 --- a/test/javascripts/mixins/selected-posts-count-test.js.es6 +++ b/test/javascripts/mixins/selected-posts-count-test.js.es6 @@ -1,4 +1,4 @@ -module("mixin:selected-posts-count"); +QUnit.module("mixin:selected-posts-count"); import SelectedPostsCount from 'discourse/mixins/selected-posts-count'; import Topic from 'discourse/models/topic'; @@ -7,30 +7,30 @@ var buildTestObj = function(params) { return Ember.Object.extend(SelectedPostsCount).create(params || {}); }; -test("without selectedPosts", function () { +QUnit.test("without selectedPosts", assert => { var testObj = buildTestObj(); - equal(testObj.get('selectedPostsCount'), 0, "No posts are selected without a selectedPosts property"); + assert.equal(testObj.get('selectedPostsCount'), 0, "No posts are selected without a selectedPosts property"); testObj.set('selectedPosts', []); - equal(testObj.get('selectedPostsCount'), 0, "No posts are selected when selectedPosts is an empty array"); + assert.equal(testObj.get('selectedPostsCount'), 0, "No posts are selected when selectedPosts is an empty array"); }); -test("with some selectedPosts", function() { +QUnit.test("with some selectedPosts", assert => { var testObj = buildTestObj({ selectedPosts: [Discourse.Post.create({id: 123})] }); - equal(testObj.get('selectedPostsCount'), 1, "It returns the amount of posts"); + assert.equal(testObj.get('selectedPostsCount'), 1, "It returns the amount of posts"); }); -test("when all posts are selected and there is a posts_count", function() { +QUnit.test("when all posts are selected and there is a posts_count", assert => { var testObj = buildTestObj({ allPostsSelected: true, posts_count: 1024 }); - equal(testObj.get('selectedPostsCount'), 1024, "It returns the posts_count"); + assert.equal(testObj.get('selectedPostsCount'), 1024, "It returns the posts_count"); }); -test("when all posts are selected and there is topic with a posts_count", function() { +QUnit.test("when all posts are selected and there is topic with a posts_count", assert => { var testObj = buildTestObj({ allPostsSelected: true, topic: Topic.create({ posts_count: 3456 }) }); - equal(testObj.get('selectedPostsCount'), 3456, "It returns the topic's posts_count"); -}); + assert.equal(testObj.get('selectedPostsCount'), 3456, "It returns the topic's posts_count"); +}); \ No newline at end of file diff --git a/test/javascripts/mixins/singleton-test.js.es6 b/test/javascripts/mixins/singleton-test.js.es6 index eeca3caa56d..2e5635a4d18 100644 --- a/test/javascripts/mixins/singleton-test.js.es6 +++ b/test/javascripts/mixins/singleton-test.js.es6 @@ -1,45 +1,44 @@ -import { blank, present } from 'helpers/qunit-helpers'; import Singleton from 'discourse/mixins/singleton'; -module("mixin:singleton"); +QUnit.module("mixin:singleton"); -test("current", function() { +QUnit.test("current", assert => { var DummyModel = Ember.Object.extend({}); DummyModel.reopenClass(Singleton); var current = DummyModel.current(); - present(current, 'current returns the current instance'); - equal(current, DummyModel.current(), 'calling it again returns the same instance'); - notEqual(current, DummyModel.create({}), 'we can create other instances that are not the same as current'); + assert.present(current, 'current returns the current instance'); + assert.equal(current, DummyModel.current(), 'calling it again returns the same instance'); + assert.notEqual(current, DummyModel.create({}), 'we can create other instances that are not the same as current'); }); -test("currentProp reading", function() { +QUnit.test("currentProp reading", assert => { var DummyModel = Ember.Object.extend({}); DummyModel.reopenClass(Singleton); var current = DummyModel.current(); - blank(DummyModel.currentProp('evil'), 'by default attributes are blank'); + assert.blank(DummyModel.currentProp('evil'), 'by default attributes are blank'); current.set('evil', 'trout'); - equal(DummyModel.currentProp('evil'), 'trout', 'after changing the instance, the value is set'); + assert.equal(DummyModel.currentProp('evil'), 'trout', 'after changing the instance, the value is set'); }); -test("currentProp writing", function() { +QUnit.test("currentProp writing", assert => { var DummyModel = Ember.Object.extend({}); DummyModel.reopenClass(Singleton); - blank(DummyModel.currentProp('adventure'), 'by default attributes are blank'); + assert.blank(DummyModel.currentProp('adventure'), 'by default attributes are blank'); var result = DummyModel.currentProp('adventure', 'time'); - equal(result, 'time', 'it returns the new value'); - equal(DummyModel.currentProp('adventure'), 'time', 'after calling currentProp the value is set'); + assert.equal(result, 'time', 'it returns the new value'); + assert.equal(DummyModel.currentProp('adventure'), 'time', 'after calling currentProp the value is set'); DummyModel.currentProp('count', 0); - equal(DummyModel.currentProp('count'), 0, 'we can set the value to 0'); + assert.equal(DummyModel.currentProp('count'), 0, 'we can set the value to 0'); DummyModel.currentProp('adventure', null); - equal(DummyModel.currentProp('adventure'), null, 'we can set the value to null'); + assert.equal(DummyModel.currentProp('adventure'), null, 'we can set the value to null'); }); -test("createCurrent", function() { +QUnit.test("createCurrent", assert => { var Shoe = Ember.Object.extend({}); Shoe.reopenClass(Singleton, { createCurrent: function() { @@ -47,11 +46,11 @@ test("createCurrent", function() { } }); - equal(Shoe.currentProp('toes'), 5, 'it created the class using `createCurrent`'); + assert.equal(Shoe.currentProp('toes'), 5, 'it created the class using `createCurrent`'); }); -test("createCurrent that returns null", function() { +QUnit.test("createCurrent that returns null", assert => { var Missing = Ember.Object.extend({}); Missing.reopenClass(Singleton, { createCurrent: function() { @@ -59,6 +58,6 @@ test("createCurrent that returns null", function() { } }); - blank(Missing.current(), "it doesn't return an instance"); - blank(Missing.currentProp('madeup'), "it won't raise an error asking for a property. Will just return null."); -}); + assert.blank(Missing.current(), "it doesn't return an instance"); + assert.blank(Missing.currentProp('madeup'), "it won't raise an error asking for a property. Will just return null."); +}); \ No newline at end of file diff --git a/test/javascripts/models/badge-test.js.es6 b/test/javascripts/models/badge-test.js.es6 index 644056d0497..d9a6e0b2d34 100644 --- a/test/javascripts/models/badge-test.js.es6 +++ b/test/javascripts/models/badge-test.js.es6 @@ -1,51 +1,51 @@ import Badge from 'discourse/models/badge'; -module("model:badge"); +QUnit.module("model:badge"); -test('newBadge', function() { +QUnit.test('newBadge', assert => { const badge1 = Badge.create({name: "New Badge"}), badge2 = Badge.create({id: 1, name: "Old Badge"}); - ok(badge1.get('newBadge'), "badges without ids are new"); - ok(!badge2.get('newBadge'), "badges with ids are not new"); + assert.ok(badge1.get('newBadge'), "badges without ids are new"); + assert.ok(!badge2.get('newBadge'), "badges with ids are not new"); }); -test('createFromJson array', function() { +QUnit.test('createFromJson array', assert => { const badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]}; const badges = Badge.createFromJson(badgesJson); - ok(Array.isArray(badges), "returns an array"); - equal(badges[0].get('name'), "Badge 1", "badge details are set"); - equal(badges[0].get('badge_type.name'), "Silver 1", "badge_type reference is set"); + assert.ok(Array.isArray(badges), "returns an array"); + assert.equal(badges[0].get('name'), "Badge 1", "badge details are set"); + assert.equal(badges[0].get('badge_type.name'), "Silver 1", "badge_type reference is set"); }); -test('createFromJson single', function() { +QUnit.test('createFromJson single', assert => { const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; const badge = Badge.createFromJson(badgeJson); - ok(!Array.isArray(badge), "does not returns an array"); + assert.ok(!Array.isArray(badge), "does not returns an array"); }); -test('updateFromJson', function() { +QUnit.test('updateFromJson', assert => { const badgeJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badge":{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}}; const badge = Badge.create({name: "Badge 1"}); badge.updateFromJson(badgeJson); - equal(badge.get('id'), 1126, "id is set"); - equal(badge.get('badge_type.name'), "Silver 1", "badge_type reference is set"); + assert.equal(badge.get('id'), 1126, "id is set"); + assert.equal(badge.get('badge_type.name'), "Silver 1", "badge_type reference is set"); }); -test('save', function() { - expect(0); +QUnit.test('save', assert => { + assert.expect(0); const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1}); return badge.save(["name", "description", "badge_type_id"]); }); -test('destroy', function() { - expect(0); +QUnit.test('destroy', assert => { + assert.expect(0); const badge = Badge.create({name: "New Badge", description: "This is a new badge.", badge_type_id: 1}); badge.destroy(); badge.set('id', 3); return badge.destroy(); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/category-test.js.es6 b/test/javascripts/models/category-test.js.es6 index ca338686eaa..fc5065566ae 100644 --- a/test/javascripts/models/category-test.js.es6 +++ b/test/javascripts/models/category-test.js.es6 @@ -1,13 +1,13 @@ import createStore from 'helpers/create-store'; import Category from 'discourse/models/category'; -module("model:category"); +QUnit.module("model:category"); -test('slugFor', function(){ +QUnit.test('slugFor', assert =>{ const store = createStore(); const slugFor = function(cat, val, text) { - equal(Discourse.Category.slugFor(cat), val, text); + assert.equal(Discourse.Category.slugFor(cat), val, text); }; slugFor(store.createRecord('category', {slug: 'hello'}), "hello", "It calculates the proper slug for hello"); @@ -31,8 +31,8 @@ test('slugFor', function(){ }); -test('findBySlug', function() { - expect(6); +QUnit.test('findBySlug', assert => { + assert.expect(6); const store = createStore(); const darth = store.createRecord('category', {id: 1, slug: 'darth'}), @@ -45,18 +45,18 @@ test('findBySlug', function() { sandbox.stub(Discourse.Category, 'list').returns(categoryList); - deepEqual(Discourse.Category.findBySlug('darth'), darth, 'we can find a category'); - deepEqual(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find the other category with parent category'); - deepEqual(Discourse.Category.findBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug'); - deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK'); - deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english'); - deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK'); + assert.deepEqual(Discourse.Category.findBySlug('darth'), darth, 'we can find a category'); + assert.deepEqual(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find the other category with parent category'); + assert.deepEqual(Discourse.Category.findBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug'); + assert.deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK'); + assert.deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english'); + assert.deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK'); sandbox.restore(); }); -test('findSingleBySlug', function() { - expect(6); +QUnit.test('findSingleBySlug', assert => { + assert.expect(6); const store = createStore(); const darth = store.createRecord('category', {id: 1, slug: 'darth'}), @@ -69,15 +69,15 @@ test('findSingleBySlug', function() { sandbox.stub(Discourse.Category, 'list').returns(categoryList); - deepEqual(Discourse.Category.findSingleBySlug('darth'), darth, 'we can find a category'); - deepEqual(Discourse.Category.findSingleBySlug('darth/luke'), luke, 'we can find the other category with parent category'); - deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug'); - deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/뉴스피드'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK'); - deepEqual(Discourse.Category.findSingleBySlug('darth/时间'), time, 'we can find a category with CJK slug whose parent slug is english'); - deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/bah'), bah, 'we can find a category with english slug whose parent slug is CJK'); + assert.deepEqual(Discourse.Category.findSingleBySlug('darth'), darth, 'we can find a category'); + assert.deepEqual(Discourse.Category.findSingleBySlug('darth/luke'), luke, 'we can find the other category with parent category'); + assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug'); + assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/뉴스피드'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK'); + assert.deepEqual(Discourse.Category.findSingleBySlug('darth/时间'), time, 'we can find a category with CJK slug whose parent slug is english'); + assert.deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/bah'), bah, 'we can find a category with english slug whose parent slug is CJK'); }); -test('findByIds', function() { +QUnit.test('findByIds', assert => { const store = createStore(); const categories = { 1: store.createRecord('category', {id: 1}), @@ -85,25 +85,25 @@ test('findByIds', function() { }; sandbox.stub(Discourse.Category, 'idMap').returns(categories); - deepEqual(Discourse.Category.findByIds([1,2,3]), _.values(categories)); + assert.deepEqual(Discourse.Category.findByIds([1,2,3]), _.values(categories)); }); -test('search with category name', () => { +QUnit.test('search with category name', assert => { const store = createStore(), category1 = store.createRecord('category', { id: 1, name: 'middle term', slug: 'different-slug' }), category2 = store.createRecord('category', { id: 2, name: 'middle term', slug: 'another-different-slug' }); sandbox.stub(Category, "listByActivity").returns([category1, category2]); - deepEqual(Category.search('term', { limit: 0 }), [], "returns an empty array when limit is 0"); - deepEqual(Category.search(''), [category1, category2], "orders by activity if no term is matched"); - deepEqual(Category.search('term'), [category1, category2], "orders by activity"); + assert.deepEqual(Category.search('term', { limit: 0 }), [], "returns an empty array when limit is 0"); + assert.deepEqual(Category.search(''), [category1, category2], "orders by activity if no term is matched"); + assert.deepEqual(Category.search('term'), [category1, category2], "orders by activity"); category2.set('name', 'TeRm start'); - deepEqual(Category.search('tErM'), [category2, category1], "ignores case of category name and search term"); + assert.deepEqual(Category.search('tErM'), [category2, category1], "ignores case of category name and search term"); category2.set('name', 'term start'); - deepEqual(Category.search('term'), [category2, category1], "orders matching begin with and then contains"); + assert.deepEqual(Category.search('term'), [category2, category1], "orders matching begin with and then contains"); sandbox.restore(); @@ -112,35 +112,35 @@ test('search with category name', () => { sandbox.stub(Category, "listByActivity").returns([read_restricted_category, category1, child_category1, category2]); - deepEqual(Category.search(''), + assert.deepEqual(Category.search(''), [category1, category2, read_restricted_category], "prioritize non read_restricted and does not include child categories when term is blank"); - deepEqual(Category.search('', { limit: 3 }), + assert.deepEqual(Category.search('', { limit: 3 }), [category1, category2, read_restricted_category], "prioritize non read_restricted and does not include child categories categories when term is blank with limit"); - deepEqual(Category.search('term'), + assert.deepEqual(Category.search('term'), [child_category1, category2, category1, read_restricted_category], "prioritize non read_restricted"); - deepEqual(Category.search('term', { limit: 3 }), + assert.deepEqual(Category.search('term', { limit: 3 }), [child_category1, category2, read_restricted_category], "prioritize non read_restricted with limit"); sandbox.restore(); }); -test('search with category slug', () => { +QUnit.test('search with category slug', assert => { const store = createStore(), category1 = store.createRecord('category', { id: 1, name: 'middle term', slug: 'different-slug' }), category2 = store.createRecord('category', { id: 2, name: 'middle term', slug: 'another-different-slug' }); sandbox.stub(Category, "listByActivity").returns([category1, category2]); - deepEqual(Category.search('different-slug'), [category1, category2], "returns the right categories"); - deepEqual(Category.search('another-different'), [category2], "returns the right categories"); + assert.deepEqual(Category.search('different-slug'), [category1, category2], "returns the right categories"); + assert.deepEqual(Category.search('another-different'), [category2], "returns the right categories"); category2.set('slug', 'ANOTher-DIFfereNT'); - deepEqual(Category.search('anOtHer-dIfFeREnt'), [category2], "ignores case of category slug and search term"); + assert.deepEqual(Category.search('anOtHer-dIfFeREnt'), [category2], "ignores case of category slug and search term"); }); diff --git a/test/javascripts/models/composer-test.js.es6 b/test/javascripts/models/composer-test.js.es6 index 039d3a18d5d..02475ddb4b6 100644 --- a/test/javascripts/models/composer-test.js.es6 +++ b/test/javascripts/models/composer-test.js.es6 @@ -1,9 +1,8 @@ -import { blank } from 'helpers/qunit-helpers'; import { currentUser } from 'helpers/qunit-helpers'; import Composer from 'discourse/models/composer'; import createStore from 'helpers/create-store'; -module("model:composer"); +QUnit.module("model:composer"); function createComposer(opts) { opts = opts || {}; @@ -17,10 +16,10 @@ function openComposer(opts) { return composer; } -test('replyLength', function() { +QUnit.test('replyLength', assert => { const replyLength = function(val, expectedLength) { const composer = createComposer({ reply: val }); - equal(composer.get('replyLength'), expectedLength); + assert.equal(composer.get('replyLength'), expectedLength); }; replyLength("basic reply", 11, "basic reply length"); @@ -30,11 +29,11 @@ test('replyLength', function() { replyLength("1[quote=]not[quote=]counted[/quote]yay[/quote]2", 2, "handles nested quotes correctly"); }); -test('missingReplyCharacters', function() { +QUnit.test('missingReplyCharacters', assert => { Discourse.SiteSettings.min_first_post_length = 40; const missingReplyCharacters = function(val, isPM, isFirstPost, expected, message) { const composer = createComposer({ reply: val, creatingPrivateMessage: isPM, creatingTopic: isFirstPost }); - equal(composer.get('missingReplyCharacters'), expected, message); + assert.equal(composer.get('missingReplyCharacters'), expected, message); }; missingReplyCharacters('hi', false, false, Discourse.SiteSettings.min_post_length - 2, 'too short public post'); @@ -44,144 +43,144 @@ test('missingReplyCharacters', function() { const link = "http://imgur.com/gallery/grxX8"; const composer = createComposer({ canEditTopicFeaturedLink: true, title: link, featuredLink: link, reply: link }); - equal(composer.get('missingReplyCharacters'), 0, "don't require any post content"); + assert.equal(composer.get('missingReplyCharacters'), 0, "don't require any post content"); }); -test('missingTitleCharacters', function() { +QUnit.test('missingTitleCharacters', assert => { const missingTitleCharacters = function(val, isPM, expected, message) { const composer = createComposer({ title: val, creatingPrivateMessage: isPM }); - equal(composer.get('missingTitleCharacters'), expected, message); + assert.equal(composer.get('missingTitleCharacters'), expected, message); }; missingTitleCharacters('hi', false, Discourse.SiteSettings.min_topic_title_length - 2, 'too short post title'); missingTitleCharacters('z', true, Discourse.SiteSettings.min_private_message_title_length - 1, 'too short pm title'); }); -test('replyDirty', function() { +QUnit.test('replyDirty', assert => { const composer = createComposer(); - ok(!composer.get('replyDirty'), "by default it's false"); + assert.ok(!composer.get('replyDirty'), "by default it's false"); composer.setProperties({ originalText: "hello", reply: "hello" }); - ok(!composer.get('replyDirty'), "it's false when the originalText is the same as the reply"); + assert.ok(!composer.get('replyDirty'), "it's false when the originalText is the same as the reply"); composer.set('reply', 'hello world'); - ok(composer.get('replyDirty'), "it's true when the reply changes"); + assert.ok(composer.get('replyDirty'), "it's true when the reply changes"); }); -test("appendText", function() { +QUnit.test("appendText", assert => { const composer = createComposer(); - blank(composer.get('reply'), "the reply is blank by default"); + assert.blank(composer.get('reply'), "the reply is blank by default"); composer.appendText("hello"); - equal(composer.get('reply'), "hello", "it appends text to nothing"); + assert.equal(composer.get('reply'), "hello", "it appends text to nothing"); composer.appendText(" world"); - equal(composer.get('reply'), "hello world", "it appends text to existing text"); + assert.equal(composer.get('reply'), "hello world", "it appends text to existing text"); composer.clearState(); composer.appendText("a\n\n\n\nb"); composer.appendText("c",3,{block: true}); - equal(composer.get("reply"), "a\n\nc\n\nb"); + assert.equal(composer.get("reply"), "a\n\nc\n\nb"); composer.clearState(); composer.appendText("ab"); composer.appendText("c",1,{block: true}); - equal(composer.get("reply"), "a\n\nc\n\nb"); + assert.equal(composer.get("reply"), "a\n\nc\n\nb"); composer.clearState(); composer.appendText("\nab"); composer.appendText("c",0,{block: true}); - equal(composer.get("reply"), "c\n\nab"); + assert.equal(composer.get("reply"), "c\n\nab"); }); -test("prependText", function() { +QUnit.test("prependText", assert => { const composer = createComposer(); - blank(composer.get('reply'), "the reply is blank by default"); + assert.blank(composer.get('reply'), "the reply is blank by default"); composer.prependText("hello"); - equal(composer.get('reply'), "hello", "it prepends text to nothing"); + assert.equal(composer.get('reply'), "hello", "it prepends text to nothing"); composer.prependText("world "); - equal(composer.get('reply'), "world hello", "it prepends text to existing text"); + assert.equal(composer.get('reply'), "world hello", "it prepends text to existing text"); composer.prependText("before new line", {new_line: true}); - equal(composer.get('reply'), "before new line\n\nworld hello", "it prepends text with new line to existing text"); + assert.equal(composer.get('reply'), "before new line\n\nworld hello", "it prepends text with new line to existing text"); }); -test("Title length for regular topics", function() { +QUnit.test("Title length for regular topics", assert => { Discourse.SiteSettings.min_topic_title_length = 5; Discourse.SiteSettings.max_topic_title_length = 10; const composer = createComposer(); composer.set('title', 'asdf'); - ok(!composer.get('titleLengthValid'), "short titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "short titles are not valid"); composer.set('title', 'this is a long title'); - ok(!composer.get('titleLengthValid'), "long titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "long titles are not valid"); composer.set('title', 'just right'); - ok(composer.get('titleLengthValid'), "in the range is okay"); + assert.ok(composer.get('titleLengthValid'), "in the range is okay"); }); -test("Title length for private messages", function() { +QUnit.test("Title length for private messages", assert => { Discourse.SiteSettings.min_private_message_title_length = 5; Discourse.SiteSettings.max_topic_title_length = 10; const composer = createComposer({action: Composer.PRIVATE_MESSAGE}); composer.set('title', 'asdf'); - ok(!composer.get('titleLengthValid'), "short titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "short titles are not valid"); composer.set('title', 'this is a long title'); - ok(!composer.get('titleLengthValid'), "long titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "long titles are not valid"); composer.set('title', 'just right'); - ok(composer.get('titleLengthValid'), "in the range is okay"); + assert.ok(composer.get('titleLengthValid'), "in the range is okay"); }); -test("Title length for private messages", function() { +QUnit.test("Title length for private messages", assert => { Discourse.SiteSettings.min_private_message_title_length = 5; Discourse.SiteSettings.max_topic_title_length = 10; const composer = createComposer({action: Composer.PRIVATE_MESSAGE}); composer.set('title', 'asdf'); - ok(!composer.get('titleLengthValid'), "short titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "short titles are not valid"); composer.set('title', 'this is a long title'); - ok(!composer.get('titleLengthValid'), "long titles are not valid"); + assert.ok(!composer.get('titleLengthValid'), "long titles are not valid"); composer.set('title', 'just right'); - ok(composer.get('titleLengthValid'), "in the range is okay"); + assert.ok(composer.get('titleLengthValid'), "in the range is okay"); }); -test("Post length for private messages with non human users", function() { +QUnit.test("Post length for private messages with non human users", assert => { const composer = createComposer({ topic: Ember.Object.create({ pm_with_non_human_user: true }) }); - equal(composer.get('minimumPostLength'), 1); + assert.equal(composer.get('minimumPostLength'), 1); }); -test('editingFirstPost', function() { +QUnit.test('editingFirstPost', assert => { const composer = createComposer(); - ok(!composer.get('editingFirstPost'), "it's false by default"); + assert.ok(!composer.get('editingFirstPost'), "it's false by default"); const post = Discourse.Post.create({id: 123, post_number: 2}); composer.setProperties({post: post, action: Composer.EDIT }); - ok(!composer.get('editingFirstPost'), "it's false when not editing the first post"); + assert.ok(!composer.get('editingFirstPost'), "it's false when not editing the first post"); post.set('post_number', 1); - ok(composer.get('editingFirstPost'), "it's true when editing the first post"); + assert.ok(composer.get('editingFirstPost'), "it's true when editing the first post"); }); -test('clearState', function() { +QUnit.test('clearState', assert => { const composer = createComposer({ originalText: 'asdf', reply: 'asdf2', @@ -191,36 +190,36 @@ test('clearState', function() { composer.clearState(); - blank(composer.get('originalText')); - blank(composer.get('reply')); - blank(composer.get('post')); - blank(composer.get('title')); + assert.blank(composer.get('originalText')); + assert.blank(composer.get('reply')); + assert.blank(composer.get('post')); + assert.blank(composer.get('title')); }); -test('initial category when uncategorized is allowed', function() { +QUnit.test('initial category when uncategorized is allowed', assert => { Discourse.SiteSettings.allow_uncategorized_topics = true; const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1}); - ok(!composer.get('categoryId'), "Uncategorized by default"); + assert.ok(!composer.get('categoryId'), "Uncategorized by default"); }); -test('initial category when uncategorized is not allowed', function() { +QUnit.test('initial category when uncategorized is not allowed', assert => { Discourse.SiteSettings.allow_uncategorized_topics = false; const composer = openComposer({action: 'createTopic', draftKey: 'asfd', draftSequence: 1}); - ok(!composer.get('categoryId'), "Uncategorized by default. Must choose a category."); + assert.ok(!composer.get('categoryId'), "Uncategorized by default. Must choose a category."); }); -test('open with a quote', function() { +QUnit.test('open with a quote', assert => { const quote = '[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]'; const newComposer = function() { return openComposer({action: Composer.REPLY, draftKey: 'asfd', draftSequence: 1, quote: quote}); }; - equal(newComposer().get('originalText'), quote, "originalText is the quote" ); - equal(newComposer().get('replyDirty'), false, "replyDirty is initally false with a quote" ); + assert.equal(newComposer().get('originalText'), quote, "originalText is the quote" ); + assert.equal(newComposer().get('replyDirty'), false, "replyDirty is initally false with a quote" ); }); -test("Title length for static page topics as admin", function() { +QUnit.test("Title length for static page topics as admin", assert => { Discourse.SiteSettings.min_topic_title_length = 5; Discourse.SiteSettings.max_topic_title_length = 10; const composer = createComposer(); @@ -229,38 +228,38 @@ test("Title length for static page topics as admin", function() { composer.setProperties({post: post, action: Composer.EDIT }); composer.set('title', 'asdf'); - ok(composer.get('titleLengthValid'), "admins can use short titles"); + assert.ok(composer.get('titleLengthValid'), "admins can use short titles"); composer.set('title', 'this is a long title'); - ok(composer.get('titleLengthValid'), "admins can use long titles"); + assert.ok(composer.get('titleLengthValid'), "admins can use long titles"); composer.set('title', 'just right'); - ok(composer.get('titleLengthValid'), "in the range is okay"); + assert.ok(composer.get('titleLengthValid'), "in the range is okay"); composer.set('title', ''); - ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character"); + assert.ok(!composer.get('titleLengthValid'), "admins must set title to at least 1 character"); }); -test("title placeholder depends on what you're doing", function() { +QUnit.test("title placeholder depends on what you're doing", assert => { let composer = createComposer({action: Composer.CREATE_TOPIC}); - equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for normal topic"); + assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for normal topic"); composer = createComposer({action: Composer.PRIVATE_MESSAGE}); - equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message"); + assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message"); Discourse.SiteSettings.topic_featured_link_enabled = true; composer = createComposer({action: Composer.CREATE_TOPIC}); - equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link"); + assert.equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link"); composer = createComposer({action: Composer.PRIVATE_MESSAGE}); - equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message with topic links enabled"); + assert.equal(composer.get('titlePlaceholder'), 'composer.title_placeholder', "placeholder for private message with topic links enabled"); }); -test("allows featured link before choosing a category", function() { +QUnit.test("allows featured link before choosing a category", assert => { Discourse.SiteSettings.topic_featured_link_enabled = true; Discourse.SiteSettings.allow_uncategorized_topics = false; let composer = createComposer({action: Composer.CREATE_TOPIC}); - equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link"); - ok(composer.get('canEditTopicFeaturedLink'), "can paste link"); -}); + assert.equal(composer.get('titlePlaceholder'), 'composer.title_or_link_placeholder', "placeholder invites you to paste a link"); + assert.ok(composer.get('canEditTopicFeaturedLink'), "can paste link"); +}); \ No newline at end of file diff --git a/test/javascripts/models/email-log-test.js.es6 b/test/javascripts/models/email-log-test.js.es6 index 98d4b714f9c..be18f9190f4 100644 --- a/test/javascripts/models/email-log-test.js.es6 +++ b/test/javascripts/models/email-log-test.js.es6 @@ -1,7 +1,7 @@ import EmailLog from 'admin/models/email-log'; -module("Discourse.EmailLog"); +QUnit.module("Discourse.EmailLog"); -test("create", function() { - ok(EmailLog.create(), "it can be created without arguments"); -}); +QUnit.test("create", assert => { + assert.ok(EmailLog.create(), "it can be created without arguments"); +}); \ No newline at end of file diff --git a/test/javascripts/models/group-test.js.es6 b/test/javascripts/models/group-test.js.es6 index 60f04ed1bbb..3a74d635dd3 100644 --- a/test/javascripts/models/group-test.js.es6 +++ b/test/javascripts/models/group-test.js.es6 @@ -1,13 +1,13 @@ import Group from 'discourse/models/group'; -module("model:group"); +QUnit.module("model:group"); -test('displayName', function() { +QUnit.test('displayName', assert => { const group = Group.create({ name: "test", display_name: 'donkey' }); - ok(group.get('displayName'), "donkey", 'it should return the display name'); + assert.ok(group.get('displayName'), "donkey", 'it should return the display name'); group.set('display_name', null); - ok(group.get('displayName'), "test", "it should return the group's name"); -}); + assert.ok(group.get('displayName'), "test", "it should return the group's name"); +}); \ No newline at end of file diff --git a/test/javascripts/models/invite-test.js.es6 b/test/javascripts/models/invite-test.js.es6 index e55a414293a..0cdc361fca6 100644 --- a/test/javascripts/models/invite-test.js.es6 +++ b/test/javascripts/models/invite-test.js.es6 @@ -1,7 +1,7 @@ import Invite from 'discourse/models/invite'; -module("model:invite"); +QUnit.module("model:invite"); -test("create", function() { - ok(Invite.create(), "it can be created without arguments"); -}); +QUnit.test("create", assert => { + assert.ok(Invite.create(), "it can be created without arguments"); +}); \ No newline at end of file diff --git a/test/javascripts/models/model-test.js.es6 b/test/javascripts/models/model-test.js.es6 index 3270af8a555..eb4d47b8d1c 100644 --- a/test/javascripts/models/model-test.js.es6 +++ b/test/javascripts/models/model-test.js.es6 @@ -1,8 +1,8 @@ import Model from 'discourse/models/model'; -module("model:discourse"); +QUnit.module("model:discourse"); -test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", function() { +QUnit.test("extractByKey: converts a list of hashes into a hash of instances of specified class, indexed by their ids", assert => { var firstObject = {id: "id_1", foo: "foo_1"}; var secondObject = {id: "id_2", foo: "foo_2"}; @@ -12,10 +12,10 @@ test("extractByKey: converts a list of hashes into a hash of instances of specif id_2: Ember.Object.create(secondObject) }; - ok(_.isEqual(actual, expected)); + assert.ok(_.isEqual(actual, expected)); }); -test("extractByKey: returns an empty hash if there isn't anything to convert", function() { - deepEqual(Model.extractByKey(), {}, "when called without parameters"); - deepEqual(Model.extractByKey([]), {}, "when called with an empty array"); -}); +QUnit.test("extractByKey: returns an empty hash if there isn't anything to convert", assert => { + assert.deepEqual(Model.extractByKey(), {}, "when called without parameters"); + assert.deepEqual(Model.extractByKey([]), {}, "when called with an empty array"); +}); \ No newline at end of file diff --git a/test/javascripts/models/nav-item-test.js.es6 b/test/javascripts/models/nav-item-test.js.es6 index 1af1bb14eac..15b75bc0dc6 100644 --- a/test/javascripts/models/nav-item-test.js.es6 +++ b/test/javascripts/models/nav-item-test.js.es6 @@ -1,6 +1,5 @@ - -module("Discourse.NavItem", { - setup: function() { +QUnit.module("Discourse.NavItem", { + beforeEach() { Ember.run(function() { const asianCategory = Discourse.Category.create({name: '确实是这样', id: 343434}); Discourse.Site.currentProp('categories').addObject(asianCategory); @@ -8,11 +7,11 @@ module("Discourse.NavItem", { } }); -test('href', function(){ - expect(4); +QUnit.test('href', assert =>{ + assert.expect(4); function href(text, expected, label) { - equal(Discourse.NavItem.fromText(text, {}).get('href'), expected, label); + assert.equal(Discourse.NavItem.fromText(text, {}).get('href'), expected, label); } href('latest', '/latest', 'latest'); diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6 index b0c455e8fa9..7418102a173 100644 --- a/test/javascripts/models/post-stream-test.js.es6 +++ b/test/javascripts/models/post-stream-test.js.es6 @@ -1,5 +1,4 @@ -import { blank, present } from 'helpers/qunit-helpers'; -module("model:post-stream"); +QUnit.module("model:post-stream"); import createStore from 'helpers/create-store'; @@ -15,93 +14,93 @@ const buildStream = function(id, stream) { const participant = {username: 'eviltrout'}; -test('create', function() { +QUnit.test('create', assert => { const store = createStore(); - ok(store.createRecord('postStream'), 'it can be created with no parameters'); + assert.ok(store.createRecord('postStream'), 'it can be created with no parameters'); }); -test('defaults', function() { +QUnit.test('defaults', assert => { const postStream = buildStream(1234); - blank(postStream.get('posts'), "there are no posts in a stream by default"); - ok(!postStream.get('loaded'), "it has never loaded"); - present(postStream.get('topic')); + assert.blank(postStream.get('posts'), "there are no posts in a stream by default"); + assert.ok(!postStream.get('loaded'), "it has never loaded"); + assert.present(postStream.get('topic')); }); -test('appending posts', function() { +QUnit.test('appending posts', assert => { const postStream = buildStream(4567, [1, 3, 4]); const store = postStream.store; - equal(postStream.get('firstPostId'), 1); - equal(postStream.get('lastPostId'), 4, "the last post id is 4"); + assert.equal(postStream.get('firstPostId'), 1); + assert.equal(postStream.get('lastPostId'), 4, "the last post id is 4"); - ok(!postStream.get('hasPosts'), "there are no posts by default"); - ok(!postStream.get('firstPostPresent'), "the first post is not loaded"); - ok(!postStream.get('loadedAllPosts'), "the last post is not loaded"); - equal(postStream.get('posts.length'), 0, "it has no posts initially"); + assert.ok(!postStream.get('hasPosts'), "there are no posts by default"); + assert.ok(!postStream.get('firstPostPresent'), "the first post is not loaded"); + assert.ok(!postStream.get('loadedAllPosts'), "the last post is not loaded"); + assert.equal(postStream.get('posts.length'), 0, "it has no posts initially"); postStream.appendPost(store.createRecord('post', {id: 2, post_number: 2})); - ok(!postStream.get('firstPostPresent'), "the first post is still not loaded"); - equal(postStream.get('posts.length'), 1, "it has one post in the stream"); + assert.ok(!postStream.get('firstPostPresent'), "the first post is still not loaded"); + assert.equal(postStream.get('posts.length'), 1, "it has one post in the stream"); postStream.appendPost(store.createRecord('post', {id: 4, post_number: 4})); - ok(!postStream.get('firstPostPresent'), "the first post is still loaded"); - ok(postStream.get('loadedAllPosts'), "the last post is now loaded"); - equal(postStream.get('posts.length'), 2, "it has two posts in the stream"); + assert.ok(!postStream.get('firstPostPresent'), "the first post is still loaded"); + assert.ok(postStream.get('loadedAllPosts'), "the last post is now loaded"); + assert.equal(postStream.get('posts.length'), 2, "it has two posts in the stream"); postStream.appendPost(store.createRecord('post', {id: 4, post_number: 4})); - equal(postStream.get('posts.length'), 2, "it will not add the same post with id twice"); + assert.equal(postStream.get('posts.length'), 2, "it will not add the same post with id twice"); const stagedPost = store.createRecord('post', {raw: 'incomplete post'}); postStream.appendPost(stagedPost); - equal(postStream.get('posts.length'), 3, "it can handle posts without ids"); + assert.equal(postStream.get('posts.length'), 3, "it can handle posts without ids"); postStream.appendPost(stagedPost); - equal(postStream.get('posts.length'), 3, "it won't add the same post without an id twice"); + assert.equal(postStream.get('posts.length'), 3, "it won't add the same post without an id twice"); // change the stream postStream.set('stream', [1, 2, 4]); - ok(!postStream.get('firstPostPresent'), "the first post no longer loaded since the stream changed."); - ok(postStream.get('loadedAllPosts'), "the last post is still the last post in the new stream"); + assert.ok(!postStream.get('firstPostPresent'), "the first post no longer loaded since the stream changed."); + assert.ok(postStream.get('loadedAllPosts'), "the last post is still the last post in the new stream"); }); -test('closestPostNumberFor', function() { +QUnit.test('closestPostNumberFor', assert => { const postStream = buildStream(1231); const store = postStream.store; - blank(postStream.closestPostNumberFor(1), "there is no closest post when nothing is loaded"); + assert.blank(postStream.closestPostNumberFor(1), "there is no closest post when nothing is loaded"); postStream.appendPost(store.createRecord('post', {id: 1, post_number: 2})); postStream.appendPost(store.createRecord('post', {id: 2, post_number: 3})); - equal(postStream.closestPostNumberFor(2), 2, "If a post is in the stream it returns its post number"); - equal(postStream.closestPostNumberFor(3), 3, "If a post is in the stream it returns its post number"); - equal(postStream.closestPostNumberFor(10), 3, "it clips to the upper bound of the stream"); - equal(postStream.closestPostNumberFor(0), 2, "it clips to the lower bound of the stream"); + assert.equal(postStream.closestPostNumberFor(2), 2, "If a post is in the stream it returns its post number"); + assert.equal(postStream.closestPostNumberFor(3), 3, "If a post is in the stream it returns its post number"); + assert.equal(postStream.closestPostNumberFor(10), 3, "it clips to the upper bound of the stream"); + assert.equal(postStream.closestPostNumberFor(0), 2, "it clips to the lower bound of the stream"); }); -test('closestDaysAgoFor', function() { +QUnit.test('closestDaysAgoFor', assert => { const postStream = buildStream(1231); postStream.set('timelineLookup', [[1, 10], [3, 8], [5, 1]]); - equal(postStream.closestDaysAgoFor(1), 10); - equal(postStream.closestDaysAgoFor(2), 10); - equal(postStream.closestDaysAgoFor(3), 8); - equal(postStream.closestDaysAgoFor(4), 8); - equal(postStream.closestDaysAgoFor(5), 1); + assert.equal(postStream.closestDaysAgoFor(1), 10); + assert.equal(postStream.closestDaysAgoFor(2), 10); + assert.equal(postStream.closestDaysAgoFor(3), 8); + assert.equal(postStream.closestDaysAgoFor(4), 8); + assert.equal(postStream.closestDaysAgoFor(5), 1); // Out of bounds - equal(postStream.closestDaysAgoFor(-1), 10); - equal(postStream.closestDaysAgoFor(0), 10); - equal(postStream.closestDaysAgoFor(10), 1); + assert.equal(postStream.closestDaysAgoFor(-1), 10); + assert.equal(postStream.closestDaysAgoFor(0), 10); + assert.equal(postStream.closestDaysAgoFor(10), 1); }); -test('closestDaysAgoFor - empty', function() { +QUnit.test('closestDaysAgoFor - empty', assert => { const postStream = buildStream(1231); postStream.set('timelineLookup', []); - equal(postStream.closestDaysAgoFor(1), null); + assert.equal(postStream.closestDaysAgoFor(1), null); }); -test('updateFromJson', function() { +QUnit.test('updateFromJson', assert => { const postStream = buildStream(1231); postStream.updateFromJson({ @@ -110,13 +109,13 @@ test('updateFromJson', function() { extra_property: 12 }); - equal(postStream.get('posts.length'), 1, 'it loaded the posts'); - containsInstance(postStream.get('posts'), Discourse.Post); + assert.equal(postStream.get('posts.length'), 1, 'it loaded the posts'); + assert.containsInstance(postStream.get('posts'), Discourse.Post); - equal(postStream.get('extra_property'), 12); + assert.equal(postStream.get('extra_property'), 12); }); -test("removePosts", function() { +QUnit.test("removePosts", assert => { const postStream = buildStream(10000001, [1,2,3]); const store = postStream.store; @@ -130,179 +129,179 @@ test("removePosts", function() { // Removing nothing does nothing postStream.removePosts(); - equal(postStream.get('posts.length'), 3); + assert.equal(postStream.get('posts.length'), 3); postStream.removePosts([p1, p3]); - equal(postStream.get('posts.length'), 1); - deepEqual(postStream.get('stream'), [2]); + assert.equal(postStream.get('posts.length'), 1); + assert.deepEqual(postStream.get('stream'), [2]); }); -test("cancelFilter", function() { +QUnit.test("cancelFilter", assert => { const postStream = buildStream(1235); sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve()); postStream.set('summary', true); postStream.cancelFilter(); - ok(!postStream.get('summary'), "summary is cancelled"); + assert.ok(!postStream.get('summary'), "summary is cancelled"); postStream.toggleParticipant(participant); postStream.cancelFilter(); - blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters"); + assert.blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters"); }); -test("findPostIdForPostNumber", function() { +QUnit.test("findPostIdForPostNumber", assert => { const postStream = buildStream(1234, [10, 20, 30, 40, 50, 60, 70]); postStream.set('gaps', { before: { 60: [55, 58] } }); - equal(postStream.findPostIdForPostNumber(500), null, 'it returns null when the post cannot be found'); - equal(postStream.findPostIdForPostNumber(1), 10, 'it finds the postId at the beginning'); - equal(postStream.findPostIdForPostNumber(5), 50, 'it finds the postId in the middle'); - equal(postStream.findPostIdForPostNumber(8), 60, 'it respects gaps'); + assert.equal(postStream.findPostIdForPostNumber(500), null, 'it returns null when the post cannot be found'); + assert.equal(postStream.findPostIdForPostNumber(1), 10, 'it finds the postId at the beginning'); + assert.equal(postStream.findPostIdForPostNumber(5), 50, 'it finds the postId in the middle'); + assert.equal(postStream.findPostIdForPostNumber(8), 60, 'it respects gaps'); }); -test("toggleParticipant", function() { +QUnit.test("toggleParticipant", assert => { const postStream = buildStream(1236); sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve()); - equal(postStream.get('userFilters.length'), 0, "by default no participants are toggled"); + assert.equal(postStream.get('userFilters.length'), 0, "by default no participants are toggled"); postStream.toggleParticipant(participant.username); - ok(postStream.get('userFilters').includes('eviltrout'), 'eviltrout is in the filters'); + assert.ok(postStream.get('userFilters').includes('eviltrout'), 'eviltrout is in the filters'); postStream.toggleParticipant(participant.username); - blank(postStream.get('userFilters'), "toggling the participant again removes them"); + assert.blank(postStream.get('userFilters'), "toggling the participant again removes them"); }); -test("streamFilters", function() { +QUnit.test("streamFilters", assert => { const postStream = buildStream(1237); sandbox.stub(postStream, "refresh").returns(new Ember.RSVP.resolve()); - deepEqual(postStream.get('streamFilters'), {}, "there are no postFilters by default"); - ok(postStream.get('hasNoFilters'), "there are no filters by default"); + assert.deepEqual(postStream.get('streamFilters'), {}, "there are no postFilters by default"); + assert.ok(postStream.get('hasNoFilters'), "there are no filters by default"); postStream.set('summary', true); - deepEqual(postStream.get('streamFilters'), {filter: "summary"}, "postFilters contains the summary flag"); - ok(!postStream.get('hasNoFilters'), "now there are filters present"); + assert.deepEqual(postStream.get('streamFilters'), {filter: "summary"}, "postFilters contains the summary flag"); + assert.ok(!postStream.get('hasNoFilters'), "now there are filters present"); postStream.toggleParticipant(participant.username); - deepEqual(postStream.get('streamFilters'), { + assert.deepEqual(postStream.get('streamFilters'), { username_filters: 'eviltrout', }, "streamFilters contains the username we filtered"); }); -test("loading", function() { +QUnit.test("loading", assert => { let postStream = buildStream(1234); - ok(!postStream.get('loading'), "we're not loading by default"); + assert.ok(!postStream.get('loading'), "we're not loading by default"); postStream.set('loadingAbove', true); - ok(postStream.get('loading'), "we're loading if loading above"); + assert.ok(postStream.get('loading'), "we're loading if loading above"); postStream = buildStream(1234); postStream.set('loadingBelow', true); - ok(postStream.get('loading'), "we're loading if loading below"); + assert.ok(postStream.get('loading'), "we're loading if loading below"); postStream = buildStream(1234); postStream.set('loadingFilter', true); - ok(postStream.get('loading'), "we're loading if loading a filter"); + assert.ok(postStream.get('loading'), "we're loading if loading a filter"); }); -test("nextWindow", function() { +QUnit.test("nextWindow", assert => { const postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]); - blank(postStream.get('nextWindow'), 'With no posts loaded, the window is blank'); + assert.blank(postStream.get('nextWindow'), 'With no posts loaded, the window is blank'); postStream.updateFromJson({ posts: [{id: 1}, {id: 2}] }); - deepEqual(postStream.get('nextWindow'), [3,5,8,9,10], + assert.deepEqual(postStream.get('nextWindow'), [3,5,8,9,10], "If we've loaded the first 2 posts, the window should be the 5 after that"); postStream.updateFromJson({ posts: [{id: 13}] }); - deepEqual(postStream.get('nextWindow'), [14, 15, 16], "Boundary check: stop at the end."); + assert.deepEqual(postStream.get('nextWindow'), [14, 15, 16], "Boundary check: stop at the end."); postStream.updateFromJson({ posts: [{id: 16}] }); - blank(postStream.get('nextWindow'), "Once we've seen everything there's nothing to load."); + assert.blank(postStream.get('nextWindow'), "Once we've seen everything there's nothing to load."); }); -test("previousWindow", function() { +QUnit.test("previousWindow", assert => { const postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]); - blank(postStream.get('previousWindow'), 'With no posts loaded, the window is blank'); + assert.blank(postStream.get('previousWindow'), 'With no posts loaded, the window is blank'); postStream.updateFromJson({ posts: [{id: 11}, {id: 13}] }); - deepEqual(postStream.get('previousWindow'), [3, 5, 8, 9, 10], + assert.deepEqual(postStream.get('previousWindow'), [3, 5, 8, 9, 10], "If we've loaded in the middle, it's the previous 5 posts"); postStream.updateFromJson({ posts: [{id: 3}] }); - deepEqual(postStream.get('previousWindow'), [1, 2], "Boundary check: stop at the beginning."); + assert.deepEqual(postStream.get('previousWindow'), [1, 2], "Boundary check: stop at the beginning."); postStream.updateFromJson({ posts: [{id: 1}] }); - blank(postStream.get('previousWindow'), "Once we've seen everything there's nothing to load."); + assert.blank(postStream.get('previousWindow'), "Once we've seen everything there's nothing to load."); }); -test("storePost", function() { +QUnit.test("storePost", assert => { const postStream = buildStream(1234), store = postStream.store, post = store.createRecord('post', {id: 1, post_number: 100, raw: 'initial value'}); - blank(postStream.get('topic.highest_post_number'), "it has no highest post number yet"); + assert.blank(postStream.get('topic.highest_post_number'), "it has no highest post number yet"); let stored = postStream.storePost(post); - equal(post, stored, "it returns the post it stored"); - equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly"); - equal(postStream.get('topic.highest_post_number'), 100, "it set the highest post number"); + assert.equal(post, stored, "it returns the post it stored"); + assert.equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly"); + assert.equal(postStream.get('topic.highest_post_number'), 100, "it set the highest post number"); const dupePost = store.createRecord('post', {id: 1, post_number: 100, raw: 'updated value'}); const storedDupe = postStream.storePost(dupePost); - equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes"); - equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post'); + assert.equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes"); + assert.equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post'); const postWithoutId = store.createRecord('post', {raw: 'hello world'}); stored = postStream.storePost(postWithoutId); - equal(stored, postWithoutId, "it returns the same post back"); + assert.equal(stored, postWithoutId, "it returns the same post back"); }); -test("identity map", function() { +QUnit.test("identity map", assert => { const postStream = buildStream(1234); const store = postStream.store; const p1 = postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1})); const p3 = postStream.appendPost(store.createRecord('post', {id: 3, post_number: 4})); - equal(postStream.findLoadedPost(1), p1, "it can return cached posts by id"); - blank(postStream.findLoadedPost(4), "it can't find uncached posts"); + assert.equal(postStream.findLoadedPost(1), p1, "it can return cached posts by id"); + assert.blank(postStream.findLoadedPost(4), "it can't find uncached posts"); // Find posts by ids uses the identity map - postStream.findPostsByIds([1, 2, 3]).then(result => { - equal(result.length, 3); - equal(result.objectAt(0), p1); - equal(result.objectAt(1).get('post_number'), 2); - equal(result.objectAt(2), p3); + return postStream.findPostsByIds([1, 2, 3]).then(result => { + assert.equal(result.length, 3); + assert.equal(result.objectAt(0), p1); + assert.equal(result.objectAt(1).get('post_number'), 2); + assert.equal(result.objectAt(2), p3); }); }); -test("loadIntoIdentityMap with no data", () => { +QUnit.test("loadIntoIdentityMap with no data", assert => { return buildStream(1234).loadIntoIdentityMap([]).then(result => { - equal(result.length, 0, 'requesting no posts produces no posts'); + assert.equal(result.length, 0, 'requesting no posts produces no posts'); }); }); -test("loadIntoIdentityMap with post ids", function() { +QUnit.test("loadIntoIdentityMap with post ids", assert => { const postStream = buildStream(1234); return postStream.loadIntoIdentityMap([10]).then(function() { - present(postStream.findLoadedPost(10), "it adds the returned post to the store"); + assert.present(postStream.findLoadedPost(10), "it adds the returned post to the store"); }); }); -test("staging and undoing a new post", function() { +QUnit.test("staging and undoing a new post", assert => { const postStream = buildStream(10101, [1]); const store = postStream.store; const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101}); postStream.appendPost(original); - ok(postStream.get('lastAppended'), original, "the original post is lastAppended"); + assert.ok(postStream.get('lastAppended'), original, "the original post is lastAppended"); const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321}); const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 }); @@ -315,39 +314,39 @@ test("staging and undoing a new post", function() { // Stage the new post in the stream const result = postStream.stagePost(stagedPost, user); - equal(result, "staged", "it returns staged"); - equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number"); - ok(postStream.get('loading'), "it is loading while the post is being staged"); - ok(postStream.get('lastAppended'), original, "it doesn't consider staged posts as the lastAppended"); + assert.equal(result, "staged", "it returns staged"); + assert.equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number"); + assert.ok(postStream.get('loading'), "it is loading while the post is being staged"); + assert.ok(postStream.get('lastAppended'), original, "it doesn't consider staged posts as the lastAppended"); - equal(topic.get('posts_count'), 2, "it increases the post count"); - present(topic.get('last_posted_at'), "it updates last_posted_at"); - equal(topic.get('details.last_poster'), user, "it changes the last poster"); + assert.equal(topic.get('posts_count'), 2, "it increases the post count"); + assert.present(topic.get('last_posted_at'), "it updates last_posted_at"); + assert.equal(topic.get('details.last_poster'), user, "it changes the last poster"); - equal(stagedPost.get('topic'), topic, "it assigns the topic reference"); - equal(stagedPost.get('post_number'), 2, "it is assigned the probable post_number"); - present(stagedPost.get('created_at'), "it is assigned a created date"); - ok(postStream.get('posts').includes(stagedPost), "the post is added to the stream"); - equal(stagedPost.get('id'), -1, "the post has a magical -1 id"); + assert.equal(stagedPost.get('topic'), topic, "it assigns the topic reference"); + assert.equal(stagedPost.get('post_number'), 2, "it is assigned the probable post_number"); + assert.present(stagedPost.get('created_at'), "it is assigned a created date"); + assert.ok(postStream.get('posts').includes(stagedPost), "the post is added to the stream"); + assert.equal(stagedPost.get('id'), -1, "the post has a magical -1 id"); // Undoing a created post (there was an error) postStream.undoPost(stagedPost); - ok(!postStream.get('loading'), "it is no longer loading"); - equal(topic.get('highest_post_number'), 1, "it reverts the highest_post_number"); - equal(topic.get('posts_count'), 1, "it reverts the post count"); - equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount"); - ok(!postStream.get('posts').includes(stagedPost), "the post is removed from the stream"); - ok(postStream.get('lastAppended'), original, "it doesn't consider undid post lastAppended"); + assert.ok(!postStream.get('loading'), "it is no longer loading"); + assert.equal(topic.get('highest_post_number'), 1, "it reverts the highest_post_number"); + assert.equal(topic.get('posts_count'), 1, "it reverts the post count"); + assert.equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount"); + assert.ok(!postStream.get('posts').includes(stagedPost), "the post is removed from the stream"); + assert.ok(postStream.get('lastAppended'), original, "it doesn't consider undid post lastAppended"); }); -test("staging and committing a post", function() { +QUnit.test("staging and committing a post", assert => { const postStream = buildStream(10101, [1]); const store = postStream.store; const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101}); postStream.appendPost(original); - ok(postStream.get('lastAppended'), original, "the original post is lastAppended"); + assert.ok(postStream.get('lastAppended'), original, "the original post is lastAppended"); const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321}); const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 }); @@ -357,29 +356,29 @@ test("staging and committing a post", function() { // Stage the new post in the stream let result = postStream.stagePost(stagedPost, user); - equal(result, "staged", "it returns staged"); + assert.equal(result, "staged", "it returns staged"); - ok(postStream.get('loading'), "it is loading while the post is being staged"); + assert.ok(postStream.get('loading'), "it is loading while the post is being staged"); stagedPost.setProperties({ id: 1234, raw: "different raw value" }); result = postStream.stagePost(stagedPost, user); - equal(result, "alreadyStaging", "you can't stage a post while it is currently staging"); - ok(postStream.get('lastAppended'), original, "staging a post doesn't change the lastAppended"); + assert.equal(result, "alreadyStaging", "you can't stage a post while it is currently staging"); + assert.ok(postStream.get('lastAppended'), original, "staging a post doesn't change the lastAppended"); postStream.commitPost(stagedPost); - ok(postStream.get('posts').includes(stagedPost), "the post is still in the stream"); - ok(!postStream.get('loading'), "it is no longer loading"); + assert.ok(postStream.get('posts').includes(stagedPost), "the post is still in the stream"); + assert.ok(!postStream.get('loading'), "it is no longer loading"); - equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount"); + assert.equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount"); const found = postStream.findLoadedPost(stagedPost.get('id')); - present(found, "the post is in the identity map"); - ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream"); - equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream'); - ok(postStream.get('lastAppended'), found, "comitting a post changes lastAppended"); + assert.present(found, "the post is in the identity map"); + assert.ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream"); + assert.equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream'); + assert.ok(postStream.get('lastAppended'), found, "comitting a post changes lastAppended"); }); -test("loadedAllPosts when the id changes", function() { +QUnit.test("loadedAllPosts when the id changes", assert => { // This can happen in a race condition between staging a post and it coming through on the // message bus. If the id of a post changes we should reconsider the loadedAllPosts property. const postStream = buildStream(10101, [1, 2]); @@ -388,13 +387,13 @@ test("loadedAllPosts when the id changes", function() { postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1})); postStream.appendPost(postWithoutId); - ok(!postStream.get('loadedAllPosts'), 'the last post is not loaded'); + assert.ok(!postStream.get('loadedAllPosts'), 'the last post is not loaded'); postWithoutId.set('id', 2); - ok(postStream.get('loadedAllPosts'), 'the last post is loaded now that the post has an id'); + assert.ok(postStream.get('loadedAllPosts'), 'the last post is loaded now that the post has an id'); }); -test("comitting and triggerNewPostInStream race condition", function() { +QUnit.test("comitting and triggerNewPostInStream race condition", assert => { const postStream = buildStream(4964); const store = postStream.store; @@ -403,18 +402,18 @@ test("comitting and triggerNewPostInStream race condition", function() { const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post' }); postStream.stagePost(stagedPost, user); - equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet"); + assert.equal(postStream.get('filteredPostsCount'), 0, "it has no filteredPostsCount yet"); stagedPost.set('id', 123); sandbox.stub(postStream, 'appendMore'); postStream.triggerNewPostInStream(123); - equal(postStream.get('filteredPostsCount'), 1, "it added the post"); + assert.equal(postStream.get('filteredPostsCount'), 1, "it added the post"); postStream.commitPost(stagedPost); - equal(postStream.get('filteredPostsCount'), 1, "it does not add the same post twice"); + assert.equal(postStream.get('filteredPostsCount'), 1, "it does not add the same post twice"); }); -test("postsWithPlaceholders", () => { +QUnit.test("postsWithPlaceholders", assert => { const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); const postsWithPlaceholders = postStream.get('postsWithPlaceholders'); const store = postStream.store; @@ -431,28 +430,28 @@ test("postsWithPlaceholders", () => { postStream.appendPost(p3); // Test enumerable and array access - equal(postsWithPlaceholders.get('length'), 3); - equal(testProxy.get('length'), 3); - equal(postsWithPlaceholders.nextObject(0), p1); - equal(postsWithPlaceholders.objectAt(0), p1); - equal(postsWithPlaceholders.nextObject(1, p1), p2); - equal(postsWithPlaceholders.objectAt(1), p2); - equal(postsWithPlaceholders.nextObject(2, p2), p3); - equal(postsWithPlaceholders.objectAt(2), p3); + assert.equal(postsWithPlaceholders.get('length'), 3); + assert.equal(testProxy.get('length'), 3); + assert.equal(postsWithPlaceholders.nextObject(0), p1); + assert.equal(postsWithPlaceholders.objectAt(0), p1); + assert.equal(postsWithPlaceholders.nextObject(1, p1), p2); + assert.equal(postsWithPlaceholders.objectAt(1), p2); + assert.equal(postsWithPlaceholders.nextObject(2, p2), p3); + assert.equal(postsWithPlaceholders.objectAt(2), p3); const promise = postStream.appendMore(); - equal(postsWithPlaceholders.get('length'), 8, 'we immediately have a larger placeholder window'); - equal(testProxy.get('length'), 8); - ok(!!postsWithPlaceholders.nextObject(3, p3)); - ok(!!postsWithPlaceholders.objectAt(4)); - ok(postsWithPlaceholders.objectAt(3) !== p4); - ok(testProxy.objectAt(3) !== p4); + assert.equal(postsWithPlaceholders.get('length'), 8, 'we immediately have a larger placeholder window'); + assert.equal(testProxy.get('length'), 8); + assert.ok(!!postsWithPlaceholders.nextObject(3, p3)); + assert.ok(!!postsWithPlaceholders.objectAt(4)); + assert.ok(postsWithPlaceholders.objectAt(3) !== p4); + assert.ok(testProxy.objectAt(3) !== p4); return promise.then(() => { - equal(postsWithPlaceholders.objectAt(3), p4); - equal(postsWithPlaceholders.get('length'), 8, 'have a larger placeholder window when loaded'); - equal(testProxy.get('length'), 8); - equal(testProxy.objectAt(3), p4); + assert.equal(postsWithPlaceholders.objectAt(3), p4); + assert.equal(postsWithPlaceholders.get('length'), 8, 'have a larger placeholder window when loaded'); + assert.equal(testProxy.get('length'), 8); + assert.equal(testProxy.objectAt(3), p4); }); }); diff --git a/test/javascripts/models/post-test.js.es6 b/test/javascripts/models/post-test.js.es6 index 1f881df1209..f2c487c1b94 100644 --- a/test/javascripts/models/post-test.js.es6 +++ b/test/javascripts/models/post-test.js.es6 @@ -1,6 +1,4 @@ -import { present, blank } from 'helpers/qunit-helpers'; - -module("Discourse.Post"); +QUnit.module("Discourse.Post"); var buildPost = function(args) { return Discourse.Post.create(_.merge({ @@ -10,29 +8,29 @@ var buildPost = function(args) { }, args || {})); }; -test('defaults', function() { +QUnit.test('defaults', assert => { var post = Discourse.Post.create({id: 1}); - blank(post.get('deleted_at'), "it has no deleted_at by default"); - blank(post.get('deleted_by'), "there is no deleted_by by default"); + assert.blank(post.get('deleted_at'), "it has no deleted_at by default"); + assert.blank(post.get('deleted_by'), "there is no deleted_by by default"); }); -test('new_user', function() { +QUnit.test('new_user', assert => { var post = Discourse.Post.create({trust_level: 0}); - ok(post.get('new_user'), "post is from a new user"); + assert.ok(post.get('new_user'), "post is from a new user"); post.set('trust_level', 1); - ok(!post.get('new_user'), "post is no longer from a new user"); + assert.ok(!post.get('new_user'), "post is no longer from a new user"); }); -test('firstPost', function() { +QUnit.test('firstPost', assert => { var post = Discourse.Post.create({post_number: 1}); - ok(post.get('firstPost'), "it's the first post"); + assert.ok(post.get('firstPost'), "it's the first post"); post.set('post_number', 10); - ok(!post.get('firstPost'), "post is no longer the first post"); + assert.ok(!post.get('firstPost'), "post is no longer the first post"); }); -test('updateFromPost', function() { +QUnit.test('updateFromPost', assert => { var post = Discourse.Post.create({ post_number: 1, raw: 'hello world' @@ -43,33 +41,32 @@ test('updateFromPost', function() { wat: function() { return 123; } })); - equal(post.get('raw'), "different raw", "raw field updated"); + assert.equal(post.get('raw'), "different raw", "raw field updated"); }); -test('destroy by staff', function() { +QUnit.test('destroy by staff', assert => { var user = Discourse.User.create({username: 'staff', staff: true}), post = buildPost({user: user}); post.destroy(user); - present(post.get('deleted_at'), "it has a `deleted_at` field."); - equal(post.get('deleted_by'), user, "it has the user in the `deleted_by` field"); + assert.present(post.get('deleted_at'), "it has a `deleted_at` field."); + assert.equal(post.get('deleted_by'), user, "it has the user in the `deleted_by` field"); post.recover(); - blank(post.get('deleted_at'), "it clears `deleted_at` when recovering"); - blank(post.get('deleted_by'), "it clears `deleted_by` when recovering"); + assert.blank(post.get('deleted_at'), "it clears `deleted_at` when recovering"); + assert.blank(post.get('deleted_by'), "it clears `deleted_by` when recovering"); }); -test('destroy by non-staff', function() { +QUnit.test('destroy by non-staff', assert => { var originalCooked = "this is the original cooked value", user = Discourse.User.create({username: 'evil trout'}), post = buildPost({user: user, cooked: originalCooked}); post.destroy(user); - ok(!post.get('can_delete'), "the post can't be deleted again in this session"); - ok(post.get('cooked') !== originalCooked, "the cooked content changed"); - equal(post.get('version'), 2, "the version number increased"); -}); - + assert.ok(!post.get('can_delete'), "the post can't be deleted again in this session"); + assert.ok(post.get('cooked') !== originalCooked, "the cooked content changed"); + assert.equal(post.get('version'), 2, "the version number increased"); +}); \ No newline at end of file diff --git a/test/javascripts/models/report-test.js.es6 b/test/javascripts/models/report-test.js.es6 index 3fcdd9d037c..1e4f73d89ea 100644 --- a/test/javascripts/models/report-test.js.es6 +++ b/test/javascripts/models/report-test.js.es6 @@ -1,7 +1,6 @@ -import { blank } from 'helpers/qunit-helpers'; import Report from 'admin/models/report'; -module("Report"); +QUnit.module("Report"); function reportWithData(data) { return Report.create({ @@ -12,53 +11,53 @@ function reportWithData(data) { }); } -test("counts", function() { +QUnit.test("counts", assert => { var report = reportWithData([5, 4, 3, 2, 1, 100, 99, 98, 1000]); - equal(report.get('todayCount'), 5); - equal(report.get('yesterdayCount'), 4); - equal(report.valueFor(2, 4), 6, "adds the values for the given range of days, inclusive"); - equal(report.get('lastSevenDaysCount'), 307, "sums 7 days excluding today"); + assert.equal(report.get('todayCount'), 5); + assert.equal(report.get('yesterdayCount'), 4); + assert.equal(report.valueFor(2, 4), 6, "adds the values for the given range of days, inclusive"); + assert.equal(report.get('lastSevenDaysCount'), 307, "sums 7 days excluding today"); report.set("method", "average"); - equal(report.valueFor(2, 4), 2, "averages the values for the given range of days"); + assert.equal(report.valueFor(2, 4), 2, "averages the values for the given range of days"); }); -test("percentChangeString", function() { +QUnit.test("percentChangeString", assert => { var report = reportWithData([]); - equal(report.percentChangeString(8, 5), "+60%", "value increased"); - equal(report.percentChangeString(2, 8), "-75%", "value decreased"); - equal(report.percentChangeString(8, 8), "0%", "value unchanged"); - blank(report.percentChangeString(8, 0), "returns blank when previous value was 0"); - equal(report.percentChangeString(0, 8), "-100%", "yesterday was 0"); - blank(report.percentChangeString(0, 0), "returns blank when both were 0"); + assert.equal(report.percentChangeString(8, 5), "+60%", "value increased"); + assert.equal(report.percentChangeString(2, 8), "-75%", "value decreased"); + assert.equal(report.percentChangeString(8, 8), "0%", "value unchanged"); + assert.blank(report.percentChangeString(8, 0), "returns blank when previous value was 0"); + assert.equal(report.percentChangeString(0, 8), "-100%", "yesterday was 0"); + assert.blank(report.percentChangeString(0, 0), "returns blank when both were 0"); }); -test("yesterdayCountTitle with valid values", function() { +QUnit.test("yesterdayCountTitle with valid values", assert => { var title = reportWithData([6,8,5,2,1]).get('yesterdayCountTitle'); - ok(title.indexOf('+60%') !== -1); - ok(title.match(/Was 5/)); + assert.ok(title.indexOf('+60%') !== -1); + assert.ok(title.match(/Was 5/)); }); -test("yesterdayCountTitle when two days ago was 0", function() { +QUnit.test("yesterdayCountTitle when two days ago was 0", assert => { var title = reportWithData([6,8,0,2,1]).get('yesterdayCountTitle'); - equal(title.indexOf('%'), -1); - ok(title.match(/Was 0/)); + assert.equal(title.indexOf('%'), -1); + assert.ok(title.match(/Was 0/)); }); -test("sevenDayCountTitle", function() { +QUnit.test("sevenDayCountTitle", assert => { var title = reportWithData([100,1,1,1,1,1,1,1,2,2,2,2,2,2,2,100,100]).get('sevenDayCountTitle'); - ok(title.match(/-50%/)); - ok(title.match(/Was 14/)); + assert.ok(title.match(/-50%/)); + assert.ok(title.match(/Was 14/)); }); -test("thirtyDayCountTitle", function() { +QUnit.test("thirtyDayCountTitle", assert => { var report = reportWithData([5,5,5,5]); report.set('prev30Days', 10); var title = report.get('thirtyDayCountTitle'); - ok(title.indexOf('+50%') !== -1); - ok(title.match(/Was 10/)); -}); + assert.ok(title.indexOf('+50%') !== -1); + assert.ok(title.match(/Was 10/)); +}); \ No newline at end of file diff --git a/test/javascripts/models/rest-model-test.js.es6 b/test/javascripts/models/rest-model-test.js.es6 index 73a77e7203d..031cb3b0c25 100644 --- a/test/javascripts/models/rest-model-test.js.es6 +++ b/test/javascripts/models/rest-model-test.js.es6 @@ -1,9 +1,9 @@ -module('rest-model'); +QUnit.module('rest-model'); import createStore from 'helpers/create-store'; import RestModel from 'discourse/models/rest'; -test('munging', function() { +QUnit.test('munging', assert => { const store = createStore(); const Grape = RestModel.extend(); Grape.reopenClass({ @@ -14,26 +14,26 @@ test('munging', function() { }); var g = Grape.create({ store, percent: 0.4 }); - equal(g.get('inverse'), 0.6, 'it runs `munge` on `create`'); + assert.equal(g.get('inverse'), 0.6, 'it runs `munge` on `create`'); }); -test('update', function() { +QUnit.test('update', assert => { const store = createStore(); return store.find('widget', 123).then(function(widget) { - equal(widget.get('name'), 'Trout Lure'); + assert.equal(widget.get('name'), 'Trout Lure'); - ok(!widget.get('isSaving')); + assert.ok(!widget.get('isSaving')); const promise = widget.update({ name: 'new name' }); - ok(widget.get('isSaving')); + assert.ok(widget.get('isSaving')); promise.then(function() { - ok(!widget.get('isSaving')); - equal(widget.get('name'), 'new name'); + assert.ok(!widget.get('isSaving')); + assert.equal(widget.get('name'), 'new name'); }); }); }); -test('updating simultaneously', function() { - expect(2); +QUnit.test('updating simultaneously', assert => { + assert.expect(2); const store = createStore(); return store.find('widget', 123).then(function(widget) { @@ -41,37 +41,37 @@ test('updating simultaneously', function() { const firstPromise = widget.update({ name: 'new name' }); const secondPromise = widget.update({ name: 'new name' }); firstPromise.then(function() { - ok(true, 'the first promise succeeeds'); + assert.ok(true, 'the first promise succeeeds'); }); secondPromise.catch(function() { - ok(true, 'the second promise fails'); + assert.ok(true, 'the second promise fails'); }); }); }); -test('save new', function() { +QUnit.test('save new', assert => { const store = createStore(); const widget = store.createRecord('widget'); - ok(widget.get('isNew'), 'it is a new record'); - ok(!widget.get('isCreated'), 'it is not created'); - ok(!widget.get('isSaving')); + assert.ok(widget.get('isNew'), 'it is a new record'); + assert.ok(!widget.get('isCreated'), 'it is not created'); + assert.ok(!widget.get('isSaving')); const promise = widget.save({ name: 'Evil Widget' }); - ok(widget.get('isSaving')); + assert.ok(widget.get('isSaving')); return promise.then(function() { - ok(!widget.get('isSaving')); - ok(widget.get('id'), 'it has an id'); - ok(widget.get('name'), 'Evil Widget'); - ok(widget.get('isCreated'), 'it is created'); - ok(!widget.get('isNew'), 'it is no longer new'); + assert.ok(!widget.get('isSaving')); + assert.ok(widget.get('id'), 'it has an id'); + assert.ok(widget.get('name'), 'Evil Widget'); + assert.ok(widget.get('isCreated'), 'it is created'); + assert.ok(!widget.get('isNew'), 'it is no longer new'); }); }); -test('creating simultaneously', function() { - expect(2); +QUnit.test('creating simultaneously', assert => { + assert.expect(2); const store = createStore(); const widget = store.createRecord('widget'); @@ -79,20 +79,19 @@ test('creating simultaneously', function() { const firstPromise = widget.save({ name: 'Evil Widget' }); const secondPromise = widget.save({ name: 'Evil Widget' }); firstPromise.then(function() { - ok(true, 'the first promise succeeeds'); + assert.ok(true, 'the first promise succeeeds'); }); secondPromise.catch(function() { - ok(true, 'the second promise fails'); + assert.ok(true, 'the second promise fails'); }); }); -test('destroyRecord', function() { +QUnit.test('destroyRecord', assert => { const store = createStore(); return store.find('widget', 123).then(function(widget) { widget.destroyRecord().then(function(result) { - ok(result); + assert.ok(result); }); }); }); - diff --git a/test/javascripts/models/result-set-test.js.es6 b/test/javascripts/models/result-set-test.js.es6 index 18c9aa0c80f..2912b8ddb80 100644 --- a/test/javascripts/models/result-set-test.js.es6 +++ b/test/javascripts/models/result-set-test.js.es6 @@ -1,49 +1,49 @@ -module('result-set'); +QUnit.module('result-set'); import ResultSet from 'discourse/models/result-set'; import createStore from 'helpers/create-store'; -test('defaults', function() { +QUnit.test('defaults', assert => { const rs = ResultSet.create({ content: [] }); - equal(rs.get('length'), 0); - equal(rs.get('totalRows'), 0); - ok(!rs.get('loadMoreUrl')); - ok(!rs.get('loading')); - ok(!rs.get('loadingMore')); - ok(!rs.get('refreshing')); + assert.equal(rs.get('length'), 0); + assert.equal(rs.get('totalRows'), 0); + assert.ok(!rs.get('loadMoreUrl')); + assert.ok(!rs.get('loading')); + assert.ok(!rs.get('loadingMore')); + assert.ok(!rs.get('refreshing')); }); -test('pagination support', function() { +QUnit.test('pagination support', assert => { const store = createStore(); return store.findAll('widget').then(function(rs) { - equal(rs.get('length'), 2); - equal(rs.get('totalRows'), 4); - ok(rs.get('loadMoreUrl'), 'has a url to load more'); - ok(!rs.get('loadingMore'), 'it is not loading more'); - ok(rs.get('canLoadMore')); + assert.equal(rs.get('length'), 2); + assert.equal(rs.get('totalRows'), 4); + assert.ok(rs.get('loadMoreUrl'), 'has a url to load more'); + assert.ok(!rs.get('loadingMore'), 'it is not loading more'); + assert.ok(rs.get('canLoadMore')); const promise = rs.loadMore(); - ok(rs.get('loadingMore'), 'it is loading more'); + assert.ok(rs.get('loadingMore'), 'it is loading more'); promise.then(function() { - ok(!rs.get('loadingMore'), 'it finished loading more'); - equal(rs.get('length'), 4); - ok(!rs.get('loadMoreUrl')); - ok(!rs.get('canLoadMore')); + assert.ok(!rs.get('loadingMore'), 'it finished loading more'); + assert.equal(rs.get('length'), 4); + assert.ok(!rs.get('loadMoreUrl')); + assert.ok(!rs.get('canLoadMore')); }); }); }); -test('refresh support', function() { +QUnit.test('refresh support', assert => { const store = createStore(); return store.findAll('widget').then(function(rs) { - equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url'); + assert.equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url'); const promise = rs.refresh(); - ok(rs.get('refreshing'), 'it is refreshing'); + assert.ok(rs.get('refreshing'), 'it is refreshing'); promise.then(function() { - ok(!rs.get('refreshing'), 'it is finished refreshing'); + assert.ok(!rs.get('refreshing'), 'it is finished refreshing'); }); }); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/session-test.js.es6 b/test/javascripts/models/session-test.js.es6 index 320b5fb3665..ff330fd77fe 100644 --- a/test/javascripts/models/session-test.js.es6 +++ b/test/javascripts/models/session-test.js.es6 @@ -1,8 +1,8 @@ import Session from "discourse/models/session"; -module("model:session"); +QUnit.module("model:session"); -test('highestSeenByTopic', function() { +QUnit.test('highestSeenByTopic', assert => { const session = Session.current(); - deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object"); -}); + assert.deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object"); +}); \ No newline at end of file diff --git a/test/javascripts/models/site-test.js.es6 b/test/javascripts/models/site-test.js.es6 index bc1c3c0ac94..bce69122dc6 100644 --- a/test/javascripts/models/site-test.js.es6 +++ b/test/javascripts/models/site-test.js.es6 @@ -1,23 +1,22 @@ import createStore from 'helpers/create-store'; -import { blank, present } from 'helpers/qunit-helpers'; -module("model:site"); +QUnit.module("model:site"); -test('create', function() { - ok(Discourse.Site.create(), 'it can create with no parameters'); +QUnit.test('create', assert => { + assert.ok(Discourse.Site.create(), 'it can create with no parameters'); }); -test('instance', function() { +QUnit.test('instance', assert => { const site = Discourse.Site.current(); - present(site, "We have a current site singleton"); - present(site.get('categories'), "The instance has a list of categories"); - present(site.get('flagTypes'), "The instance has a list of flag types"); - present(site.get('trustLevels'), "The instance has a list of trust levels"); + assert.present(site, "We have a current site singleton"); + assert.present(site.get('categories'), "The instance has a list of categories"); + assert.present(site.get('flagTypes'), "The instance has a list of flag types"); + assert.present(site.get('trustLevels'), "The instance has a list of trust levels"); }); -test('create categories', function() { +QUnit.test('create categories', assert => { const store = createStore(); const site = store.createRecord('site', { categories: [{ id: 1234, name: 'Test'}, @@ -28,22 +27,22 @@ test('create categories', function() { const categories = site.get('categories'); site.get('sortedCategories'); - present(categories, "The categories are present"); - equal(categories.length, 3, "it loaded all three categories"); + assert.present(categories, "The categories are present"); + assert.equal(categories.length, 3, "it loaded all three categories"); const parent = categories.findBy('id', 1234); - present(parent, "it loaded the parent category"); - blank(parent.get('parentCategory'), 'it has no parent category'); + assert.present(parent, "it loaded the parent category"); + assert.blank(parent.get('parentCategory'), 'it has no parent category'); const subcategory = categories.findBy('id', 3456); - present(subcategory, "it loaded the subcategory"); - equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent"); + assert.present(subcategory, "it loaded the subcategory"); + assert.equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent"); // remove invalid category and child categories.removeObject(categories[2]); categories.removeObject(categories[1]); - equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal"); - equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal"); + assert.equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal"); + assert.equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal"); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/staff-action-log-test.js.es6 b/test/javascripts/models/staff-action-log-test.js.es6 index 933dd6271d8..2e9756ff9e7 100644 --- a/test/javascripts/models/staff-action-log-test.js.es6 +++ b/test/javascripts/models/staff-action-log-test.js.es6 @@ -1,7 +1,7 @@ import StaffActionLog from 'admin/models/staff-action-log'; -module("StaffActionLog"); +QUnit.module("StaffActionLog"); -test("create", function() { - ok(StaffActionLog.create(), "it can be created without arguments"); -}); +QUnit.test("create", assert => { + assert.ok(StaffActionLog.create(), "it can be created without arguments"); +}); \ No newline at end of file diff --git a/test/javascripts/models/store-test.js.es6 b/test/javascripts/models/store-test.js.es6 index e54f5740b90..f532ad6f77d 100644 --- a/test/javascripts/models/store-test.js.es6 +++ b/test/javascripts/models/store-test.js.es6 @@ -1,81 +1,81 @@ -module('store:main'); +QUnit.module('store:main'); import createStore from 'helpers/create-store'; -test('createRecord', function() { +QUnit.test('createRecord', assert => { const store = createStore(); const widget = store.createRecord('widget', {id: 111, name: 'hello'}); - ok(!widget.get('isNew'), 'it is not a new record'); - equal(widget.get('name'), 'hello'); - equal(widget.get('id'), 111); + assert.ok(!widget.get('isNew'), 'it is not a new record'); + assert.equal(widget.get('name'), 'hello'); + assert.equal(widget.get('id'), 111); }); -test('createRecord without an `id`', function() { +QUnit.test('createRecord without an `id`', assert => { const store = createStore(); const widget = store.createRecord('widget', {name: 'hello'}); - ok(widget.get('isNew'), 'it is a new record'); - ok(!widget.get('id'), 'there is no id'); + assert.ok(widget.get('isNew'), 'it is a new record'); + assert.ok(!widget.get('id'), 'there is no id'); }); -test("createRecord doesn't modify the input `id` field", () => { +QUnit.test("createRecord doesn't modify the input `id` field", assert => { const store = createStore(); const widget = store.createRecord('widget', {id: 1, name: 'hello'}); const obj = { id: 1, name: 'something' }; const other = store.createRecord('widget', obj); - equal(widget, other, 'returns the same record'); - equal(widget.name, 'something', 'it updates the properties'); - equal(obj.id, 1, 'it does not remove the id from the input'); + assert.equal(widget, other, 'returns the same record'); + assert.equal(widget.name, 'something', 'it updates the properties'); + assert.equal(obj.id, 1, 'it does not remove the id from the input'); }); -test('createRecord without attributes', function() { +QUnit.test('createRecord without attributes', assert => { const store = createStore(); const widget = store.createRecord('widget'); - ok(!widget.get('id'), 'there is no id'); - ok(widget.get('isNew'), 'it is a new record'); + assert.ok(!widget.get('id'), 'there is no id'); + assert.ok(widget.get('isNew'), 'it is a new record'); }); -test('createRecord with a record as attributes returns that record from the map', function() { +QUnit.test('createRecord with a record as attributes returns that record from the map', assert => { const store = createStore(); const widget = store.createRecord('widget', {id: 33}); const secondWidget = store.createRecord('widget', {id: 33}); - equal(widget, secondWidget, 'they should be the same'); + assert.equal(widget, secondWidget, 'they should be the same'); }); -test('find', function() { +QUnit.test('find', assert => { const store = createStore(); return store.find('widget', 123).then(function(w) { - equal(w.get('name'), 'Trout Lure'); - equal(w.get('id'), 123); - ok(!w.get('isNew'), 'found records are not new'); + assert.equal(w.get('name'), 'Trout Lure'); + assert.equal(w.get('id'), 123); + assert.ok(!w.get('isNew'), 'found records are not new'); // A second find by id returns the same object store.find('widget', 123).then(function(w2) { - equal(w, w2); + assert.equal(w, w2); }); }); }); -test('find with object id', function() { +QUnit.test('find with object id', assert => { const store = createStore(); return store.find('widget', {id: 123}).then(function(w) { - equal(w.get('firstObject.name'), 'Trout Lure'); + assert.equal(w.get('firstObject.name'), 'Trout Lure'); }); }); -test('find with query param', function() { +QUnit.test('find with query param', assert => { const store = createStore(); return store.find('widget', {name: 'Trout Lure'}).then(function(w) { - equal(w.get('firstObject.id'), 123); + assert.equal(w.get('firstObject.id'), 123); }); }); -test('findStale with no stale results', (assert) => { +QUnit.test('findStale with no stale results', (assert) => { const store = createStore(); const stale = store.findStale('widget', {name: 'Trout Lure'}); @@ -86,14 +86,14 @@ test('findStale with no stale results', (assert) => { }); }); -test('update', function() { +QUnit.test('update', assert => { const store = createStore(); return store.update('widget', 123, {name: 'hello'}).then(function(result) { - ok(result); + assert.ok(result); }); }); -test('update with a multi world name', function(assert) { +QUnit.test('update with a multi world name', function(assert) { const store = createStore(); return store.update('cool-thing', 123, {name: 'hello'}).then(function(result) { assert.ok(result); @@ -101,17 +101,17 @@ test('update with a multi world name', function(assert) { }); }); -test('findAll', function() { +QUnit.test('findAll', assert => { const store = createStore(); return store.findAll('widget').then(function(result) { - equal(result.get('length'), 2); + assert.equal(result.get('length'), 2); const w = result.findBy('id', 124); - ok(!w.get('isNew'), 'found records are not new'); - equal(w.get('name'), 'Evil Repellant'); + assert.ok(!w.get('isNew'), 'found records are not new'); + assert.equal(w.get('name'), 'Evil Repellant'); }); }); -test('destroyRecord', function(assert) { +QUnit.test('destroyRecord', function(assert) { const store = createStore(); return store.find('widget', 123).then(function(w) { store.destroyRecord('widget', w).then(function(result) { @@ -120,7 +120,7 @@ test('destroyRecord', function(assert) { }); }); -test('destroyRecord when new', function(assert) { +QUnit.test('destroyRecord when new', function(assert) { const store = createStore(); const w = store.createRecord('widget', {name: 'hello'}); store.destroyRecord('widget', w).then(function(result) { @@ -128,7 +128,7 @@ test('destroyRecord when new', function(assert) { }); }); -test('find embedded', function(assert) { +QUnit.test('find embedded', function(assert) { const store = createStore(); return store.find('fruit', 2).then(function(f) { assert.ok(f.get('farmer'), 'it has the embedded object'); @@ -142,7 +142,7 @@ test('find embedded', function(assert) { }); }); -test('findAll embedded', function(assert) { +QUnit.test('findAll embedded', function(assert) { const store = createStore(); return store.findAll('fruit').then(function(fruits) { assert.equal(fruits.objectAt(0).get('farmer.name'), 'Old MacDonald'); @@ -156,5 +156,4 @@ test('findAll embedded', function(assert) { assert.equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker'); }); -}); - +}); \ No newline at end of file diff --git a/test/javascripts/models/topic-details-test.js.es6 b/test/javascripts/models/topic-details-test.js.es6 index 75719ad3e94..760cdaa76a7 100644 --- a/test/javascripts/models/topic-details-test.js.es6 +++ b/test/javascripts/models/topic-details-test.js.es6 @@ -1,5 +1,4 @@ -import { present } from 'helpers/qunit-helpers'; -module("model:topic-details"); +QUnit.module("model:topic-details"); import Topic from 'discourse/models/topic'; @@ -8,13 +7,13 @@ var buildDetails = function(id) { return topic.get('details'); }; -test('defaults', function() { +QUnit.test('defaults', assert => { var details = buildDetails(1234); - present(details, "the details are present by default"); - ok(!details.get('loaded'), "details are not loaded by default"); + assert.present(details, "the details are present by default"); + assert.ok(!details.get('loaded'), "details are not loaded by default"); }); -test('updateFromJson', function() { +QUnit.test('updateFromJson', assert => { var details = buildDetails(1234); details.updateFromJson({ @@ -22,10 +21,10 @@ test('updateFromJson', function() { allowed_users: [{username: 'eviltrout'}] }); - equal(details.get('suggested_topics.length'), 2, 'it loaded the suggested_topics'); - containsInstance(details.get('suggested_topics'), Topic); + assert.equal(details.get('suggested_topics.length'), 2, 'it loaded the suggested_topics'); + assert.containsInstance(details.get('suggested_topics'), Topic); - equal(details.get('allowed_users.length'), 1, 'it loaded the allowed users'); - containsInstance(details.get('allowed_users'), Discourse.User); + assert.equal(details.get('allowed_users.length'), 1, 'it loaded the allowed users'); + assert.containsInstance(details.get('allowed_users'), Discourse.User); }); diff --git a/test/javascripts/models/topic-test.js.es6 b/test/javascripts/models/topic-test.js.es6 index 2c1ceac923a..681a4378a7f 100644 --- a/test/javascripts/models/topic-test.js.es6 +++ b/test/javascripts/models/topic-test.js.es6 @@ -1,40 +1,39 @@ -import { blank, present } from 'helpers/qunit-helpers'; import { IMAGE_VERSION as v} from 'pretty-text/emoji'; -module("model:topic"); +QUnit.module("model:topic"); import Topic from 'discourse/models/topic'; -test("defaults", function() { +QUnit.test("defaults", assert => { var topic = Topic.create({id: 1234}); - blank(topic.get('deleted_at'), 'deleted_at defaults to blank'); - blank(topic.get('deleted_by'), 'deleted_by defaults to blank'); + assert.blank(topic.get('deleted_at'), 'deleted_at defaults to blank'); + assert.blank(topic.get('deleted_by'), 'deleted_by defaults to blank'); }); -test('has details', function() { +QUnit.test('has details', assert => { var topic = Topic.create({id: 1234}); var topicDetails = topic.get('details'); - present(topicDetails, "a topic has topicDetails after we create it"); - equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic"); + assert.present(topicDetails, "a topic has topicDetails after we create it"); + assert.equal(topicDetails.get('topic'), topic, "the topicDetails has a reference back to the topic"); }); -test('has a postStream', function() { +QUnit.test('has a postStream', assert => { var topic = Topic.create({id: 1234}); var postStream = topic.get('postStream'); - present(postStream, "a topic has a postStream after we create it"); - equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic"); + assert.present(postStream, "a topic has a postStream after we create it"); + assert.equal(postStream.get('topic'), topic, "the postStream has a reference back to the topic"); }); -test('category relationship', function() { +QUnit.test('category relationship', assert => { // It finds the category by id var category = Discourse.Category.list()[0], topic = Topic.create({id: 1111, category_id: category.get('id') }); - equal(topic.get('category'), category); + assert.equal(topic.get('category'), category); }); -test("updateFromJson", function() { +QUnit.test("updateFromJson", assert => { var topic = Topic.create({id: 1234}), category = Discourse.Category.list()[0]; @@ -45,34 +44,34 @@ test("updateFromJson", function() { category_id: category.get('id') }); - blank(topic.get('post_stream'), "it does not update post_stream"); - equal(topic.get('details.hello'), 'world', 'it updates the details'); - equal(topic.get('cool'), "property", "it updates other properties"); - equal(topic.get('category'), category); + assert.blank(topic.get('post_stream'), "it does not update post_stream"); + assert.equal(topic.get('details.hello'), 'world', 'it updates the details'); + assert.equal(topic.get('cool'), "property", "it updates other properties"); + assert.equal(topic.get('category'), category); }); -test("destroy", function() { +QUnit.test("destroy", assert => { var user = Discourse.User.create({username: 'eviltrout'}); var topic = Topic.create({id: 1234}); topic.destroy(user); - present(topic.get('deleted_at'), 'deleted at is set'); - equal(topic.get('deleted_by'), user, 'deleted by is set'); + assert.present(topic.get('deleted_at'), 'deleted at is set'); + assert.equal(topic.get('deleted_by'), user, 'deleted by is set'); }); -test("recover", function() { +QUnit.test("recover", assert => { var user = Discourse.User.create({username: 'eviltrout'}); var topic = Topic.create({id: 1234, deleted_at: new Date(), deleted_by: user}); topic.recover(); - blank(topic.get('deleted_at'), "it clears deleted_at"); - blank(topic.get('deleted_by'), "it clears deleted_by"); + assert.blank(topic.get('deleted_at'), "it clears deleted_at"); + assert.blank(topic.get('deleted_by'), "it clears deleted_by"); }); -test('fancyTitle', function() { +QUnit.test('fancyTitle', assert => { var topic = Topic.create({ fancy_title: ":smile: with all :) the emojis :pear::peach:" }); - equal(topic.get('fancyTitle'), + assert.equal(topic.get('fancyTitle'), `smile with all slight_smile the emojis pearpeach`, "supports emojis"); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/topic-tracking-state-test.js.es6 b/test/javascripts/models/topic-tracking-state-test.js.es6 index 0814487950c..3c184cb7591 100644 --- a/test/javascripts/models/topic-tracking-state-test.js.es6 +++ b/test/javascripts/models/topic-tracking-state-test.js.es6 @@ -1,9 +1,9 @@ import TopicTrackingState from 'discourse/models/topic-tracking-state'; import createStore from 'helpers/create-store'; -module("model:topic-tracking-state"); +QUnit.module("model:topic-tracking-state"); -test("sync", function (assert) { +QUnit.test("sync", function (assert) { const state = TopicTrackingState.create(); state.states["t111"] = {last_read_post_number: null}; @@ -19,7 +19,7 @@ test("sync", function (assert) { assert.equal(list.topics.length, 0, "expect new topic to be removed as it was seen"); }); -test("subscribe to category", function(assert){ +QUnit.test("subscribe to category", function(assert){ const store = createStore(); const darth = store.createRecord('category', {id: 1, slug: 'darth'}), @@ -47,4 +47,4 @@ test("subscribe to category", function(assert){ state.notify({message_type: 'new_topic', topic_id: 3, payload: {category_id: 1, topic_id: 3}}); assert.equal(state.get("incomingCount"), 1, "expect to properly track incoming for subcategory"); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/user-action-test.js.es6 b/test/javascripts/models/user-action-test.js.es6 index fd0bd043f1d..93a988acac7 100644 --- a/test/javascripts/models/user-action-test.js.es6 +++ b/test/javascripts/models/user-action-test.js.es6 @@ -1,6 +1,6 @@ -module("Discourse.UserAction"); +QUnit.module("Discourse.UserAction"); -test("collapsing likes", function () { +QUnit.test("collapsing likes", assert => { var actions = Discourse.UserAction.collapseStream([ Discourse.UserAction.create({ action_type: Discourse.UserAction.TYPES.likes_given, @@ -20,8 +20,8 @@ test("collapsing likes", function () { }) ]); - equal(actions.length, 2); + assert.equal(actions.length, 2); - equal(actions[0].get('children.length'), 1); - equal(actions[0].get('children')[0].items.length, 2); -}); + assert.equal(actions[0].get('children.length'), 1); + assert.equal(actions[0].get('children')[0].items.length, 2); +}); \ No newline at end of file diff --git a/test/javascripts/models/user-badge-test.js.es6 b/test/javascripts/models/user-badge-test.js.es6 index 5258d98b06c..0794c2f92ca 100644 --- a/test/javascripts/models/user-badge-test.js.es6 +++ b/test/javascripts/models/user-badge-test.js.es6 @@ -1,42 +1,42 @@ import UserBadge from 'discourse/models/user-badge'; import badgeFixtures from 'fixtures/user-badges'; -module("model:user-badge"); +QUnit.module("model:user-badge"); -test('createFromJson single', function() { +QUnit.test('createFromJson single', assert => { const userBadge = UserBadge.createFromJson(badgeFixtures['/user_badges']); - ok(!Array.isArray(userBadge), "does not return an array"); - equal(userBadge.get('badge.name'), "Badge 2", "badge reference is set"); - equal(userBadge.get('badge.badge_type.name'), "Silver 2", "badge.badge_type reference is set"); - equal(userBadge.get('granted_by.username'), "anne3", "granted_by reference is set"); + assert.ok(!Array.isArray(userBadge), "does not return an array"); + assert.equal(userBadge.get('badge.name'), "Badge 2", "badge reference is set"); + assert.equal(userBadge.get('badge.badge_type.name'), "Silver 2", "badge.badge_type reference is set"); + assert.equal(userBadge.get('granted_by.username'), "anne3", "granted_by reference is set"); }); -test('createFromJson array', function() { +QUnit.test('createFromJson array', assert => { const userBadges = UserBadge.createFromJson(badgeFixtures['/user-badges/:username']); - ok(Array.isArray(userBadges), "returns an array"); - equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null"); + assert.ok(Array.isArray(userBadges), "returns an array"); + assert.equal(userBadges[0].get('granted_by'), null, "granted_by reference is not set when null"); }); -test('findByUsername', function() { +QUnit.test('findByUsername', assert => { return UserBadge.findByUsername("anne3").then(function(badges) { - ok(Array.isArray(badges), "returns an array"); + assert.ok(Array.isArray(badges), "returns an array"); }); }); -test('findByBadgeId', function() { +QUnit.test('findByBadgeId', assert => { return UserBadge.findByBadgeId(880).then(function(badges) { - ok(Array.isArray(badges), "returns an array"); + assert.ok(Array.isArray(badges), "returns an array"); }); }); -test('grant', function() { +QUnit.test('grant', assert => { return UserBadge.grant(1, "username").then(function(userBadge) { - ok(!Array.isArray(userBadge), "does not return an array"); + assert.ok(!Array.isArray(userBadge), "does not return an array"); }); }); -test('revoke', function() { - expect(0); +QUnit.test('revoke', assert => { + assert.expect(0); const userBadge = UserBadge.create({id: 1}); return userBadge.revoke(); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/user-stream-test.js.es6 b/test/javascripts/models/user-stream-test.js.es6 index c5b35985e30..272dae3d334 100644 --- a/test/javascripts/models/user-stream-test.js.es6 +++ b/test/javascripts/models/user-stream-test.js.es6 @@ -1,32 +1,30 @@ -import { blank, present } from 'helpers/qunit-helpers'; +QUnit.module("Discourse.UserStream"); -module("Discourse.UserStream"); - -test('basics', function(){ +QUnit.test('basics', assert =>{ var user = Discourse.User.create({id: 1, username: 'eviltrout'}); var stream = user.get('stream'); - present(stream, "a user has a stream by default"); - equal(stream.get('user'), user, "the stream points back to the user"); + assert.present(stream, "a user has a stream by default"); + assert.equal(stream.get('user'), user, "the stream points back to the user"); - equal(stream.get('itemsLoaded'), 0, "no items are loaded by default"); - blank(stream.get('content'), "no content by default"); - blank(stream.get('filter'), "no filter by default"); + assert.equal(stream.get('itemsLoaded'), 0, "no items are loaded by default"); + assert.blank(stream.get('content'), "no content by default"); + assert.blank(stream.get('filter'), "no filter by default"); - ok(!stream.get('loaded'), "the stream is not loaded by default"); + assert.ok(!stream.get('loaded'), "the stream is not loaded by default"); }); -test('filterParam', function() { +QUnit.test('filterParam', assert => { var user = Discourse.User.create({id: 1, username: 'eviltrout'}); var stream = user.get('stream'); // defaults to posts/topics - equal(stream.get('filterParam'), "4,5"); + assert.equal(stream.get('filterParam'), "4,5"); stream.set('filter', Discourse.UserAction.TYPES.likes_given); - equal(stream.get('filterParam'), Discourse.UserAction.TYPES.likes_given); + assert.equal(stream.get('filterParam'), Discourse.UserAction.TYPES.likes_given); stream.set('filter', Discourse.UserAction.TYPES.replies); - equal(stream.get('filterParam'), '6,9'); + assert.equal(stream.get('filterParam'), '6,9'); -}); +}); \ No newline at end of file diff --git a/test/javascripts/models/user-test.js.es6 b/test/javascripts/models/user-test.js.es6 index ea845d582f2..fb379374952 100644 --- a/test/javascripts/models/user-test.js.es6 +++ b/test/javascripts/models/user-test.js.es6 @@ -1,46 +1,46 @@ import User from 'discourse/models/user'; import Group from 'discourse/models/group'; -module("model:user"); +QUnit.module("model:user"); -test('staff', function(){ +QUnit.test('staff', assert =>{ var user = User.create({id: 1, username: 'eviltrout'}); - ok(!user.get('staff'), "user is not staff"); + assert.ok(!user.get('staff'), "user is not staff"); user.toggleProperty('moderator'); - ok(user.get('staff'), "moderators are staff"); + assert.ok(user.get('staff'), "moderators are staff"); user.setProperties({moderator: false, admin: true}); - ok(user.get('staff'), "admins are staff"); + assert.ok(user.get('staff'), "admins are staff"); }); -test('searchContext', function() { +QUnit.test('searchContext', assert => { var user = User.create({id: 1, username: 'EvilTrout'}); - deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context"); + assert.deepEqual(user.get('searchContext'), {type: 'user', id: 'eviltrout', user: user}, "has a search context"); }); -test("isAllowedToUploadAFile", function() { +QUnit.test("isAllowedToUploadAFile", assert => { var user = User.create({ trust_level: 0, admin: true }); - ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file"); + assert.ok(user.isAllowedToUploadAFile("image"), "admin can always upload a file"); user.setProperties({ admin: false, moderator: true }); - ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file"); + assert.ok(user.isAllowedToUploadAFile("image"), "moderator can always upload a file"); }); -test('canMangeGroup', function() { +QUnit.test('canMangeGroup', assert => { let user = User.create({ admin: true }); let group = Group.create({ automatic: true }); - equal(user.canManageGroup(group), false, "automatic groups cannot be managed."); + assert.equal(user.canManageGroup(group), false, "automatic groups cannot be managed."); group.set("automatic", false); - equal(user.canManageGroup(group), true, "an admin should be able to manage the group"); + assert.equal(user.canManageGroup(group), true, "an admin should be able to manage the group"); user.set('admin', false); group.setProperties({ is_group_owner: true }); - equal(user.canManageGroup(group), true, "a group owner should be able to manage the group"); -}); + assert.equal(user.canManageGroup(group), true, "a group owner should be able to manage the group"); +}); \ No newline at end of file diff --git a/test/javascripts/models/version-check-test.js.es6 b/test/javascripts/models/version-check-test.js.es6 index 4b8b6bc94f1..fa1f3d78d84 100644 --- a/test/javascripts/models/version-check-test.js.es6 +++ b/test/javascripts/models/version-check-test.js.es6 @@ -1,10 +1,10 @@ import VersionCheck from 'admin/models/version-check'; -module("VersionCheck"); +QUnit.module("VersionCheck"); -test('dataIsOld', function() { +QUnit.test('dataIsOld', assert => { var dataIsOld = function(args, expected, message) { - equal(VersionCheck.create(args).get('dataIsOld'), expected, message); + assert.equal(VersionCheck.create(args).get('dataIsOld'), expected, message); }; dataIsOld({updated_at: moment().subtract(2, 'hours').toJSON()}, false, '2 hours ago'); @@ -12,12 +12,12 @@ test('dataIsOld', function() { dataIsOld({updated_at: moment().subtract(2, 'hours').toJSON(), version_check_pending: true}, true, 'version check pending'); }); -test('staleData', function() { +QUnit.test('staleData', assert => { var updatedAt = function(hoursAgo) { return moment().subtract(hoursAgo, 'hours').toJSON(); }; var staleData = function(args, expected, message) { - equal(VersionCheck.create(args).get('staleData'), expected, message); + assert.equal(VersionCheck.create(args).get('staleData'), expected, message); }; staleData({missing_versions_count: 0, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(2)}, false, 'up to date'); @@ -25,4 +25,4 @@ test('staleData', function() { staleData({missing_versions_count: 1, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(2)}, true, 'installed and latest match, but missing_versions_count is not 0'); staleData({missing_versions_count: 0, installed_version: '0.9.3', latest_version: '0.9.3', updated_at: updatedAt(50)}, true, 'old version check data'); staleData({version_check_pending: true, missing_versions_count: 0, installed_version: '0.9.4', latest_version: '0.9.3', updated_at: updatedAt(2)}, true, 'version was upgraded, but no version check has been done since the upgrade'); -}); +}); \ No newline at end of file diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index e1ac22f381b..129db1593c2 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -52,6 +52,8 @@ d.write(''); d.write('
'); d.write(''); +Ember.Test.adapter = window.QUnitAdapter.create(); + Discourse.rootElement = '#ember-testing'; Discourse.setupForTesting(); Discourse.injectTestHelpers(); diff --git a/test/javascripts/widgets/actions-summary-test.js.es6 b/test/javascripts/widgets/actions-summary-test.js.es6 index 6542d17b12c..4e900f14741 100644 --- a/test/javascripts/widgets/actions-summary-test.js.es6 +++ b/test/javascripts/widgets/actions-summary-test.js.es6 @@ -4,7 +4,7 @@ moduleForWidget('actions-summary'); widgetTest('listing actions', { template: '{{mount-widget widget="actions-summary" args=args}}', - setup() { + beforeEach() { this.set('args', { actionsSummary: [ {id: 1, action: 'off_topic', description: 'very off topic'}, @@ -24,7 +24,7 @@ widgetTest('listing actions', { widgetTest('undo', { template: '{{mount-widget widget="actions-summary" args=args undoPostAction=undoPostAction}}', - setup() { + beforeEach() { this.set('args', { actionsSummary: [ {action: 'off_topic', description: 'very off topic', canUndo: true}, @@ -45,7 +45,7 @@ widgetTest('undo', { widgetTest('deferFlags', { template: '{{mount-widget widget="actions-summary" args=args deferPostActionFlags="deferPostActionFlags"}}', - setup() { + beforeEach() { this.set('args', { actionsSummary: [ {action: 'off_topic', description: 'very off topic', canDeferFlags: true, count: 1}, @@ -66,7 +66,7 @@ widgetTest('deferFlags', { widgetTest('post deleted', { template: '{{mount-widget widget="actions-summary" args=args}}', - setup() { + beforeEach() { this.set('args', { deleted_at: "2016-01-01", deletedByUsername: 'eviltrout', diff --git a/test/javascripts/widgets/hamburger-menu-test.js.es6 b/test/javascripts/widgets/hamburger-menu-test.js.es6 index 9c6454e47ce..c8f67ccf1ec 100644 --- a/test/javascripts/widgets/hamburger-menu-test.js.es6 +++ b/test/javascripts/widgets/hamburger-menu-test.js.es6 @@ -5,7 +5,7 @@ moduleForWidget('hamburger-menu'); widgetTest('prioritize faq', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.siteSettings.faq_url = 'http://example.com/faq'; this.currentUser.set('read_faq', false); }, @@ -19,7 +19,7 @@ widgetTest('prioritize faq', { widgetTest('prioritize faq - user has read', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.siteSettings.faq_url = 'http://example.com/faq'; this.currentUser.set('read_faq', true); }, @@ -33,7 +33,7 @@ widgetTest('prioritize faq - user has read', { widgetTest('staff menu - not staff', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.currentUser.set('staff', false); }, @@ -45,7 +45,7 @@ widgetTest('staff menu - not staff', { widgetTest('staff menu', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ staff: true, site_flagged_posts_count: 3 }); }, @@ -60,7 +60,7 @@ widgetTest('staff menu', { widgetTest('staff menu - admin', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ staff: true, admin: true }); }, @@ -73,7 +73,7 @@ widgetTest('staff menu - admin', { widgetTest('queued posts', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ staff: true, show_queued_posts: true, @@ -90,7 +90,7 @@ widgetTest('queued posts', { widgetTest('queued posts - disabled', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ staff: true, show_queued_posts: false }); }, @@ -127,7 +127,7 @@ widgetTest('general links', { widgetTest('badges link - disabled', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.siteSettings.enable_badges = false; }, @@ -155,7 +155,7 @@ widgetTest('user directory link', { widgetTest('user directory link - disabled', { template: '{{mount-widget widget="hamburger-menu"}}', - setup() { + beforeEach() { this.siteSettings.enable_user_directory = false; }, diff --git a/test/javascripts/widgets/header-test.js.es6 b/test/javascripts/widgets/header-test.js.es6 index 71676a0338c..f91ab7755ea 100644 --- a/test/javascripts/widgets/header-test.js.es6 +++ b/test/javascripts/widgets/header-test.js.es6 @@ -14,7 +14,7 @@ widgetTest('sign up / login buttons', { template: '{{mount-widget widget="header" showCreateAccount="showCreateAccount" showLogin="showLogin" args=args}}', anonymous: true, - setup() { + beforeEach() { this.set('args', { canSignUp: true }); this.on('showCreateAccount', () => this.signupShown = true); this.on('showLogin', () => this.loginShown = true); @@ -40,7 +40,7 @@ widgetTest('anon when login required', { template: '{{mount-widget widget="header" showCreateAccount="showCreateAccount" showLogin="showLogin" args=args}}', anonymous: true, - setup() { + beforeEach() { this.set('args', { canSignUp: true }); this.on('showCreateAccount', () => this.signupShown = true); this.on('showLogin', () => this.loginShown = true); @@ -58,7 +58,7 @@ widgetTest('anon when login required', { widgetTest('logged in when login required', { template: '{{mount-widget widget="header" showCreateAccount="showCreateAccount" showLogin="showLogin" args=args}}', - setup() { + beforeEach() { this.set('args', { canSignUp: true }); this.on('showCreateAccount', () => this.signupShown = true); this.on('showLogin', () => this.loginShown = true); diff --git a/test/javascripts/widgets/home-logo-test.js.es6 b/test/javascripts/widgets/home-logo-test.js.es6 index 81db555c20b..ddc032391ed 100644 --- a/test/javascripts/widgets/home-logo-test.js.es6 +++ b/test/javascripts/widgets/home-logo-test.js.es6 @@ -9,7 +9,7 @@ const title = "Cool Forum"; widgetTest('basics', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.logo_url = bigLogo; this.siteSettings.logo_small_url = smallLogo; this.siteSettings.title = title; @@ -27,7 +27,7 @@ widgetTest('basics', { widgetTest('basics - minimized', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.logo_url = bigLogo; this.siteSettings.logo_small_url= smallLogo; this.siteSettings.title = title; @@ -43,7 +43,7 @@ widgetTest('basics - minimized', { widgetTest('no logo', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.logo_url = ''; this.siteSettings.logo_small_url = ''; this.siteSettings.title = title; @@ -58,7 +58,7 @@ widgetTest('no logo', { widgetTest('no logo - minimized', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.logo_url = ''; this.siteSettings.logo_small_url = ''; this.siteSettings.title = title; @@ -72,7 +72,7 @@ widgetTest('no logo - minimized', { widgetTest('mobile logo', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.mobile_logo_url = mobileLogo; this.siteSettings.logo_small_url= smallLogo; this.site.mobileView = true; @@ -86,7 +86,7 @@ widgetTest('mobile logo', { widgetTest('mobile without logo', { template: '{{mount-widget widget="home-logo" args=args}}', - setup() { + beforeEach() { this.siteSettings.logo_url = bigLogo; this.site.mobileView = true; }, diff --git a/test/javascripts/widgets/post-links-test.js.es6 b/test/javascripts/widgets/post-links-test.js.es6 index 3efc3f2b0f6..c3e8f0c267f 100644 --- a/test/javascripts/widgets/post-links-test.js.es6 +++ b/test/javascripts/widgets/post-links-test.js.es6 @@ -4,7 +4,7 @@ moduleForWidget('post-links'); widgetTest("duplicate links", { template: '{{mount-widget widget="post-links" args=args}}', - setup() { + beforeEach() { this.set('args', { id: 2, links: [ @@ -20,7 +20,7 @@ widgetTest("duplicate links", { widgetTest("collapsed links", { template: '{{mount-widget widget="post-links" args=args}}', - setup() { + beforeEach() { this.set('args', { id: 1, links: [ diff --git a/test/javascripts/widgets/post-stream-test.js.es6 b/test/javascripts/widgets/post-stream-test.js.es6 index 2438f8d8abe..a09cc6bcbac 100644 --- a/test/javascripts/widgets/post-stream-test.js.es6 +++ b/test/javascripts/widgets/post-stream-test.js.es6 @@ -7,7 +7,7 @@ moduleForWidget('post-stream'); function postStreamTest(name, attrs) { widgetTest(name, { template: `{{mount-widget widget="post-stream" args=(hash posts=posts)}}`, - setup() { + beforeEach() { this.set('posts', attrs.posts.call(this)); }, test: attrs.test diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6 index 80b97b548a8..243290deece 100644 --- a/test/javascripts/widgets/post-test.js.es6 +++ b/test/javascripts/widgets/post-test.js.es6 @@ -4,7 +4,7 @@ moduleForWidget('post'); widgetTest('basic elements', { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { shareUrl: '/example', post_number: 1 }); }, test(assert) { @@ -18,7 +18,7 @@ widgetTest('basic elements', { widgetTest('wiki', { template: '{{mount-widget widget="post" args=args showHistory="showHistory"}}', - setup() { + beforeEach() { this.set('args', { wiki: true, version: 2, canViewEditHistory: true }); this.on('showHistory', () => this.historyShown = true); }, @@ -32,7 +32,7 @@ widgetTest('wiki', { widgetTest('wiki without revision', { template: '{{mount-widget widget="post" args=args editPost="editPost"}}', - setup() { + beforeEach() { this.set('args', { wiki: true, version: 1, canViewEditHistory: true }); this.on('editPost', () => this.editPostCalled = true); }, @@ -46,7 +46,7 @@ widgetTest('wiki without revision', { widgetTest('via-email', { template: '{{mount-widget widget="post" args=args showRawEmail="showRawEmail"}}', - setup() { + beforeEach() { this.set('args', { via_email: true, canViewRawEmail: true }); this.on('showRawEmail', () => this.rawEmailShown = true); }, @@ -60,7 +60,7 @@ widgetTest('via-email', { widgetTest('via-email without permission', { template: '{{mount-widget widget="post" args=args showRawEmail="showRawEmail"}}', - setup() { + beforeEach() { this.set('args', { via_email: true, canViewRawEmail: false }); this.on('showRawEmail', () => this.rawEmailShown = true); }, @@ -74,7 +74,7 @@ widgetTest('via-email without permission', { widgetTest('history', { template: '{{mount-widget widget="post" args=args showHistory="showHistory"}}', - setup() { + beforeEach() { this.set('args', { version: 3, canViewEditHistory: true }); this.on('showHistory', () => this.historyShown = true); }, @@ -88,7 +88,7 @@ widgetTest('history', { widgetTest('history without view permission', { template: '{{mount-widget widget="post" args=args showHistory="showHistory"}}', - setup() { + beforeEach() { this.set('args', { version: 3, canViewEditHistory: false }); this.on('showHistory', () => this.historyShown = true); }, @@ -102,7 +102,7 @@ widgetTest('history without view permission', { widgetTest('whisper', { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { isWhisper: true }); }, test(assert) { @@ -113,7 +113,7 @@ widgetTest('whisper', { widgetTest('like count button', { template: '{{mount-widget widget="post" model=post args=args}}', - setup(store) { + beforeEach(store) { const topic = store.createRecord('topic', {id: 123}); const post = store.createRecord('post', { id: 1, @@ -147,7 +147,7 @@ widgetTest('like count button', { widgetTest(`like count with no likes`, { template: '{{mount-widget widget="post" model=post args=args}}', - setup() { + beforeEach() { this.set('args', { likeCount: 0 }); }, test(assert) { @@ -157,7 +157,7 @@ widgetTest(`like count with no likes`, { widgetTest('share button', { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { shareUrl: 'http://share-me.example.com' }); }, test(assert) { @@ -167,7 +167,7 @@ widgetTest('share button', { widgetTest('liking', { template: '{{mount-widget widget="post-menu" args=args toggleLike="toggleLike"}}', - setup() { + beforeEach() { const args = { showLike: true, canToggleLike: true }; this.set('args', args); this.on('toggleLike', () => { @@ -198,7 +198,7 @@ widgetTest('liking', { widgetTest('anon liking', { template: '{{mount-widget widget="post-menu" args=args showLogin="showLogin"}}', anonymous: true, - setup() { + beforeEach() { const args = { showLike: true }; this.set('args', args); this.on("showLogin", () => this.loginShown = true); @@ -217,7 +217,7 @@ widgetTest('anon liking', { widgetTest('edit button', { template: '{{mount-widget widget="post" args=args editPost="editPost"}}', - setup() { + beforeEach() { this.set('args', { canEdit: true }); this.on('editPost', () => this.editPostCalled = true); }, @@ -231,7 +231,7 @@ widgetTest('edit button', { widgetTest(`edit button - can't edit`, { template: '{{mount-widget widget="post" args=args editPost="editPost"}}', - setup() { + beforeEach() { this.set('args', { canEdit: false }); }, test(assert) { @@ -241,7 +241,7 @@ widgetTest(`edit button - can't edit`, { widgetTest('recover button', { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canDelete: true }); this.on('deletePost', () => this.deletePostCalled = true); }, @@ -255,7 +255,7 @@ widgetTest('recover button', { widgetTest('delete topic button', { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canDeleteTopic: true }); this.on('deletePost', () => this.deletePostCalled = true); }, @@ -269,7 +269,7 @@ widgetTest('delete topic button', { widgetTest(`delete topic button - can't delete`, { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canDeleteTopic: false }); }, test(assert) { @@ -279,7 +279,7 @@ widgetTest(`delete topic button - can't delete`, { widgetTest('recover topic button', { template: '{{mount-widget widget="post" args=args recoverPost="recoverPost"}}', - setup() { + beforeEach() { this.set('args', { canRecoverTopic: true }); this.on('recoverPost', () => this.recovered = true); }, @@ -291,7 +291,7 @@ widgetTest('recover topic button', { widgetTest(`recover topic button - can't recover`, { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canRecoverTopic: false }); }, test(assert) { @@ -301,7 +301,7 @@ widgetTest(`recover topic button - can't recover`, { widgetTest('delete post button', { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canDelete: true }); this.on('deletePost', () => this.deletePostCalled = true); }, @@ -315,7 +315,7 @@ widgetTest('delete post button', { widgetTest(`delete post button - can't delete`, { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canDelete: false }); }, test(assert) { @@ -325,7 +325,7 @@ widgetTest(`delete post button - can't delete`, { widgetTest('recover post button', { template: '{{mount-widget widget="post" args=args recoverPost="recoverPost"}}', - setup() { + beforeEach() { this.set('args', { canRecover: true }); this.on('recoverPost', () => this.recovered = true); }, @@ -337,7 +337,7 @@ widgetTest('recover post button', { widgetTest(`recover post button - can't recover`, { template: '{{mount-widget widget="post" args=args deletePost="deletePost"}}', - setup() { + beforeEach() { this.set('args', { canRecover: false }); }, test(assert) { @@ -347,7 +347,7 @@ widgetTest(`recover post button - can't recover`, { widgetTest(`flagging`, { template: '{{mount-widget widget="post" args=args showFlags="showFlags"}}', - setup() { + beforeEach() { this.set('args', { canFlag: true }); this.on('showFlags', () => this.flagsShown = true); }, @@ -363,7 +363,7 @@ widgetTest(`flagging`, { widgetTest(`flagging: can't flag`, { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canFlag: false }); }, test(assert) { @@ -373,7 +373,7 @@ widgetTest(`flagging: can't flag`, { widgetTest(`read indicator`, { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { read: true }); }, test(assert) { @@ -383,7 +383,7 @@ widgetTest(`read indicator`, { widgetTest(`unread indicator`, { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { read: false }); }, test(assert) { @@ -393,7 +393,7 @@ widgetTest(`unread indicator`, { widgetTest("reply directly above (supressed)", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { replyToUsername: 'eviltrout', replyToAvatarTemplate: '/images/avatar.png', @@ -408,7 +408,7 @@ widgetTest("reply directly above (supressed)", { widgetTest("reply a few posts above (supressed)", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { replyToUsername: 'eviltrout', replyToAvatarTemplate: '/images/avatar.png', @@ -423,7 +423,7 @@ widgetTest("reply a few posts above (supressed)", { widgetTest("reply directly above", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { replyToUsername: 'eviltrout', replyToAvatarTemplate: '/images/avatar.png', @@ -443,7 +443,7 @@ widgetTest("reply directly above", { widgetTest("cooked content hidden", { template: '{{mount-widget widget="post" args=args expandHidden="expandHidden"}}', - setup() { + beforeEach() { this.set('args', { cooked_hidden: true }); this.on('expandHidden', () => this.unhidden = true); }, @@ -457,7 +457,7 @@ widgetTest("cooked content hidden", { widgetTest("expand first post", { template: '{{mount-widget widget="post" model=post args=args}}', - setup(store) { + beforeEach(store) { this.set('args', { expandablePost: true }); this.set('post', store.createRecord('post', { id: 1234 })); }, @@ -471,7 +471,7 @@ widgetTest("expand first post", { widgetTest("can't bookmark", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canBookmark: false }); }, test(assert) { @@ -482,7 +482,7 @@ widgetTest("can't bookmark", { widgetTest("bookmark", { template: '{{mount-widget widget="post" args=args toggleBookmark="toggleBookmark"}}', - setup() { + beforeEach() { const args = { canBookmark: true }; this.set('args', args); @@ -501,7 +501,7 @@ widgetTest("bookmark", { widgetTest("can't show admin menu when you can't manage", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canManage: false }); }, test(assert) { @@ -511,7 +511,7 @@ widgetTest("can't show admin menu when you can't manage", { widgetTest("show admin menu", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canManage: true }); }, test(assert) { @@ -529,7 +529,7 @@ widgetTest("show admin menu", { widgetTest("toggle moderator post", { template: '{{mount-widget widget="post" args=args togglePostType="togglePostType"}}', - setup() { + beforeEach() { this.set('args', { canManage: true }); this.on('togglePostType', () => this.toggled = true); }, @@ -544,7 +544,7 @@ widgetTest("toggle moderator post", { }); widgetTest("toggle moderator post", { template: '{{mount-widget widget="post" args=args togglePostType="togglePostType"}}', - setup() { + beforeEach() { this.set('args', { canManage: true }); this.on('togglePostType', () => this.toggled = true); }, @@ -560,7 +560,7 @@ widgetTest("toggle moderator post", { widgetTest("rebake post", { template: '{{mount-widget widget="post" args=args rebakePost="rebakePost"}}', - setup() { + beforeEach() { this.set('args', { canManage: true }); this.on('rebakePost', () => this.baked = true); }, @@ -576,7 +576,7 @@ widgetTest("rebake post", { widgetTest("unhide post", { template: '{{mount-widget widget="post" args=args unhidePost="unhidePost"}}', - setup() { + beforeEach() { this.set('args', { canManage: true, hidden: true }); this.on('unhidePost', () => this.unhidden = true); }, @@ -592,7 +592,7 @@ widgetTest("unhide post", { widgetTest("change owner", { template: '{{mount-widget widget="post" args=args changePostOwner="changePostOwner"}}', - setup() { + beforeEach() { this.currentUser.admin = true; this.set('args', { canManage: true }); this.on('changePostOwner', () => this.owned = true); @@ -609,7 +609,7 @@ widgetTest("change owner", { widgetTest("reply", { template: '{{mount-widget widget="post" args=args replyToPost="replyToPost"}}', - setup() { + beforeEach() { this.set('args', { canCreatePost: true }); this.on('replyToPost', () => this.replied = true); }, @@ -623,7 +623,7 @@ widgetTest("reply", { widgetTest("reply - without permissions", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { canCreatePost: false }); }, test(assert) { @@ -633,7 +633,7 @@ widgetTest("reply - without permissions", { widgetTest("replies - no replies", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', {replyCount: 0}); }, test(assert) { @@ -643,7 +643,7 @@ widgetTest("replies - no replies", { widgetTest("replies - multiple replies", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.siteSettings.suppress_reply_directly_below = true; this.set('args', {replyCount: 2, replyDirectlyBelow: true}); }, @@ -654,7 +654,7 @@ widgetTest("replies - multiple replies", { widgetTest("replies - one below, suppressed", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.siteSettings.suppress_reply_directly_below = true; this.set('args', {replyCount: 1, replyDirectlyBelow: true}); }, @@ -665,7 +665,7 @@ widgetTest("replies - one below, suppressed", { widgetTest("replies - one below, not suppressed", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.siteSettings.suppress_reply_directly_below = false; this.set('args', {id: 6654, replyCount: 1, replyDirectlyBelow: true}); }, @@ -680,7 +680,7 @@ widgetTest("replies - one below, not suppressed", { widgetTest("topic map not shown", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: false }); }, test(assert) { @@ -690,7 +690,7 @@ widgetTest("topic map not shown", { widgetTest("topic map - few posts", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true, topicPostsCount: 2, @@ -712,7 +712,7 @@ widgetTest("topic map - few posts", { widgetTest("topic map - participants", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true, topicPostsCount: 10, @@ -739,7 +739,7 @@ widgetTest("topic map - participants", { widgetTest("topic map - links", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true, topicLinks: [ @@ -774,7 +774,7 @@ widgetTest("topic map - links", { widgetTest("topic map - no summary", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true }); }, test(assert) { @@ -784,7 +784,7 @@ widgetTest("topic map - no summary", { widgetTest("topic map - has summary", { template: '{{mount-widget widget="post" args=args toggleSummary="toggleSummary"}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true, hasTopicSummary: true }); this.on('toggleSummary', () => this.summaryToggled = true); }, @@ -798,7 +798,7 @@ widgetTest("topic map - has summary", { widgetTest("pm map", { template: '{{mount-widget widget="post" args=args}}', - setup() { + beforeEach() { this.set('args', { showTopicMap: true, showPMMap: true, diff --git a/test/javascripts/widgets/poster-name-test.js.es6 b/test/javascripts/widgets/poster-name-test.js.es6 index fe9add7afde..d399e91fef2 100644 --- a/test/javascripts/widgets/poster-name-test.js.es6 +++ b/test/javascripts/widgets/poster-name-test.js.es6 @@ -4,7 +4,7 @@ moduleForWidget('poster-name'); widgetTest('basic rendering', { template: '{{mount-widget widget="poster-name" args=args}}', - setup() { + beforeEach() { this.set('args', { username: 'eviltrout', usernameUrl: '/u/eviltrout', @@ -23,7 +23,7 @@ widgetTest('basic rendering', { widgetTest('extra classes and glyphs', { template: '{{mount-widget widget="poster-name" args=args}}', - setup() { + beforeEach() { this.set('args', { username: 'eviltrout', usernameUrl: '/u/eviltrout', @@ -46,7 +46,7 @@ widgetTest('extra classes and glyphs', { widgetTest('disable display name on posts', { template: '{{mount-widget widget="poster-name" args=args}}', - setup() { + beforeEach() { this.siteSettings.display_name_on_posts = false; this.set('args', { username: 'eviltrout', name: 'Robin Ward' }); }, @@ -57,7 +57,7 @@ widgetTest('disable display name on posts', { widgetTest("doesn't render a name if it's similar to the username", { template: '{{mount-widget widget="poster-name" args=args}}', - setup() { + beforeEach() { this.siteSettings.prioritize_username_in_ux = true; this.siteSettings.display_name_on_posts = true; this.set('args', { username: 'eviltrout', name: 'evil-trout' }); diff --git a/test/javascripts/widgets/topic-participant-test.js.es6 b/test/javascripts/widgets/topic-participant-test.js.es6 index 078d562457f..67ba90a0635 100644 --- a/test/javascripts/widgets/topic-participant-test.js.es6 +++ b/test/javascripts/widgets/topic-participant-test.js.es6 @@ -5,7 +5,7 @@ moduleForWidget('topic-participant'); widgetTest('one post', { template: '{{mount-widget widget="topic-participant" args=args}}', - setup() { + beforeEach() { this.set('args', { username: 'test', avatar_template: '/images/avatar.png', @@ -23,7 +23,7 @@ widgetTest('one post', { widgetTest('many posts, a primary group with flair', { template: '{{mount-widget widget="topic-participant" args=args}}', - setup() { + beforeEach() { this.set('args', { username: 'test', avatar_template: '/images/avatar.png', diff --git a/test/javascripts/widgets/user-menu-test.js.es6 b/test/javascripts/widgets/user-menu-test.js.es6 index 3c043090eb1..c208d91b4b5 100644 --- a/test/javascripts/widgets/user-menu-test.js.es6 +++ b/test/javascripts/widgets/user-menu-test.js.es6 @@ -17,7 +17,7 @@ widgetTest('basics', { widgetTest('log out', { template: '{{mount-widget widget="user-menu" logout="logout"}}', - setup() { + beforeEach() { this.on('logout', () => this.loggedOut = true); }, @@ -33,7 +33,7 @@ widgetTest('log out', { widgetTest('private messages - disabled', { template: '{{mount-widget widget="user-menu"}}', - setup() { + beforeEach() { this.siteSettings.enable_private_messages = false; }, @@ -44,7 +44,7 @@ widgetTest('private messages - disabled', { widgetTest('private messages - enabled', { template: '{{mount-widget widget="user-menu"}}', - setup() { + beforeEach() { this.siteSettings.enable_private_messages = true; }, @@ -56,7 +56,7 @@ widgetTest('private messages - enabled', { widgetTest('anonymous', { template: '{{mount-widget widget="user-menu" toggleAnonymous="toggleAnonymous"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ is_anonymous: false, trust_level: 3 }); this.siteSettings.allow_anonymous_posting = true; this.siteSettings.anonymous_posting_min_trust_level = 3; @@ -76,7 +76,7 @@ widgetTest('anonymous', { widgetTest('anonymous - disabled', { template: '{{mount-widget widget="user-menu"}}', - setup() { + beforeEach() { this.siteSettings.allow_anonymous_posting = false; }, @@ -88,7 +88,7 @@ widgetTest('anonymous - disabled', { widgetTest('anonymous - switch back', { template: '{{mount-widget widget="user-menu" toggleAnonymous="toggleAnonymous"}}', - setup() { + beforeEach() { this.currentUser.setProperties({ is_anonymous: true }); this.siteSettings.allow_anonymous_posting = true; @@ -103,4 +103,3 @@ widgetTest('anonymous - switch back', { }); } }); - diff --git a/test/javascripts/widgets/widget-test.js.es6 b/test/javascripts/widgets/widget-test.js.es6 index ed52f81bee4..7ea8432d7c3 100644 --- a/test/javascripts/widgets/widget-test.js.es6 +++ b/test/javascripts/widgets/widget-test.js.es6 @@ -7,7 +7,7 @@ moduleForWidget('base'); widgetTest('widget attributes are passed in via args', { template: `{{mount-widget widget="hello-test" args=args}}`, - setup() { + beforeEach() { createWidget('hello-test', { tagName: 'div.test', @@ -27,7 +27,7 @@ widgetTest('widget attributes are passed in via args', { widgetTest('buildClasses', { template: `{{mount-widget widget="classname-test" args=args}}`, - setup() { + beforeEach() { createWidget('classname-test', { tagName: 'div.test', @@ -47,7 +47,7 @@ widgetTest('buildClasses', { widgetTest('buildAttributes', { template: `{{mount-widget widget="attributes-test" args=args}}`, - setup() { + beforeEach() { createWidget('attributes-test', { tagName: 'div.test', @@ -68,7 +68,7 @@ widgetTest('buildAttributes', { widgetTest('buildId', { template: `{{mount-widget widget="id-test" args=args}}`, - setup() { + beforeEach() { createWidget('id-test', { buildId(attrs) { return `test-${attrs.id}`; @@ -86,7 +86,7 @@ widgetTest('buildId', { widgetTest('widget state', { template: `{{mount-widget widget="state-test"}}`, - setup() { + beforeEach() { createWidget('state-test', { tagName: 'button.test', buildKey: () => `button-test`, @@ -119,7 +119,7 @@ widgetTest('widget state', { widgetTest('widget update with promise', { template: `{{mount-widget widget="promise-test"}}`, - setup() { + beforeEach() { createWidget('promise-test', { tagName: 'button.test', buildKey: () => 'promise-test', @@ -152,7 +152,7 @@ widgetTest('widget update with promise', { widgetTest('widget attaching', { template: `{{mount-widget widget="attach-test"}}`, - setup() { + beforeEach() { createWidget('test-embedded', { tagName: 'div.embedded' }); createWidget('attach-test', { @@ -172,7 +172,7 @@ widgetTest('widget attaching', { widgetTest('widget decorating', { template: `{{mount-widget widget="decorate-test"}}`, - setup() { + beforeEach() { createWidget('decorate-test', { tagName: 'div.decorate', html() { @@ -201,7 +201,7 @@ widgetTest('widget decorating', { widgetTest('widget settings', { template: `{{mount-widget widget="settings-test"}}`, - setup() { + beforeEach() { createWidget('settings-test', { tagName: 'div.settings', @@ -223,7 +223,7 @@ widgetTest('widget settings', { widgetTest('override settings', { template: `{{mount-widget widget="ov-settings-test"}}`, - setup() { + beforeEach() { createWidget('ov-settings-test', { tagName: 'div.settings', diff --git a/vendor/assets/javascripts/ember-qunit.js b/vendor/assets/javascripts/ember-qunit.js index cf41920e2e6..fd722360ee7 100644 --- a/vendor/assets/javascripts/ember-qunit.js +++ b/vendor/assets/javascripts/ember-qunit.js @@ -1,116 +1,318 @@ (function() { -var define, requireModule, require, requirejs; +var loader, define, requireModule, require, requirejs; -(function() { +(function (global) { + 'use strict'; + + var heimdall = global.heimdall; + + function dict() { + var obj = Object.create(null); + obj['__'] = undefined; + delete obj['__']; + return obj; + } + + // Save off the original values of these globals, so we can restore them if someone asks us to + var oldGlobals = { + loader: loader, + define: define, + requireModule: requireModule, + require: require, + requirejs: requirejs + }; + + requirejs = require = requireModule = function (name) { + var pending = []; + var mod = findModule(name, '(require)', pending); + + for (var i = pending.length - 1; i >= 0; i--) { + pending[i].exports(); + } + + return mod.module.exports; + }; + + loader = { + noConflict: function (aliases) { + var oldName, newName; + + for (oldName in aliases) { + if (aliases.hasOwnProperty(oldName)) { + if (oldGlobals.hasOwnProperty(oldName)) { + newName = aliases[oldName]; + + global[newName] = global[oldName]; + global[oldName] = oldGlobals[oldName]; + } + } + } + } + }; var _isArray; if (!Array.isArray) { _isArray = function (x) { - return Object.prototype.toString.call(x) === "[object Array]"; + return Object.prototype.toString.call(x) === '[object Array]'; }; } else { _isArray = Array.isArray; } - - var registry = {}, seen = {}, state = {}; - var FAILED = false; - define = function(name, deps, callback) { - - if (!_isArray(deps)) { - callback = deps; - deps = []; - } - - registry[name] = { - deps: deps, - callback: callback - }; - }; + var registry = dict(); + var seen = dict(); - function reify(deps, name, seen) { - var length = deps.length; - var reified = new Array(length); - var dep; - var exports; + var uuid = 0; - for (var i = 0, l = length; i < l; i++) { - dep = deps[i]; - if (dep === 'exports') { - exports = reified[i] = seen; - } else { - reified[i] = require(resolve(dep, name)); - } - } - - return { - deps: reified, - exports: exports - }; + function unsupportedModule(length) { + throw new Error('an unsupported module was defined, expected `define(name, deps, module)` instead got: `' + length + '` arguments to define`'); } - requirejs = require = requireModule = function(name) { - if (state[name] !== FAILED && - seen.hasOwnProperty(name)) { - return seen[name]; + var defaultDeps = ['require', 'exports', 'module']; + + function Module(name, deps, callback, alias) { + this.id = uuid++; + this.name = name; + this.deps = !deps.length && callback.length ? defaultDeps : deps; + this.module = { exports: {} }; + this.callback = callback; + this.hasExportsAsDep = false; + this.isAlias = alias; + this.reified = new Array(deps.length); + + /* + Each module normally passes through these states, in order: + new : initial state + pending : this module is scheduled to be executed + reifying : this module's dependencies are being executed + reified : this module's dependencies finished executing successfully + errored : this module's dependencies failed to execute + finalized : this module executed successfully + */ + this.state = 'new'; + } + + Module.prototype.makeDefaultExport = function () { + var exports = this.module.exports; + if (exports !== null && (typeof exports === 'object' || typeof exports === 'function') && exports['default'] === undefined && Object.isExtensible(exports)) { + exports['default'] = exports; } - - if (!registry[name]) { - throw new Error('Could not find module ' + name); - } - - var mod = registry[name]; - var reified; - var module; - var loaded = false; - - seen[name] = { }; // placeholder for run-time cycles - - try { - reified = reify(mod.deps, name, seen[name]); - module = mod.callback.apply(this, reified.deps); - loaded = true; - } finally { - if (!loaded) { - state[name] = FAILED; - } - } - - return reified.exports ? seen[name] : (seen[name] = module); }; + Module.prototype.exports = function () { + // if finalized, there is no work to do. If reifying, there is a + // circular dependency so we must return our (partial) exports. + if (this.state === 'finalized' || this.state === 'reifying') { + return this.module.exports; + } + + if (loader.wrapModules) { + this.callback = loader.wrapModules(this.name, this.callback); + } + + this.reify(); + + var result = this.callback.apply(this, this.reified); + this.state = 'finalized'; + + if (!(this.hasExportsAsDep && result === undefined)) { + this.module.exports = result; + } + this.makeDefaultExport(); + return this.module.exports; + }; + + Module.prototype.unsee = function () { + this.state = 'new'; + this.module = { exports: {} }; + }; + + Module.prototype.reify = function () { + if (this.state === 'reified') { + return; + } + this.state = 'reifying'; + try { + this.reified = this._reify(); + this.state = 'reified'; + } finally { + if (this.state === 'reifying') { + this.state = 'errored'; + } + } + }; + + Module.prototype._reify = function () { + var reified = this.reified.slice(); + for (var i = 0; i < reified.length; i++) { + var mod = reified[i]; + reified[i] = mod.exports ? mod.exports : mod.module.exports(); + } + return reified; + }; + + Module.prototype.findDeps = function (pending) { + if (this.state !== 'new') { + return; + } + + this.state = 'pending'; + + var deps = this.deps; + + for (var i = 0; i < deps.length; i++) { + var dep = deps[i]; + var entry = this.reified[i] = { exports: undefined, module: undefined }; + if (dep === 'exports') { + this.hasExportsAsDep = true; + entry.exports = this.module.exports; + } else if (dep === 'require') { + entry.exports = this.makeRequire(); + } else if (dep === 'module') { + entry.exports = this.module; + } else { + entry.module = findModule(resolve(dep, this.name), this.name, pending); + } + } + }; + + Module.prototype.makeRequire = function () { + var name = this.name; + var r = function (dep) { + return require(resolve(dep, name)); + }; + r['default'] = r; + r.has = function (dep) { + return has(resolve(dep, name)); + }; + return r; + }; + + define = function (name, deps, callback) { + var module = registry[name]; + + // If a module for this name has already been defined and is in any state + // other than `new` (meaning it has been or is currently being required), + // then we return early to avoid redefinition. + if (module && module.state !== 'new') { + return; + } + + if (arguments.length < 2) { + unsupportedModule(arguments.length); + } + + if (!_isArray(deps)) { + callback = deps; + deps = []; + } + + if (callback instanceof Alias) { + registry[name] = new Module(callback.name, deps, callback, true); + } else { + registry[name] = new Module(name, deps, callback, false); + } + }; + + // we don't support all of AMD + // define.amd = {}; + + function Alias(path) { + this.name = path; + } + + define.alias = function (path) { + return new Alias(path); + }; + + function missingModule(name, referrer) { + throw new Error('Could not find module `' + name + '` imported from `' + referrer + '`'); + } + + function findModule(name, referrer, pending) { + var mod = registry[name] || registry[name + '/index']; + + while (mod && mod.isAlias) { + mod = registry[mod.name]; + } + + if (!mod) { + missingModule(name, referrer); + } + + if (pending && mod.state !== 'pending' && mod.state !== 'finalized') { + mod.findDeps(pending); + pending.push(mod); + } + return mod; + } + function resolve(child, name) { - if (child.charAt(0) !== '.') { return child; } + if (child.charAt(0) !== '.') { + return child; + } var parts = child.split('/'); var nameParts = name.split('/'); - var parentBase; - - if (nameParts.length === 1) { - parentBase = nameParts; - } else { - parentBase = nameParts.slice(0, -1); - } + var parentBase = nameParts.slice(0, -1); for (var i = 0, l = parts.length; i < l; i++) { var part = parts[i]; - if (part === '..') { parentBase.pop(); } - else if (part === '.') { continue; } - else { parentBase.push(part); } + if (part === '..') { + if (parentBase.length === 0) { + throw new Error('Cannot access parent module of root'); + } + parentBase.pop(); + } else if (part === '.') { + continue; + } else { + parentBase.push(part); + } } return parentBase.join('/'); } - requirejs.entries = requirejs._eak_seen = registry; - requirejs.clear = function(){ - requirejs.entries = requirejs._eak_seen = registry = {}; - seen = state = {}; - }; -})(); + function has(name) { + return !!(registry[name] || registry[name + '/index']); + } + requirejs.entries = requirejs._eak_seen = registry; + requirejs.has = has; + requirejs.unsee = function (moduleName) { + findModule(moduleName, '(unsee)', false).unsee(); + }; + + requirejs.clear = function () { + requirejs.entries = requirejs._eak_seen = registry = dict(); + seen = dict(); + }; + + // This code primes the JS engine for good performance by warming the + // JIT compiler for these functions. + define('foo', function () {}); + define('foo/bar', [], function () {}); + define('foo/asdf', ['module', 'exports', 'require'], function (module, exports, require) { + if (require.has('foo/bar')) { + require('foo/bar'); + } + }); + define('foo/baz', [], define.alias('foo')); + define('foo/quz', define.alias('foo')); + define('foo/bar', ['foo', './quz', './baz', './asdf', './bar', '../foo'], function () {}); + define('foo/main', ['foo/bar'], function () {}); + + require('foo/main'); + require.unsee('foo/bar'); + + requirejs.clear(); + + if (typeof exports === 'object' && typeof module === 'object' && module.exports) { + module.exports = { require: require, define: define }; + } +})(this); define('ember-qunit', ['exports', 'ember-qunit/module-for', 'ember-qunit/module-for-component', 'ember-qunit/module-for-model', 'ember-qunit/adapter', 'ember-test-helpers', 'qunit'], function (exports, _emberQunitModuleFor, _emberQunitModuleForComponent, _emberQunitModuleForModel, _emberQunitAdapter, _emberTestHelpers, _qunit) { 'use strict'; @@ -118,6 +320,7 @@ define('ember-qunit', ['exports', 'ember-qunit/module-for', 'ember-qunit/module- exports.test = _qunit.test; exports.skip = _qunit.skip; exports.only = _qunit.only; + exports.todo = _qunit.todo; exports.moduleFor = _emberQunitModuleFor['default']; exports.moduleForComponent = _emberQunitModuleForComponent['default']; exports.moduleForModel = _emberQunitModuleForModel['default']; @@ -133,11 +336,15 @@ define('ember-qunit/adapter', ['exports', 'ember', 'qunit'], function (exports, }, asyncStart: function asyncStart() { - this.doneCallbacks.push(_qunit['default'].config.current.assert.async()); + this.doneCallbacks.push(_qunit['default'].config.current ? _qunit['default'].config.current.assert.async() : null); }, asyncEnd: function asyncEnd() { - this.doneCallbacks.pop()(); + var done = this.doneCallbacks.pop(); + // This can be null if asyncStart() was called outside of a test + if (done) { + done(); + } }, exception: function exception(error) { @@ -177,75 +384,78 @@ define('ember-qunit/qunit-module', ['exports', 'ember', 'qunit'], function (expo exports.createModule = createModule; - function beforeEachCallback(callbacks) { + function noop() {} + + function callbackFor(name, callbacks) { if (typeof callbacks !== 'object') { - return; + return noop; } if (!callbacks) { - return; + return noop; } - var beforeEach; + var callback = noop; - if (callbacks.beforeEach) { - beforeEach = callbacks.beforeEach; - delete callbacks.beforeEach; + if (callbacks[name]) { + callback = callbacks[name]; + delete callbacks[name]; } - return beforeEach; - } - - function afterEachCallback(callbacks) { - if (typeof callbacks !== 'object') { - return; - } - if (!callbacks) { - return; - } - - var afterEach; - - if (callbacks.afterEach) { - afterEach = callbacks.afterEach; - delete callbacks.afterEach; - } - - return afterEach; + return callback; } function createModule(Constructor, name, description, callbacks) { - var _beforeEach = beforeEachCallback(callbacks || description); - var _afterEach = afterEachCallback(callbacks || description); + if (!callbacks && typeof description === 'object') { + callbacks = description; + description = name; + } - var module = new Constructor(name, description, callbacks); + var _before = callbackFor('before', callbacks); + var _beforeEach = callbackFor('beforeEach', callbacks); + var _afterEach = callbackFor('afterEach', callbacks); + var _after = callbackFor('after', callbacks); + + var module; + var moduleName = typeof description === 'string' ? description : name; + + _qunit.module(moduleName, { + before: function before() { + // storing this in closure scope to avoid exposing these + // private internals to the test context + module = new Constructor(name, description, callbacks); + return _before.apply(this, arguments); + }, - _qunit.module(module.name, { beforeEach: function beforeEach() { - var _this = this, + var _module2, + _this = this, _arguments = arguments; // provide the test context to the underlying module module.setContext(this); - return module.setup.apply(module, arguments).then(function () { - if (_beforeEach) { - return _beforeEach.apply(_this, _arguments); - } + return (_module2 = module).setup.apply(_module2, arguments).then(function () { + return _beforeEach.apply(_this, _arguments); }); }, afterEach: function afterEach() { var _arguments2 = arguments; - var result = undefined; - - if (_afterEach) { - result = _afterEach.apply(this, arguments); - } - + var result = _afterEach.apply(this, arguments); return _ember['default'].RSVP.resolve(result).then(function () { - return module.teardown.apply(module, _arguments2); + var _module3; + + return (_module3 = module).teardown.apply(_module3, _arguments2); }); + }, + + after: function after() { + try { + return _after.apply(this, arguments); + } finally { + _after = _afterEach = _before = _beforeEach = callbacks = module = null; + } } }); } @@ -546,8 +756,8 @@ define('ember-test-helpers/abstract-test-module', ['exports', './wait', './test- exports['default'] = _default; }); -define('ember-test-helpers/build-registry', ['exports', 'ember'], function (exports, _ember) { - /* globals global, self, requirejs, require */ +define('ember-test-helpers/build-registry', ['exports', 'require', 'ember'], function (exports, _require, _ember) { + /* globals global, self, requirejs */ 'use strict'; @@ -586,7 +796,7 @@ define('ember-test-helpers/build-registry', ['exports', 'ember'], function (expo function register(name, factory) { var thingToRegisterWith = registry || container; - if (!container.lookupFactory(name)) { + if (!(container.factoryFor ? container.factoryFor(name) : container.lookupFactory(name))) { thingToRegisterWith.register(name, factory); } } @@ -647,7 +857,7 @@ define('ember-test-helpers/build-registry', ['exports', 'ember'], function (expo // available on the globalContext and hence ember-data wouldn't be setup // correctly for the tests; that's why we import and call setupContainer // here; also see https://github.com/emberjs/data/issues/4071 for context - var setupContainer = require('ember-data/setup-container')['default']; + var setupContainer = _require['default']('ember-data/setup-container')['default']; setupContainer(registry || container); } else if (globalContext.DS) { var DS = globalContext.DS; @@ -786,12 +996,13 @@ define('ember-test-helpers/test-module-for-component', ['exports', './test-modul } var integrationOption = callbacks.integration; + var hasNeeds = Array.isArray(callbacks.needs); _TestModule.call(this, 'component:' + componentName, description, callbacks); this.componentName = componentName; - if (callbacks.needs || callbacks.unit || integrationOption === false) { + if (hasNeeds || callbacks.unit || integrationOption === false) { this.isUnitTest = true; } else if (integrationOption) { this.isUnitTest = false; @@ -901,7 +1112,7 @@ define('ember-test-helpers/test-module-for-component', ['exports', './test-modul // only setup the injection if we are running against a version // of Ember that has `-view-registry:main` (Ember >= 1.12) - if (this.container.lookupFactory('-view-registry:main')) { + if (this.container.factoryFor ? this.container.factoryFor('-view-registry:main') : this.container.lookupFactory('-view-registry:main')) { (this.registry || this.container).injection('component', '_viewRegistry', '-view-registry:main'); } @@ -932,7 +1143,7 @@ define('ember-test-helpers/test-module-for-component', ['exports', './test-modul context.dispatcher.setup({}, '#ember-testing'); var hasRendered = false; - var OutletView = module.container.lookupFactory('view:-outlet'); + var OutletView = module.container.factoryFor ? module.container.factoryFor('view:-outlet') : module.container.lookupFactory('view:-outlet'); var OutletTemplate = module.container.lookup('template:-outlet'); var toplevelView = module.component = OutletView.create(); var hasOutletTemplate = !!OutletTemplate; @@ -1078,13 +1289,6 @@ define('ember-test-helpers/test-module-for-integration', ['exports', 'ember', '. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - var ACTION_KEY = undefined; - if (_hasEmberVersion['default'](2, 0)) { - ACTION_KEY = 'actions'; - } else { - ACTION_KEY = '_actions'; - } - var isPreGlimmer = !_hasEmberVersion['default'](1, 13); var _default = (function (_AbstractTestModule) { @@ -1168,7 +1372,7 @@ define('ember-test-helpers/test-module-for-integration', ['exports', 'ember', '. var container = this.container; var factory = function factory() { - return container.lookupFactory(subjectName); + return container.factoryFor ? container.factoryFor(subjectName) : container.lookupFactory(subjectName); }; _AbstractTestModule.prototype.setupContext.call(this, { @@ -1201,7 +1405,7 @@ define('ember-test-helpers/test-module-for-integration', ['exports', 'ember', '. // only setup the injection if we are running against a version // of Ember that has `-view-registry:main` (Ember >= 1.12) - if (this.container.lookupFactory('-view-registry:main')) { + if (this.container.factoryFor ? this.container.factoryFor('-view-registry:main') : this.container.lookupFactory('-view-registry:main')) { (this.registry || this.container).injection('component', '_viewRegistry', '-view-registry:main'); } }; @@ -1286,8 +1490,8 @@ define('ember-test-helpers/test-module-for-integration', ['exports', 'ember', '. exports['default'] = _default; }); -define('ember-test-helpers/test-module-for-model', ['exports', './test-module', 'ember'], function (exports, _testModule, _ember) { - /* global DS, require, requirejs */ // added here to prevent an import from erroring when ED is not present +define('ember-test-helpers/test-module-for-model', ['exports', 'require', './test-module', 'ember'], function (exports, _require, _testModule, _ember) { + /* global DS, requirejs */ // added here to prevent an import from erroring when ED is not present 'use strict'; @@ -1314,10 +1518,10 @@ define('ember-test-helpers/test-module-for-model', ['exports', './test-module', var callbacks = this.callbacks; var modelName = this.modelName; - var adapterFactory = container.lookupFactory('adapter:application'); + var adapterFactory = container.factoryFor ? container.factoryFor('adapter:application') : container.lookupFactory('adapter:application'); if (!adapterFactory) { if (requirejs.entries['ember-data/adapters/json-api']) { - adapterFactory = require('ember-data/adapters/json-api')['default']; + adapterFactory = _require['default']('ember-data/adapters/json-api')['default']; } // when ember-data/adapters/json-api is provided via ember-cli shims @@ -1466,7 +1670,7 @@ define('ember-test-helpers/test-module', ['exports', 'ember', './abstract-test-m var container = this.container; var factory = function factory() { - return container.lookupFactory(subjectName); + return container.factoryFor ? container.factoryFor(subjectName) : container.lookupFactory(subjectName); }; _AbstractTestModule.prototype.setupContext.call(this, { @@ -1767,21 +1971,21 @@ define("qunit", ["exports"], function (exports) { var skip = QUnit.skip; exports.skip = skip; var only = QUnit.only; - exports.only = only; + var todo = QUnit.todo; + + exports.todo = todo; exports["default"] = QUnit; }); define("ember", ["exports"], function(__exports__) { __exports__["default"] = window.Ember; }); -var emberQunit = requireModule("ember-qunit"); +var emberQUnit = requireModule("ember-qunit"); -window.moduleFor = emberQunit.moduleFor; -window.moduleForComponent = emberQunit.moduleForComponent; -window.moduleForModel = emberQunit.moduleForModel; -window.test = emberQunit.test; -window.setResolver = emberQunit.setResolver; +for (var exportName in emberQUnit) { + window[exportName] = emberQUnit[exportName]; +} })(); //# sourceMappingURL=ember-qunit.map \ No newline at end of file diff --git a/vendor/assets/javascripts/qunit.js b/vendor/assets/javascripts/qunit.js index 5df0822ea42..3cda99631a9 100644 --- a/vendor/assets/javascripts/qunit.js +++ b/vendor/assets/javascripts/qunit.js @@ -1,4334 +1,4926 @@ /*! - * QUnit 1.23.1 + * QUnit 2.3.3 * https://qunitjs.com/ * * Copyright jQuery Foundation and other contributors * Released under the MIT license * https://jquery.org/license * - * Date: 2016-04-12T17:29Z + * Date: 2017-06-02T14:07Z */ +(function (global$1) { + 'use strict'; -( function( global ) { - -var QUnit = {}; - -var Date = global.Date; -var now = Date.now || function() { - return new Date().getTime(); -}; - -var setTimeout = global.setTimeout; -var clearTimeout = global.clearTimeout; - -// Store a local window from the global to allow direct references. -var window = global.window; - -var defined = { - document: window && window.document !== undefined, - setTimeout: setTimeout !== undefined, - sessionStorage: ( function() { - var x = "qunit-test-string"; - try { - sessionStorage.setItem( x, x ); - sessionStorage.removeItem( x ); - return true; - } catch ( e ) { - return false; - } - }() ) -}; - -var fileName = ( sourceFromStacktrace( 0 ) || "" ).replace( /(:\d+)+\)?/, "" ).replace( /.+\//, "" ); -var globalStartCalled = false; -var runStarted = false; - -var toString = Object.prototype.toString, - hasOwn = Object.prototype.hasOwnProperty; - -// Returns a new Array with the elements that are in a but not in b -function diff( a, b ) { - var i, j, - result = a.slice(); - - for ( i = 0; i < result.length; i++ ) { - for ( j = 0; j < b.length; j++ ) { - if ( result[ i ] === b[ j ] ) { - result.splice( i, 1 ); - i--; - break; - } - } - } - return result; -} - -// From jquery.js -function inArray( elem, array ) { - if ( array.indexOf ) { - return array.indexOf( elem ); - } - - for ( var i = 0, length = array.length; i < length; i++ ) { - if ( array[ i ] === elem ) { - return i; - } - } - - return -1; -} - -/** - * Makes a clone of an object using only Array or Object as base, - * and copies over the own enumerable properties. - * - * @param {Object} obj - * @return {Object} New object with only the own properties (recursively). - */ -function objectValues ( obj ) { - var key, val, - vals = QUnit.is( "array", obj ) ? [] : {}; - for ( key in obj ) { - if ( hasOwn.call( obj, key ) ) { - val = obj[ key ]; - vals[ key ] = val === Object( val ) ? objectValues( val ) : val; - } - } - return vals; -} - -function extend( a, b, undefOnly ) { - for ( var prop in b ) { - if ( hasOwn.call( b, prop ) ) { - - // Avoid "Member not found" error in IE8 caused by messing with window.constructor - // This block runs on every environment, so `global` is being used instead of `window` - // to avoid errors on node. - if ( prop !== "constructor" || a !== global ) { - if ( b[ prop ] === undefined ) { - delete a[ prop ]; - } else if ( !( undefOnly && typeof a[ prop ] !== "undefined" ) ) { - a[ prop ] = b[ prop ]; - } - } - } - } - - return a; -} - -function objectType( obj ) { - if ( typeof obj === "undefined" ) { - return "undefined"; - } - - // Consider: typeof null === object - if ( obj === null ) { - return "null"; - } - - var match = toString.call( obj ).match( /^\[object\s(.*)\]$/ ), - type = match && match[ 1 ]; - - switch ( type ) { - case "Number": - if ( isNaN( obj ) ) { - return "nan"; - } - return "number"; - case "String": - case "Boolean": - case "Array": - case "Set": - case "Map": - case "Date": - case "RegExp": - case "Function": - case "Symbol": - return type.toLowerCase(); - } - if ( typeof obj === "object" ) { - return "object"; - } -} - -// Safe object type checking -function is( type, obj ) { - return QUnit.objectType( obj ) === type; -} - -// Doesn't support IE6 to IE9, it will return undefined on these browsers -// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack -function extractStacktrace( e, offset ) { - offset = offset === undefined ? 4 : offset; - - var stack, include, i; - - if ( e.stack ) { - stack = e.stack.split( "\n" ); - if ( /^error$/i.test( stack[ 0 ] ) ) { - stack.shift(); - } - if ( fileName ) { - include = []; - for ( i = offset; i < stack.length; i++ ) { - if ( stack[ i ].indexOf( fileName ) !== -1 ) { - break; - } - include.push( stack[ i ] ); - } - if ( include.length ) { - return include.join( "\n" ); - } - } - return stack[ offset ]; - - // Support: Safari <=6 only - } else if ( e.sourceURL ) { - - // Exclude useless self-reference for generated Error objects - if ( /qunit.js$/.test( e.sourceURL ) ) { - return; - } - - // For actual exceptions, this is useful - return e.sourceURL + ":" + e.line; - } -} - -function sourceFromStacktrace( offset ) { - var error = new Error(); - - // Support: Safari <=7 only, IE <=10 - 11 only - // Not all browsers generate the `stack` property for `new Error()`, see also #636 - if ( !error.stack ) { - try { - throw error; - } catch ( err ) { - error = err; - } - } - - return extractStacktrace( error, offset ); -} - -/** - * Config object: Maintain internal state - * Later exposed as QUnit.config - * `config` initialized at top of scope - */ -var config = { - - // The queue of tests to run - queue: [], - - // Block until document ready - blocking: true, - - // By default, run previously failed tests first - // very useful in combination with "Hide passed tests" checked - reorder: true, - - // By default, modify document.title when suite is done - altertitle: true, - - // HTML Reporter: collapse every test except the first failing test - // If false, all failing tests will be expanded - collapse: true, - - // By default, scroll to top of the page when suite is done - scrolltop: true, - - // Depth up-to which object will be dumped - maxDepth: 5, - - // When enabled, all tests must call expect() - requireExpects: false, - - // Placeholder for user-configurable form-exposed URL parameters - urlConfig: [], - - // Set of all modules. - modules: [], - - // Stack of nested modules - moduleStack: [], - - // The first unnamed module - currentModule: { - name: "", - tests: [] - }, - - callbacks: {} -}; - -// Push a loose unnamed module to the modules collection -config.modules.push( config.currentModule ); - -var loggingCallbacks = {}; - -// Register logging callbacks -function registerLoggingCallbacks( obj ) { - var i, l, key, - callbackNames = [ "begin", "done", "log", "testStart", "testDone", - "moduleStart", "moduleDone" ]; - - function registerLoggingCallback( key ) { - var loggingCallback = function( callback ) { - if ( objectType( callback ) !== "function" ) { - throw new Error( - "QUnit logging methods require a callback function as their first parameters." - ); - } - - config.callbacks[ key ].push( callback ); - }; - - // DEPRECATED: This will be removed on QUnit 2.0.0+ - // Stores the registered functions allowing restoring - // at verifyLoggingCallbacks() if modified - loggingCallbacks[ key ] = loggingCallback; - - return loggingCallback; - } - - for ( i = 0, l = callbackNames.length; i < l; i++ ) { - key = callbackNames[ i ]; - - // Initialize key collection of logging callback - if ( objectType( config.callbacks[ key ] ) === "undefined" ) { - config.callbacks[ key ] = []; - } - - obj[ key ] = registerLoggingCallback( key ); - } -} - -function runLoggingCallbacks( key, args ) { - var i, l, callbacks; - - callbacks = config.callbacks[ key ]; - for ( i = 0, l = callbacks.length; i < l; i++ ) { - callbacks[ i ]( args ); - } -} - -// DEPRECATED: This will be removed on 2.0.0+ -// This function verifies if the loggingCallbacks were modified by the user -// If so, it will restore it, assign the given callback and print a console warning -function verifyLoggingCallbacks() { - var loggingCallback, userCallback; - - for ( loggingCallback in loggingCallbacks ) { - if ( QUnit[ loggingCallback ] !== loggingCallbacks[ loggingCallback ] ) { - - userCallback = QUnit[ loggingCallback ]; - - // Restore the callback function - QUnit[ loggingCallback ] = loggingCallbacks[ loggingCallback ]; - - // Assign the deprecated given callback - QUnit[ loggingCallback ]( userCallback ); - - if ( global.console && global.console.warn ) { - global.console.warn( - "QUnit." + loggingCallback + " was replaced with a new value.\n" + - "Please, check out the documentation on how to apply logging callbacks.\n" + - "Reference: https://api.qunitjs.com/category/callbacks/" - ); - } - } - } -} - -( function() { - if ( !defined.document ) { - return; - } - - // `onErrorFnPrev` initialized at top of scope - // Preserve other handlers - var onErrorFnPrev = window.onerror; - - // Cover uncaught exceptions - // Returning true will suppress the default browser handler, - // returning false will let it run. - window.onerror = function( error, filePath, linerNr ) { - var ret = false; - if ( onErrorFnPrev ) { - ret = onErrorFnPrev( error, filePath, linerNr ); - } - - // Treat return value as window.onerror itself does, - // Only do our handling if not suppressed. - if ( ret !== true ) { - if ( QUnit.config.current ) { - if ( QUnit.config.current.ignoreGlobalErrors ) { - return true; - } - QUnit.pushFailure( error, filePath + ":" + linerNr ); - } else { - QUnit.test( "global failure", extend( function() { - QUnit.pushFailure( error, filePath + ":" + linerNr ); - }, { validTest: true } ) ); - } - return false; - } - - return ret; - }; -}() ); - -// Figure out if we're running the tests from a server or not -QUnit.isLocal = !( defined.document && window.location.protocol !== "file:" ); - -// Expose the current QUnit version -QUnit.version = "1.23.1"; - -extend( QUnit, { - - // Call on start of module test to prepend name to all tests - module: function( name, testEnvironment, executeNow ) { - var module, moduleFns; - var currentModule = config.currentModule; - - if ( arguments.length === 2 ) { - if ( objectType( testEnvironment ) === "function" ) { - executeNow = testEnvironment; - testEnvironment = undefined; - } - } - - // DEPRECATED: handles setup/teardown functions, - // beforeEach and afterEach should be used instead - if ( testEnvironment && testEnvironment.setup ) { - testEnvironment.beforeEach = testEnvironment.setup; - delete testEnvironment.setup; - } - if ( testEnvironment && testEnvironment.teardown ) { - testEnvironment.afterEach = testEnvironment.teardown; - delete testEnvironment.teardown; - } - - module = createModule(); - - moduleFns = { - beforeEach: setHook( module, "beforeEach" ), - afterEach: setHook( module, "afterEach" ) - }; - - if ( objectType( executeNow ) === "function" ) { - config.moduleStack.push( module ); - setCurrentModule( module ); - executeNow.call( module.testEnvironment, moduleFns ); - config.moduleStack.pop(); - module = module.parentModule || currentModule; - } - - setCurrentModule( module ); - - function createModule() { - var parentModule = config.moduleStack.length ? - config.moduleStack.slice( -1 )[ 0 ] : null; - var moduleName = parentModule !== null ? - [ parentModule.name, name ].join( " > " ) : name; - var module = { - name: moduleName, - parentModule: parentModule, - tests: [], - moduleId: generateHash( moduleName ) - }; - - var env = {}; - if ( parentModule ) { - extend( env, parentModule.testEnvironment ); - delete env.beforeEach; - delete env.afterEach; - } - extend( env, testEnvironment ); - module.testEnvironment = env; - - config.modules.push( module ); - return module; - } - - function setCurrentModule( module ) { - config.currentModule = module; - } - - }, - - // DEPRECATED: QUnit.asyncTest() will be removed in QUnit 2.0. - asyncTest: asyncTest, - - test: test, - - skip: skip, - - only: only, - - // DEPRECATED: The functionality of QUnit.start() will be altered in QUnit 2.0. - // In QUnit 2.0, invoking it will ONLY affect the `QUnit.config.autostart` blocking behavior. - start: function( count ) { - var globalStartAlreadyCalled = globalStartCalled; - - if ( !config.current ) { - globalStartCalled = true; - - if ( runStarted ) { - throw new Error( "Called start() outside of a test context while already started" ); - } else if ( globalStartAlreadyCalled || count > 1 ) { - throw new Error( "Called start() outside of a test context too many times" ); - } else if ( config.autostart ) { - throw new Error( "Called start() outside of a test context when " + - "QUnit.config.autostart was true" ); - } else if ( !config.pageLoaded ) { - - // The page isn't completely loaded yet, so bail out and let `QUnit.load` handle it - config.autostart = true; - return; - } - } else { - - // If a test is running, adjust its semaphore - config.current.semaphore -= count || 1; - - // If semaphore is non-numeric, throw error - if ( isNaN( config.current.semaphore ) ) { - config.current.semaphore = 0; - - QUnit.pushFailure( - "Called start() with a non-numeric decrement.", - sourceFromStacktrace( 2 ) - ); - return; - } - - // Don't start until equal number of stop-calls - if ( config.current.semaphore > 0 ) { - return; - } - - // Throw an Error if start is called more often than stop - if ( config.current.semaphore < 0 ) { - config.current.semaphore = 0; - - QUnit.pushFailure( - "Called start() while already started (test's semaphore was 0 already)", - sourceFromStacktrace( 2 ) - ); - return; - } - } - - resumeProcessing(); - }, - - // DEPRECATED: QUnit.stop() will be removed in QUnit 2.0. - stop: function( count ) { - - // If there isn't a test running, don't allow QUnit.stop() to be called - if ( !config.current ) { - throw new Error( "Called stop() outside of a test context" ); - } - - // If a test is running, adjust its semaphore - config.current.semaphore += count || 1; - - pauseProcessing(); - }, - - config: config, - - is: is, - - objectType: objectType, - - extend: extend, - - load: function() { - config.pageLoaded = true; - - // Initialize the configuration options - extend( config, { - stats: { all: 0, bad: 0 }, - moduleStats: { all: 0, bad: 0 }, - started: 0, - updateRate: 1000, - autostart: true, - filter: "" - }, true ); - - config.blocking = false; - - if ( config.autostart ) { - resumeProcessing(); - } - }, - - stack: function( offset ) { - offset = ( offset || 0 ) + 2; - return sourceFromStacktrace( offset ); - } -} ); - -registerLoggingCallbacks( QUnit ); - -function begin() { - var i, l, - modulesLog = []; - - // If the test run hasn't officially begun yet - if ( !config.started ) { - - // Record the time of the test run's beginning - config.started = now(); - - verifyLoggingCallbacks(); - - // Delete the loose unnamed module if unused. - if ( config.modules[ 0 ].name === "" && config.modules[ 0 ].tests.length === 0 ) { - config.modules.shift(); - } - - // Avoid unnecessary information by not logging modules' test environments - for ( i = 0, l = config.modules.length; i < l; i++ ) { - modulesLog.push( { - name: config.modules[ i ].name, - tests: config.modules[ i ].tests - } ); - } - - // The test run is officially beginning now - runLoggingCallbacks( "begin", { - totalTests: Test.count, - modules: modulesLog - } ); - } - - config.blocking = false; - process( true ); -} - -function process( last ) { - function next() { - process( last ); - } - var start = now(); - config.depth = ( config.depth || 0 ) + 1; - - while ( config.queue.length && !config.blocking ) { - if ( !defined.setTimeout || config.updateRate <= 0 || - ( ( now() - start ) < config.updateRate ) ) { - if ( config.current ) { - - // Reset async tracking for each phase of the Test lifecycle - config.current.usedAsync = false; - } - config.queue.shift()(); - } else { - setTimeout( next, 13 ); - break; - } - } - config.depth--; - if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { - done(); - } -} - -function pauseProcessing() { - config.blocking = true; - - if ( config.testTimeout && defined.setTimeout ) { - clearTimeout( config.timeout ); - config.timeout = setTimeout( function() { - if ( config.current ) { - config.current.semaphore = 0; - QUnit.pushFailure( "Test timed out", sourceFromStacktrace( 2 ) ); - } else { - throw new Error( "Test timed out" ); - } - resumeProcessing(); - }, config.testTimeout ); - } -} - -function resumeProcessing() { - runStarted = true; - - // A slight delay to allow this iteration of the event loop to finish (more assertions, etc.) - if ( defined.setTimeout ) { - setTimeout( function() { - if ( config.current && config.current.semaphore > 0 ) { - return; - } - if ( config.timeout ) { - clearTimeout( config.timeout ); - } - - begin(); - }, 13 ); - } else { - begin(); - } -} - -function done() { - var runtime, passed; - - config.autorun = true; - - // Log the last module results - if ( config.previousModule ) { - runLoggingCallbacks( "moduleDone", { - name: config.previousModule.name, - tests: config.previousModule.tests, - failed: config.moduleStats.bad, - passed: config.moduleStats.all - config.moduleStats.bad, - total: config.moduleStats.all, - runtime: now() - config.moduleStats.started - } ); - } - delete config.previousModule; - - runtime = now() - config.started; - passed = config.stats.all - config.stats.bad; - - runLoggingCallbacks( "done", { - failed: config.stats.bad, - passed: passed, - total: config.stats.all, - runtime: runtime - } ); -} - -function setHook( module, hookName ) { - if ( module.testEnvironment === undefined ) { - module.testEnvironment = {}; - } - - return function( callback ) { - module.testEnvironment[ hookName ] = callback; - }; -} - -var focused = false; -var priorityCount = 0; -var unitSampler; - -function Test( settings ) { - var i, l; - - ++Test.count; - - extend( this, settings ); - this.assertions = []; - this.semaphore = 0; - this.usedAsync = false; - this.module = config.currentModule; - this.stack = sourceFromStacktrace( 3 ); - - // Register unique strings - for ( i = 0, l = this.module.tests; i < l.length; i++ ) { - if ( this.module.tests[ i ].name === this.testName ) { - this.testName += " "; - } - } - - this.testId = generateHash( this.module.name, this.testName ); - - this.module.tests.push( { - name: this.testName, - testId: this.testId - } ); - - if ( settings.skip ) { - - // Skipped tests will fully ignore any sent callback - this.callback = function() {}; - this.async = false; - this.expected = 0; - } else { - this.assert = new Assert( this ); - } -} - -Test.count = 0; - -Test.prototype = { - before: function() { - if ( - - // Emit moduleStart when we're switching from one module to another - this.module !== config.previousModule || - - // They could be equal (both undefined) but if the previousModule property doesn't - // yet exist it means this is the first test in a suite that isn't wrapped in a - // module, in which case we'll just emit a moduleStart event for 'undefined'. - // Without this, reporters can get testStart before moduleStart which is a problem. - !hasOwn.call( config, "previousModule" ) - ) { - if ( hasOwn.call( config, "previousModule" ) ) { - runLoggingCallbacks( "moduleDone", { - name: config.previousModule.name, - tests: config.previousModule.tests, - failed: config.moduleStats.bad, - passed: config.moduleStats.all - config.moduleStats.bad, - total: config.moduleStats.all, - runtime: now() - config.moduleStats.started - } ); - } - config.previousModule = this.module; - config.moduleStats = { all: 0, bad: 0, started: now() }; - runLoggingCallbacks( "moduleStart", { - name: this.module.name, - tests: this.module.tests - } ); - } - - config.current = this; - - if ( this.module.testEnvironment ) { - delete this.module.testEnvironment.beforeEach; - delete this.module.testEnvironment.afterEach; - } - this.testEnvironment = extend( {}, this.module.testEnvironment ); - - this.started = now(); - runLoggingCallbacks( "testStart", { - name: this.testName, - module: this.module.name, - testId: this.testId - } ); - - if ( !config.pollution ) { - saveGlobal(); - } - }, - - run: function() { - var promise; - - config.current = this; - - if ( this.async ) { - QUnit.stop(); - } - - this.callbackStarted = now(); - - if ( config.notrycatch ) { - runTest( this ); - return; - } - - try { - runTest( this ); - } catch ( e ) { - this.pushFailure( "Died on test #" + ( this.assertions.length + 1 ) + " " + - this.stack + ": " + ( e.message || e ), extractStacktrace( e, 0 ) ); - - // Else next test will carry the responsibility - saveGlobal(); - - // Restart the tests if they're blocking - if ( config.blocking ) { - QUnit.start(); - } - } - - function runTest( test ) { - promise = test.callback.call( test.testEnvironment, test.assert ); - test.resolvePromise( promise ); - } - }, - - after: function() { - checkPollution(); - }, - - queueHook: function( hook, hookName ) { - var promise, - test = this; - return function runHook() { - config.current = test; - if ( config.notrycatch ) { - callHook(); - return; - } - try { - callHook(); - } catch ( error ) { - test.pushFailure( hookName + " failed on " + test.testName + ": " + - ( error.message || error ), extractStacktrace( error, 0 ) ); - } - - function callHook() { - promise = hook.call( test.testEnvironment, test.assert ); - test.resolvePromise( promise, hookName ); - } - }; - }, - - // Currently only used for module level hooks, can be used to add global level ones - hooks: function( handler ) { - var hooks = []; - - function processHooks( test, module ) { - if ( module.parentModule ) { - processHooks( test, module.parentModule ); - } - if ( module.testEnvironment && - QUnit.objectType( module.testEnvironment[ handler ] ) === "function" ) { - hooks.push( test.queueHook( module.testEnvironment[ handler ], handler ) ); - } - } - - // Hooks are ignored on skipped tests - if ( !this.skip ) { - processHooks( this, this.module ); - } - return hooks; - }, - - finish: function() { - config.current = this; - if ( config.requireExpects && this.expected === null ) { - this.pushFailure( "Expected number of assertions to be defined, but expect() was " + - "not called.", this.stack ); - } else if ( this.expected !== null && this.expected !== this.assertions.length ) { - this.pushFailure( "Expected " + this.expected + " assertions, but " + - this.assertions.length + " were run", this.stack ); - } else if ( this.expected === null && !this.assertions.length ) { - this.pushFailure( "Expected at least one assertion, but none were run - call " + - "expect(0) to accept zero assertions.", this.stack ); - } - - var i, - bad = 0; - - this.runtime = now() - this.started; - config.stats.all += this.assertions.length; - config.moduleStats.all += this.assertions.length; - - for ( i = 0; i < this.assertions.length; i++ ) { - if ( !this.assertions[ i ].result ) { - bad++; - config.stats.bad++; - config.moduleStats.bad++; - } - } - - runLoggingCallbacks( "testDone", { - name: this.testName, - module: this.module.name, - skipped: !!this.skip, - failed: bad, - passed: this.assertions.length - bad, - total: this.assertions.length, - runtime: this.runtime, - - // HTML Reporter use - assertions: this.assertions, - testId: this.testId, - - // Source of Test - source: this.stack, - - // DEPRECATED: this property will be removed in 2.0.0, use runtime instead - duration: this.runtime - } ); - - // QUnit.reset() is deprecated and will be replaced for a new - // fixture reset function on QUnit 2.0/2.1. - // It's still called here for backwards compatibility handling - QUnit.reset(); - - config.current = undefined; - }, - - queue: function() { - var priority, - test = this; - - if ( !this.valid() ) { - return; - } - - function run() { - - // Each of these can by async - synchronize( [ - function() { - test.before(); - }, - - test.hooks( "beforeEach" ), - function() { - test.run(); - }, - - test.hooks( "afterEach" ).reverse(), - - function() { - test.after(); - }, - function() { - test.finish(); - } - ] ); - } - - // Prioritize previously failed tests, detected from sessionStorage - priority = QUnit.config.reorder && defined.sessionStorage && - +sessionStorage.getItem( "qunit-test-" + this.module.name + "-" + this.testName ); - - return synchronize( run, priority, config.seed ); - }, - - pushResult: function( resultInfo ) { - - // Destructure of resultInfo = { result, actual, expected, message, negative } - var source, - details = { - module: this.module.name, - name: this.testName, - result: resultInfo.result, - message: resultInfo.message, - actual: resultInfo.actual, - expected: resultInfo.expected, - testId: this.testId, - negative: resultInfo.negative || false, - runtime: now() - this.started - }; - - if ( !resultInfo.result ) { - source = sourceFromStacktrace(); - - if ( source ) { - details.source = source; - } - } - - runLoggingCallbacks( "log", details ); - - this.assertions.push( { - result: !!resultInfo.result, - message: resultInfo.message - } ); - }, - - pushFailure: function( message, source, actual ) { - if ( !( this instanceof Test ) ) { - throw new Error( "pushFailure() assertion outside test context, was " + - sourceFromStacktrace( 2 ) ); - } - - var details = { - module: this.module.name, - name: this.testName, - result: false, - message: message || "error", - actual: actual || null, - testId: this.testId, - runtime: now() - this.started - }; - - if ( source ) { - details.source = source; - } - - runLoggingCallbacks( "log", details ); - - this.assertions.push( { - result: false, - message: message - } ); - }, - - resolvePromise: function( promise, phase ) { - var then, message, - test = this; - if ( promise != null ) { - then = promise.then; - if ( QUnit.objectType( then ) === "function" ) { - QUnit.stop(); - then.call( - promise, - function() { QUnit.start(); }, - function( error ) { - message = "Promise rejected " + - ( !phase ? "during" : phase.replace( /Each$/, "" ) ) + - " " + test.testName + ": " + ( error.message || error ); - test.pushFailure( message, extractStacktrace( error, 0 ) ); - - // Else next test will carry the responsibility - saveGlobal(); - - // Unblock - QUnit.start(); - } - ); - } - } - }, - - valid: function() { - var filter = config.filter, - regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec( filter ), - module = config.module && config.module.toLowerCase(), - fullName = ( this.module.name + ": " + this.testName ); - - function moduleChainNameMatch( testModule ) { - var testModuleName = testModule.name ? testModule.name.toLowerCase() : null; - if ( testModuleName === module ) { - return true; - } else if ( testModule.parentModule ) { - return moduleChainNameMatch( testModule.parentModule ); - } else { - return false; - } - } - - function moduleChainIdMatch( testModule ) { - return inArray( testModule.moduleId, config.moduleId ) > -1 || - testModule.parentModule && moduleChainIdMatch( testModule.parentModule ); - } - - // Internally-generated tests are always valid - if ( this.callback && this.callback.validTest ) { - return true; - } - - if ( config.moduleId && config.moduleId.length > 0 && - !moduleChainIdMatch( this.module ) ) { - - return false; - } - - if ( config.testId && config.testId.length > 0 && - inArray( this.testId, config.testId ) < 0 ) { - - return false; - } - - if ( module && !moduleChainNameMatch( this.module ) ) { - return false; - } - - if ( !filter ) { - return true; - } - - return regexFilter ? - this.regexFilter( !!regexFilter[ 1 ], regexFilter[ 2 ], regexFilter[ 3 ], fullName ) : - this.stringFilter( filter, fullName ); - }, - - regexFilter: function( exclude, pattern, flags, fullName ) { - var regex = new RegExp( pattern, flags ); - var match = regex.test( fullName ); - - return match !== exclude; - }, - - stringFilter: function( filter, fullName ) { - filter = filter.toLowerCase(); - fullName = fullName.toLowerCase(); - - var include = filter.charAt( 0 ) !== "!"; - if ( !include ) { - filter = filter.slice( 1 ); - } - - // If the filter matches, we need to honour include - if ( fullName.indexOf( filter ) !== -1 ) { - return include; - } - - // Otherwise, do the opposite - return !include; - } -}; - -// Resets the test setup. Useful for tests that modify the DOM. -/* -DEPRECATED: Use multiple tests instead of resetting inside a test. -Use testStart or testDone for custom cleanup. -This method will throw an error in 2.0, and will be removed in 2.1 -*/ -QUnit.reset = function() { - - // Return on non-browser environments - // This is necessary to not break on node tests - if ( !defined.document ) { - return; - } - - var fixture = defined.document && document.getElementById && - document.getElementById( "qunit-fixture" ); - - if ( fixture ) { - fixture.innerHTML = config.fixture; - } -}; - -QUnit.pushFailure = function() { - if ( !QUnit.config.current ) { - throw new Error( "pushFailure() assertion outside test context, in " + - sourceFromStacktrace( 2 ) ); - } - - // Gets current test obj - var currentTest = QUnit.config.current; - - return currentTest.pushFailure.apply( currentTest, arguments ); -}; - -// Based on Java's String.hashCode, a simple but not -// rigorously collision resistant hashing function -function generateHash( module, testName ) { - var hex, - i = 0, - hash = 0, - str = module + "\x1C" + testName, - len = str.length; - - for ( ; i < len; i++ ) { - hash = ( ( hash << 5 ) - hash ) + str.charCodeAt( i ); - hash |= 0; - } - - // Convert the possibly negative integer hash code into an 8 character hex string, which isn't - // strictly necessary but increases user understanding that the id is a SHA-like hash - hex = ( 0x100000000 + hash ).toString( 16 ); - if ( hex.length < 8 ) { - hex = "0000000" + hex; - } - - return hex.slice( -8 ); -} - -function synchronize( callback, priority, seed ) { - var last = !priority, - index; - - if ( QUnit.objectType( callback ) === "array" ) { - while ( callback.length ) { - synchronize( callback.shift() ); - } - return; - } - - if ( priority ) { - config.queue.splice( priorityCount++, 0, callback ); - } else if ( seed ) { - if ( !unitSampler ) { - unitSampler = unitSamplerGenerator( seed ); - } - - // Insert into a random position after all priority items - index = Math.floor( unitSampler() * ( config.queue.length - priorityCount + 1 ) ); - config.queue.splice( priorityCount + index, 0, callback ); - } else { - config.queue.push( callback ); - } - - if ( config.autorun && !config.blocking ) { - process( last ); - } -} - -function unitSamplerGenerator( seed ) { - - // 32-bit xorshift, requires only a nonzero seed - // http://excamera.com/sphinx/article-xorshift.html - var sample = parseInt( generateHash( seed ), 16 ) || -1; - return function() { - sample ^= sample << 13; - sample ^= sample >>> 17; - sample ^= sample << 5; - - // ECMAScript has no unsigned number type - if ( sample < 0 ) { - sample += 0x100000000; - } - - return sample / 0x100000000; - }; -} - -function saveGlobal() { - config.pollution = []; - - if ( config.noglobals ) { - for ( var key in global ) { - if ( hasOwn.call( global, key ) ) { - - // In Opera sometimes DOM element ids show up here, ignore them - if ( /^qunit-test-output/.test( key ) ) { - continue; - } - config.pollution.push( key ); - } - } - } -} - -function checkPollution() { - var newGlobals, - deletedGlobals, - old = config.pollution; - - saveGlobal(); - - newGlobals = diff( config.pollution, old ); - if ( newGlobals.length > 0 ) { - QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join( ", " ) ); - } - - deletedGlobals = diff( old, config.pollution ); - if ( deletedGlobals.length > 0 ) { - QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join( ", " ) ); - } -} - -// Will be exposed as QUnit.asyncTest -function asyncTest( testName, expected, callback ) { - if ( arguments.length === 2 ) { - callback = expected; - expected = null; - } - - QUnit.test( testName, expected, callback, true ); -} - -// Will be exposed as QUnit.test -function test( testName, expected, callback, async ) { - if ( focused ) { return; } - - var newTest; - - if ( arguments.length === 2 ) { - callback = expected; - expected = null; - } - - newTest = new Test( { - testName: testName, - expected: expected, - async: async, - callback: callback - } ); - - newTest.queue(); -} - -// Will be exposed as QUnit.skip -function skip( testName ) { - if ( focused ) { return; } - - var test = new Test( { - testName: testName, - skip: true - } ); - - test.queue(); -} - -// Will be exposed as QUnit.only -function only( testName, expected, callback, async ) { - var newTest; - - if ( focused ) { return; } - - QUnit.config.queue.length = 0; - focused = true; - - if ( arguments.length === 2 ) { - callback = expected; - expected = null; - } - - newTest = new Test( { - testName: testName, - expected: expected, - async: async, - callback: callback - } ); - - newTest.queue(); -} - -function Assert( testContext ) { - this.test = testContext; -} - -// Assert helpers -QUnit.assert = Assert.prototype = { - - // Specify the number of expected assertions to guarantee that failed test - // (no assertions are run at all) don't slip through. - expect: function( asserts ) { - if ( arguments.length === 1 ) { - this.test.expected = asserts; - } else { - return this.test.expected; - } - }, - - // Increment this Test's semaphore counter, then return a function that - // decrements that counter a maximum of once. - async: function( count ) { - var test = this.test, - popped = false, - acceptCallCount = count; - - if ( typeof acceptCallCount === "undefined" ) { - acceptCallCount = 1; - } - - test.semaphore += 1; - test.usedAsync = true; - pauseProcessing(); - - return function done() { - - if ( popped ) { - test.pushFailure( "Too many calls to the `assert.async` callback", - sourceFromStacktrace( 2 ) ); - return; - } - acceptCallCount -= 1; - if ( acceptCallCount > 0 ) { - return; - } - - test.semaphore -= 1; - popped = true; - resumeProcessing(); - }; - }, - - // Exports test.push() to the user API - // Alias of pushResult. - push: function( result, actual, expected, message, negative ) { - var currentAssert = this instanceof Assert ? this : QUnit.config.current.assert; - return currentAssert.pushResult( { - result: result, - actual: actual, - expected: expected, - message: message, - negative: negative - } ); - }, - - pushResult: function( resultInfo ) { - - // Destructure of resultInfo = { result, actual, expected, message, negative } - var assert = this, - currentTest = ( assert instanceof Assert && assert.test ) || QUnit.config.current; - - // Backwards compatibility fix. - // Allows the direct use of global exported assertions and QUnit.assert.* - // Although, it's use is not recommended as it can leak assertions - // to other tests from async tests, because we only get a reference to the current test, - // not exactly the test where assertion were intended to be called. - if ( !currentTest ) { - throw new Error( "assertion outside test context, in " + sourceFromStacktrace( 2 ) ); - } - - if ( currentTest.usedAsync === true && currentTest.semaphore === 0 ) { - currentTest.pushFailure( "Assertion after the final `assert.async` was resolved", - sourceFromStacktrace( 2 ) ); - - // Allow this assertion to continue running anyway... - } - - if ( !( assert instanceof Assert ) ) { - assert = currentTest.assert; - } - - return assert.test.pushResult( resultInfo ); - }, - - ok: function( result, message ) { - message = message || ( result ? "okay" : "failed, expected argument to be truthy, was: " + - QUnit.dump.parse( result ) ); - this.pushResult( { - result: !!result, - actual: result, - expected: true, - message: message - } ); - }, - - notOk: function( result, message ) { - message = message || ( !result ? "okay" : "failed, expected argument to be falsy, was: " + - QUnit.dump.parse( result ) ); - this.pushResult( { - result: !result, - actual: result, - expected: false, - message: message - } ); - }, - - equal: function( actual, expected, message ) { - /*jshint eqeqeq:false */ - this.pushResult( { - result: expected == actual, - actual: actual, - expected: expected, - message: message - } ); - }, - - notEqual: function( actual, expected, message ) { - /*jshint eqeqeq:false */ - this.pushResult( { - result: expected != actual, - actual: actual, - expected: expected, - message: message, - negative: true - } ); - }, - - propEqual: function( actual, expected, message ) { - actual = objectValues( actual ); - expected = objectValues( expected ); - this.pushResult( { - result: QUnit.equiv( actual, expected ), - actual: actual, - expected: expected, - message: message - } ); - }, - - notPropEqual: function( actual, expected, message ) { - actual = objectValues( actual ); - expected = objectValues( expected ); - this.pushResult( { - result: !QUnit.equiv( actual, expected ), - actual: actual, - expected: expected, - message: message, - negative: true - } ); - }, - - deepEqual: function( actual, expected, message ) { - this.pushResult( { - result: QUnit.equiv( actual, expected ), - actual: actual, - expected: expected, - message: message - } ); - }, - - notDeepEqual: function( actual, expected, message ) { - this.pushResult( { - result: !QUnit.equiv( actual, expected ), - actual: actual, - expected: expected, - message: message, - negative: true - } ); - }, - - strictEqual: function( actual, expected, message ) { - this.pushResult( { - result: expected === actual, - actual: actual, - expected: expected, - message: message - } ); - }, - - notStrictEqual: function( actual, expected, message ) { - this.pushResult( { - result: expected !== actual, - actual: actual, - expected: expected, - message: message, - negative: true - } ); - }, - - "throws": function( block, expected, message ) { - var actual, expectedType, - expectedOutput = expected, - ok = false, - currentTest = ( this instanceof Assert && this.test ) || QUnit.config.current; - - // 'expected' is optional unless doing string comparison - if ( message == null && typeof expected === "string" ) { - message = expected; - expected = null; - } - - currentTest.ignoreGlobalErrors = true; - try { - block.call( currentTest.testEnvironment ); - } catch ( e ) { - actual = e; - } - currentTest.ignoreGlobalErrors = false; - - if ( actual ) { - expectedType = QUnit.objectType( expected ); - - // We don't want to validate thrown error - if ( !expected ) { - ok = true; - expectedOutput = null; - - // Expected is a regexp - } else if ( expectedType === "regexp" ) { - ok = expected.test( errorString( actual ) ); - - // Expected is a string - } else if ( expectedType === "string" ) { - ok = expected === errorString( actual ); - - // Expected is a constructor, maybe an Error constructor - } else if ( expectedType === "function" && actual instanceof expected ) { - ok = true; - - // Expected is an Error object - } else if ( expectedType === "object" ) { - ok = actual instanceof expected.constructor && - actual.name === expected.name && - actual.message === expected.message; - - // Expected is a validation function which returns true if validation passed - } else if ( expectedType === "function" && expected.call( {}, actual ) === true ) { - expectedOutput = null; - ok = true; - } - } - - currentTest.assert.pushResult( { - result: ok, - actual: actual, - expected: expectedOutput, - message: message - } ); - } -}; - -// Provide an alternative to assert.throws(), for environments that consider throws a reserved word -// Known to us are: Closure Compiler, Narwhal -( function() { - /*jshint sub:true */ - Assert.prototype.raises = Assert.prototype [ "throws" ]; //jscs:ignore requireDotNotation -}() ); - -function errorString( error ) { - var name, message, - resultErrorString = error.toString(); - if ( resultErrorString.substring( 0, 7 ) === "[object" ) { - name = error.name ? error.name.toString() : "Error"; - message = error.message ? error.message.toString() : ""; - if ( name && message ) { - return name + ": " + message; - } else if ( name ) { - return name; - } else if ( message ) { - return message; - } else { - return "Error"; - } - } else { - return resultErrorString; - } -} - -// Test for equality any JavaScript type. -// Author: Philippe Rathé -QUnit.equiv = ( function() { - - // Stack to decide between skip/abort functions - var callers = []; - - // Stack to avoiding loops from circular referencing - var parents = []; - var parentsB = []; - - var getProto = Object.getPrototypeOf || function( obj ) { - - /*jshint proto: true */ - return obj.__proto__; - }; - - function useStrictEquality( b, a ) { - - // To catch short annotation VS 'new' annotation of a declaration. e.g.: - // `var i = 1;` - // `var j = new Number(1);` - if ( typeof a === "object" ) { - a = a.valueOf(); - } - if ( typeof b === "object" ) { - b = b.valueOf(); - } - - return a === b; - } - - function compareConstructors( a, b ) { - var protoA = getProto( a ); - var protoB = getProto( b ); - - // Comparing constructors is more strict than using `instanceof` - if ( a.constructor === b.constructor ) { - return true; - } - - // Ref #851 - // If the obj prototype descends from a null constructor, treat it - // as a null prototype. - if ( protoA && protoA.constructor === null ) { - protoA = null; - } - if ( protoB && protoB.constructor === null ) { - protoB = null; - } - - // Allow objects with no prototype to be equivalent to - // objects with Object as their constructor. - if ( ( protoA === null && protoB === Object.prototype ) || - ( protoB === null && protoA === Object.prototype ) ) { - return true; - } - - return false; - } - - function getRegExpFlags( regexp ) { - return "flags" in regexp ? regexp.flags : regexp.toString().match( /[gimuy]*$/ )[ 0 ]; - } - - var callbacks = { - "string": useStrictEquality, - "boolean": useStrictEquality, - "number": useStrictEquality, - "null": useStrictEquality, - "undefined": useStrictEquality, - "symbol": useStrictEquality, - "date": useStrictEquality, - - "nan": function() { - return true; - }, - - "regexp": function( b, a ) { - return a.source === b.source && - - // Include flags in the comparison - getRegExpFlags( a ) === getRegExpFlags( b ); - }, - - // - skip when the property is a method of an instance (OOP) - // - abort otherwise, - // initial === would have catch identical references anyway - "function": function() { - var caller = callers[ callers.length - 1 ]; - return caller !== Object && typeof caller !== "undefined"; - }, - - "array": function( b, a ) { - var i, j, len, loop, aCircular, bCircular; - - len = a.length; - if ( len !== b.length ) { - - // Safe and faster - return false; - } - - // Track reference to avoid circular references - parents.push( a ); - parentsB.push( b ); - for ( i = 0; i < len; i++ ) { - loop = false; - for ( j = 0; j < parents.length; j++ ) { - aCircular = parents[ j ] === a[ i ]; - bCircular = parentsB[ j ] === b[ i ]; - if ( aCircular || bCircular ) { - if ( a[ i ] === b[ i ] || aCircular && bCircular ) { - loop = true; - } else { - parents.pop(); - parentsB.pop(); - return false; - } - } - } - if ( !loop && !innerEquiv( a[ i ], b[ i ] ) ) { - parents.pop(); - parentsB.pop(); - return false; - } - } - parents.pop(); - parentsB.pop(); - return true; - }, - - "set": function( b, a ) { - var innerEq, - outerEq = true; - - if ( a.size !== b.size ) { - return false; - } - - a.forEach( function( aVal ) { - innerEq = false; - - b.forEach( function( bVal ) { - if ( innerEquiv( bVal, aVal ) ) { - innerEq = true; - } - } ); - - if ( !innerEq ) { - outerEq = false; - } - } ); - - return outerEq; - }, - - "map": function( b, a ) { - var innerEq, - outerEq = true; - - if ( a.size !== b.size ) { - return false; - } - - a.forEach( function( aVal, aKey ) { - innerEq = false; - - b.forEach( function( bVal, bKey ) { - if ( innerEquiv( [ bVal, bKey ], [ aVal, aKey ] ) ) { - innerEq = true; - } - } ); - - if ( !innerEq ) { - outerEq = false; - } - } ); - - return outerEq; - }, - - "object": function( b, a ) { - var i, j, loop, aCircular, bCircular; - - // Default to true - var eq = true; - var aProperties = []; - var bProperties = []; - - if ( compareConstructors( a, b ) === false ) { - return false; - } - - // Stack constructor before traversing properties - callers.push( a.constructor ); - - // Track reference to avoid circular references - parents.push( a ); - parentsB.push( b ); - - // Be strict: don't ensure hasOwnProperty and go deep - for ( i in a ) { - loop = false; - for ( j = 0; j < parents.length; j++ ) { - aCircular = parents[ j ] === a[ i ]; - bCircular = parentsB[ j ] === b[ i ]; - if ( aCircular || bCircular ) { - if ( a[ i ] === b[ i ] || aCircular && bCircular ) { - loop = true; - } else { - eq = false; - break; - } - } - } - aProperties.push( i ); - if ( !loop && !innerEquiv( a[ i ], b[ i ] ) ) { - eq = false; - break; - } - } - - parents.pop(); - parentsB.pop(); - - // Unstack, we are done - callers.pop(); - - for ( i in b ) { - - // Collect b's properties - bProperties.push( i ); - } - - // Ensures identical properties name - return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); - } - }; - - function typeEquiv( a, b ) { - var type = QUnit.objectType( a ); - return QUnit.objectType( b ) === type && callbacks[ type ]( b, a ); - } - - // The real equiv function - function innerEquiv( a, b ) { - - // We're done when there's nothing more to compare - if ( arguments.length < 2 ) { - return true; - } - - // Require type-specific equality - return ( a === b || typeEquiv( a, b ) ) && - - // ...across all consecutive argument pairs - ( arguments.length === 2 || innerEquiv.apply( this, [].slice.call( arguments, 1 ) ) ); - } - - return innerEquiv; -}() ); - -// Based on jsDump by Ariel Flesler -// http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html -QUnit.dump = ( function() { - function quote( str ) { - return "\"" + str.toString().replace( /\\/g, "\\\\" ).replace( /"/g, "\\\"" ) + "\""; - } - function literal( o ) { - return o + ""; - } - function join( pre, arr, post ) { - var s = dump.separator(), - base = dump.indent(), - inner = dump.indent( 1 ); - if ( arr.join ) { - arr = arr.join( "," + s + inner ); - } - if ( !arr ) { - return pre + post; - } - return [ pre, inner + arr, base + post ].join( s ); - } - function array( arr, stack ) { - var i = arr.length, - ret = new Array( i ); - - if ( dump.maxDepth && dump.depth > dump.maxDepth ) { - return "[object Array]"; - } - - this.up(); - while ( i-- ) { - ret[ i ] = this.parse( arr[ i ], undefined, stack ); - } - this.down(); - return join( "[", ret, "]" ); - } - - var reName = /^function (\w+)/, - dump = { - - // The objType is used mostly internally, you can fix a (custom) type in advance - parse: function( obj, objType, stack ) { - stack = stack || []; - var res, parser, parserType, - inStack = inArray( obj, stack ); - - if ( inStack !== -1 ) { - return "recursion(" + ( inStack - stack.length ) + ")"; - } - - objType = objType || this.typeOf( obj ); - parser = this.parsers[ objType ]; - parserType = typeof parser; - - if ( parserType === "function" ) { - stack.push( obj ); - res = parser.call( this, obj, stack ); - stack.pop(); - return res; - } - return ( parserType === "string" ) ? parser : this.parsers.error; - }, - typeOf: function( obj ) { - var type; - if ( obj === null ) { - type = "null"; - } else if ( typeof obj === "undefined" ) { - type = "undefined"; - } else if ( QUnit.is( "regexp", obj ) ) { - type = "regexp"; - } else if ( QUnit.is( "date", obj ) ) { - type = "date"; - } else if ( QUnit.is( "function", obj ) ) { - type = "function"; - } else if ( obj.setInterval !== undefined && - obj.document !== undefined && - obj.nodeType === undefined ) { - type = "window"; - } else if ( obj.nodeType === 9 ) { - type = "document"; - } else if ( obj.nodeType ) { - type = "node"; - } else if ( - - // Native arrays - toString.call( obj ) === "[object Array]" || - - // NodeList objects - ( typeof obj.length === "number" && obj.item !== undefined && - ( obj.length ? obj.item( 0 ) === obj[ 0 ] : ( obj.item( 0 ) === null && - obj[ 0 ] === undefined ) ) ) - ) { - type = "array"; - } else if ( obj.constructor === Error.prototype.constructor ) { - type = "error"; - } else { - type = typeof obj; - } - return type; - }, - - separator: function() { - return this.multiline ? this.HTML ? "
" : "\n" : this.HTML ? " " : " "; - }, - - // Extra can be a number, shortcut for increasing-calling-decreasing - indent: function( extra ) { - if ( !this.multiline ) { - return ""; - } - var chr = this.indentChar; - if ( this.HTML ) { - chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); - } - return new Array( this.depth + ( extra || 0 ) ).join( chr ); - }, - up: function( a ) { - this.depth += a || 1; - }, - down: function( a ) { - this.depth -= a || 1; - }, - setParser: function( name, parser ) { - this.parsers[ name ] = parser; - }, - - // The next 3 are exposed so you can use them - quote: quote, - literal: literal, - join: join, - depth: 1, - maxDepth: QUnit.config.maxDepth, - - // This is the list of parsers, to modify them, use dump.setParser - parsers: { - window: "[Window]", - document: "[Document]", - error: function( error ) { - return "Error(\"" + error.message + "\")"; - }, - unknown: "[Unknown]", - "null": "null", - "undefined": "undefined", - "function": function( fn ) { - var ret = "function", - - // Functions never have name in IE - name = "name" in fn ? fn.name : ( reName.exec( fn ) || [] )[ 1 ]; - - if ( name ) { - ret += " " + name; - } - ret += "("; - - ret = [ ret, dump.parse( fn, "functionArgs" ), "){" ].join( "" ); - return join( ret, dump.parse( fn, "functionCode" ), "}" ); - }, - array: array, - nodelist: array, - "arguments": array, - object: function( map, stack ) { - var keys, key, val, i, nonEnumerableProperties, - ret = []; - - if ( dump.maxDepth && dump.depth > dump.maxDepth ) { - return "[object Object]"; - } - - dump.up(); - keys = []; - for ( key in map ) { - keys.push( key ); - } - - // Some properties are not always enumerable on Error objects. - nonEnumerableProperties = [ "message", "name" ]; - for ( i in nonEnumerableProperties ) { - key = nonEnumerableProperties[ i ]; - if ( key in map && inArray( key, keys ) < 0 ) { - keys.push( key ); - } - } - keys.sort(); - for ( i = 0; i < keys.length; i++ ) { - key = keys[ i ]; - val = map[ key ]; - ret.push( dump.parse( key, "key" ) + ": " + - dump.parse( val, undefined, stack ) ); - } - dump.down(); - return join( "{", ret, "}" ); - }, - node: function( node ) { - var len, i, val, - open = dump.HTML ? "<" : "<", - close = dump.HTML ? ">" : ">", - tag = node.nodeName.toLowerCase(), - ret = open + tag, - attrs = node.attributes; - - if ( attrs ) { - for ( i = 0, len = attrs.length; i < len; i++ ) { - val = attrs[ i ].nodeValue; - - // IE6 includes all attributes in .attributes, even ones not explicitly - // set. Those have values like undefined, null, 0, false, "" or - // "inherit". - if ( val && val !== "inherit" ) { - ret += " " + attrs[ i ].nodeName + "=" + - dump.parse( val, "attribute" ); - } - } - } - ret += close; - - // Show content of TextNode or CDATASection - if ( node.nodeType === 3 || node.nodeType === 4 ) { - ret += node.nodeValue; - } - - return ret + open + "/" + tag + close; - }, - - // Function calls it internally, it's the arguments part of the function - functionArgs: function( fn ) { - var args, - l = fn.length; - - if ( !l ) { - return ""; - } - - args = new Array( l ); - while ( l-- ) { - - // 97 is 'a' - args[ l ] = String.fromCharCode( 97 + l ); - } - return " " + args.join( ", " ) + " "; - }, - - // Object calls it internally, the key part of an item in a map - key: quote, - - // Function calls it internally, it's the content of the function - functionCode: "[code]", - - // Node calls it internally, it's a html attribute value - attribute: quote, - string: quote, - date: quote, - regexp: literal, - number: literal, - "boolean": literal - }, - - // If true, entities are escaped ( <, >, \t, space and \n ) - HTML: false, - - // Indentation unit - indentChar: " ", - - // If true, items in a collection, are separated by a \n, else just a space. - multiline: true - }; - - return dump; -}() ); - -// Back compat -QUnit.jsDump = QUnit.dump; - -// Deprecated -// Extend assert methods to QUnit for Backwards compatibility -( function() { - var i, - assertions = Assert.prototype; - - function applyCurrent( current ) { - return function() { - var assert = new Assert( QUnit.config.current ); - current.apply( assert, arguments ); - }; - } - - for ( i in assertions ) { - QUnit[ i ] = applyCurrent( assertions[ i ] ); - } -}() ); - -// For browser, export only select globals -if ( defined.document ) { - - ( function() { - var i, l, - keys = [ - "test", - "module", - "expect", - "asyncTest", - "start", - "stop", - "ok", - "notOk", - "equal", - "notEqual", - "propEqual", - "notPropEqual", - "deepEqual", - "notDeepEqual", - "strictEqual", - "notStrictEqual", - "throws", - "raises" - ]; - - for ( i = 0, l = keys.length; i < l; i++ ) { - window[ keys[ i ] ] = QUnit[ keys[ i ] ]; - } - }() ); - - window.QUnit = QUnit; -} - -// For nodejs -if ( typeof module !== "undefined" && module && module.exports ) { - module.exports = QUnit; - - // For consistency with CommonJS environments' exports - module.exports.QUnit = QUnit; -} - -// For CommonJS with exports, but without module.exports, like Rhino -if ( typeof exports !== "undefined" && exports ) { - exports.QUnit = QUnit; -} - -if ( typeof define === "function" && define.amd ) { - define( function() { - return QUnit; - } ); - QUnit.config.autostart = false; -} - -// Get a reference to the global object, like window in browsers -}( ( function() { - return this; -}() ) ) ); - -( function() { - -// Only interact with URLs via window.location -var location = typeof window !== "undefined" && window.location; -if ( !location ) { - return; -} - -var urlParams = getUrlParams(); - -QUnit.urlParams = urlParams; - -// Match module/test by inclusion in an array -QUnit.config.moduleId = [].concat( urlParams.moduleId || [] ); -QUnit.config.testId = [].concat( urlParams.testId || [] ); - -// Exact case-insensitive match of the module name -QUnit.config.module = urlParams.module; - -// Regular expression or case-insenstive substring match against "moduleName: testName" -QUnit.config.filter = urlParams.filter; - -// Test order randomization -if ( urlParams.seed === true ) { - - // Generate a random seed if the option is specified without a value - QUnit.config.seed = Math.random().toString( 36 ).slice( 2 ); -} else if ( urlParams.seed ) { - QUnit.config.seed = urlParams.seed; -} - -// Add URL-parameter-mapped config values with UI form rendering data -QUnit.config.urlConfig.push( - { - id: "hidepassed", - label: "Hide passed tests", - tooltip: "Only show tests and assertions that fail. Stored as query-strings." - }, - { - id: "noglobals", - label: "Check for Globals", - tooltip: "Enabling this will test if any test introduces new properties on the " + - "global object (`window` in Browsers). Stored as query-strings." - }, - { - id: "notrycatch", - label: "No try-catch", - tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging " + - "exceptions in IE reasonable. Stored as query-strings." - } -); - -QUnit.begin( function() { - var i, option, - urlConfig = QUnit.config.urlConfig; - - for ( i = 0; i < urlConfig.length; i++ ) { - - // Options can be either strings or objects with nonempty "id" properties - option = QUnit.config.urlConfig[ i ]; - if ( typeof option !== "string" ) { - option = option.id; - } - - if ( QUnit.config[ option ] === undefined ) { - QUnit.config[ option ] = urlParams[ option ]; - } - } -} ); - -function getUrlParams() { - var i, param, name, value; - var urlParams = {}; - var params = location.search.slice( 1 ).split( "&" ); - var length = params.length; - - for ( i = 0; i < length; i++ ) { - if ( params[ i ] ) { - param = params[ i ].split( "=" ); - name = decodeURIComponent( param[ 0 ] ); - - // Allow just a key to turn on a flag, e.g., test.html?noglobals - value = param.length === 1 || - decodeURIComponent( param.slice( 1 ).join( "=" ) ) ; - if ( urlParams[ name ] ) { - urlParams[ name ] = [].concat( urlParams[ name ], value ); - } else { - urlParams[ name ] = value; - } - } - } - - return urlParams; -} - -// Don't load the HTML Reporter on non-browser environments -if ( typeof window === "undefined" || !window.document ) { - return; -} - -// Deprecated QUnit.init - Ref #530 -// Re-initialize the configuration options -QUnit.init = function() { - var config = QUnit.config; - - config.stats = { all: 0, bad: 0 }; - config.moduleStats = { all: 0, bad: 0 }; - config.started = 0; - config.updateRate = 1000; - config.blocking = false; - config.autostart = true; - config.autorun = false; - config.filter = ""; - config.queue = []; - - appendInterface(); -}; - -var config = QUnit.config, - document = window.document, - collapseNext = false, - hasOwn = Object.prototype.hasOwnProperty, - unfilteredUrl = setUrl( { filter: undefined, module: undefined, - moduleId: undefined, testId: undefined } ), - defined = { - sessionStorage: ( function() { - var x = "qunit-test-string"; - try { - sessionStorage.setItem( x, x ); - sessionStorage.removeItem( x ); - return true; - } catch ( e ) { - return false; - } - }() ) - }, - modulesList = []; - -/** -* Escape text for attribute or text content. -*/ -function escapeText( s ) { - if ( !s ) { - return ""; - } - s = s + ""; - - // Both single quotes and double quotes (for attributes) - return s.replace( /['"<>&]/g, function( s ) { - switch ( s ) { - case "'": - return "'"; - case "\"": - return """; - case "<": - return "<"; - case ">": - return ">"; - case "&": - return "&"; - } - } ); -} - -/** - * @param {HTMLElement} elem - * @param {string} type - * @param {Function} fn - */ -function addEvent( elem, type, fn ) { - if ( elem.addEventListener ) { - - // Standards-based browsers - elem.addEventListener( type, fn, false ); - } else if ( elem.attachEvent ) { - - // Support: IE <9 - elem.attachEvent( "on" + type, function() { - var event = window.event; - if ( !event.target ) { - event.target = event.srcElement || document; - } - - fn.call( elem, event ); - } ); - } -} - -/** - * @param {Array|NodeList} elems - * @param {string} type - * @param {Function} fn - */ -function addEvents( elems, type, fn ) { - var i = elems.length; - while ( i-- ) { - addEvent( elems[ i ], type, fn ); - } -} - -function hasClass( elem, name ) { - return ( " " + elem.className + " " ).indexOf( " " + name + " " ) >= 0; -} - -function addClass( elem, name ) { - if ( !hasClass( elem, name ) ) { - elem.className += ( elem.className ? " " : "" ) + name; - } -} - -function toggleClass( elem, name, force ) { - if ( force || typeof force === "undefined" && !hasClass( elem, name ) ) { - addClass( elem, name ); - } else { - removeClass( elem, name ); - } -} - -function removeClass( elem, name ) { - var set = " " + elem.className + " "; - - // Class name may appear multiple times - while ( set.indexOf( " " + name + " " ) >= 0 ) { - set = set.replace( " " + name + " ", " " ); - } - - // Trim for prettiness - elem.className = typeof set.trim === "function" ? set.trim() : set.replace( /^\s+|\s+$/g, "" ); -} - -function id( name ) { - return document.getElementById && document.getElementById( name ); -} - -function getUrlConfigHtml() { - var i, j, val, - escaped, escapedTooltip, - selection = false, - urlConfig = config.urlConfig, - urlConfigHtml = ""; - - for ( i = 0; i < urlConfig.length; i++ ) { - - // Options can be either strings or objects with nonempty "id" properties - val = config.urlConfig[ i ]; - if ( typeof val === "string" ) { - val = { - id: val, - label: val - }; - } - - escaped = escapeText( val.id ); - escapedTooltip = escapeText( val.tooltip ); - - if ( !val.value || typeof val.value === "string" ) { - urlConfigHtml += ""; - } else { - urlConfigHtml += ""; - } - } - - return urlConfigHtml; -} - -// Handle "click" events on toolbar checkboxes and "change" for select menus. -// Updates the URL with the new state of `config.urlConfig` values. -function toolbarChanged() { - var updatedUrl, value, tests, - field = this, - params = {}; - - // Detect if field is a select menu or a checkbox - if ( "selectedIndex" in field ) { - value = field.options[ field.selectedIndex ].value || undefined; - } else { - value = field.checked ? ( field.defaultValue || true ) : undefined; - } - - params[ field.name ] = value; - updatedUrl = setUrl( params ); - - // Check if we can apply the change without a page refresh - if ( "hidepassed" === field.name && "replaceState" in window.history ) { - QUnit.urlParams[ field.name ] = value; - config[ field.name ] = value || false; - tests = id( "qunit-tests" ); - if ( tests ) { - toggleClass( tests, "hidepass", value || false ); - } - window.history.replaceState( null, "", updatedUrl ); - } else { - window.location = updatedUrl; - } -} - -function setUrl( params ) { - var key, arrValue, i, - querystring = "?", - location = window.location; - - params = QUnit.extend( QUnit.extend( {}, QUnit.urlParams ), params ); - - for ( key in params ) { - - // Skip inherited or undefined properties - if ( hasOwn.call( params, key ) && params[ key ] !== undefined ) { - - // Output a parameter for each value of this key (but usually just one) - arrValue = [].concat( params[ key ] ); - for ( i = 0; i < arrValue.length; i++ ) { - querystring += encodeURIComponent( key ); - if ( arrValue[ i ] !== true ) { - querystring += "=" + encodeURIComponent( arrValue[ i ] ); - } - querystring += "&"; - } - } - } - return location.protocol + "//" + location.host + - location.pathname + querystring.slice( 0, -1 ); -} - -function applyUrlParams() { - var selectedModule, - modulesList = id( "qunit-modulefilter" ), - filter = id( "qunit-filter-input" ).value; - - selectedModule = modulesList ? - decodeURIComponent( modulesList.options[ modulesList.selectedIndex ].value ) : - undefined; - - window.location = setUrl( { - module: ( selectedModule === "" ) ? undefined : selectedModule, - filter: ( filter === "" ) ? undefined : filter, - - // Remove moduleId and testId filters - moduleId: undefined, - testId: undefined - } ); -} - -function toolbarUrlConfigContainer() { - var urlConfigContainer = document.createElement( "span" ); - - urlConfigContainer.innerHTML = getUrlConfigHtml(); - addClass( urlConfigContainer, "qunit-url-config" ); - - // For oldIE support: - // * Add handlers to the individual elements instead of the container - // * Use "click" instead of "change" for checkboxes - addEvents( urlConfigContainer.getElementsByTagName( "input" ), "click", toolbarChanged ); - addEvents( urlConfigContainer.getElementsByTagName( "select" ), "change", toolbarChanged ); - - return urlConfigContainer; -} - -function toolbarLooseFilter() { - var filter = document.createElement( "form" ), - label = document.createElement( "label" ), - input = document.createElement( "input" ), - button = document.createElement( "button" ); - - addClass( filter, "qunit-filter" ); - - label.innerHTML = "Filter: "; - - input.type = "text"; - input.value = config.filter || ""; - input.name = "filter"; - input.id = "qunit-filter-input"; - - button.innerHTML = "Go"; - - label.appendChild( input ); - - filter.appendChild( label ); - filter.appendChild( button ); - addEvent( filter, "submit", function( ev ) { - applyUrlParams(); - - if ( ev && ev.preventDefault ) { - ev.preventDefault(); - } - - return false; - } ); - - return filter; -} - -function toolbarModuleFilterHtml() { - var i, - moduleFilterHtml = ""; - - if ( !modulesList.length ) { - return false; - } - - moduleFilterHtml += "" + - ""; - - return moduleFilterHtml; -} - -function toolbarModuleFilter() { - var toolbar = id( "qunit-testrunner-toolbar" ), - moduleFilter = document.createElement( "span" ), - moduleFilterHtml = toolbarModuleFilterHtml(); - - if ( !toolbar || !moduleFilterHtml ) { - return false; - } - - moduleFilter.setAttribute( "id", "qunit-modulefilter-container" ); - moduleFilter.innerHTML = moduleFilterHtml; - - addEvent( moduleFilter.lastChild, "change", applyUrlParams ); - - toolbar.appendChild( moduleFilter ); -} - -function appendToolbar() { - var toolbar = id( "qunit-testrunner-toolbar" ); - - if ( toolbar ) { - toolbar.appendChild( toolbarUrlConfigContainer() ); - toolbar.appendChild( toolbarLooseFilter() ); - toolbarModuleFilter(); - } -} - -function appendHeader() { - var header = id( "qunit-header" ); - - if ( header ) { - header.innerHTML = "" + header.innerHTML + - " "; - } -} - -function appendBanner() { - var banner = id( "qunit-banner" ); - - if ( banner ) { - banner.className = ""; - } -} - -function appendTestResults() { - var tests = id( "qunit-tests" ), - result = id( "qunit-testresult" ); - - if ( result ) { - result.parentNode.removeChild( result ); - } - - if ( tests ) { - tests.innerHTML = ""; - result = document.createElement( "p" ); - result.id = "qunit-testresult"; - result.className = "result"; - tests.parentNode.insertBefore( result, tests ); - result.innerHTML = "Running...
 "; - } -} - -function storeFixture() { - var fixture = id( "qunit-fixture" ); - if ( fixture ) { - config.fixture = fixture.innerHTML; - } -} - -function appendFilteredTest() { - var testId = QUnit.config.testId; - if ( !testId || testId.length <= 0 ) { - return ""; - } - return "
Rerunning selected tests: " + - escapeText( testId.join( ", " ) ) + - " Run all tests
"; -} - -function appendUserAgent() { - var userAgent = id( "qunit-userAgent" ); - - if ( userAgent ) { - userAgent.innerHTML = ""; - userAgent.appendChild( - document.createTextNode( - "QUnit " + QUnit.version + "; " + navigator.userAgent - ) - ); - } -} - -function appendInterface() { - var qunit = id( "qunit" ); - - if ( qunit ) { - qunit.innerHTML = - "

" + escapeText( document.title ) + "

" + - "

" + - "
" + - appendFilteredTest() + - "

" + - "
    "; - } - - appendHeader(); - appendBanner(); - appendTestResults(); - appendUserAgent(); - appendToolbar(); -} - -function appendTestsList( modules ) { - var i, l, x, z, test, moduleObj; - - for ( i = 0, l = modules.length; i < l; i++ ) { - moduleObj = modules[ i ]; - - for ( x = 0, z = moduleObj.tests.length; x < z; x++ ) { - test = moduleObj.tests[ x ]; - - appendTest( test.name, test.testId, moduleObj.name ); - } - } -} - -function appendTest( name, testId, moduleName ) { - var title, rerunTrigger, testBlock, assertList, - tests = id( "qunit-tests" ); - - if ( !tests ) { - return; - } - - title = document.createElement( "strong" ); - title.innerHTML = getNameHtml( name, moduleName ); - - rerunTrigger = document.createElement( "a" ); - rerunTrigger.innerHTML = "Rerun"; - rerunTrigger.href = setUrl( { testId: testId } ); - - testBlock = document.createElement( "li" ); - testBlock.appendChild( title ); - testBlock.appendChild( rerunTrigger ); - testBlock.id = "qunit-test-output-" + testId; - - assertList = document.createElement( "ol" ); - assertList.className = "qunit-assert-list"; - - testBlock.appendChild( assertList ); - - tests.appendChild( testBlock ); -} - -// HTML Reporter initialization and load -QUnit.begin( function( details ) { - var i, moduleObj, tests; - - // Sort modules by name for the picker - for ( i = 0; i < details.modules.length; i++ ) { - moduleObj = details.modules[ i ]; - if ( moduleObj.name ) { - modulesList.push( moduleObj.name ); - } - } - modulesList.sort( function( a, b ) { - return a.localeCompare( b ); - } ); - - // Capture fixture HTML from the page - storeFixture(); - - // Initialize QUnit elements - appendInterface(); - appendTestsList( details.modules ); - tests = id( "qunit-tests" ); - if ( tests && config.hidepassed ) { - addClass( tests, "hidepass" ); - } -} ); - -QUnit.done( function( details ) { - var i, key, - banner = id( "qunit-banner" ), - tests = id( "qunit-tests" ), - html = [ - "Tests completed in ", - details.runtime, - " milliseconds.
    ", - "", - details.passed, - " assertions of ", - details.total, - " passed, ", - details.failed, - " failed." - ].join( "" ); - - if ( banner ) { - banner.className = details.failed ? "qunit-fail" : "qunit-pass"; - } - - if ( tests ) { - id( "qunit-testresult" ).innerHTML = html; - } - - if ( config.altertitle && document.title ) { - - // Show ✖ for good, ✔ for bad suite result in title - // use escape sequences in case file gets loaded with non-utf-8-charset - document.title = [ - ( details.failed ? "\u2716" : "\u2714" ), - document.title.replace( /^[\u2714\u2716] /i, "" ) - ].join( " " ); - } - - // Clear own sessionStorage items if all tests passed - if ( config.reorder && defined.sessionStorage && details.failed === 0 ) { - for ( i = 0; i < sessionStorage.length; i++ ) { - key = sessionStorage.key( i++ ); - if ( key.indexOf( "qunit-test-" ) === 0 ) { - sessionStorage.removeItem( key ); - } - } - } - - // Scroll back to top to show results - if ( config.scrolltop && window.scrollTo ) { - window.scrollTo( 0, 0 ); - } -} ); - -function getNameHtml( name, module ) { - var nameHtml = ""; - - if ( module ) { - nameHtml = "" + escapeText( module ) + ": "; - } - - nameHtml += "" + escapeText( name ) + ""; - - return nameHtml; -} - -QUnit.testStart( function( details ) { - var running, testBlock, bad; - - testBlock = id( "qunit-test-output-" + details.testId ); - if ( testBlock ) { - testBlock.className = "running"; - } else { - - // Report later registered tests - appendTest( details.name, details.testId, details.module ); - } - - running = id( "qunit-testresult" ); - if ( running ) { - bad = QUnit.config.reorder && defined.sessionStorage && - +sessionStorage.getItem( "qunit-test-" + details.module + "-" + details.name ); - - running.innerHTML = ( bad ? - "Rerunning previously failed test:
    " : - "Running:
    " ) + - getNameHtml( details.name, details.module ); - } - -} ); - -function stripHtml( string ) { - - // Strip tags, html entity and whitespaces - return string.replace( /<\/?[^>]+(>|$)/g, "" ).replace( /\"/g, "" ).replace( /\s+/g, "" ); -} - -QUnit.log( function( details ) { - var assertList, assertLi, - message, expected, actual, diff, - showDiff = false, - testItem = id( "qunit-test-output-" + details.testId ); - - if ( !testItem ) { - return; - } - - message = escapeText( details.message ) || ( details.result ? "okay" : "failed" ); - message = "" + message + ""; - message += "@ " + details.runtime + " ms"; - - // The pushFailure doesn't provide details.expected - // when it calls, it's implicit to also not show expected and diff stuff - // Also, we need to check details.expected existence, as it can exist and be undefined - if ( !details.result && hasOwn.call( details, "expected" ) ) { - if ( details.negative ) { - expected = "NOT " + QUnit.dump.parse( details.expected ); - } else { - expected = QUnit.dump.parse( details.expected ); - } - - actual = QUnit.dump.parse( details.actual ); - message += ""; - - if ( actual !== expected ) { - - message += ""; - - // Don't show diff if actual or expected are booleans - if ( !( /^(true|false)$/.test( actual ) ) && - !( /^(true|false)$/.test( expected ) ) ) { - diff = QUnit.diff( expected, actual ); - showDiff = stripHtml( diff ).length !== - stripHtml( expected ).length + - stripHtml( actual ).length; - } - - // Don't show diff if expected and actual are totally different - if ( showDiff ) { - message += ""; - } - } else if ( expected.indexOf( "[object Array]" ) !== -1 || - expected.indexOf( "[object Object]" ) !== -1 ) { - message += ""; - } else { - message += ""; - } - - if ( details.source ) { - message += ""; - } - - message += "
    Expected:
    " +
    -			escapeText( expected ) +
    -			"
    Result:
    " +
    -				escapeText( actual ) + "
    Diff:
    " +
    -					diff + "
    Message: " + - "Diff suppressed as the depth of object is more than current max depth (" + - QUnit.config.maxDepth + ").

    Hint: Use QUnit.dump.maxDepth to " + - " run with a higher max depth or " + - "Rerun without max depth.

    Message: " + - "Diff suppressed as the expected and actual results have an equivalent" + - " serialization
    Source:
    " +
    -				escapeText( details.source ) + "
    "; - - // This occurs when pushFailure is set and we have an extracted stack trace - } else if ( !details.result && details.source ) { - message += "" + - "" + - "
    Source:
    " +
    -			escapeText( details.source ) + "
    "; - } - - assertList = testItem.getElementsByTagName( "ol" )[ 0 ]; - - assertLi = document.createElement( "li" ); - assertLi.className = details.result ? "pass" : "fail"; - assertLi.innerHTML = message; - assertList.appendChild( assertLi ); -} ); - -QUnit.testDone( function( details ) { - var testTitle, time, testItem, assertList, - good, bad, testCounts, skipped, sourceName, - tests = id( "qunit-tests" ); - - if ( !tests ) { - return; - } - - testItem = id( "qunit-test-output-" + details.testId ); - - assertList = testItem.getElementsByTagName( "ol" )[ 0 ]; - - good = details.passed; - bad = details.failed; - - // Store result when possible - if ( config.reorder && defined.sessionStorage ) { - if ( bad ) { - sessionStorage.setItem( "qunit-test-" + details.module + "-" + details.name, bad ); - } else { - sessionStorage.removeItem( "qunit-test-" + details.module + "-" + details.name ); - } - } - - if ( bad === 0 ) { - - // Collapse the passing tests - addClass( assertList, "qunit-collapsed" ); - } else if ( bad && config.collapse && !collapseNext ) { - - // Skip collapsing the first failing test - collapseNext = true; - } else { - - // Collapse remaining tests - addClass( assertList, "qunit-collapsed" ); - } - - // The testItem.firstChild is the test name - testTitle = testItem.firstChild; - - testCounts = bad ? - "" + bad + ", " + "" + good + ", " : - ""; - - testTitle.innerHTML += " (" + testCounts + - details.assertions.length + ")"; - - if ( details.skipped ) { - testItem.className = "skipped"; - skipped = document.createElement( "em" ); - skipped.className = "qunit-skipped-label"; - skipped.innerHTML = "skipped"; - testItem.insertBefore( skipped, testTitle ); - } else { - addEvent( testTitle, "click", function() { - toggleClass( assertList, "qunit-collapsed" ); - } ); - - testItem.className = bad ? "fail" : "pass"; - - time = document.createElement( "span" ); - time.className = "runtime"; - time.innerHTML = details.runtime + " ms"; - testItem.insertBefore( time, assertList ); - } - - // Show the source of the test when showing assertions - if ( details.source ) { - sourceName = document.createElement( "p" ); - sourceName.innerHTML = "Source: " + details.source; - addClass( sourceName, "qunit-source" ); - if ( bad === 0 ) { - addClass( sourceName, "qunit-collapsed" ); - } - addEvent( testTitle, "click", function() { - toggleClass( sourceName, "qunit-collapsed" ); - } ); - testItem.appendChild( sourceName ); - } -} ); - -// Avoid readyState issue with phantomjs -// Ref: #818 -var notPhantom = ( function( p ) { - return !( p && p.version && p.version.major > 0 ); -} )( window.phantom ); - -if ( notPhantom && document.readyState === "complete" ) { - QUnit.load(); -} else { - addEvent( window, "load", QUnit.load ); -} - -/* - * This file is a modified version of google-diff-match-patch's JavaScript implementation - * (https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript/diff_match_patch_uncompressed.js), - * modifications are licensed as more fully set forth in LICENSE.txt. - * - * The original source of google-diff-match-patch is attributable and licensed as follows: - * - * Copyright 2006 Google Inc. - * https://code.google.com/p/google-diff-match-patch/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * More Info: - * https://code.google.com/p/google-diff-match-patch/ - * - * Usage: QUnit.diff(expected, actual) - * - */ -QUnit.diff = ( function() { - function DiffMatchPatch() { - } - - // DIFF FUNCTIONS - - /** - * The data structure representing a diff is an array of tuples: - * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] - * which means: delete 'Hello', add 'Goodbye' and keep ' world.' - */ - var DIFF_DELETE = -1, - DIFF_INSERT = 1, - DIFF_EQUAL = 0; - - /** - * Find the differences between two texts. Simplifies the problem by stripping - * any common prefix or suffix off the texts before diffing. - * @param {string} text1 Old string to be diffed. - * @param {string} text2 New string to be diffed. - * @param {boolean=} optChecklines Optional speedup flag. If present and false, - * then don't run a line-level diff first to identify the changed areas. - * Defaults to true, which does a faster, slightly less optimal diff. - * @return {!Array.} Array of diff tuples. - */ - DiffMatchPatch.prototype.DiffMain = function( text1, text2, optChecklines ) { - var deadline, checklines, commonlength, - commonprefix, commonsuffix, diffs; - - // The diff must be complete in up to 1 second. - deadline = ( new Date() ).getTime() + 1000; - - // Check for null inputs. - if ( text1 === null || text2 === null ) { - throw new Error( "Null input. (DiffMain)" ); - } - - // Check for equality (speedup). - if ( text1 === text2 ) { - if ( text1 ) { - return [ - [ DIFF_EQUAL, text1 ] - ]; - } - return []; - } - - if ( typeof optChecklines === "undefined" ) { - optChecklines = true; - } - - checklines = optChecklines; - - // Trim off common prefix (speedup). - commonlength = this.diffCommonPrefix( text1, text2 ); - commonprefix = text1.substring( 0, commonlength ); - text1 = text1.substring( commonlength ); - text2 = text2.substring( commonlength ); - - // Trim off common suffix (speedup). - commonlength = this.diffCommonSuffix( text1, text2 ); - commonsuffix = text1.substring( text1.length - commonlength ); - text1 = text1.substring( 0, text1.length - commonlength ); - text2 = text2.substring( 0, text2.length - commonlength ); - - // Compute the diff on the middle block. - diffs = this.diffCompute( text1, text2, checklines, deadline ); - - // Restore the prefix and suffix. - if ( commonprefix ) { - diffs.unshift( [ DIFF_EQUAL, commonprefix ] ); - } - if ( commonsuffix ) { - diffs.push( [ DIFF_EQUAL, commonsuffix ] ); - } - this.diffCleanupMerge( diffs ); - return diffs; - }; - - /** - * Reduce the number of edits by eliminating operationally trivial equalities. - * @param {!Array.} diffs Array of diff tuples. - */ - DiffMatchPatch.prototype.diffCleanupEfficiency = function( diffs ) { - var changes, equalities, equalitiesLength, lastequality, - pointer, preIns, preDel, postIns, postDel; - changes = false; - equalities = []; // Stack of indices where equalities are found. - equalitiesLength = 0; // Keeping our own length var is faster in JS. - /** @type {?string} */ - lastequality = null; - - // Always equal to diffs[equalities[equalitiesLength - 1]][1] - pointer = 0; // Index of current position. - - // Is there an insertion operation before the last equality. - preIns = false; - - // Is there a deletion operation before the last equality. - preDel = false; - - // Is there an insertion operation after the last equality. - postIns = false; - - // Is there a deletion operation after the last equality. - postDel = false; - while ( pointer < diffs.length ) { - - // Equality found. - if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { - if ( diffs[ pointer ][ 1 ].length < 4 && ( postIns || postDel ) ) { - - // Candidate found. - equalities[ equalitiesLength++ ] = pointer; - preIns = postIns; - preDel = postDel; - lastequality = diffs[ pointer ][ 1 ]; - } else { - - // Not a candidate, and can never become one. - equalitiesLength = 0; - lastequality = null; - } - postIns = postDel = false; - - // An insertion or deletion. - } else { - - if ( diffs[ pointer ][ 0 ] === DIFF_DELETE ) { - postDel = true; - } else { - postIns = true; - } - - /* - * Five types to be split: - * ABXYCD - * AXCD - * ABXC - * AXCD - * ABXC - */ - if ( lastequality && ( ( preIns && preDel && postIns && postDel ) || - ( ( lastequality.length < 2 ) && - ( preIns + preDel + postIns + postDel ) === 3 ) ) ) { - - // Duplicate record. - diffs.splice( - equalities[ equalitiesLength - 1 ], - 0, - [ DIFF_DELETE, lastequality ] - ); - - // Change second copy to insert. - diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT; - equalitiesLength--; // Throw away the equality we just deleted; - lastequality = null; - if ( preIns && preDel ) { - - // No changes made which could affect previous entry, keep going. - postIns = postDel = true; - equalitiesLength = 0; - } else { - equalitiesLength--; // Throw away the previous equality. - pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1; - postIns = postDel = false; - } - changes = true; - } - } - pointer++; - } - - if ( changes ) { - this.diffCleanupMerge( diffs ); - } - }; - - /** - * Convert a diff array into a pretty HTML report. - * @param {!Array.} diffs Array of diff tuples. - * @param {integer} string to be beautified. - * @return {string} HTML representation. - */ - DiffMatchPatch.prototype.diffPrettyHtml = function( diffs ) { - var op, data, x, - html = []; - for ( x = 0; x < diffs.length; x++ ) { - op = diffs[ x ][ 0 ]; // Operation (insert, delete, equal) - data = diffs[ x ][ 1 ]; // Text of change. - switch ( op ) { - case DIFF_INSERT: - html[ x ] = "" + escapeText( data ) + ""; - break; - case DIFF_DELETE: - html[ x ] = "" + escapeText( data ) + ""; - break; - case DIFF_EQUAL: - html[ x ] = "" + escapeText( data ) + ""; - break; - } - } - return html.join( "" ); - }; - - /** - * Determine the common prefix of two strings. - * @param {string} text1 First string. - * @param {string} text2 Second string. - * @return {number} The number of characters common to the start of each - * string. - */ - DiffMatchPatch.prototype.diffCommonPrefix = function( text1, text2 ) { - var pointermid, pointermax, pointermin, pointerstart; - - // Quick check for common null cases. - if ( !text1 || !text2 || text1.charAt( 0 ) !== text2.charAt( 0 ) ) { - return 0; - } - - // Binary search. - // Performance analysis: https://neil.fraser.name/news/2007/10/09/ - pointermin = 0; - pointermax = Math.min( text1.length, text2.length ); - pointermid = pointermax; - pointerstart = 0; - while ( pointermin < pointermid ) { - if ( text1.substring( pointerstart, pointermid ) === - text2.substring( pointerstart, pointermid ) ) { - pointermin = pointermid; - pointerstart = pointermin; - } else { - pointermax = pointermid; - } - pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); - } - return pointermid; - }; - - /** - * Determine the common suffix of two strings. - * @param {string} text1 First string. - * @param {string} text2 Second string. - * @return {number} The number of characters common to the end of each string. - */ - DiffMatchPatch.prototype.diffCommonSuffix = function( text1, text2 ) { - var pointermid, pointermax, pointermin, pointerend; - - // Quick check for common null cases. - if ( !text1 || - !text2 || - text1.charAt( text1.length - 1 ) !== text2.charAt( text2.length - 1 ) ) { - return 0; - } - - // Binary search. - // Performance analysis: https://neil.fraser.name/news/2007/10/09/ - pointermin = 0; - pointermax = Math.min( text1.length, text2.length ); - pointermid = pointermax; - pointerend = 0; - while ( pointermin < pointermid ) { - if ( text1.substring( text1.length - pointermid, text1.length - pointerend ) === - text2.substring( text2.length - pointermid, text2.length - pointerend ) ) { - pointermin = pointermid; - pointerend = pointermin; - } else { - pointermax = pointermid; - } - pointermid = Math.floor( ( pointermax - pointermin ) / 2 + pointermin ); - } - return pointermid; - }; - - /** - * Find the differences between two texts. Assumes that the texts do not - * have any common prefix or suffix. - * @param {string} text1 Old string to be diffed. - * @param {string} text2 New string to be diffed. - * @param {boolean} checklines Speedup flag. If false, then don't run a - * line-level diff first to identify the changed areas. - * If true, then run a faster, slightly less optimal diff. - * @param {number} deadline Time when the diff should be complete by. - * @return {!Array.} Array of diff tuples. - * @private - */ - DiffMatchPatch.prototype.diffCompute = function( text1, text2, checklines, deadline ) { - var diffs, longtext, shorttext, i, hm, - text1A, text2A, text1B, text2B, - midCommon, diffsA, diffsB; - - if ( !text1 ) { - - // Just add some text (speedup). - return [ - [ DIFF_INSERT, text2 ] - ]; - } - - if ( !text2 ) { - - // Just delete some text (speedup). - return [ - [ DIFF_DELETE, text1 ] - ]; - } - - longtext = text1.length > text2.length ? text1 : text2; - shorttext = text1.length > text2.length ? text2 : text1; - i = longtext.indexOf( shorttext ); - if ( i !== -1 ) { - - // Shorter text is inside the longer text (speedup). - diffs = [ - [ DIFF_INSERT, longtext.substring( 0, i ) ], - [ DIFF_EQUAL, shorttext ], - [ DIFF_INSERT, longtext.substring( i + shorttext.length ) ] - ]; - - // Swap insertions for deletions if diff is reversed. - if ( text1.length > text2.length ) { - diffs[ 0 ][ 0 ] = diffs[ 2 ][ 0 ] = DIFF_DELETE; - } - return diffs; - } - - if ( shorttext.length === 1 ) { - - // Single character string. - // After the previous speedup, the character can't be an equality. - return [ - [ DIFF_DELETE, text1 ], - [ DIFF_INSERT, text2 ] - ]; - } - - // Check to see if the problem can be split in two. - hm = this.diffHalfMatch( text1, text2 ); - if ( hm ) { - - // A half-match was found, sort out the return data. - text1A = hm[ 0 ]; - text1B = hm[ 1 ]; - text2A = hm[ 2 ]; - text2B = hm[ 3 ]; - midCommon = hm[ 4 ]; - - // Send both pairs off for separate processing. - diffsA = this.DiffMain( text1A, text2A, checklines, deadline ); - diffsB = this.DiffMain( text1B, text2B, checklines, deadline ); - - // Merge the results. - return diffsA.concat( [ - [ DIFF_EQUAL, midCommon ] - ], diffsB ); - } - - if ( checklines && text1.length > 100 && text2.length > 100 ) { - return this.diffLineMode( text1, text2, deadline ); - } - - return this.diffBisect( text1, text2, deadline ); - }; - - /** - * Do the two texts share a substring which is at least half the length of the - * longer text? - * This speedup can produce non-minimal diffs. - * @param {string} text1 First string. - * @param {string} text2 Second string. - * @return {Array.} Five element Array, containing the prefix of - * text1, the suffix of text1, the prefix of text2, the suffix of - * text2 and the common middle. Or null if there was no match. - * @private - */ - DiffMatchPatch.prototype.diffHalfMatch = function( text1, text2 ) { - var longtext, shorttext, dmp, - text1A, text2B, text2A, text1B, midCommon, - hm1, hm2, hm; - - longtext = text1.length > text2.length ? text1 : text2; - shorttext = text1.length > text2.length ? text2 : text1; - if ( longtext.length < 4 || shorttext.length * 2 < longtext.length ) { - return null; // Pointless. - } - dmp = this; // 'this' becomes 'window' in a closure. - - /** - * Does a substring of shorttext exist within longtext such that the substring - * is at least half the length of longtext? - * Closure, but does not reference any external variables. - * @param {string} longtext Longer string. - * @param {string} shorttext Shorter string. - * @param {number} i Start index of quarter length substring within longtext. - * @return {Array.} Five element Array, containing the prefix of - * longtext, the suffix of longtext, the prefix of shorttext, the suffix - * of shorttext and the common middle. Or null if there was no match. - * @private - */ - function diffHalfMatchI( longtext, shorttext, i ) { - var seed, j, bestCommon, prefixLength, suffixLength, - bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB; - - // Start with a 1/4 length substring at position i as a seed. - seed = longtext.substring( i, i + Math.floor( longtext.length / 4 ) ); - j = -1; - bestCommon = ""; - while ( ( j = shorttext.indexOf( seed, j + 1 ) ) !== -1 ) { - prefixLength = dmp.diffCommonPrefix( longtext.substring( i ), - shorttext.substring( j ) ); - suffixLength = dmp.diffCommonSuffix( longtext.substring( 0, i ), - shorttext.substring( 0, j ) ); - if ( bestCommon.length < suffixLength + prefixLength ) { - bestCommon = shorttext.substring( j - suffixLength, j ) + - shorttext.substring( j, j + prefixLength ); - bestLongtextA = longtext.substring( 0, i - suffixLength ); - bestLongtextB = longtext.substring( i + prefixLength ); - bestShorttextA = shorttext.substring( 0, j - suffixLength ); - bestShorttextB = shorttext.substring( j + prefixLength ); - } - } - if ( bestCommon.length * 2 >= longtext.length ) { - return [ bestLongtextA, bestLongtextB, - bestShorttextA, bestShorttextB, bestCommon - ]; - } else { - return null; - } - } - - // First check if the second quarter is the seed for a half-match. - hm1 = diffHalfMatchI( longtext, shorttext, - Math.ceil( longtext.length / 4 ) ); - - // Check again based on the third quarter. - hm2 = diffHalfMatchI( longtext, shorttext, - Math.ceil( longtext.length / 2 ) ); - if ( !hm1 && !hm2 ) { - return null; - } else if ( !hm2 ) { - hm = hm1; - } else if ( !hm1 ) { - hm = hm2; - } else { - - // Both matched. Select the longest. - hm = hm1[ 4 ].length > hm2[ 4 ].length ? hm1 : hm2; - } - - // A half-match was found, sort out the return data. - text1A, text1B, text2A, text2B; - if ( text1.length > text2.length ) { - text1A = hm[ 0 ]; - text1B = hm[ 1 ]; - text2A = hm[ 2 ]; - text2B = hm[ 3 ]; - } else { - text2A = hm[ 0 ]; - text2B = hm[ 1 ]; - text1A = hm[ 2 ]; - text1B = hm[ 3 ]; - } - midCommon = hm[ 4 ]; - return [ text1A, text1B, text2A, text2B, midCommon ]; - }; - - /** - * Do a quick line-level diff on both strings, then rediff the parts for - * greater accuracy. - * This speedup can produce non-minimal diffs. - * @param {string} text1 Old string to be diffed. - * @param {string} text2 New string to be diffed. - * @param {number} deadline Time when the diff should be complete by. - * @return {!Array.} Array of diff tuples. - * @private - */ - DiffMatchPatch.prototype.diffLineMode = function( text1, text2, deadline ) { - var a, diffs, linearray, pointer, countInsert, - countDelete, textInsert, textDelete, j; - - // Scan the text on a line-by-line basis first. - a = this.diffLinesToChars( text1, text2 ); - text1 = a.chars1; - text2 = a.chars2; - linearray = a.lineArray; - - diffs = this.DiffMain( text1, text2, false, deadline ); - - // Convert the diff back to original text. - this.diffCharsToLines( diffs, linearray ); - - // Eliminate freak matches (e.g. blank lines) - this.diffCleanupSemantic( diffs ); - - // Rediff any replacement blocks, this time character-by-character. - // Add a dummy entry at the end. - diffs.push( [ DIFF_EQUAL, "" ] ); - pointer = 0; - countDelete = 0; - countInsert = 0; - textDelete = ""; - textInsert = ""; - while ( pointer < diffs.length ) { - switch ( diffs[ pointer ][ 0 ] ) { - case DIFF_INSERT: - countInsert++; - textInsert += diffs[ pointer ][ 1 ]; - break; - case DIFF_DELETE: - countDelete++; - textDelete += diffs[ pointer ][ 1 ]; - break; - case DIFF_EQUAL: - - // Upon reaching an equality, check for prior redundancies. - if ( countDelete >= 1 && countInsert >= 1 ) { - - // Delete the offending records and add the merged ones. - diffs.splice( pointer - countDelete - countInsert, - countDelete + countInsert ); - pointer = pointer - countDelete - countInsert; - a = this.DiffMain( textDelete, textInsert, false, deadline ); - for ( j = a.length - 1; j >= 0; j-- ) { - diffs.splice( pointer, 0, a[ j ] ); - } - pointer = pointer + a.length; - } - countInsert = 0; - countDelete = 0; - textDelete = ""; - textInsert = ""; - break; - } - pointer++; - } - diffs.pop(); // Remove the dummy entry at the end. - - return diffs; - }; - - /** - * Find the 'middle snake' of a diff, split the problem in two - * and return the recursively constructed diff. - * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. - * @param {string} text1 Old string to be diffed. - * @param {string} text2 New string to be diffed. - * @param {number} deadline Time at which to bail if not yet complete. - * @return {!Array.} Array of diff tuples. - * @private - */ - DiffMatchPatch.prototype.diffBisect = function( text1, text2, deadline ) { - var text1Length, text2Length, maxD, vOffset, vLength, - v1, v2, x, delta, front, k1start, k1end, k2start, - k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2; - - // Cache the text lengths to prevent multiple calls. - text1Length = text1.length; - text2Length = text2.length; - maxD = Math.ceil( ( text1Length + text2Length ) / 2 ); - vOffset = maxD; - vLength = 2 * maxD; - v1 = new Array( vLength ); - v2 = new Array( vLength ); - - // Setting all elements to -1 is faster in Chrome & Firefox than mixing - // integers and undefined. - for ( x = 0; x < vLength; x++ ) { - v1[ x ] = -1; - v2[ x ] = -1; - } - v1[ vOffset + 1 ] = 0; - v2[ vOffset + 1 ] = 0; - delta = text1Length - text2Length; - - // If the total number of characters is odd, then the front path will collide - // with the reverse path. - front = ( delta % 2 !== 0 ); - - // Offsets for start and end of k loop. - // Prevents mapping of space beyond the grid. - k1start = 0; - k1end = 0; - k2start = 0; - k2end = 0; - for ( d = 0; d < maxD; d++ ) { - - // Bail out if deadline is reached. - if ( ( new Date() ).getTime() > deadline ) { - break; - } - - // Walk the front path one step. - for ( k1 = -d + k1start; k1 <= d - k1end; k1 += 2 ) { - k1Offset = vOffset + k1; - if ( k1 === -d || ( k1 !== d && v1[ k1Offset - 1 ] < v1[ k1Offset + 1 ] ) ) { - x1 = v1[ k1Offset + 1 ]; - } else { - x1 = v1[ k1Offset - 1 ] + 1; - } - y1 = x1 - k1; - while ( x1 < text1Length && y1 < text2Length && - text1.charAt( x1 ) === text2.charAt( y1 ) ) { - x1++; - y1++; - } - v1[ k1Offset ] = x1; - if ( x1 > text1Length ) { - - // Ran off the right of the graph. - k1end += 2; - } else if ( y1 > text2Length ) { - - // Ran off the bottom of the graph. - k1start += 2; - } else if ( front ) { - k2Offset = vOffset + delta - k1; - if ( k2Offset >= 0 && k2Offset < vLength && v2[ k2Offset ] !== -1 ) { - - // Mirror x2 onto top-left coordinate system. - x2 = text1Length - v2[ k2Offset ]; - if ( x1 >= x2 ) { - - // Overlap detected. - return this.diffBisectSplit( text1, text2, x1, y1, deadline ); - } - } - } - } - - // Walk the reverse path one step. - for ( k2 = -d + k2start; k2 <= d - k2end; k2 += 2 ) { - k2Offset = vOffset + k2; - if ( k2 === -d || ( k2 !== d && v2[ k2Offset - 1 ] < v2[ k2Offset + 1 ] ) ) { - x2 = v2[ k2Offset + 1 ]; - } else { - x2 = v2[ k2Offset - 1 ] + 1; - } - y2 = x2 - k2; - while ( x2 < text1Length && y2 < text2Length && - text1.charAt( text1Length - x2 - 1 ) === - text2.charAt( text2Length - y2 - 1 ) ) { - x2++; - y2++; - } - v2[ k2Offset ] = x2; - if ( x2 > text1Length ) { - - // Ran off the left of the graph. - k2end += 2; - } else if ( y2 > text2Length ) { - - // Ran off the top of the graph. - k2start += 2; - } else if ( !front ) { - k1Offset = vOffset + delta - k2; - if ( k1Offset >= 0 && k1Offset < vLength && v1[ k1Offset ] !== -1 ) { - x1 = v1[ k1Offset ]; - y1 = vOffset + x1 - k1Offset; - - // Mirror x2 onto top-left coordinate system. - x2 = text1Length - x2; - if ( x1 >= x2 ) { - - // Overlap detected. - return this.diffBisectSplit( text1, text2, x1, y1, deadline ); - } - } - } - } - } - - // Diff took too long and hit the deadline or - // number of diffs equals number of characters, no commonality at all. - return [ - [ DIFF_DELETE, text1 ], - [ DIFF_INSERT, text2 ] - ]; - }; - - /** - * Given the location of the 'middle snake', split the diff in two parts - * and recurse. - * @param {string} text1 Old string to be diffed. - * @param {string} text2 New string to be diffed. - * @param {number} x Index of split point in text1. - * @param {number} y Index of split point in text2. - * @param {number} deadline Time at which to bail if not yet complete. - * @return {!Array.} Array of diff tuples. - * @private - */ - DiffMatchPatch.prototype.diffBisectSplit = function( text1, text2, x, y, deadline ) { - var text1a, text1b, text2a, text2b, diffs, diffsb; - text1a = text1.substring( 0, x ); - text2a = text2.substring( 0, y ); - text1b = text1.substring( x ); - text2b = text2.substring( y ); - - // Compute both diffs serially. - diffs = this.DiffMain( text1a, text2a, false, deadline ); - diffsb = this.DiffMain( text1b, text2b, false, deadline ); - - return diffs.concat( diffsb ); - }; - - /** - * Reduce the number of edits by eliminating semantically trivial equalities. - * @param {!Array.} diffs Array of diff tuples. - */ - DiffMatchPatch.prototype.diffCleanupSemantic = function( diffs ) { - var changes, equalities, equalitiesLength, lastequality, - pointer, lengthInsertions2, lengthDeletions2, lengthInsertions1, - lengthDeletions1, deletion, insertion, overlapLength1, overlapLength2; - changes = false; - equalities = []; // Stack of indices where equalities are found. - equalitiesLength = 0; // Keeping our own length var is faster in JS. - /** @type {?string} */ - lastequality = null; - - // Always equal to diffs[equalities[equalitiesLength - 1]][1] - pointer = 0; // Index of current position. - - // Number of characters that changed prior to the equality. - lengthInsertions1 = 0; - lengthDeletions1 = 0; - - // Number of characters that changed after the equality. - lengthInsertions2 = 0; - lengthDeletions2 = 0; - while ( pointer < diffs.length ) { - if ( diffs[ pointer ][ 0 ] === DIFF_EQUAL ) { // Equality found. - equalities[ equalitiesLength++ ] = pointer; - lengthInsertions1 = lengthInsertions2; - lengthDeletions1 = lengthDeletions2; - lengthInsertions2 = 0; - lengthDeletions2 = 0; - lastequality = diffs[ pointer ][ 1 ]; - } else { // An insertion or deletion. - if ( diffs[ pointer ][ 0 ] === DIFF_INSERT ) { - lengthInsertions2 += diffs[ pointer ][ 1 ].length; - } else { - lengthDeletions2 += diffs[ pointer ][ 1 ].length; - } - - // Eliminate an equality that is smaller or equal to the edits on both - // sides of it. - if ( lastequality && ( lastequality.length <= - Math.max( lengthInsertions1, lengthDeletions1 ) ) && - ( lastequality.length <= Math.max( lengthInsertions2, - lengthDeletions2 ) ) ) { - - // Duplicate record. - diffs.splice( - equalities[ equalitiesLength - 1 ], - 0, - [ DIFF_DELETE, lastequality ] - ); - - // Change second copy to insert. - diffs[ equalities[ equalitiesLength - 1 ] + 1 ][ 0 ] = DIFF_INSERT; - - // Throw away the equality we just deleted. - equalitiesLength--; - - // Throw away the previous equality (it needs to be reevaluated). - equalitiesLength--; - pointer = equalitiesLength > 0 ? equalities[ equalitiesLength - 1 ] : -1; - - // Reset the counters. - lengthInsertions1 = 0; - lengthDeletions1 = 0; - lengthInsertions2 = 0; - lengthDeletions2 = 0; - lastequality = null; - changes = true; - } - } - pointer++; - } - - // Normalize the diff. - if ( changes ) { - this.diffCleanupMerge( diffs ); - } - - // Find any overlaps between deletions and insertions. - // e.g: abcxxxxxxdef - // -> abcxxxdef - // e.g: xxxabcdefxxx - // -> defxxxabc - // Only extract an overlap if it is as big as the edit ahead or behind it. - pointer = 1; - while ( pointer < diffs.length ) { - if ( diffs[ pointer - 1 ][ 0 ] === DIFF_DELETE && - diffs[ pointer ][ 0 ] === DIFF_INSERT ) { - deletion = diffs[ pointer - 1 ][ 1 ]; - insertion = diffs[ pointer ][ 1 ]; - overlapLength1 = this.diffCommonOverlap( deletion, insertion ); - overlapLength2 = this.diffCommonOverlap( insertion, deletion ); - if ( overlapLength1 >= overlapLength2 ) { - if ( overlapLength1 >= deletion.length / 2 || - overlapLength1 >= insertion.length / 2 ) { - - // Overlap found. Insert an equality and trim the surrounding edits. - diffs.splice( - pointer, - 0, - [ DIFF_EQUAL, insertion.substring( 0, overlapLength1 ) ] - ); - diffs[ pointer - 1 ][ 1 ] = - deletion.substring( 0, deletion.length - overlapLength1 ); - diffs[ pointer + 1 ][ 1 ] = insertion.substring( overlapLength1 ); - pointer++; - } - } else { - if ( overlapLength2 >= deletion.length / 2 || - overlapLength2 >= insertion.length / 2 ) { - - // Reverse overlap found. - // Insert an equality and swap and trim the surrounding edits. - diffs.splice( - pointer, - 0, - [ DIFF_EQUAL, deletion.substring( 0, overlapLength2 ) ] - ); - - diffs[ pointer - 1 ][ 0 ] = DIFF_INSERT; - diffs[ pointer - 1 ][ 1 ] = - insertion.substring( 0, insertion.length - overlapLength2 ); - diffs[ pointer + 1 ][ 0 ] = DIFF_DELETE; - diffs[ pointer + 1 ][ 1 ] = - deletion.substring( overlapLength2 ); - pointer++; - } - } - pointer++; - } - pointer++; - } - }; - - /** - * Determine if the suffix of one string is the prefix of another. - * @param {string} text1 First string. - * @param {string} text2 Second string. - * @return {number} The number of characters common to the end of the first - * string and the start of the second string. - * @private - */ - DiffMatchPatch.prototype.diffCommonOverlap = function( text1, text2 ) { - var text1Length, text2Length, textLength, - best, length, pattern, found; - - // Cache the text lengths to prevent multiple calls. - text1Length = text1.length; - text2Length = text2.length; - - // Eliminate the null case. - if ( text1Length === 0 || text2Length === 0 ) { - return 0; - } - - // Truncate the longer string. - if ( text1Length > text2Length ) { - text1 = text1.substring( text1Length - text2Length ); - } else if ( text1Length < text2Length ) { - text2 = text2.substring( 0, text1Length ); - } - textLength = Math.min( text1Length, text2Length ); - - // Quick check for the worst case. - if ( text1 === text2 ) { - return textLength; - } - - // Start by looking for a single character match - // and increase length until no match is found. - // Performance analysis: https://neil.fraser.name/news/2010/11/04/ - best = 0; - length = 1; - while ( true ) { - pattern = text1.substring( textLength - length ); - found = text2.indexOf( pattern ); - if ( found === -1 ) { - return best; - } - length += found; - if ( found === 0 || text1.substring( textLength - length ) === - text2.substring( 0, length ) ) { - best = length; - length++; - } - } - }; - - /** - * Split two texts into an array of strings. Reduce the texts to a string of - * hashes where each Unicode character represents one line. - * @param {string} text1 First string. - * @param {string} text2 Second string. - * @return {{chars1: string, chars2: string, lineArray: !Array.}} - * An object containing the encoded text1, the encoded text2 and - * the array of unique strings. - * The zeroth element of the array of unique strings is intentionally blank. - * @private - */ - DiffMatchPatch.prototype.diffLinesToChars = function( text1, text2 ) { - var lineArray, lineHash, chars1, chars2; - lineArray = []; // E.g. lineArray[4] === 'Hello\n' - lineHash = {}; // E.g. lineHash['Hello\n'] === 4 - - // '\x00' is a valid character, but various debuggers don't like it. - // So we'll insert a junk entry to avoid generating a null character. - lineArray[ 0 ] = ""; - - /** - * Split a text into an array of strings. Reduce the texts to a string of - * hashes where each Unicode character represents one line. - * Modifies linearray and linehash through being a closure. - * @param {string} text String to encode. - * @return {string} Encoded string. - * @private - */ - function diffLinesToCharsMunge( text ) { - var chars, lineStart, lineEnd, lineArrayLength, line; - chars = ""; - - // Walk the text, pulling out a substring for each line. - // text.split('\n') would would temporarily double our memory footprint. - // Modifying text would create many large strings to garbage collect. - lineStart = 0; - lineEnd = -1; - - // Keeping our own length variable is faster than looking it up. - lineArrayLength = lineArray.length; - while ( lineEnd < text.length - 1 ) { - lineEnd = text.indexOf( "\n", lineStart ); - if ( lineEnd === -1 ) { - lineEnd = text.length - 1; - } - line = text.substring( lineStart, lineEnd + 1 ); - lineStart = lineEnd + 1; - - if ( lineHash.hasOwnProperty ? lineHash.hasOwnProperty( line ) : - ( lineHash[ line ] !== undefined ) ) { - chars += String.fromCharCode( lineHash[ line ] ); - } else { - chars += String.fromCharCode( lineArrayLength ); - lineHash[ line ] = lineArrayLength; - lineArray[ lineArrayLength++ ] = line; - } - } - return chars; - } - - chars1 = diffLinesToCharsMunge( text1 ); - chars2 = diffLinesToCharsMunge( text2 ); - return { - chars1: chars1, - chars2: chars2, - lineArray: lineArray - }; - }; - - /** - * Rehydrate the text in a diff from a string of line hashes to real lines of - * text. - * @param {!Array.} diffs Array of diff tuples. - * @param {!Array.} lineArray Array of unique strings. - * @private - */ - DiffMatchPatch.prototype.diffCharsToLines = function( diffs, lineArray ) { - var x, chars, text, y; - for ( x = 0; x < diffs.length; x++ ) { - chars = diffs[ x ][ 1 ]; - text = []; - for ( y = 0; y < chars.length; y++ ) { - text[ y ] = lineArray[ chars.charCodeAt( y ) ]; - } - diffs[ x ][ 1 ] = text.join( "" ); - } - }; - - /** - * Reorder and merge like edit sections. Merge equalities. - * Any edit section can move as long as it doesn't cross an equality. - * @param {!Array.} diffs Array of diff tuples. - */ - DiffMatchPatch.prototype.diffCleanupMerge = function( diffs ) { - var pointer, countDelete, countInsert, textInsert, textDelete, - commonlength, changes, diffPointer, position; - diffs.push( [ DIFF_EQUAL, "" ] ); // Add a dummy entry at the end. - pointer = 0; - countDelete = 0; - countInsert = 0; - textDelete = ""; - textInsert = ""; - commonlength; - while ( pointer < diffs.length ) { - switch ( diffs[ pointer ][ 0 ] ) { - case DIFF_INSERT: - countInsert++; - textInsert += diffs[ pointer ][ 1 ]; - pointer++; - break; - case DIFF_DELETE: - countDelete++; - textDelete += diffs[ pointer ][ 1 ]; - pointer++; - break; - case DIFF_EQUAL: - - // Upon reaching an equality, check for prior redundancies. - if ( countDelete + countInsert > 1 ) { - if ( countDelete !== 0 && countInsert !== 0 ) { - - // Factor out any common prefixes. - commonlength = this.diffCommonPrefix( textInsert, textDelete ); - if ( commonlength !== 0 ) { - if ( ( pointer - countDelete - countInsert ) > 0 && - diffs[ pointer - countDelete - countInsert - 1 ][ 0 ] === - DIFF_EQUAL ) { - diffs[ pointer - countDelete - countInsert - 1 ][ 1 ] += - textInsert.substring( 0, commonlength ); - } else { - diffs.splice( 0, 0, [ DIFF_EQUAL, - textInsert.substring( 0, commonlength ) - ] ); - pointer++; - } - textInsert = textInsert.substring( commonlength ); - textDelete = textDelete.substring( commonlength ); - } - - // Factor out any common suffixies. - commonlength = this.diffCommonSuffix( textInsert, textDelete ); - if ( commonlength !== 0 ) { - diffs[ pointer ][ 1 ] = textInsert.substring( textInsert.length - - commonlength ) + diffs[ pointer ][ 1 ]; - textInsert = textInsert.substring( 0, textInsert.length - - commonlength ); - textDelete = textDelete.substring( 0, textDelete.length - - commonlength ); - } - } - - // Delete the offending records and add the merged ones. - if ( countDelete === 0 ) { - diffs.splice( pointer - countInsert, - countDelete + countInsert, [ DIFF_INSERT, textInsert ] ); - } else if ( countInsert === 0 ) { - diffs.splice( pointer - countDelete, - countDelete + countInsert, [ DIFF_DELETE, textDelete ] ); - } else { - diffs.splice( - pointer - countDelete - countInsert, - countDelete + countInsert, - [ DIFF_DELETE, textDelete ], [ DIFF_INSERT, textInsert ] - ); - } - pointer = pointer - countDelete - countInsert + - ( countDelete ? 1 : 0 ) + ( countInsert ? 1 : 0 ) + 1; - } else if ( pointer !== 0 && diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL ) { - - // Merge this equality with the previous one. - diffs[ pointer - 1 ][ 1 ] += diffs[ pointer ][ 1 ]; - diffs.splice( pointer, 1 ); - } else { - pointer++; - } - countInsert = 0; - countDelete = 0; - textDelete = ""; - textInsert = ""; - break; - } - } - if ( diffs[ diffs.length - 1 ][ 1 ] === "" ) { - diffs.pop(); // Remove the dummy entry at the end. - } - - // Second pass: look for single edits surrounded on both sides by equalities - // which can be shifted sideways to eliminate an equality. - // e.g: ABAC -> ABAC - changes = false; - pointer = 1; - - // Intentionally ignore the first and last element (don't need checking). - while ( pointer < diffs.length - 1 ) { - if ( diffs[ pointer - 1 ][ 0 ] === DIFF_EQUAL && - diffs[ pointer + 1 ][ 0 ] === DIFF_EQUAL ) { - - diffPointer = diffs[ pointer ][ 1 ]; - position = diffPointer.substring( - diffPointer.length - diffs[ pointer - 1 ][ 1 ].length - ); - - // This is a single edit surrounded by equalities. - if ( position === diffs[ pointer - 1 ][ 1 ] ) { - - // Shift the edit over the previous equality. - diffs[ pointer ][ 1 ] = diffs[ pointer - 1 ][ 1 ] + - diffs[ pointer ][ 1 ].substring( 0, diffs[ pointer ][ 1 ].length - - diffs[ pointer - 1 ][ 1 ].length ); - diffs[ pointer + 1 ][ 1 ] = - diffs[ pointer - 1 ][ 1 ] + diffs[ pointer + 1 ][ 1 ]; - diffs.splice( pointer - 1, 1 ); - changes = true; - } else if ( diffPointer.substring( 0, diffs[ pointer + 1 ][ 1 ].length ) === - diffs[ pointer + 1 ][ 1 ] ) { - - // Shift the edit over the next equality. - diffs[ pointer - 1 ][ 1 ] += diffs[ pointer + 1 ][ 1 ]; - diffs[ pointer ][ 1 ] = - diffs[ pointer ][ 1 ].substring( diffs[ pointer + 1 ][ 1 ].length ) + - diffs[ pointer + 1 ][ 1 ]; - diffs.splice( pointer + 1, 1 ); - changes = true; - } - } - pointer++; - } - - // If shifts were made, the diff needs reordering and another shift sweep. - if ( changes ) { - this.diffCleanupMerge( diffs ); - } - }; - - return function( o, n ) { - var diff, output, text; - diff = new DiffMatchPatch(); - output = diff.DiffMain( o, n ); - diff.diffCleanupEfficiency( output ); - text = diff.diffPrettyHtml( output ); - - return text; - }; -}() ); - -}() ); + global$1 = 'default' in global$1 ? global$1['default'] : global$1; + + var window = global$1.window; + var self$1 = global$1.self; + var console = global$1.console; + var setTimeout = global$1.setTimeout; + var clearTimeout = global$1.clearTimeout; + + var document = window && window.document; + var navigator = window && window.navigator; + + var localSessionStorage = function () { + var x = "qunit-test-string"; + try { + global$1.sessionStorage.setItem(x, x); + global$1.sessionStorage.removeItem(x); + return global$1.sessionStorage; + } catch (e) { + return undefined; + } + }(); + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + + + + + + + + + + + var classCallCheck = function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + }; + + var createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + var toConsumableArray = function (arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + + return arr2; + } else { + return Array.from(arr); + } + }; + + var toString = Object.prototype.toString; + var hasOwn = Object.prototype.hasOwnProperty; + var now = Date.now || function () { + return new Date().getTime(); + }; + + var defined = { + document: window && window.document !== undefined, + setTimeout: setTimeout !== undefined + }; + + // Returns a new Array with the elements that are in a but not in b + function diff(a, b) { + var i, + j, + result = a.slice(); + + for (i = 0; i < result.length; i++) { + for (j = 0; j < b.length; j++) { + if (result[i] === b[j]) { + result.splice(i, 1); + i--; + break; + } + } + } + return result; + } + + /** + * Determines whether an element exists in a given array or not. + * + * @method inArray + * @param {Any} elem + * @param {Array} array + * @return {Boolean} + */ + function inArray(elem, array) { + return array.indexOf(elem) !== -1; + } + + /** + * Makes a clone of an object using only Array or Object as base, + * and copies over the own enumerable properties. + * + * @param {Object} obj + * @return {Object} New object with only the own properties (recursively). + */ + function objectValues(obj) { + var key, + val, + vals = is("array", obj) ? [] : {}; + for (key in obj) { + if (hasOwn.call(obj, key)) { + val = obj[key]; + vals[key] = val === Object(val) ? objectValues(val) : val; + } + } + return vals; + } + + function extend(a, b, undefOnly) { + for (var prop in b) { + if (hasOwn.call(b, prop)) { + if (b[prop] === undefined) { + delete a[prop]; + } else if (!(undefOnly && typeof a[prop] !== "undefined")) { + a[prop] = b[prop]; + } + } + } + + return a; + } + + function objectType(obj) { + if (typeof obj === "undefined") { + return "undefined"; + } + + // Consider: typeof null === object + if (obj === null) { + return "null"; + } + + var match = toString.call(obj).match(/^\[object\s(.*)\]$/), + type = match && match[1]; + + switch (type) { + case "Number": + if (isNaN(obj)) { + return "nan"; + } + return "number"; + case "String": + case "Boolean": + case "Array": + case "Set": + case "Map": + case "Date": + case "RegExp": + case "Function": + case "Symbol": + return type.toLowerCase(); + } + + if ((typeof obj === "undefined" ? "undefined" : _typeof(obj)) === "object") { + return "object"; + } + } + + // Safe object type checking + function is(type, obj) { + return objectType(obj) === type; + } + + // Based on Java's String.hashCode, a simple but not + // rigorously collision resistant hashing function + function generateHash(module, testName) { + var str = module + "\x1C" + testName; + var hash = 0; + + for (var i = 0; i < str.length; i++) { + hash = (hash << 5) - hash + str.charCodeAt(i); + hash |= 0; + } + + // Convert the possibly negative integer hash code into an 8 character hex string, which isn't + // strictly necessary but increases user understanding that the id is a SHA-like hash + var hex = (0x100000000 + hash).toString(16); + if (hex.length < 8) { + hex = "0000000" + hex; + } + + return hex.slice(-8); + } + + // Test for equality any JavaScript type. + // Authors: Philippe Rathé , David Chan + var equiv = (function () { + + // Value pairs queued for comparison. Used for breadth-first processing order, recursion + // detection and avoiding repeated comparison (see below for details). + // Elements are { a: val, b: val }. + var pairs = []; + + var getProto = Object.getPrototypeOf || function (obj) { + return obj.__proto__; + }; + + function useStrictEquality(a, b) { + + // This only gets called if a and b are not strict equal, and is used to compare on + // the primitive values inside object wrappers. For example: + // `var i = 1;` + // `var j = new Number(1);` + // Neither a nor b can be null, as a !== b and they have the same type. + if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === "object") { + a = a.valueOf(); + } + if ((typeof b === "undefined" ? "undefined" : _typeof(b)) === "object") { + b = b.valueOf(); + } + + return a === b; + } + + function compareConstructors(a, b) { + var protoA = getProto(a); + var protoB = getProto(b); + + // Comparing constructors is more strict than using `instanceof` + if (a.constructor === b.constructor) { + return true; + } + + // Ref #851 + // If the obj prototype descends from a null constructor, treat it + // as a null prototype. + if (protoA && protoA.constructor === null) { + protoA = null; + } + if (protoB && protoB.constructor === null) { + protoB = null; + } + + // Allow objects with no prototype to be equivalent to + // objects with Object as their constructor. + if (protoA === null && protoB === Object.prototype || protoB === null && protoA === Object.prototype) { + return true; + } + + return false; + } + + function getRegExpFlags(regexp) { + return "flags" in regexp ? regexp.flags : regexp.toString().match(/[gimuy]*$/)[0]; + } + + function isContainer(val) { + return ["object", "array", "map", "set"].indexOf(objectType(val)) !== -1; + } + + function breadthFirstCompareChild(a, b) { + + // If a is a container not reference-equal to b, postpone the comparison to the + // end of the pairs queue -- unless (a, b) has been seen before, in which case skip + // over the pair. + if (a === b) { + return true; + } + if (!isContainer(a)) { + return typeEquiv(a, b); + } + if (pairs.every(function (pair) { + return pair.a !== a || pair.b !== b; + })) { + + // Not yet started comparing this pair + pairs.push({ a: a, b: b }); + } + return true; + } + + var callbacks = { + "string": useStrictEquality, + "boolean": useStrictEquality, + "number": useStrictEquality, + "null": useStrictEquality, + "undefined": useStrictEquality, + "symbol": useStrictEquality, + "date": useStrictEquality, + + "nan": function nan() { + return true; + }, + + "regexp": function regexp(a, b) { + return a.source === b.source && + + // Include flags in the comparison + getRegExpFlags(a) === getRegExpFlags(b); + }, + + // abort (identical references / instance methods were skipped earlier) + "function": function _function() { + return false; + }, + + "array": function array(a, b) { + var i, len; + + len = a.length; + if (len !== b.length) { + + // Safe and faster + return false; + } + + for (i = 0; i < len; i++) { + + // Compare non-containers; queue non-reference-equal containers + if (!breadthFirstCompareChild(a[i], b[i])) { + return false; + } + } + return true; + }, + + // Define sets a and b to be equivalent if for each element aVal in a, there + // is some element bVal in b such that aVal and bVal are equivalent. Element + // repetitions are not counted, so these are equivalent: + // a = new Set( [ {}, [], [] ] ); + // b = new Set( [ {}, {}, [] ] ); + "set": function set$$1(a, b) { + var innerEq, + outerEq = true; + + if (a.size !== b.size) { + + // This optimization has certain quirks because of the lack of + // repetition counting. For instance, adding the same + // (reference-identical) element to two equivalent sets can + // make them non-equivalent. + return false; + } + + a.forEach(function (aVal) { + + // Short-circuit if the result is already known. (Using for...of + // with a break clause would be cleaner here, but it would cause + // a syntax error on older Javascript implementations even if + // Set is unused) + if (!outerEq) { + return; + } + + innerEq = false; + + b.forEach(function (bVal) { + var parentPairs; + + // Likewise, short-circuit if the result is already known + if (innerEq) { + return; + } + + // Swap out the global pairs list, as the nested call to + // innerEquiv will clobber its contents + parentPairs = pairs; + if (innerEquiv(bVal, aVal)) { + innerEq = true; + } + + // Replace the global pairs list + pairs = parentPairs; + }); + + if (!innerEq) { + outerEq = false; + } + }); + + return outerEq; + }, + + // Define maps a and b to be equivalent if for each key-value pair (aKey, aVal) + // in a, there is some key-value pair (bKey, bVal) in b such that + // [ aKey, aVal ] and [ bKey, bVal ] are equivalent. Key repetitions are not + // counted, so these are equivalent: + // a = new Map( [ [ {}, 1 ], [ {}, 1 ], [ [], 1 ] ] ); + // b = new Map( [ [ {}, 1 ], [ [], 1 ], [ [], 1 ] ] ); + "map": function map(a, b) { + var innerEq, + outerEq = true; + + if (a.size !== b.size) { + + // This optimization has certain quirks because of the lack of + // repetition counting. For instance, adding the same + // (reference-identical) key-value pair to two equivalent maps + // can make them non-equivalent. + return false; + } + + a.forEach(function (aVal, aKey) { + + // Short-circuit if the result is already known. (Using for...of + // with a break clause would be cleaner here, but it would cause + // a syntax error on older Javascript implementations even if + // Map is unused) + if (!outerEq) { + return; + } + + innerEq = false; + + b.forEach(function (bVal, bKey) { + var parentPairs; + + // Likewise, short-circuit if the result is already known + if (innerEq) { + return; + } + + // Swap out the global pairs list, as the nested call to + // innerEquiv will clobber its contents + parentPairs = pairs; + if (innerEquiv([bVal, bKey], [aVal, aKey])) { + innerEq = true; + } + + // Replace the global pairs list + pairs = parentPairs; + }); + + if (!innerEq) { + outerEq = false; + } + }); + + return outerEq; + }, + + "object": function object(a, b) { + var i, + aProperties = [], + bProperties = []; + + if (compareConstructors(a, b) === false) { + return false; + } + + // Be strict: don't ensure hasOwnProperty and go deep + for (i in a) { + + // Collect a's properties + aProperties.push(i); + + // Skip OOP methods that look the same + if (a.constructor !== Object && typeof a.constructor !== "undefined" && typeof a[i] === "function" && typeof b[i] === "function" && a[i].toString() === b[i].toString()) { + continue; + } + + // Compare non-containers; queue non-reference-equal containers + if (!breadthFirstCompareChild(a[i], b[i])) { + return false; + } + } + + for (i in b) { + + // Collect b's properties + bProperties.push(i); + } + + // Ensures identical properties name + return typeEquiv(aProperties.sort(), bProperties.sort()); + } + }; + + function typeEquiv(a, b) { + var type = objectType(a); + + // Callbacks for containers will append to the pairs queue to achieve breadth-first + // search order. The pairs queue is also used to avoid reprocessing any pair of + // containers that are reference-equal to a previously visited pair (a special case + // this being recursion detection). + // + // Because of this approach, once typeEquiv returns a false value, it should not be + // called again without clearing the pair queue else it may wrongly report a visited + // pair as being equivalent. + return objectType(b) === type && callbacks[type](a, b); + } + + function innerEquiv(a, b) { + var i, pair; + + // We're done when there's nothing more to compare + if (arguments.length < 2) { + return true; + } + + // Clear the global pair queue and add the top-level values being compared + pairs = [{ a: a, b: b }]; + + for (i = 0; i < pairs.length; i++) { + pair = pairs[i]; + + // Perform type-specific comparison on any pairs that are not strictly + // equal. For container types, that comparison will postpone comparison + // of any sub-container pair to the end of the pair queue. This gives + // breadth-first search order. It also avoids the reprocessing of + // reference-equal siblings, cousins etc, which can have a significant speed + // impact when comparing a container of small objects each of which has a + // reference to the same (singleton) large object. + if (pair.a !== pair.b && !typeEquiv(pair.a, pair.b)) { + return false; + } + } + + // ...across all consecutive argument pairs + return arguments.length === 2 || innerEquiv.apply(this, [].slice.call(arguments, 1)); + } + + return innerEquiv; + })(); + + /** + * Config object: Maintain internal state + * Later exposed as QUnit.config + * `config` initialized at top of scope + */ + var config = { + + // The queue of tests to run + queue: [], + + // Block until document ready + blocking: true, + + // By default, run previously failed tests first + // very useful in combination with "Hide passed tests" checked + reorder: true, + + // By default, modify document.title when suite is done + altertitle: true, + + // HTML Reporter: collapse every test except the first failing test + // If false, all failing tests will be expanded + collapse: true, + + // By default, scroll to top of the page when suite is done + scrolltop: true, + + // Depth up-to which object will be dumped + maxDepth: 5, + + // When enabled, all tests must call expect() + requireExpects: false, + + // Placeholder for user-configurable form-exposed URL parameters + urlConfig: [], + + // Set of all modules. + modules: [], + + // The first unnamed module + currentModule: { + name: "", + tests: [], + childModules: [], + testsRun: 0, + unskippedTestsRun: 0 + }, + + callbacks: {}, + + // The storage module to use for reordering tests + storage: localSessionStorage + }; + + // take a predefined QUnit.config and extend the defaults + var globalConfig = window && window.QUnit && window.QUnit.config; + + // only extend the global config if there is no QUnit overload + if (window && window.QUnit && !window.QUnit.version) { + extend(config, globalConfig); + } + + // Push a loose unnamed module to the modules collection + config.modules.push(config.currentModule); + + // Based on jsDump by Ariel Flesler + // http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html + var dump = (function () { + function quote(str) { + return "\"" + str.toString().replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\""; + } + function literal(o) { + return o + ""; + } + function join(pre, arr, post) { + var s = dump.separator(), + base = dump.indent(), + inner = dump.indent(1); + if (arr.join) { + arr = arr.join("," + s + inner); + } + if (!arr) { + return pre + post; + } + return [pre, inner + arr, base + post].join(s); + } + function array(arr, stack) { + var i = arr.length, + ret = new Array(i); + + if (dump.maxDepth && dump.depth > dump.maxDepth) { + return "[object Array]"; + } + + this.up(); + while (i--) { + ret[i] = this.parse(arr[i], undefined, stack); + } + this.down(); + return join("[", ret, "]"); + } + + function isArray(obj) { + return ( + + //Native Arrays + toString.call(obj) === "[object Array]" || + + // NodeList objects + typeof obj.length === "number" && obj.item !== undefined && (obj.length ? obj.item(0) === obj[0] : obj.item(0) === null && obj[0] === undefined) + ); + } + + var reName = /^function (\w+)/, + dump = { + + // The objType is used mostly internally, you can fix a (custom) type in advance + parse: function parse(obj, objType, stack) { + stack = stack || []; + var res, + parser, + parserType, + objIndex = stack.indexOf(obj); + + if (objIndex !== -1) { + return "recursion(" + (objIndex - stack.length) + ")"; + } + + objType = objType || this.typeOf(obj); + parser = this.parsers[objType]; + parserType = typeof parser === "undefined" ? "undefined" : _typeof(parser); + + if (parserType === "function") { + stack.push(obj); + res = parser.call(this, obj, stack); + stack.pop(); + return res; + } + return parserType === "string" ? parser : this.parsers.error; + }, + typeOf: function typeOf(obj) { + var type; + + if (obj === null) { + type = "null"; + } else if (typeof obj === "undefined") { + type = "undefined"; + } else if (is("regexp", obj)) { + type = "regexp"; + } else if (is("date", obj)) { + type = "date"; + } else if (is("function", obj)) { + type = "function"; + } else if (obj.setInterval !== undefined && obj.document !== undefined && obj.nodeType === undefined) { + type = "window"; + } else if (obj.nodeType === 9) { + type = "document"; + } else if (obj.nodeType) { + type = "node"; + } else if (isArray(obj)) { + type = "array"; + } else if (obj.constructor === Error.prototype.constructor) { + type = "error"; + } else { + type = typeof obj === "undefined" ? "undefined" : _typeof(obj); + } + return type; + }, + + separator: function separator() { + if (this.multiline) { + return this.HTML ? "
    " : "\n"; + } else { + return this.HTML ? " " : " "; + } + }, + + // Extra can be a number, shortcut for increasing-calling-decreasing + indent: function indent(extra) { + if (!this.multiline) { + return ""; + } + var chr = this.indentChar; + if (this.HTML) { + chr = chr.replace(/\t/g, " ").replace(/ /g, " "); + } + return new Array(this.depth + (extra || 0)).join(chr); + }, + up: function up(a) { + this.depth += a || 1; + }, + down: function down(a) { + this.depth -= a || 1; + }, + setParser: function setParser(name, parser) { + this.parsers[name] = parser; + }, + + // The next 3 are exposed so you can use them + quote: quote, + literal: literal, + join: join, + depth: 1, + maxDepth: config.maxDepth, + + // This is the list of parsers, to modify them, use dump.setParser + parsers: { + window: "[Window]", + document: "[Document]", + error: function error(_error) { + return "Error(\"" + _error.message + "\")"; + }, + unknown: "[Unknown]", + "null": "null", + "undefined": "undefined", + "function": function _function(fn) { + var ret = "function", + + + // Functions never have name in IE + name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1]; + + if (name) { + ret += " " + name; + } + ret += "("; + + ret = [ret, dump.parse(fn, "functionArgs"), "){"].join(""); + return join(ret, dump.parse(fn, "functionCode"), "}"); + }, + array: array, + nodelist: array, + "arguments": array, + object: function object(map, stack) { + var keys, + key, + val, + i, + nonEnumerableProperties, + ret = []; + + if (dump.maxDepth && dump.depth > dump.maxDepth) { + return "[object Object]"; + } + + dump.up(); + keys = []; + for (key in map) { + keys.push(key); + } + + // Some properties are not always enumerable on Error objects. + nonEnumerableProperties = ["message", "name"]; + for (i in nonEnumerableProperties) { + key = nonEnumerableProperties[i]; + if (key in map && !inArray(key, keys)) { + keys.push(key); + } + } + keys.sort(); + for (i = 0; i < keys.length; i++) { + key = keys[i]; + val = map[key]; + ret.push(dump.parse(key, "key") + ": " + dump.parse(val, undefined, stack)); + } + dump.down(); + return join("{", ret, "}"); + }, + node: function node(_node) { + var len, + i, + val, + open = dump.HTML ? "<" : "<", + close = dump.HTML ? ">" : ">", + tag = _node.nodeName.toLowerCase(), + ret = open + tag, + attrs = _node.attributes; + + if (attrs) { + for (i = 0, len = attrs.length; i < len; i++) { + val = attrs[i].nodeValue; + + // IE6 includes all attributes in .attributes, even ones not explicitly + // set. Those have values like undefined, null, 0, false, "" or + // "inherit". + if (val && val !== "inherit") { + ret += " " + attrs[i].nodeName + "=" + dump.parse(val, "attribute"); + } + } + } + ret += close; + + // Show content of TextNode or CDATASection + if (_node.nodeType === 3 || _node.nodeType === 4) { + ret += _node.nodeValue; + } + + return ret + open + "/" + tag + close; + }, + + // Function calls it internally, it's the arguments part of the function + functionArgs: function functionArgs(fn) { + var args, + l = fn.length; + + if (!l) { + return ""; + } + + args = new Array(l); + while (l--) { + + // 97 is 'a' + args[l] = String.fromCharCode(97 + l); + } + return " " + args.join(", ") + " "; + }, + + // Object calls it internally, the key part of an item in a map + key: quote, + + // Function calls it internally, it's the content of the function + functionCode: "[code]", + + // Node calls it internally, it's a html attribute value + attribute: quote, + string: quote, + date: quote, + regexp: literal, + number: literal, + "boolean": literal, + symbol: function symbol(sym) { + return sym.toString(); + } + }, + + // If true, entities are escaped ( <, >, \t, space and \n ) + HTML: false, + + // Indentation unit + indentChar: " ", + + // If true, items in a collection, are separated by a \n, else just a space. + multiline: true + }; + + return dump; + })(); + + var LISTENERS = Object.create(null); + var SUPPORTED_EVENTS = ["runStart", "suiteStart", "testStart", "assertion", "testEnd", "suiteEnd", "runEnd"]; + + /** + * Emits an event with the specified data to all currently registered listeners. + * Callbacks will fire in the order in which they are registered (FIFO). This + * function is not exposed publicly; it is used by QUnit internals to emit + * logging events. + * + * @private + * @method emit + * @param {String} eventName + * @param {Object} data + * @return {Void} + */ + function emit(eventName, data) { + if (objectType(eventName) !== "string") { + throw new TypeError("eventName must be a string when emitting an event"); + } + + // Clone the callbacks in case one of them registers a new callback + var originalCallbacks = LISTENERS[eventName]; + var callbacks = originalCallbacks ? [].concat(toConsumableArray(originalCallbacks)) : []; + + for (var i = 0; i < callbacks.length; i++) { + callbacks[i](data); + } + } + + /** + * Registers a callback as a listener to the specified event. + * + * @public + * @method on + * @param {String} eventName + * @param {Function} callback + * @return {Void} + */ + function on(eventName, callback) { + if (objectType(eventName) !== "string") { + throw new TypeError("eventName must be a string when registering a listener"); + } else if (!inArray(eventName, SUPPORTED_EVENTS)) { + var events = SUPPORTED_EVENTS.join(", "); + throw new Error("\"" + eventName + "\" is not a valid event; must be one of: " + events + "."); + } else if (objectType(callback) !== "function") { + throw new TypeError("callback must be a function when registering a listener"); + } + + if (!LISTENERS[eventName]) { + LISTENERS[eventName] = []; + } + + // Don't register the same callback more than once + if (!inArray(callback, LISTENERS[eventName])) { + LISTENERS[eventName].push(callback); + } + } + + // Register logging callbacks + function registerLoggingCallbacks(obj) { + var i, + l, + key, + callbackNames = ["begin", "done", "log", "testStart", "testDone", "moduleStart", "moduleDone"]; + + function registerLoggingCallback(key) { + var loggingCallback = function loggingCallback(callback) { + if (objectType(callback) !== "function") { + throw new Error("QUnit logging methods require a callback function as their first parameters."); + } + + config.callbacks[key].push(callback); + }; + + return loggingCallback; + } + + for (i = 0, l = callbackNames.length; i < l; i++) { + key = callbackNames[i]; + + // Initialize key collection of logging callback + if (objectType(config.callbacks[key]) === "undefined") { + config.callbacks[key] = []; + } + + obj[key] = registerLoggingCallback(key); + } + } + + function runLoggingCallbacks(key, args) { + var i, l, callbacks; + + callbacks = config.callbacks[key]; + for (i = 0, l = callbacks.length; i < l; i++) { + callbacks[i](args); + } + } + + // Doesn't support IE9, it will return undefined on these browsers + // See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack + var fileName = (sourceFromStacktrace(0) || "").replace(/(:\d+)+\)?/, "").replace(/.+\//, ""); + + function extractStacktrace(e, offset) { + offset = offset === undefined ? 4 : offset; + + var stack, include, i; + + if (e && e.stack) { + stack = e.stack.split("\n"); + if (/^error$/i.test(stack[0])) { + stack.shift(); + } + if (fileName) { + include = []; + for (i = offset; i < stack.length; i++) { + if (stack[i].indexOf(fileName) !== -1) { + break; + } + include.push(stack[i]); + } + if (include.length) { + return include.join("\n"); + } + } + return stack[offset]; + } + } + + function sourceFromStacktrace(offset) { + var error = new Error(); + + // Support: Safari <=7 only, IE <=10 - 11 only + // Not all browsers generate the `stack` property for `new Error()`, see also #636 + if (!error.stack) { + try { + throw error; + } catch (err) { + error = err; + } + } + + return extractStacktrace(error, offset); + } + + var priorityCount = 0; + var unitSampler = void 0; + + /** + * Advances the ProcessingQueue to the next item if it is ready. + * @param {Boolean} last + */ + function advance() { + var start = now(); + config.depth = (config.depth || 0) + 1; + + while (config.queue.length && !config.blocking) { + var elapsedTime = now() - start; + + if (!defined.setTimeout || config.updateRate <= 0 || elapsedTime < config.updateRate) { + if (priorityCount > 0) { + priorityCount--; + } + + config.queue.shift()(); + } else { + setTimeout(advance, 13); + break; + } + } + + config.depth--; + + if (!config.blocking && !config.queue.length && config.depth === 0) { + done(); + } + } + + function addToQueueImmediate(callback) { + if (objectType(callback) === "array") { + while (callback.length) { + addToQueueImmediate(callback.pop()); + } + + return; + } + + config.queue.unshift(callback); + priorityCount++; + } + + /** + * Adds a function to the ProcessingQueue for execution. + * @param {Function|Array} callback + * @param {Boolean} priority + * @param {String} seed + */ + function addToQueue(callback, prioritize, seed) { + if (prioritize) { + config.queue.splice(priorityCount++, 0, callback); + } else if (seed) { + if (!unitSampler) { + unitSampler = unitSamplerGenerator(seed); + } + + // Insert into a random position after all prioritized items + var index = Math.floor(unitSampler() * (config.queue.length - priorityCount + 1)); + config.queue.splice(priorityCount + index, 0, callback); + } else { + config.queue.push(callback); + } + } + + /** + * Creates a seeded "sample" generator which is used for randomizing tests. + */ + function unitSamplerGenerator(seed) { + + // 32-bit xorshift, requires only a nonzero seed + // http://excamera.com/sphinx/article-xorshift.html + var sample = parseInt(generateHash(seed), 16) || -1; + return function () { + sample ^= sample << 13; + sample ^= sample >>> 17; + sample ^= sample << 5; + + // ECMAScript has no unsigned number type + if (sample < 0) { + sample += 0x100000000; + } + + return sample / 0x100000000; + }; + } + + /** + * This function is called when the ProcessingQueue is done processing all + * items. It handles emitting the final run events. + */ + function done() { + var storage = config.storage; + + ProcessingQueue.finished = true; + + var runtime = now() - config.started; + var passed = config.stats.all - config.stats.bad; + + emit("runEnd", globalSuite.end(true)); + runLoggingCallbacks("done", { + passed: passed, + failed: config.stats.bad, + total: config.stats.all, + runtime: runtime + }); + + // Clear own storage items if all tests passed + if (storage && config.stats.bad === 0) { + for (var i = storage.length - 1; i >= 0; i--) { + var key = storage.key(i); + + if (key.indexOf("qunit-test-") === 0) { + storage.removeItem(key); + } + } + } + } + + var ProcessingQueue = { + finished: false, + add: addToQueue, + addImmediate: addToQueueImmediate, + advance: advance + }; + + var TestReport = function () { + function TestReport(name, suite, options) { + classCallCheck(this, TestReport); + + this.name = name; + this.suiteName = suite.name; + this.fullName = suite.fullName.concat(name); + this.runtime = 0; + this.assertions = []; + + this.skipped = !!options.skip; + this.todo = !!options.todo; + + this.valid = options.valid; + + this._startTime = 0; + this._endTime = 0; + + suite.pushTest(this); + } + + createClass(TestReport, [{ + key: "start", + value: function start(recordTime) { + if (recordTime) { + this._startTime = Date.now(); + } + + return { + name: this.name, + suiteName: this.suiteName, + fullName: this.fullName.slice() + }; + } + }, { + key: "end", + value: function end(recordTime) { + if (recordTime) { + this._endTime = Date.now(); + } + + return extend(this.start(), { + runtime: this.getRuntime(), + status: this.getStatus(), + errors: this.getFailedAssertions(), + assertions: this.getAssertions() + }); + } + }, { + key: "pushAssertion", + value: function pushAssertion(assertion) { + this.assertions.push(assertion); + } + }, { + key: "getRuntime", + value: function getRuntime() { + return this._endTime - this._startTime; + } + }, { + key: "getStatus", + value: function getStatus() { + if (this.skipped) { + return "skipped"; + } + + var testPassed = this.getFailedAssertions().length > 0 ? this.todo : !this.todo; + + if (!testPassed) { + return "failed"; + } else if (this.todo) { + return "todo"; + } else { + return "passed"; + } + } + }, { + key: "getFailedAssertions", + value: function getFailedAssertions() { + return this.assertions.filter(function (assertion) { + return !assertion.passed; + }); + } + }, { + key: "getAssertions", + value: function getAssertions() { + return this.assertions.slice(); + } + + // Remove actual and expected values from assertions. This is to prevent + // leaking memory throughout a test suite. + + }, { + key: "slimAssertions", + value: function slimAssertions() { + this.assertions = this.assertions.map(function (assertion) { + delete assertion.actual; + delete assertion.expected; + return assertion; + }); + } + }]); + return TestReport; + }(); + + var focused = false; + + function Test(settings) { + var i, l; + + ++Test.count; + + this.expected = null; + extend(this, settings); + this.assertions = []; + this.semaphore = 0; + this.module = config.currentModule; + this.stack = sourceFromStacktrace(3); + this.steps = []; + + this.testReport = new TestReport(settings.testName, this.module.suiteReport, { + todo: settings.todo, + skip: settings.skip, + valid: this.valid() + }); + + // Register unique strings + for (i = 0, l = this.module.tests; i < l.length; i++) { + if (this.module.tests[i].name === this.testName) { + this.testName += " "; + } + } + + this.testId = generateHash(this.module.name, this.testName); + + this.module.tests.push({ + name: this.testName, + testId: this.testId, + skip: !!settings.skip + }); + + if (settings.skip) { + + // Skipped tests will fully ignore any sent callback + this.callback = function () {}; + this.async = false; + this.expected = 0; + } else { + this.assert = new Assert(this); + } + } + + Test.count = 0; + + function getNotStartedModules(startModule) { + var module = startModule, + modules = []; + + while (module && module.testsRun === 0) { + modules.push(module); + module = module.parentModule; + } + + return modules; + } + + Test.prototype = { + before: function before() { + var i, + startModule, + module = this.module, + notStartedModules = getNotStartedModules(module); + + for (i = notStartedModules.length - 1; i >= 0; i--) { + startModule = notStartedModules[i]; + startModule.stats = { all: 0, bad: 0, started: now() }; + emit("suiteStart", startModule.suiteReport.start(true)); + runLoggingCallbacks("moduleStart", { + name: startModule.name, + tests: startModule.tests + }); + } + + config.current = this; + + this.testEnvironment = extend({}, module.testEnvironment); + + this.started = now(); + emit("testStart", this.testReport.start(true)); + runLoggingCallbacks("testStart", { + name: this.testName, + module: module.name, + testId: this.testId, + previousFailure: this.previousFailure + }); + + if (!config.pollution) { + saveGlobal(); + } + }, + + run: function run() { + var promise; + + config.current = this; + + this.callbackStarted = now(); + + if (config.notrycatch) { + runTest(this); + return; + } + + try { + runTest(this); + } catch (e) { + this.pushFailure("Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + (e.message || e), extractStacktrace(e, 0)); + + // Else next test will carry the responsibility + saveGlobal(); + + // Restart the tests if they're blocking + if (config.blocking) { + internalRecover(this); + } + } + + function runTest(test) { + promise = test.callback.call(test.testEnvironment, test.assert); + test.resolvePromise(promise); + } + }, + + after: function after() { + checkPollution(); + }, + + queueHook: function queueHook(hook, hookName, hookOwner) { + var promise, + test = this; + return function runHook() { + if (hookName === "before") { + if (hookOwner.unskippedTestsRun !== 0) { + return; + } + + test.preserveEnvironment = true; + } + + if (hookName === "after" && hookOwner.unskippedTestsRun !== numberOfUnskippedTests(hookOwner) - 1 && config.queue.length > 2) { + return; + } + + config.current = test; + if (config.notrycatch) { + callHook(); + return; + } + try { + callHook(); + } catch (error) { + test.pushFailure(hookName + " failed on " + test.testName + ": " + (error.message || error), extractStacktrace(error, 0)); + } + + function callHook() { + promise = hook.call(test.testEnvironment, test.assert); + test.resolvePromise(promise, hookName); + } + }; + }, + + // Currently only used for module level hooks, can be used to add global level ones + hooks: function hooks(handler) { + var hooks = []; + + function processHooks(test, module) { + if (module.parentModule) { + processHooks(test, module.parentModule); + } + if (module.hooks && objectType(module.hooks[handler]) === "function") { + hooks.push(test.queueHook(module.hooks[handler], handler, module)); + } + } + + // Hooks are ignored on skipped tests + if (!this.skip) { + processHooks(this, this.module); + } + return hooks; + }, + + finish: function finish() { + config.current = this; + if (config.requireExpects && this.expected === null) { + this.pushFailure("Expected number of assertions to be defined, but expect() was " + "not called.", this.stack); + } else if (this.expected !== null && this.expected !== this.assertions.length) { + this.pushFailure("Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack); + } else if (this.expected === null && !this.assertions.length) { + this.pushFailure("Expected at least one assertion, but none were run - call " + "expect(0) to accept zero assertions.", this.stack); + } + + var i, + module = this.module, + moduleName = module.name, + testName = this.testName, + skipped = !!this.skip, + todo = !!this.todo, + bad = 0, + storage = config.storage; + + this.runtime = now() - this.started; + + config.stats.all += this.assertions.length; + module.stats.all += this.assertions.length; + + for (i = 0; i < this.assertions.length; i++) { + if (!this.assertions[i].result) { + bad++; + config.stats.bad++; + module.stats.bad++; + } + } + + notifyTestsRan(module, skipped); + + // Store result when possible + if (storage) { + if (bad) { + storage.setItem("qunit-test-" + moduleName + "-" + testName, bad); + } else { + storage.removeItem("qunit-test-" + moduleName + "-" + testName); + } + } + + // After emitting the js-reporters event we cleanup the assertion data to + // avoid leaking it. It is not used by the legacy testDone callbacks. + emit("testEnd", this.testReport.end(true)); + this.testReport.slimAssertions(); + + runLoggingCallbacks("testDone", { + name: testName, + module: moduleName, + skipped: skipped, + todo: todo, + failed: bad, + passed: this.assertions.length - bad, + total: this.assertions.length, + runtime: skipped ? 0 : this.runtime, + + // HTML Reporter use + assertions: this.assertions, + testId: this.testId, + + // Source of Test + source: this.stack + }); + + if (module.testsRun === numberOfTests(module)) { + logSuiteEnd(module); + + // Check if the parent modules, iteratively, are done. If that the case, + // we emit the `suiteEnd` event and trigger `moduleDone` callback. + var parent = module.parentModule; + while (parent && parent.testsRun === numberOfTests(parent)) { + logSuiteEnd(parent); + parent = parent.parentModule; + } + } + + config.current = undefined; + + function logSuiteEnd(module) { + emit("suiteEnd", module.suiteReport.end(true)); + runLoggingCallbacks("moduleDone", { + name: module.name, + tests: module.tests, + failed: module.stats.bad, + passed: module.stats.all - module.stats.bad, + total: module.stats.all, + runtime: now() - module.stats.started + }); + } + }, + + preserveTestEnvironment: function preserveTestEnvironment() { + if (this.preserveEnvironment) { + this.module.testEnvironment = this.testEnvironment; + this.testEnvironment = extend({}, this.module.testEnvironment); + } + }, + + queue: function queue() { + var test = this; + + if (!this.valid()) { + return; + } + + function runTest() { + + // Each of these can by async + ProcessingQueue.addImmediate([function () { + test.before(); + }, test.hooks("before"), function () { + test.preserveTestEnvironment(); + }, test.hooks("beforeEach"), function () { + test.run(); + }, test.hooks("afterEach").reverse(), test.hooks("after").reverse(), function () { + test.after(); + }, function () { + test.finish(); + }]); + } + + var previousFailCount = config.storage && +config.storage.getItem("qunit-test-" + this.module.name + "-" + this.testName); + + // Prioritize previously failed tests, detected from storage + var prioritize = config.reorder && !!previousFailCount; + + this.previousFailure = !!previousFailCount; + + ProcessingQueue.add(runTest, prioritize, config.seed); + + // If the queue has already finished, we manually process the new test + if (ProcessingQueue.finished) { + ProcessingQueue.advance(); + } + }, + + + pushResult: function pushResult(resultInfo) { + if (this !== config.current) { + throw new Error("Assertion occured after test had finished."); + } + + // Destructure of resultInfo = { result, actual, expected, message, negative } + var source, + details = { + module: this.module.name, + name: this.testName, + result: resultInfo.result, + message: resultInfo.message, + actual: resultInfo.actual, + expected: resultInfo.expected, + testId: this.testId, + negative: resultInfo.negative || false, + runtime: now() - this.started, + todo: !!this.todo + }; + + if (!resultInfo.result) { + source = resultInfo.source || sourceFromStacktrace(); + + if (source) { + details.source = source; + } + } + + this.logAssertion(details); + + this.assertions.push({ + result: !!resultInfo.result, + message: resultInfo.message + }); + }, + + pushFailure: function pushFailure(message, source, actual) { + if (!(this instanceof Test)) { + throw new Error("pushFailure() assertion outside test context, was " + sourceFromStacktrace(2)); + } + + this.pushResult({ + result: false, + message: message || "error", + actual: actual || null, + expected: null, + source: source + }); + }, + + /** + * Log assertion details using both the old QUnit.log interface and + * QUnit.on( "assertion" ) interface. + * + * @private + */ + logAssertion: function logAssertion(details) { + runLoggingCallbacks("log", details); + + var assertion = { + passed: details.result, + actual: details.actual, + expected: details.expected, + message: details.message, + stack: details.source, + todo: details.todo + }; + this.testReport.pushAssertion(assertion); + emit("assertion", assertion); + }, + + + resolvePromise: function resolvePromise(promise, phase) { + var then, + resume, + message, + test = this; + if (promise != null) { + then = promise.then; + if (objectType(then) === "function") { + resume = internalStop(test); + then.call(promise, function () { + resume(); + }, function (error) { + message = "Promise rejected " + (!phase ? "during" : phase.replace(/Each$/, "")) + " \"" + test.testName + "\": " + (error && error.message || error); + test.pushFailure(message, extractStacktrace(error, 0)); + + // Else next test will carry the responsibility + saveGlobal(); + + // Unblock + resume(); + }); + } + } + }, + + valid: function valid() { + var filter = config.filter, + regexFilter = /^(!?)\/([\w\W]*)\/(i?$)/.exec(filter), + module = config.module && config.module.toLowerCase(), + fullName = this.module.name + ": " + this.testName; + + function moduleChainNameMatch(testModule) { + var testModuleName = testModule.name ? testModule.name.toLowerCase() : null; + if (testModuleName === module) { + return true; + } else if (testModule.parentModule) { + return moduleChainNameMatch(testModule.parentModule); + } else { + return false; + } + } + + function moduleChainIdMatch(testModule) { + return inArray(testModule.moduleId, config.moduleId) || testModule.parentModule && moduleChainIdMatch(testModule.parentModule); + } + + // Internally-generated tests are always valid + if (this.callback && this.callback.validTest) { + return true; + } + + if (config.moduleId && config.moduleId.length > 0 && !moduleChainIdMatch(this.module)) { + + return false; + } + + if (config.testId && config.testId.length > 0 && !inArray(this.testId, config.testId)) { + + return false; + } + + if (module && !moduleChainNameMatch(this.module)) { + return false; + } + + if (!filter) { + return true; + } + + return regexFilter ? this.regexFilter(!!regexFilter[1], regexFilter[2], regexFilter[3], fullName) : this.stringFilter(filter, fullName); + }, + + regexFilter: function regexFilter(exclude, pattern, flags, fullName) { + var regex = new RegExp(pattern, flags); + var match = regex.test(fullName); + + return match !== exclude; + }, + + stringFilter: function stringFilter(filter, fullName) { + filter = filter.toLowerCase(); + fullName = fullName.toLowerCase(); + + var include = filter.charAt(0) !== "!"; + if (!include) { + filter = filter.slice(1); + } + + // If the filter matches, we need to honour include + if (fullName.indexOf(filter) !== -1) { + return include; + } + + // Otherwise, do the opposite + return !include; + } + }; + + function pushFailure() { + if (!config.current) { + throw new Error("pushFailure() assertion outside test context, in " + sourceFromStacktrace(2)); + } + + // Gets current test obj + var currentTest = config.current; + + return currentTest.pushFailure.apply(currentTest, arguments); + } + + function saveGlobal() { + config.pollution = []; + + if (config.noglobals) { + for (var key in global$1) { + if (hasOwn.call(global$1, key)) { + + // In Opera sometimes DOM element ids show up here, ignore them + if (/^qunit-test-output/.test(key)) { + continue; + } + config.pollution.push(key); + } + } + } + } + + function checkPollution() { + var newGlobals, + deletedGlobals, + old = config.pollution; + + saveGlobal(); + + newGlobals = diff(config.pollution, old); + if (newGlobals.length > 0) { + pushFailure("Introduced global variable(s): " + newGlobals.join(", ")); + } + + deletedGlobals = diff(old, config.pollution); + if (deletedGlobals.length > 0) { + pushFailure("Deleted global variable(s): " + deletedGlobals.join(", ")); + } + } + + // Will be exposed as QUnit.test + function test(testName, callback) { + if (focused) { + return; + } + + var newTest = new Test({ + testName: testName, + callback: callback + }); + + newTest.queue(); + } + + function todo(testName, callback) { + if (focused) { + return; + } + + var newTest = new Test({ + testName: testName, + callback: callback, + todo: true + }); + + newTest.queue(); + } + + // Will be exposed as QUnit.skip + function skip(testName) { + if (focused) { + return; + } + + var test = new Test({ + testName: testName, + skip: true + }); + + test.queue(); + } + + // Will be exposed as QUnit.only + function only(testName, callback) { + if (focused) { + return; + } + + config.queue.length = 0; + focused = true; + + var newTest = new Test({ + testName: testName, + callback: callback + }); + + newTest.queue(); + } + + // Put a hold on processing and return a function that will release it. + function internalStop(test) { + var released = false; + + test.semaphore += 1; + config.blocking = true; + + // Set a recovery timeout, if so configured. + if (config.testTimeout && defined.setTimeout) { + clearTimeout(config.timeout); + config.timeout = setTimeout(function () { + pushFailure("Test timed out", sourceFromStacktrace(2)); + internalRecover(test); + }, config.testTimeout); + } + + return function resume() { + if (released) { + return; + } + + released = true; + test.semaphore -= 1; + internalStart(test); + }; + } + + // Forcefully release all processing holds. + function internalRecover(test) { + test.semaphore = 0; + internalStart(test); + } + + // Release a processing hold, scheduling a resumption attempt if no holds remain. + function internalStart(test) { + + // If semaphore is non-numeric, throw error + if (isNaN(test.semaphore)) { + test.semaphore = 0; + + pushFailure("Invalid value on test.semaphore", sourceFromStacktrace(2)); + return; + } + + // Don't start until equal number of stop-calls + if (test.semaphore > 0) { + return; + } + + // Throw an Error if start is called more often than stop + if (test.semaphore < 0) { + test.semaphore = 0; + + pushFailure("Tried to restart test while already started (test's semaphore was 0 already)", sourceFromStacktrace(2)); + return; + } + + // Add a slight delay to allow more assertions etc. + if (defined.setTimeout) { + if (config.timeout) { + clearTimeout(config.timeout); + } + config.timeout = setTimeout(function () { + if (test.semaphore > 0) { + return; + } + + if (config.timeout) { + clearTimeout(config.timeout); + } + + begin(); + }, 13); + } else { + begin(); + } + } + + function collectTests(module) { + var tests = [].concat(module.tests); + var modules = [].concat(toConsumableArray(module.childModules)); + + // Do a breadth-first traversal of the child modules + while (modules.length) { + var nextModule = modules.shift(); + tests.push.apply(tests, nextModule.tests); + modules.push.apply(modules, toConsumableArray(nextModule.childModules)); + } + + return tests; + } + + function numberOfTests(module) { + return collectTests(module).length; + } + + function numberOfUnskippedTests(module) { + return collectTests(module).filter(function (test) { + return !test.skip; + }).length; + } + + function notifyTestsRan(module, skipped) { + module.testsRun++; + if (!skipped) { + module.unskippedTestsRun++; + } + while (module = module.parentModule) { + module.testsRun++; + if (!skipped) { + module.unskippedTestsRun++; + } + } + } + + /** + * Returns a function that proxies to the given method name on the globals + * console object. The proxy will also detect if the console doesn't exist and + * will appropriately no-op. This allows support for IE9, which doesn't have a + * console if the developer tools are not open. + */ + function consoleProxy(method) { + return function () { + if (console) { + console[method].apply(console, arguments); + } + }; + } + + var Logger = { + warn: consoleProxy("warn") + }; + + var Assert = function () { + function Assert(testContext) { + classCallCheck(this, Assert); + + this.test = testContext; + } + + // Assert helpers + + // Documents a "step", which is a string value, in a test as a passing assertion + + + createClass(Assert, [{ + key: "step", + value: function step(message) { + var result = !!message; + + this.test.steps.push(message); + + return this.pushResult({ + result: result, + message: message || "You must provide a message to assert.step" + }); + } + + // Verifies the steps in a test match a given array of string values + + }, { + key: "verifySteps", + value: function verifySteps(steps, message) { + this.deepEqual(this.test.steps, steps, message); + } + + // Specify the number of expected assertions to guarantee that failed test + // (no assertions are run at all) don't slip through. + + }, { + key: "expect", + value: function expect(asserts) { + if (arguments.length === 1) { + this.test.expected = asserts; + } else { + return this.test.expected; + } + } + + // Put a hold on processing and return a function that will release it a maximum of once. + + }, { + key: "async", + value: function async(count) { + var test$$1 = this.test; + + var popped = false, + acceptCallCount = count; + + if (typeof acceptCallCount === "undefined") { + acceptCallCount = 1; + } + + var resume = internalStop(test$$1); + + return function done() { + if (config.current !== test$$1) { + throw Error("assert.async callback called after test finished."); + } + + if (popped) { + test$$1.pushFailure("Too many calls to the `assert.async` callback", sourceFromStacktrace(2)); + return; + } + + acceptCallCount -= 1; + if (acceptCallCount > 0) { + return; + } + + popped = true; + resume(); + }; + } + + // Exports test.push() to the user API + // Alias of pushResult. + + }, { + key: "push", + value: function push(result, actual, expected, message, negative) { + Logger.warn("assert.push is deprecated and will be removed in QUnit 3.0." + " Please use assert.pushResult instead (http://api.qunitjs.com/pushResult/)."); + + var currentAssert = this instanceof Assert ? this : config.current.assert; + return currentAssert.pushResult({ + result: result, + actual: actual, + expected: expected, + message: message, + negative: negative + }); + } + }, { + key: "pushResult", + value: function pushResult(resultInfo) { + + // Destructure of resultInfo = { result, actual, expected, message, negative } + var assert = this; + var currentTest = assert instanceof Assert && assert.test || config.current; + + // Backwards compatibility fix. + // Allows the direct use of global exported assertions and QUnit.assert.* + // Although, it's use is not recommended as it can leak assertions + // to other tests from async tests, because we only get a reference to the current test, + // not exactly the test where assertion were intended to be called. + if (!currentTest) { + throw new Error("assertion outside test context, in " + sourceFromStacktrace(2)); + } + + if (!(assert instanceof Assert)) { + assert = currentTest.assert; + } + + return assert.test.pushResult(resultInfo); + } + }, { + key: "ok", + value: function ok(result, message) { + if (!message) { + message = result ? "okay" : "failed, expected argument to be truthy, was: " + dump.parse(result); + } + + this.pushResult({ + result: !!result, + actual: result, + expected: true, + message: message + }); + } + }, { + key: "notOk", + value: function notOk(result, message) { + if (!message) { + message = !result ? "okay" : "failed, expected argument to be falsy, was: " + dump.parse(result); + } + + this.pushResult({ + result: !result, + actual: result, + expected: false, + message: message + }); + } + }, { + key: "equal", + value: function equal(actual, expected, message) { + + // eslint-disable-next-line eqeqeq + var result = expected == actual; + + this.pushResult({ + result: result, + actual: actual, + expected: expected, + message: message + }); + } + }, { + key: "notEqual", + value: function notEqual(actual, expected, message) { + + // eslint-disable-next-line eqeqeq + var result = expected != actual; + + this.pushResult({ + result: result, + actual: actual, + expected: expected, + message: message, + negative: true + }); + } + }, { + key: "propEqual", + value: function propEqual(actual, expected, message) { + actual = objectValues(actual); + expected = objectValues(expected); + + this.pushResult({ + result: equiv(actual, expected), + actual: actual, + expected: expected, + message: message + }); + } + }, { + key: "notPropEqual", + value: function notPropEqual(actual, expected, message) { + actual = objectValues(actual); + expected = objectValues(expected); + + this.pushResult({ + result: !equiv(actual, expected), + actual: actual, + expected: expected, + message: message, + negative: true + }); + } + }, { + key: "deepEqual", + value: function deepEqual(actual, expected, message) { + this.pushResult({ + result: equiv(actual, expected), + actual: actual, + expected: expected, + message: message + }); + } + }, { + key: "notDeepEqual", + value: function notDeepEqual(actual, expected, message) { + this.pushResult({ + result: !equiv(actual, expected), + actual: actual, + expected: expected, + message: message, + negative: true + }); + } + }, { + key: "strictEqual", + value: function strictEqual(actual, expected, message) { + this.pushResult({ + result: expected === actual, + actual: actual, + expected: expected, + message: message + }); + } + }, { + key: "notStrictEqual", + value: function notStrictEqual(actual, expected, message) { + this.pushResult({ + result: expected !== actual, + actual: actual, + expected: expected, + message: message, + negative: true + }); + } + }, { + key: "throws", + value: function throws(block, expected, message) { + var actual = void 0, + result = false; + + var currentTest = this instanceof Assert && this.test || config.current; + + // 'expected' is optional unless doing string comparison + if (objectType(expected) === "string") { + if (message == null) { + message = expected; + expected = null; + } else { + throw new Error("throws/raises does not accept a string value for the expected argument.\n" + "Use a non-string object value (e.g. regExp) instead if it's necessary."); + } + } + + currentTest.ignoreGlobalErrors = true; + try { + block.call(currentTest.testEnvironment); + } catch (e) { + actual = e; + } + currentTest.ignoreGlobalErrors = false; + + if (actual) { + var expectedType = objectType(expected); + + // We don't want to validate thrown error + if (!expected) { + result = true; + expected = null; + + // Expected is a regexp + } else if (expectedType === "regexp") { + result = expected.test(errorString(actual)); + + // Expected is a constructor, maybe an Error constructor + } else if (expectedType === "function" && actual instanceof expected) { + result = true; + + // Expected is an Error object + } else if (expectedType === "object") { + result = actual instanceof expected.constructor && actual.name === expected.name && actual.message === expected.message; + + // Expected is a validation function which returns true if validation passed + } else if (expectedType === "function" && expected.call({}, actual) === true) { + expected = null; + result = true; + } + } + + currentTest.assert.pushResult({ + result: result, + actual: actual, + expected: expected, + message: message + }); + } + }]); + return Assert; + }(); + + // Provide an alternative to assert.throws(), for environments that consider throws a reserved word + // Known to us are: Closure Compiler, Narwhal + // eslint-disable-next-line dot-notation + + + Assert.prototype.raises = Assert.prototype["throws"]; + + /** + * Converts an error into a simple string for comparisons. + * + * @param {Error} error + * @return {String} + */ + function errorString(error) { + var resultErrorString = error.toString(); + + if (resultErrorString.substring(0, 7) === "[object") { + var name = error.name ? error.name.toString() : "Error"; + var message = error.message ? error.message.toString() : ""; + + if (name && message) { + return name + ": " + message; + } else if (name) { + return name; + } else if (message) { + return message; + } else { + return "Error"; + } + } else { + return resultErrorString; + } + } + + /* global module, exports, define */ + function exportQUnit(QUnit) { + + if (defined.document) { + + // QUnit may be defined when it is preconfigured but then only QUnit and QUnit.config may be defined. + if (window.QUnit && window.QUnit.version) { + throw new Error("QUnit has already been defined."); + } + + window.QUnit = QUnit; + } + + // For nodejs + if (typeof module !== "undefined" && module && module.exports) { + module.exports = QUnit; + + // For consistency with CommonJS environments' exports + module.exports.QUnit = QUnit; + } + + // For CommonJS with exports, but without module.exports, like Rhino + if (typeof exports !== "undefined" && exports) { + exports.QUnit = QUnit; + } + + if (typeof define === "function" && define.amd) { + define(function () { + return QUnit; + }); + QUnit.config.autostart = false; + } + + // For Web/Service Workers + if (self$1 && self$1.WorkerGlobalScope && self$1 instanceof self$1.WorkerGlobalScope) { + self$1.QUnit = QUnit; + } + } + + var SuiteReport = function () { + function SuiteReport(name, parentSuite) { + classCallCheck(this, SuiteReport); + + this.name = name; + this.fullName = parentSuite ? parentSuite.fullName.concat(name) : []; + + this.tests = []; + this.childSuites = []; + + if (parentSuite) { + parentSuite.pushChildSuite(this); + } + } + + createClass(SuiteReport, [{ + key: "start", + value: function start(recordTime) { + if (recordTime) { + this._startTime = Date.now(); + } + + return { + name: this.name, + fullName: this.fullName.slice(), + tests: this.tests.map(function (test) { + return test.start(); + }), + childSuites: this.childSuites.map(function (suite) { + return suite.start(); + }), + testCounts: { + total: this.getTestCounts().total + } + }; + } + }, { + key: "end", + value: function end(recordTime) { + if (recordTime) { + this._endTime = Date.now(); + } + + return { + name: this.name, + fullName: this.fullName.slice(), + tests: this.tests.map(function (test) { + return test.end(); + }), + childSuites: this.childSuites.map(function (suite) { + return suite.end(); + }), + testCounts: this.getTestCounts(), + runtime: this.getRuntime(), + status: this.getStatus() + }; + } + }, { + key: "pushChildSuite", + value: function pushChildSuite(suite) { + this.childSuites.push(suite); + } + }, { + key: "pushTest", + value: function pushTest(test) { + this.tests.push(test); + } + }, { + key: "getRuntime", + value: function getRuntime() { + return this._endTime - this._startTime; + } + }, { + key: "getTestCounts", + value: function getTestCounts() { + var counts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { passed: 0, failed: 0, skipped: 0, todo: 0, total: 0 }; + + counts = this.tests.reduce(function (counts, test) { + if (test.valid) { + counts[test.getStatus()]++; + counts.total++; + } + + return counts; + }, counts); + + return this.childSuites.reduce(function (counts, suite) { + return suite.getTestCounts(counts); + }, counts); + } + }, { + key: "getStatus", + value: function getStatus() { + var _getTestCounts = this.getTestCounts(), + total = _getTestCounts.total, + failed = _getTestCounts.failed, + skipped = _getTestCounts.skipped, + todo = _getTestCounts.todo; + + if (failed) { + return "failed"; + } else { + if (skipped === total) { + return "skipped"; + } else if (todo === total) { + return "todo"; + } else { + return "passed"; + } + } + } + }]); + return SuiteReport; + }(); + + // Handle an unhandled exception. By convention, returns true if further + // error handling should be suppressed and false otherwise. + // In this case, we will only suppress further error handling if the + // "ignoreGlobalErrors" configuration option is enabled. + function onError(error) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + if (config.current) { + if (config.current.ignoreGlobalErrors) { + return true; + } + pushFailure.apply(undefined, [error.message, error.fileName + ":" + error.lineNumber].concat(args)); + } else { + test("global failure", extend(function () { + pushFailure.apply(undefined, [error.message, error.fileName + ":" + error.lineNumber].concat(args)); + }, { validTest: true })); + } + + return false; + } + + var QUnit = {}; + var globalSuite = new SuiteReport(); + + // The initial "currentModule" represents the global (or top-level) module that + // is not explicitly defined by the user, therefore we add the "globalSuite" to + // it since each module has a suiteReport associated with it. + config.currentModule.suiteReport = globalSuite; + + var moduleStack = []; + var globalStartCalled = false; + var runStarted = false; + + // Figure out if we're running the tests from a server or not + QUnit.isLocal = !(defined.document && window.location.protocol !== "file:"); + + // Expose the current QUnit version + QUnit.version = "2.3.3"; + + function createModule(name, testEnvironment) { + var parentModule = moduleStack.length ? moduleStack.slice(-1)[0] : null; + var moduleName = parentModule !== null ? [parentModule.name, name].join(" > ") : name; + var parentSuite = parentModule ? parentModule.suiteReport : globalSuite; + + var module = { + name: moduleName, + parentModule: parentModule, + tests: [], + moduleId: generateHash(moduleName), + testsRun: 0, + unskippedTestsRun: 0, + childModules: [], + suiteReport: new SuiteReport(name, parentSuite) + }; + + var env = {}; + if (parentModule) { + parentModule.childModules.push(module); + extend(env, parentModule.testEnvironment); + } + extend(env, testEnvironment); + module.testEnvironment = env; + + config.modules.push(module); + return module; + } + + extend(QUnit, { + on: on, + + // Call on start of module test to prepend name to all tests + module: function module(name, testEnvironment, executeNow) { + if (arguments.length === 2) { + if (objectType(testEnvironment) === "function") { + executeNow = testEnvironment; + testEnvironment = undefined; + } + } + + var module = createModule(name, testEnvironment); + + // Move any hooks to a 'hooks' object + if (module.testEnvironment) { + module.hooks = { + before: module.testEnvironment.before, + beforeEach: module.testEnvironment.beforeEach, + afterEach: module.testEnvironment.afterEach, + after: module.testEnvironment.after + }; + + delete module.testEnvironment.before; + delete module.testEnvironment.beforeEach; + delete module.testEnvironment.afterEach; + delete module.testEnvironment.after; + } + + var moduleFns = { + before: setHook(module, "before"), + beforeEach: setHook(module, "beforeEach"), + afterEach: setHook(module, "afterEach"), + after: setHook(module, "after") + }; + + var currentModule = config.currentModule; + if (objectType(executeNow) === "function") { + moduleStack.push(module); + config.currentModule = module; + executeNow.call(module.testEnvironment, moduleFns); + moduleStack.pop(); + module = module.parentModule || currentModule; + } + + config.currentModule = module; + }, + + test: test, + + todo: todo, + + skip: skip, + + only: only, + + start: function start(count) { + var globalStartAlreadyCalled = globalStartCalled; + + if (!config.current) { + globalStartCalled = true; + + if (runStarted) { + throw new Error("Called start() while test already started running"); + } else if (globalStartAlreadyCalled || count > 1) { + throw new Error("Called start() outside of a test context too many times"); + } else if (config.autostart) { + throw new Error("Called start() outside of a test context when " + "QUnit.config.autostart was true"); + } else if (!config.pageLoaded) { + + // The page isn't completely loaded yet, so we set autostart and then + // load if we're in Node or wait for the browser's load event. + config.autostart = true; + + // Starts from Node even if .load was not previously called. We still return + // early otherwise we'll wind up "beginning" twice. + if (!defined.document) { + QUnit.load(); + } + + return; + } + } else { + throw new Error("QUnit.start cannot be called inside a test context."); + } + + scheduleBegin(); + }, + + config: config, + + is: is, + + objectType: objectType, + + extend: extend, + + load: function load() { + config.pageLoaded = true; + + // Initialize the configuration options + extend(config, { + stats: { all: 0, bad: 0 }, + started: 0, + updateRate: 1000, + autostart: true, + filter: "" + }, true); + + if (!runStarted) { + config.blocking = false; + + if (config.autostart) { + scheduleBegin(); + } + } + }, + + stack: function stack(offset) { + offset = (offset || 0) + 2; + return sourceFromStacktrace(offset); + }, + + onError: onError + }); + + QUnit.pushFailure = pushFailure; + QUnit.assert = Assert.prototype; + QUnit.equiv = equiv; + QUnit.dump = dump; + + registerLoggingCallbacks(QUnit); + + function scheduleBegin() { + + runStarted = true; + + // Add a slight delay to allow definition of more modules and tests. + if (defined.setTimeout) { + setTimeout(function () { + begin(); + }, 13); + } else { + begin(); + } + } + + function begin() { + var i, + l, + modulesLog = []; + + // If the test run hasn't officially begun yet + if (!config.started) { + + // Record the time of the test run's beginning + config.started = now(); + + // Delete the loose unnamed module if unused. + if (config.modules[0].name === "" && config.modules[0].tests.length === 0) { + config.modules.shift(); + } + + // Avoid unnecessary information by not logging modules' test environments + for (i = 0, l = config.modules.length; i < l; i++) { + modulesLog.push({ + name: config.modules[i].name, + tests: config.modules[i].tests + }); + } + + // The test run is officially beginning now + emit("runStart", globalSuite.start(true)); + runLoggingCallbacks("begin", { + totalTests: Test.count, + modules: modulesLog + }); + } + + config.blocking = false; + ProcessingQueue.advance(); + } + + function setHook(module, hookName) { + if (!module.hooks) { + module.hooks = {}; + } + + return function (callback) { + module.hooks[hookName] = callback; + }; + } + + exportQUnit(QUnit); + + (function () { + + if (typeof window === "undefined" || typeof document === "undefined") { + return; + } + + var config = QUnit.config, + hasOwn = Object.prototype.hasOwnProperty; + + // Stores fixture HTML for resetting later + function storeFixture() { + + // Avoid overwriting user-defined values + if (hasOwn.call(config, "fixture")) { + return; + } + + var fixture = document.getElementById("qunit-fixture"); + if (fixture) { + config.fixture = fixture.innerHTML; + } + } + + QUnit.begin(storeFixture); + + // Resets the fixture DOM element if available. + function resetFixture() { + if (config.fixture == null) { + return; + } + + var fixture = document.getElementById("qunit-fixture"); + if (fixture) { + fixture.innerHTML = config.fixture; + } + } + + QUnit.testStart(resetFixture); + })(); + + (function () { + + // Only interact with URLs via window.location + var location = typeof window !== "undefined" && window.location; + if (!location) { + return; + } + + var urlParams = getUrlParams(); + + QUnit.urlParams = urlParams; + + // Match module/test by inclusion in an array + QUnit.config.moduleId = [].concat(urlParams.moduleId || []); + QUnit.config.testId = [].concat(urlParams.testId || []); + + // Exact case-insensitive match of the module name + QUnit.config.module = urlParams.module; + + // Regular expression or case-insenstive substring match against "moduleName: testName" + QUnit.config.filter = urlParams.filter; + + // Test order randomization + if (urlParams.seed === true) { + + // Generate a random seed if the option is specified without a value + QUnit.config.seed = Math.random().toString(36).slice(2); + } else if (urlParams.seed) { + QUnit.config.seed = urlParams.seed; + } + + // Add URL-parameter-mapped config values with UI form rendering data + QUnit.config.urlConfig.push({ + id: "hidepassed", + label: "Hide passed tests", + tooltip: "Only show tests and assertions that fail. Stored as query-strings." + }, { + id: "noglobals", + label: "Check for Globals", + tooltip: "Enabling this will test if any test introduces new properties on the " + "global object (`window` in Browsers). Stored as query-strings." + }, { + id: "notrycatch", + label: "No try-catch", + tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging " + "exceptions in IE reasonable. Stored as query-strings." + }); + + QUnit.begin(function () { + var i, + option, + urlConfig = QUnit.config.urlConfig; + + for (i = 0; i < urlConfig.length; i++) { + + // Options can be either strings or objects with nonempty "id" properties + option = QUnit.config.urlConfig[i]; + if (typeof option !== "string") { + option = option.id; + } + + if (QUnit.config[option] === undefined) { + QUnit.config[option] = urlParams[option]; + } + } + }); + + function getUrlParams() { + var i, param, name, value; + var urlParams = Object.create(null); + var params = location.search.slice(1).split("&"); + var length = params.length; + + for (i = 0; i < length; i++) { + if (params[i]) { + param = params[i].split("="); + name = decodeQueryParam(param[0]); + + // Allow just a key to turn on a flag, e.g., test.html?noglobals + value = param.length === 1 || decodeQueryParam(param.slice(1).join("=")); + if (name in urlParams) { + urlParams[name] = [].concat(urlParams[name], value); + } else { + urlParams[name] = value; + } + } + } + + return urlParams; + } + + function decodeQueryParam(param) { + return decodeURIComponent(param.replace(/\+/g, "%20")); + } + })(); + + var stats = { + passedTests: 0, + failedTests: 0, + skippedTests: 0, + todoTests: 0 + }; + + // Escape text for attribute or text content. + function escapeText(s) { + if (!s) { + return ""; + } + s = s + ""; + + // Both single quotes and double quotes (for attributes) + return s.replace(/['"<>&]/g, function (s) { + switch (s) { + case "'": + return "'"; + case "\"": + return """; + case "<": + return "<"; + case ">": + return ">"; + case "&": + return "&"; + } + }); + } + + (function () { + + // Don't load the HTML Reporter on non-browser environments + if (typeof window === "undefined" || !window.document) { + return; + } + + var config = QUnit.config, + document$$1 = window.document, + collapseNext = false, + hasOwn = Object.prototype.hasOwnProperty, + unfilteredUrl = setUrl({ filter: undefined, module: undefined, + moduleId: undefined, testId: undefined }), + modulesList = []; + + function addEvent(elem, type, fn) { + elem.addEventListener(type, fn, false); + } + + function removeEvent(elem, type, fn) { + elem.removeEventListener(type, fn, false); + } + + function addEvents(elems, type, fn) { + var i = elems.length; + while (i--) { + addEvent(elems[i], type, fn); + } + } + + function hasClass(elem, name) { + return (" " + elem.className + " ").indexOf(" " + name + " ") >= 0; + } + + function addClass(elem, name) { + if (!hasClass(elem, name)) { + elem.className += (elem.className ? " " : "") + name; + } + } + + function toggleClass(elem, name, force) { + if (force || typeof force === "undefined" && !hasClass(elem, name)) { + addClass(elem, name); + } else { + removeClass(elem, name); + } + } + + function removeClass(elem, name) { + var set = " " + elem.className + " "; + + // Class name may appear multiple times + while (set.indexOf(" " + name + " ") >= 0) { + set = set.replace(" " + name + " ", " "); + } + + // Trim for prettiness + elem.className = typeof set.trim === "function" ? set.trim() : set.replace(/^\s+|\s+$/g, ""); + } + + function id(name) { + return document$$1.getElementById && document$$1.getElementById(name); + } + + function abortTests() { + var abortButton = id("qunit-abort-tests-button"); + if (abortButton) { + abortButton.disabled = true; + abortButton.innerHTML = "Aborting..."; + } + QUnit.config.queue.length = 0; + return false; + } + + function interceptNavigation(ev) { + applyUrlParams(); + + if (ev && ev.preventDefault) { + ev.preventDefault(); + } + + return false; + } + + function getUrlConfigHtml() { + var i, + j, + val, + escaped, + escapedTooltip, + selection = false, + urlConfig = config.urlConfig, + urlConfigHtml = ""; + + for (i = 0; i < urlConfig.length; i++) { + + // Options can be either strings or objects with nonempty "id" properties + val = config.urlConfig[i]; + if (typeof val === "string") { + val = { + id: val, + label: val + }; + } + + escaped = escapeText(val.id); + escapedTooltip = escapeText(val.tooltip); + + if (!val.value || typeof val.value === "string") { + urlConfigHtml += ""; + } else { + urlConfigHtml += ""; + } + } + + return urlConfigHtml; + } + + // Handle "click" events on toolbar checkboxes and "change" for select menus. + // Updates the URL with the new state of `config.urlConfig` values. + function toolbarChanged() { + var updatedUrl, + value, + tests, + field = this, + params = {}; + + // Detect if field is a select menu or a checkbox + if ("selectedIndex" in field) { + value = field.options[field.selectedIndex].value || undefined; + } else { + value = field.checked ? field.defaultValue || true : undefined; + } + + params[field.name] = value; + updatedUrl = setUrl(params); + + // Check if we can apply the change without a page refresh + if ("hidepassed" === field.name && "replaceState" in window.history) { + QUnit.urlParams[field.name] = value; + config[field.name] = value || false; + tests = id("qunit-tests"); + if (tests) { + toggleClass(tests, "hidepass", value || false); + } + window.history.replaceState(null, "", updatedUrl); + } else { + window.location = updatedUrl; + } + } + + function setUrl(params) { + var key, + arrValue, + i, + querystring = "?", + location = window.location; + + params = QUnit.extend(QUnit.extend({}, QUnit.urlParams), params); + + for (key in params) { + + // Skip inherited or undefined properties + if (hasOwn.call(params, key) && params[key] !== undefined) { + + // Output a parameter for each value of this key (but usually just one) + arrValue = [].concat(params[key]); + for (i = 0; i < arrValue.length; i++) { + querystring += encodeURIComponent(key); + if (arrValue[i] !== true) { + querystring += "=" + encodeURIComponent(arrValue[i]); + } + querystring += "&"; + } + } + } + return location.protocol + "//" + location.host + location.pathname + querystring.slice(0, -1); + } + + function applyUrlParams() { + var i, + selectedModules = [], + modulesList = id("qunit-modulefilter-dropdown-list").getElementsByTagName("input"), + filter = id("qunit-filter-input").value; + + for (i = 0; i < modulesList.length; i++) { + if (modulesList[i].checked) { + selectedModules.push(modulesList[i].value); + } + } + + window.location = setUrl({ + filter: filter === "" ? undefined : filter, + moduleId: selectedModules.length === 0 ? undefined : selectedModules, + + // Remove module and testId filter + module: undefined, + testId: undefined + }); + } + + function toolbarUrlConfigContainer() { + var urlConfigContainer = document$$1.createElement("span"); + + urlConfigContainer.innerHTML = getUrlConfigHtml(); + addClass(urlConfigContainer, "qunit-url-config"); + + addEvents(urlConfigContainer.getElementsByTagName("input"), "change", toolbarChanged); + addEvents(urlConfigContainer.getElementsByTagName("select"), "change", toolbarChanged); + + return urlConfigContainer; + } + + function abortTestsButton() { + var button = document$$1.createElement("button"); + button.id = "qunit-abort-tests-button"; + button.innerHTML = "Abort"; + addEvent(button, "click", abortTests); + return button; + } + + function toolbarLooseFilter() { + var filter = document$$1.createElement("form"), + label = document$$1.createElement("label"), + input = document$$1.createElement("input"), + button = document$$1.createElement("button"); + + addClass(filter, "qunit-filter"); + + label.innerHTML = "Filter: "; + + input.type = "text"; + input.value = config.filter || ""; + input.name = "filter"; + input.id = "qunit-filter-input"; + + button.innerHTML = "Go"; + + label.appendChild(input); + + filter.appendChild(label); + filter.appendChild(document$$1.createTextNode(" ")); + filter.appendChild(button); + addEvent(filter, "submit", interceptNavigation); + + return filter; + } + + function moduleListHtml() { + var i, + checked, + html = ""; + + for (i = 0; i < config.modules.length; i++) { + if (config.modules[i].name !== "") { + checked = config.moduleId.indexOf(config.modules[i].moduleId) > -1; + html += "
  1. "; + } + } + + return html; + } + + function toolbarModuleFilter() { + var allCheckbox, + commit, + reset, + moduleFilter = document$$1.createElement("form"), + label = document$$1.createElement("label"), + moduleSearch = document$$1.createElement("input"), + dropDown = document$$1.createElement("div"), + actions = document$$1.createElement("span"), + dropDownList = document$$1.createElement("ul"), + dirty = false; + + moduleSearch.id = "qunit-modulefilter-search"; + addEvent(moduleSearch, "input", searchInput); + addEvent(moduleSearch, "input", searchFocus); + addEvent(moduleSearch, "focus", searchFocus); + addEvent(moduleSearch, "click", searchFocus); + + label.id = "qunit-modulefilter-search-container"; + label.innerHTML = "Module: "; + label.appendChild(moduleSearch); + + actions.id = "qunit-modulefilter-actions"; + actions.innerHTML = "" + "" + ""; + allCheckbox = actions.lastChild.firstChild; + commit = actions.firstChild; + reset = commit.nextSibling; + addEvent(commit, "click", applyUrlParams); + + dropDownList.id = "qunit-modulefilter-dropdown-list"; + dropDownList.innerHTML = moduleListHtml(); + + dropDown.id = "qunit-modulefilter-dropdown"; + dropDown.style.display = "none"; + dropDown.appendChild(actions); + dropDown.appendChild(dropDownList); + addEvent(dropDown, "change", selectionChange); + selectionChange(); + + moduleFilter.id = "qunit-modulefilter"; + moduleFilter.appendChild(label); + moduleFilter.appendChild(dropDown); + addEvent(moduleFilter, "submit", interceptNavigation); + addEvent(moduleFilter, "reset", function () { + + // Let the reset happen, then update styles + window.setTimeout(selectionChange); + }); + + // Enables show/hide for the dropdown + function searchFocus() { + if (dropDown.style.display !== "none") { + return; + } + + dropDown.style.display = "block"; + addEvent(document$$1, "click", hideHandler); + addEvent(document$$1, "keydown", hideHandler); + + // Hide on Escape keydown or outside-container click + function hideHandler(e) { + var inContainer = moduleFilter.contains(e.target); + + if (e.keyCode === 27 || !inContainer) { + if (e.keyCode === 27 && inContainer) { + moduleSearch.focus(); + } + dropDown.style.display = "none"; + removeEvent(document$$1, "click", hideHandler); + removeEvent(document$$1, "keydown", hideHandler); + moduleSearch.value = ""; + searchInput(); + } + } + } + + // Processes module search box input + function searchInput() { + var i, + item, + searchText = moduleSearch.value.toLowerCase(), + listItems = dropDownList.children; + + for (i = 0; i < listItems.length; i++) { + item = listItems[i]; + if (!searchText || item.textContent.toLowerCase().indexOf(searchText) > -1) { + item.style.display = ""; + } else { + item.style.display = "none"; + } + } + } + + // Processes selection changes + function selectionChange(evt) { + var i, + item, + checkbox = evt && evt.target || allCheckbox, + modulesList = dropDownList.getElementsByTagName("input"), + selectedNames = []; + + toggleClass(checkbox.parentNode, "checked", checkbox.checked); + + dirty = false; + if (checkbox.checked && checkbox !== allCheckbox) { + allCheckbox.checked = false; + removeClass(allCheckbox.parentNode, "checked"); + } + for (i = 0; i < modulesList.length; i++) { + item = modulesList[i]; + if (!evt) { + toggleClass(item.parentNode, "checked", item.checked); + } else if (checkbox === allCheckbox && checkbox.checked) { + item.checked = false; + removeClass(item.parentNode, "checked"); + } + dirty = dirty || item.checked !== item.defaultChecked; + if (item.checked) { + selectedNames.push(item.parentNode.textContent); + } + } + + commit.style.display = reset.style.display = dirty ? "" : "none"; + moduleSearch.placeholder = selectedNames.join(", ") || allCheckbox.parentNode.textContent; + moduleSearch.title = "Type to filter list. Current selection:\n" + (selectedNames.join("\n") || allCheckbox.parentNode.textContent); + } + + return moduleFilter; + } + + function appendToolbar() { + var toolbar = id("qunit-testrunner-toolbar"); + + if (toolbar) { + toolbar.appendChild(toolbarUrlConfigContainer()); + toolbar.appendChild(toolbarModuleFilter()); + toolbar.appendChild(toolbarLooseFilter()); + toolbar.appendChild(document$$1.createElement("div")).className = "clearfix"; + } + } + + function appendHeader() { + var header = id("qunit-header"); + + if (header) { + header.innerHTML = "" + header.innerHTML + " "; + } + } + + function appendBanner() { + var banner = id("qunit-banner"); + + if (banner) { + banner.className = ""; + } + } + + function appendTestResults() { + var tests = id("qunit-tests"), + result = id("qunit-testresult"), + controls; + + if (result) { + result.parentNode.removeChild(result); + } + + if (tests) { + tests.innerHTML = ""; + result = document$$1.createElement("p"); + result.id = "qunit-testresult"; + result.className = "result"; + tests.parentNode.insertBefore(result, tests); + result.innerHTML = "
    Running...
     
    " + "
    " + "
    "; + controls = id("qunit-testresult-controls"); + } + + if (controls) { + controls.appendChild(abortTestsButton()); + } + } + + function appendFilteredTest() { + var testId = QUnit.config.testId; + if (!testId || testId.length <= 0) { + return ""; + } + return "
    Rerunning selected tests: " + escapeText(testId.join(", ")) + " Run all tests
    "; + } + + function appendUserAgent() { + var userAgent = id("qunit-userAgent"); + + if (userAgent) { + userAgent.innerHTML = ""; + userAgent.appendChild(document$$1.createTextNode("QUnit " + QUnit.version + "; " + navigator.userAgent)); + } + } + + function appendInterface() { + var qunit = id("qunit"); + + if (qunit) { + qunit.innerHTML = "

    " + escapeText(document$$1.title) + "

    " + "

    " + "
    " + appendFilteredTest() + "

    " + "
      "; + } + + appendHeader(); + appendBanner(); + appendTestResults(); + appendUserAgent(); + appendToolbar(); + } + + function appendTestsList(modules) { + var i, l, x, z, test, moduleObj; + + for (i = 0, l = modules.length; i < l; i++) { + moduleObj = modules[i]; + + for (x = 0, z = moduleObj.tests.length; x < z; x++) { + test = moduleObj.tests[x]; + + appendTest(test.name, test.testId, moduleObj.name); + } + } + } + + function appendTest(name, testId, moduleName) { + var title, + rerunTrigger, + testBlock, + assertList, + tests = id("qunit-tests"); + + if (!tests) { + return; + } + + title = document$$1.createElement("strong"); + title.innerHTML = getNameHtml(name, moduleName); + + rerunTrigger = document$$1.createElement("a"); + rerunTrigger.innerHTML = "Rerun"; + rerunTrigger.href = setUrl({ testId: testId }); + + testBlock = document$$1.createElement("li"); + testBlock.appendChild(title); + testBlock.appendChild(rerunTrigger); + testBlock.id = "qunit-test-output-" + testId; + + assertList = document$$1.createElement("ol"); + assertList.className = "qunit-assert-list"; + + testBlock.appendChild(assertList); + + tests.appendChild(testBlock); + } + + // HTML Reporter initialization and load + QUnit.begin(function (details) { + var i, moduleObj, tests; + + // Sort modules by name for the picker + for (i = 0; i < details.modules.length; i++) { + moduleObj = details.modules[i]; + if (moduleObj.name) { + modulesList.push(moduleObj.name); + } + } + modulesList.sort(function (a, b) { + return a.localeCompare(b); + }); + + // Initialize QUnit elements + appendInterface(); + appendTestsList(details.modules); + tests = id("qunit-tests"); + if (tests && config.hidepassed) { + addClass(tests, "hidepass"); + } + }); + + QUnit.done(function (details) { + var banner = id("qunit-banner"), + tests = id("qunit-tests"), + abortButton = id("qunit-abort-tests-button"), + totalTests = stats.passedTests + stats.skippedTests + stats.todoTests + stats.failedTests, + html = [totalTests, " tests completed in ", details.runtime, " milliseconds, with ", stats.failedTests, " failed, ", stats.skippedTests, " skipped, and ", stats.todoTests, " todo.
      ", "", details.passed, " assertions of ", details.total, " passed, ", details.failed, " failed."].join(""), + test, + assertLi, + assertList; + + // Update remaing tests to aborted + if (abortButton && abortButton.disabled) { + html = "Tests aborted after " + details.runtime + " milliseconds."; + + for (var i = 0; i < tests.children.length; i++) { + test = tests.children[i]; + if (test.className === "" || test.className === "running") { + test.className = "aborted"; + assertList = test.getElementsByTagName("ol")[0]; + assertLi = document$$1.createElement("li"); + assertLi.className = "fail"; + assertLi.innerHTML = "Test aborted."; + assertList.appendChild(assertLi); + } + } + } + + if (banner && (!abortButton || abortButton.disabled === false)) { + banner.className = stats.failedTests ? "qunit-fail" : "qunit-pass"; + } + + if (abortButton) { + abortButton.parentNode.removeChild(abortButton); + } + + if (tests) { + id("qunit-testresult-display").innerHTML = html; + } + + if (config.altertitle && document$$1.title) { + + // Show ✖ for good, ✔ for bad suite result in title + // use escape sequences in case file gets loaded with non-utf-8-charset + document$$1.title = [stats.failedTests ? "\u2716" : "\u2714", document$$1.title.replace(/^[\u2714\u2716] /i, "")].join(" "); + } + + // Scroll back to top to show results + if (config.scrolltop && window.scrollTo) { + window.scrollTo(0, 0); + } + }); + + function getNameHtml(name, module) { + var nameHtml = ""; + + if (module) { + nameHtml = "" + escapeText(module) + ": "; + } + + nameHtml += "" + escapeText(name) + ""; + + return nameHtml; + } + + QUnit.testStart(function (details) { + var running, testBlock, bad; + + testBlock = id("qunit-test-output-" + details.testId); + if (testBlock) { + testBlock.className = "running"; + } else { + + // Report later registered tests + appendTest(details.name, details.testId, details.module); + } + + running = id("qunit-testresult-display"); + if (running) { + bad = QUnit.config.reorder && details.previousFailure; + + running.innerHTML = (bad ? "Rerunning previously failed test:
      " : "Running:
      ") + getNameHtml(details.name, details.module); + } + }); + + function stripHtml(string) { + + // Strip tags, html entity and whitespaces + return string.replace(/<\/?[^>]+(>|$)/g, "").replace(/\"/g, "").replace(/\s+/g, ""); + } + + QUnit.log(function (details) { + var assertList, + assertLi, + message, + expected, + actual, + diff, + showDiff = false, + testItem = id("qunit-test-output-" + details.testId); + + if (!testItem) { + return; + } + + message = escapeText(details.message) || (details.result ? "okay" : "failed"); + message = "" + message + ""; + message += "@ " + details.runtime + " ms"; + + // The pushFailure doesn't provide details.expected + // when it calls, it's implicit to also not show expected and diff stuff + // Also, we need to check details.expected existence, as it can exist and be undefined + if (!details.result && hasOwn.call(details, "expected")) { + if (details.negative) { + expected = "NOT " + QUnit.dump.parse(details.expected); + } else { + expected = QUnit.dump.parse(details.expected); + } + + actual = QUnit.dump.parse(details.actual); + message += ""; + + if (actual !== expected) { + + message += ""; + + if (typeof details.actual === "number" && typeof details.expected === "number") { + if (!isNaN(details.actual) && !isNaN(details.expected)) { + showDiff = true; + diff = details.actual - details.expected; + diff = (diff > 0 ? "+" : "") + diff; + } + } else if (typeof details.actual !== "boolean" && typeof details.expected !== "boolean") { + diff = QUnit.diff(expected, actual); + + // don't show diff if there is zero overlap + showDiff = stripHtml(diff).length !== stripHtml(expected).length + stripHtml(actual).length; + } + + if (showDiff) { + message += ""; + } + } else if (expected.indexOf("[object Array]") !== -1 || expected.indexOf("[object Object]") !== -1) { + message += ""; + } else { + message += ""; + } + + if (details.source) { + message += ""; + } + + message += "
      Expected:
      " + escapeText(expected) + "
      Result:
      " + escapeText(actual) + "
      Diff:
      " + diff + "
      Message: " + "Diff suppressed as the depth of object is more than current max depth (" + QUnit.config.maxDepth + ").

      Hint: Use QUnit.dump.maxDepth to " + " run with a higher max depth or " + "Rerun without max depth.

      Message: " + "Diff suppressed as the expected and actual results have an equivalent" + " serialization
      Source:
      " + escapeText(details.source) + "
      "; + + // This occurs when pushFailure is set and we have an extracted stack trace + } else if (!details.result && details.source) { + message += "" + "" + "
      Source:
      " + escapeText(details.source) + "
      "; + } + + assertList = testItem.getElementsByTagName("ol")[0]; + + assertLi = document$$1.createElement("li"); + assertLi.className = details.result ? "pass" : "fail"; + assertLi.innerHTML = message; + assertList.appendChild(assertLi); + }); + + QUnit.testDone(function (details) { + var testTitle, + time, + testItem, + assertList, + good, + bad, + testCounts, + skipped, + sourceName, + tests = id("qunit-tests"); + + if (!tests) { + return; + } + + testItem = id("qunit-test-output-" + details.testId); + + assertList = testItem.getElementsByTagName("ol")[0]; + + good = details.passed; + bad = details.failed; + + // This test passed if it has no unexpected failed assertions + var testPassed = details.failed > 0 ? details.todo : !details.todo; + + if (testPassed) { + + // Collapse the passing tests + addClass(assertList, "qunit-collapsed"); + } else if (config.collapse) { + if (!collapseNext) { + + // Skip collapsing the first failing test + collapseNext = true; + } else { + + // Collapse remaining tests + addClass(assertList, "qunit-collapsed"); + } + } + + // The testItem.firstChild is the test name + testTitle = testItem.firstChild; + + testCounts = bad ? "" + bad + ", " + "" + good + ", " : ""; + + testTitle.innerHTML += " (" + testCounts + details.assertions.length + ")"; + + if (details.skipped) { + stats.skippedTests++; + + testItem.className = "skipped"; + skipped = document$$1.createElement("em"); + skipped.className = "qunit-skipped-label"; + skipped.innerHTML = "skipped"; + testItem.insertBefore(skipped, testTitle); + } else { + addEvent(testTitle, "click", function () { + toggleClass(assertList, "qunit-collapsed"); + }); + + testItem.className = testPassed ? "pass" : "fail"; + + if (details.todo) { + var todoLabel = document$$1.createElement("em"); + todoLabel.className = "qunit-todo-label"; + todoLabel.innerHTML = "todo"; + testItem.className += " todo"; + testItem.insertBefore(todoLabel, testTitle); + } + + time = document$$1.createElement("span"); + time.className = "runtime"; + time.innerHTML = details.runtime + " ms"; + testItem.insertBefore(time, assertList); + + if (!testPassed) { + stats.failedTests++; + } else if (details.todo) { + stats.todoTests++; + } else { + stats.passedTests++; + } + } + + // Show the source of the test when showing assertions + if (details.source) { + sourceName = document$$1.createElement("p"); + sourceName.innerHTML = "Source: " + details.source; + addClass(sourceName, "qunit-source"); + if (testPassed) { + addClass(sourceName, "qunit-collapsed"); + } + addEvent(testTitle, "click", function () { + toggleClass(sourceName, "qunit-collapsed"); + }); + testItem.appendChild(sourceName); + } + }); + + // Avoid readyState issue with phantomjs + // Ref: #818 + var notPhantom = function (p) { + return !(p && p.version && p.version.major > 0); + }(window.phantom); + + if (notPhantom && document$$1.readyState === "complete") { + QUnit.load(); + } else { + addEvent(window, "load", QUnit.load); + } + + // Wrap window.onerror. We will call the original window.onerror to see if + // the existing handler fully handles the error; if not, we will call the + // QUnit.onError function. + var originalWindowOnError = window.onerror; + + // Cover uncaught exceptions + // Returning true will suppress the default browser handler, + // returning false will let it run. + window.onerror = function (message, fileName, lineNumber) { + var ret = false; + if (originalWindowOnError) { + for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { + args[_key - 3] = arguments[_key]; + } + + ret = originalWindowOnError.call.apply(originalWindowOnError, [this, message, fileName, lineNumber].concat(args)); + } + + // Treat return value as window.onerror itself does, + // Only do our handling if not suppressed. + if (ret !== true) { + var error = { + message: message, + fileName: fileName, + lineNumber: lineNumber + }; + + ret = QUnit.onError(error); + } + + return ret; + }; + })(); + + /* + * This file is a modified version of google-diff-match-patch's JavaScript implementation + * (https://code.google.com/p/google-diff-match-patch/source/browse/trunk/javascript/diff_match_patch_uncompressed.js), + * modifications are licensed as more fully set forth in LICENSE.txt. + * + * The original source of google-diff-match-patch is attributable and licensed as follows: + * + * Copyright 2006 Google Inc. + * https://code.google.com/p/google-diff-match-patch/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * More Info: + * https://code.google.com/p/google-diff-match-patch/ + * + * Usage: QUnit.diff(expected, actual) + * + */ + QUnit.diff = function () { + function DiffMatchPatch() {} + + // DIFF FUNCTIONS + + /** + * The data structure representing a diff is an array of tuples: + * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']] + * which means: delete 'Hello', add 'Goodbye' and keep ' world.' + */ + var DIFF_DELETE = -1, + DIFF_INSERT = 1, + DIFF_EQUAL = 0; + + /** + * Find the differences between two texts. Simplifies the problem by stripping + * any common prefix or suffix off the texts before diffing. + * @param {string} text1 Old string to be diffed. + * @param {string} text2 New string to be diffed. + * @param {boolean=} optChecklines Optional speedup flag. If present and false, + * then don't run a line-level diff first to identify the changed areas. + * Defaults to true, which does a faster, slightly less optimal diff. + * @return {!Array.} Array of diff tuples. + */ + DiffMatchPatch.prototype.DiffMain = function (text1, text2, optChecklines) { + var deadline, checklines, commonlength, commonprefix, commonsuffix, diffs; + + // The diff must be complete in up to 1 second. + deadline = new Date().getTime() + 1000; + + // Check for null inputs. + if (text1 === null || text2 === null) { + throw new Error("Null input. (DiffMain)"); + } + + // Check for equality (speedup). + if (text1 === text2) { + if (text1) { + return [[DIFF_EQUAL, text1]]; + } + return []; + } + + if (typeof optChecklines === "undefined") { + optChecklines = true; + } + + checklines = optChecklines; + + // Trim off common prefix (speedup). + commonlength = this.diffCommonPrefix(text1, text2); + commonprefix = text1.substring(0, commonlength); + text1 = text1.substring(commonlength); + text2 = text2.substring(commonlength); + + // Trim off common suffix (speedup). + commonlength = this.diffCommonSuffix(text1, text2); + commonsuffix = text1.substring(text1.length - commonlength); + text1 = text1.substring(0, text1.length - commonlength); + text2 = text2.substring(0, text2.length - commonlength); + + // Compute the diff on the middle block. + diffs = this.diffCompute(text1, text2, checklines, deadline); + + // Restore the prefix and suffix. + if (commonprefix) { + diffs.unshift([DIFF_EQUAL, commonprefix]); + } + if (commonsuffix) { + diffs.push([DIFF_EQUAL, commonsuffix]); + } + this.diffCleanupMerge(diffs); + return diffs; + }; + + /** + * Reduce the number of edits by eliminating operationally trivial equalities. + * @param {!Array.} diffs Array of diff tuples. + */ + DiffMatchPatch.prototype.diffCleanupEfficiency = function (diffs) { + var changes, equalities, equalitiesLength, lastequality, pointer, preIns, preDel, postIns, postDel; + changes = false; + equalities = []; // Stack of indices where equalities are found. + equalitiesLength = 0; // Keeping our own length var is faster in JS. + /** @type {?string} */ + lastequality = null; + + // Always equal to diffs[equalities[equalitiesLength - 1]][1] + pointer = 0; // Index of current position. + + // Is there an insertion operation before the last equality. + preIns = false; + + // Is there a deletion operation before the last equality. + preDel = false; + + // Is there an insertion operation after the last equality. + postIns = false; + + // Is there a deletion operation after the last equality. + postDel = false; + while (pointer < diffs.length) { + + // Equality found. + if (diffs[pointer][0] === DIFF_EQUAL) { + if (diffs[pointer][1].length < 4 && (postIns || postDel)) { + + // Candidate found. + equalities[equalitiesLength++] = pointer; + preIns = postIns; + preDel = postDel; + lastequality = diffs[pointer][1]; + } else { + + // Not a candidate, and can never become one. + equalitiesLength = 0; + lastequality = null; + } + postIns = postDel = false; + + // An insertion or deletion. + } else { + + if (diffs[pointer][0] === DIFF_DELETE) { + postDel = true; + } else { + postIns = true; + } + + /* + * Five types to be split: + * ABXYCD + * AXCD + * ABXC + * AXCD + * ABXC + */ + if (lastequality && (preIns && preDel && postIns && postDel || lastequality.length < 2 && preIns + preDel + postIns + postDel === 3)) { + + // Duplicate record. + diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]); + + // Change second copy to insert. + diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; + equalitiesLength--; // Throw away the equality we just deleted; + lastequality = null; + if (preIns && preDel) { + + // No changes made which could affect previous entry, keep going. + postIns = postDel = true; + equalitiesLength = 0; + } else { + equalitiesLength--; // Throw away the previous equality. + pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; + postIns = postDel = false; + } + changes = true; + } + } + pointer++; + } + + if (changes) { + this.diffCleanupMerge(diffs); + } + }; + + /** + * Convert a diff array into a pretty HTML report. + * @param {!Array.} diffs Array of diff tuples. + * @param {integer} string to be beautified. + * @return {string} HTML representation. + */ + DiffMatchPatch.prototype.diffPrettyHtml = function (diffs) { + var op, + data, + x, + html = []; + for (x = 0; x < diffs.length; x++) { + op = diffs[x][0]; // Operation (insert, delete, equal) + data = diffs[x][1]; // Text of change. + switch (op) { + case DIFF_INSERT: + html[x] = "" + escapeText(data) + ""; + break; + case DIFF_DELETE: + html[x] = "" + escapeText(data) + ""; + break; + case DIFF_EQUAL: + html[x] = "" + escapeText(data) + ""; + break; + } + } + return html.join(""); + }; + + /** + * Determine the common prefix of two strings. + * @param {string} text1 First string. + * @param {string} text2 Second string. + * @return {number} The number of characters common to the start of each + * string. + */ + DiffMatchPatch.prototype.diffCommonPrefix = function (text1, text2) { + var pointermid, pointermax, pointermin, pointerstart; + + // Quick check for common null cases. + if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) { + return 0; + } + + // Binary search. + // Performance analysis: https://neil.fraser.name/news/2007/10/09/ + pointermin = 0; + pointermax = Math.min(text1.length, text2.length); + pointermid = pointermax; + pointerstart = 0; + while (pointermin < pointermid) { + if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) { + pointermin = pointermid; + pointerstart = pointermin; + } else { + pointermax = pointermid; + } + pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); + } + return pointermid; + }; + + /** + * Determine the common suffix of two strings. + * @param {string} text1 First string. + * @param {string} text2 Second string. + * @return {number} The number of characters common to the end of each string. + */ + DiffMatchPatch.prototype.diffCommonSuffix = function (text1, text2) { + var pointermid, pointermax, pointermin, pointerend; + + // Quick check for common null cases. + if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) { + return 0; + } + + // Binary search. + // Performance analysis: https://neil.fraser.name/news/2007/10/09/ + pointermin = 0; + pointermax = Math.min(text1.length, text2.length); + pointermid = pointermax; + pointerend = 0; + while (pointermin < pointermid) { + if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) { + pointermin = pointermid; + pointerend = pointermin; + } else { + pointermax = pointermid; + } + pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin); + } + return pointermid; + }; + + /** + * Find the differences between two texts. Assumes that the texts do not + * have any common prefix or suffix. + * @param {string} text1 Old string to be diffed. + * @param {string} text2 New string to be diffed. + * @param {boolean} checklines Speedup flag. If false, then don't run a + * line-level diff first to identify the changed areas. + * If true, then run a faster, slightly less optimal diff. + * @param {number} deadline Time when the diff should be complete by. + * @return {!Array.} Array of diff tuples. + * @private + */ + DiffMatchPatch.prototype.diffCompute = function (text1, text2, checklines, deadline) { + var diffs, longtext, shorttext, i, hm, text1A, text2A, text1B, text2B, midCommon, diffsA, diffsB; + + if (!text1) { + + // Just add some text (speedup). + return [[DIFF_INSERT, text2]]; + } + + if (!text2) { + + // Just delete some text (speedup). + return [[DIFF_DELETE, text1]]; + } + + longtext = text1.length > text2.length ? text1 : text2; + shorttext = text1.length > text2.length ? text2 : text1; + i = longtext.indexOf(shorttext); + if (i !== -1) { + + // Shorter text is inside the longer text (speedup). + diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]]; + + // Swap insertions for deletions if diff is reversed. + if (text1.length > text2.length) { + diffs[0][0] = diffs[2][0] = DIFF_DELETE; + } + return diffs; + } + + if (shorttext.length === 1) { + + // Single character string. + // After the previous speedup, the character can't be an equality. + return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; + } + + // Check to see if the problem can be split in two. + hm = this.diffHalfMatch(text1, text2); + if (hm) { + + // A half-match was found, sort out the return data. + text1A = hm[0]; + text1B = hm[1]; + text2A = hm[2]; + text2B = hm[3]; + midCommon = hm[4]; + + // Send both pairs off for separate processing. + diffsA = this.DiffMain(text1A, text2A, checklines, deadline); + diffsB = this.DiffMain(text1B, text2B, checklines, deadline); + + // Merge the results. + return diffsA.concat([[DIFF_EQUAL, midCommon]], diffsB); + } + + if (checklines && text1.length > 100 && text2.length > 100) { + return this.diffLineMode(text1, text2, deadline); + } + + return this.diffBisect(text1, text2, deadline); + }; + + /** + * Do the two texts share a substring which is at least half the length of the + * longer text? + * This speedup can produce non-minimal diffs. + * @param {string} text1 First string. + * @param {string} text2 Second string. + * @return {Array.} Five element Array, containing the prefix of + * text1, the suffix of text1, the prefix of text2, the suffix of + * text2 and the common middle. Or null if there was no match. + * @private + */ + DiffMatchPatch.prototype.diffHalfMatch = function (text1, text2) { + var longtext, shorttext, dmp, text1A, text2B, text2A, text1B, midCommon, hm1, hm2, hm; + + longtext = text1.length > text2.length ? text1 : text2; + shorttext = text1.length > text2.length ? text2 : text1; + if (longtext.length < 4 || shorttext.length * 2 < longtext.length) { + return null; // Pointless. + } + dmp = this; // 'this' becomes 'window' in a closure. + + /** + * Does a substring of shorttext exist within longtext such that the substring + * is at least half the length of longtext? + * Closure, but does not reference any external variables. + * @param {string} longtext Longer string. + * @param {string} shorttext Shorter string. + * @param {number} i Start index of quarter length substring within longtext. + * @return {Array.} Five element Array, containing the prefix of + * longtext, the suffix of longtext, the prefix of shorttext, the suffix + * of shorttext and the common middle. Or null if there was no match. + * @private + */ + function diffHalfMatchI(longtext, shorttext, i) { + var seed, j, bestCommon, prefixLength, suffixLength, bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB; + + // Start with a 1/4 length substring at position i as a seed. + seed = longtext.substring(i, i + Math.floor(longtext.length / 4)); + j = -1; + bestCommon = ""; + while ((j = shorttext.indexOf(seed, j + 1)) !== -1) { + prefixLength = dmp.diffCommonPrefix(longtext.substring(i), shorttext.substring(j)); + suffixLength = dmp.diffCommonSuffix(longtext.substring(0, i), shorttext.substring(0, j)); + if (bestCommon.length < suffixLength + prefixLength) { + bestCommon = shorttext.substring(j - suffixLength, j) + shorttext.substring(j, j + prefixLength); + bestLongtextA = longtext.substring(0, i - suffixLength); + bestLongtextB = longtext.substring(i + prefixLength); + bestShorttextA = shorttext.substring(0, j - suffixLength); + bestShorttextB = shorttext.substring(j + prefixLength); + } + } + if (bestCommon.length * 2 >= longtext.length) { + return [bestLongtextA, bestLongtextB, bestShorttextA, bestShorttextB, bestCommon]; + } else { + return null; + } + } + + // First check if the second quarter is the seed for a half-match. + hm1 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 4)); + + // Check again based on the third quarter. + hm2 = diffHalfMatchI(longtext, shorttext, Math.ceil(longtext.length / 2)); + if (!hm1 && !hm2) { + return null; + } else if (!hm2) { + hm = hm1; + } else if (!hm1) { + hm = hm2; + } else { + + // Both matched. Select the longest. + hm = hm1[4].length > hm2[4].length ? hm1 : hm2; + } + + // A half-match was found, sort out the return data. + if (text1.length > text2.length) { + text1A = hm[0]; + text1B = hm[1]; + text2A = hm[2]; + text2B = hm[3]; + } else { + text2A = hm[0]; + text2B = hm[1]; + text1A = hm[2]; + text1B = hm[3]; + } + midCommon = hm[4]; + return [text1A, text1B, text2A, text2B, midCommon]; + }; + + /** + * Do a quick line-level diff on both strings, then rediff the parts for + * greater accuracy. + * This speedup can produce non-minimal diffs. + * @param {string} text1 Old string to be diffed. + * @param {string} text2 New string to be diffed. + * @param {number} deadline Time when the diff should be complete by. + * @return {!Array.} Array of diff tuples. + * @private + */ + DiffMatchPatch.prototype.diffLineMode = function (text1, text2, deadline) { + var a, diffs, linearray, pointer, countInsert, countDelete, textInsert, textDelete, j; + + // Scan the text on a line-by-line basis first. + a = this.diffLinesToChars(text1, text2); + text1 = a.chars1; + text2 = a.chars2; + linearray = a.lineArray; + + diffs = this.DiffMain(text1, text2, false, deadline); + + // Convert the diff back to original text. + this.diffCharsToLines(diffs, linearray); + + // Eliminate freak matches (e.g. blank lines) + this.diffCleanupSemantic(diffs); + + // Rediff any replacement blocks, this time character-by-character. + // Add a dummy entry at the end. + diffs.push([DIFF_EQUAL, ""]); + pointer = 0; + countDelete = 0; + countInsert = 0; + textDelete = ""; + textInsert = ""; + while (pointer < diffs.length) { + switch (diffs[pointer][0]) { + case DIFF_INSERT: + countInsert++; + textInsert += diffs[pointer][1]; + break; + case DIFF_DELETE: + countDelete++; + textDelete += diffs[pointer][1]; + break; + case DIFF_EQUAL: + + // Upon reaching an equality, check for prior redundancies. + if (countDelete >= 1 && countInsert >= 1) { + + // Delete the offending records and add the merged ones. + diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert); + pointer = pointer - countDelete - countInsert; + a = this.DiffMain(textDelete, textInsert, false, deadline); + for (j = a.length - 1; j >= 0; j--) { + diffs.splice(pointer, 0, a[j]); + } + pointer = pointer + a.length; + } + countInsert = 0; + countDelete = 0; + textDelete = ""; + textInsert = ""; + break; + } + pointer++; + } + diffs.pop(); // Remove the dummy entry at the end. + + return diffs; + }; + + /** + * Find the 'middle snake' of a diff, split the problem in two + * and return the recursively constructed diff. + * See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. + * @param {string} text1 Old string to be diffed. + * @param {string} text2 New string to be diffed. + * @param {number} deadline Time at which to bail if not yet complete. + * @return {!Array.} Array of diff tuples. + * @private + */ + DiffMatchPatch.prototype.diffBisect = function (text1, text2, deadline) { + var text1Length, text2Length, maxD, vOffset, vLength, v1, v2, x, delta, front, k1start, k1end, k2start, k2end, k2Offset, k1Offset, x1, x2, y1, y2, d, k1, k2; + + // Cache the text lengths to prevent multiple calls. + text1Length = text1.length; + text2Length = text2.length; + maxD = Math.ceil((text1Length + text2Length) / 2); + vOffset = maxD; + vLength = 2 * maxD; + v1 = new Array(vLength); + v2 = new Array(vLength); + + // Setting all elements to -1 is faster in Chrome & Firefox than mixing + // integers and undefined. + for (x = 0; x < vLength; x++) { + v1[x] = -1; + v2[x] = -1; + } + v1[vOffset + 1] = 0; + v2[vOffset + 1] = 0; + delta = text1Length - text2Length; + + // If the total number of characters is odd, then the front path will collide + // with the reverse path. + front = delta % 2 !== 0; + + // Offsets for start and end of k loop. + // Prevents mapping of space beyond the grid. + k1start = 0; + k1end = 0; + k2start = 0; + k2end = 0; + for (d = 0; d < maxD; d++) { + + // Bail out if deadline is reached. + if (new Date().getTime() > deadline) { + break; + } + + // Walk the front path one step. + for (k1 = -d + k1start; k1 <= d - k1end; k1 += 2) { + k1Offset = vOffset + k1; + if (k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1]) { + x1 = v1[k1Offset + 1]; + } else { + x1 = v1[k1Offset - 1] + 1; + } + y1 = x1 - k1; + while (x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1)) { + x1++; + y1++; + } + v1[k1Offset] = x1; + if (x1 > text1Length) { + + // Ran off the right of the graph. + k1end += 2; + } else if (y1 > text2Length) { + + // Ran off the bottom of the graph. + k1start += 2; + } else if (front) { + k2Offset = vOffset + delta - k1; + if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) { + + // Mirror x2 onto top-left coordinate system. + x2 = text1Length - v2[k2Offset]; + if (x1 >= x2) { + + // Overlap detected. + return this.diffBisectSplit(text1, text2, x1, y1, deadline); + } + } + } + } + + // Walk the reverse path one step. + for (k2 = -d + k2start; k2 <= d - k2end; k2 += 2) { + k2Offset = vOffset + k2; + if (k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1]) { + x2 = v2[k2Offset + 1]; + } else { + x2 = v2[k2Offset - 1] + 1; + } + y2 = x2 - k2; + while (x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1)) { + x2++; + y2++; + } + v2[k2Offset] = x2; + if (x2 > text1Length) { + + // Ran off the left of the graph. + k2end += 2; + } else if (y2 > text2Length) { + + // Ran off the top of the graph. + k2start += 2; + } else if (!front) { + k1Offset = vOffset + delta - k2; + if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) { + x1 = v1[k1Offset]; + y1 = vOffset + x1 - k1Offset; + + // Mirror x2 onto top-left coordinate system. + x2 = text1Length - x2; + if (x1 >= x2) { + + // Overlap detected. + return this.diffBisectSplit(text1, text2, x1, y1, deadline); + } + } + } + } + } + + // Diff took too long and hit the deadline or + // number of diffs equals number of characters, no commonality at all. + return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]]; + }; + + /** + * Given the location of the 'middle snake', split the diff in two parts + * and recurse. + * @param {string} text1 Old string to be diffed. + * @param {string} text2 New string to be diffed. + * @param {number} x Index of split point in text1. + * @param {number} y Index of split point in text2. + * @param {number} deadline Time at which to bail if not yet complete. + * @return {!Array.} Array of diff tuples. + * @private + */ + DiffMatchPatch.prototype.diffBisectSplit = function (text1, text2, x, y, deadline) { + var text1a, text1b, text2a, text2b, diffs, diffsb; + text1a = text1.substring(0, x); + text2a = text2.substring(0, y); + text1b = text1.substring(x); + text2b = text2.substring(y); + + // Compute both diffs serially. + diffs = this.DiffMain(text1a, text2a, false, deadline); + diffsb = this.DiffMain(text1b, text2b, false, deadline); + + return diffs.concat(diffsb); + }; + + /** + * Reduce the number of edits by eliminating semantically trivial equalities. + * @param {!Array.} diffs Array of diff tuples. + */ + DiffMatchPatch.prototype.diffCleanupSemantic = function (diffs) { + var changes, equalities, equalitiesLength, lastequality, pointer, lengthInsertions2, lengthDeletions2, lengthInsertions1, lengthDeletions1, deletion, insertion, overlapLength1, overlapLength2; + changes = false; + equalities = []; // Stack of indices where equalities are found. + equalitiesLength = 0; // Keeping our own length var is faster in JS. + /** @type {?string} */ + lastequality = null; + + // Always equal to diffs[equalities[equalitiesLength - 1]][1] + pointer = 0; // Index of current position. + + // Number of characters that changed prior to the equality. + lengthInsertions1 = 0; + lengthDeletions1 = 0; + + // Number of characters that changed after the equality. + lengthInsertions2 = 0; + lengthDeletions2 = 0; + while (pointer < diffs.length) { + if (diffs[pointer][0] === DIFF_EQUAL) { + // Equality found. + equalities[equalitiesLength++] = pointer; + lengthInsertions1 = lengthInsertions2; + lengthDeletions1 = lengthDeletions2; + lengthInsertions2 = 0; + lengthDeletions2 = 0; + lastequality = diffs[pointer][1]; + } else { + // An insertion or deletion. + if (diffs[pointer][0] === DIFF_INSERT) { + lengthInsertions2 += diffs[pointer][1].length; + } else { + lengthDeletions2 += diffs[pointer][1].length; + } + + // Eliminate an equality that is smaller or equal to the edits on both + // sides of it. + if (lastequality && lastequality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastequality.length <= Math.max(lengthInsertions2, lengthDeletions2)) { + + // Duplicate record. + diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastequality]); + + // Change second copy to insert. + diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT; + + // Throw away the equality we just deleted. + equalitiesLength--; + + // Throw away the previous equality (it needs to be reevaluated). + equalitiesLength--; + pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1; + + // Reset the counters. + lengthInsertions1 = 0; + lengthDeletions1 = 0; + lengthInsertions2 = 0; + lengthDeletions2 = 0; + lastequality = null; + changes = true; + } + } + pointer++; + } + + // Normalize the diff. + if (changes) { + this.diffCleanupMerge(diffs); + } + + // Find any overlaps between deletions and insertions. + // e.g: abcxxxxxxdef + // -> abcxxxdef + // e.g: xxxabcdefxxx + // -> defxxxabc + // Only extract an overlap if it is as big as the edit ahead or behind it. + pointer = 1; + while (pointer < diffs.length) { + if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) { + deletion = diffs[pointer - 1][1]; + insertion = diffs[pointer][1]; + overlapLength1 = this.diffCommonOverlap(deletion, insertion); + overlapLength2 = this.diffCommonOverlap(insertion, deletion); + if (overlapLength1 >= overlapLength2) { + if (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) { + + // Overlap found. Insert an equality and trim the surrounding edits. + diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]); + diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1); + diffs[pointer + 1][1] = insertion.substring(overlapLength1); + pointer++; + } + } else { + if (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) { + + // Reverse overlap found. + // Insert an equality and swap and trim the surrounding edits. + diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]); + + diffs[pointer - 1][0] = DIFF_INSERT; + diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2); + diffs[pointer + 1][0] = DIFF_DELETE; + diffs[pointer + 1][1] = deletion.substring(overlapLength2); + pointer++; + } + } + pointer++; + } + pointer++; + } + }; + + /** + * Determine if the suffix of one string is the prefix of another. + * @param {string} text1 First string. + * @param {string} text2 Second string. + * @return {number} The number of characters common to the end of the first + * string and the start of the second string. + * @private + */ + DiffMatchPatch.prototype.diffCommonOverlap = function (text1, text2) { + var text1Length, text2Length, textLength, best, length, pattern, found; + + // Cache the text lengths to prevent multiple calls. + text1Length = text1.length; + text2Length = text2.length; + + // Eliminate the null case. + if (text1Length === 0 || text2Length === 0) { + return 0; + } + + // Truncate the longer string. + if (text1Length > text2Length) { + text1 = text1.substring(text1Length - text2Length); + } else if (text1Length < text2Length) { + text2 = text2.substring(0, text1Length); + } + textLength = Math.min(text1Length, text2Length); + + // Quick check for the worst case. + if (text1 === text2) { + return textLength; + } + + // Start by looking for a single character match + // and increase length until no match is found. + // Performance analysis: https://neil.fraser.name/news/2010/11/04/ + best = 0; + length = 1; + while (true) { + pattern = text1.substring(textLength - length); + found = text2.indexOf(pattern); + if (found === -1) { + return best; + } + length += found; + if (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) { + best = length; + length++; + } + } + }; + + /** + * Split two texts into an array of strings. Reduce the texts to a string of + * hashes where each Unicode character represents one line. + * @param {string} text1 First string. + * @param {string} text2 Second string. + * @return {{chars1: string, chars2: string, lineArray: !Array.}} + * An object containing the encoded text1, the encoded text2 and + * the array of unique strings. + * The zeroth element of the array of unique strings is intentionally blank. + * @private + */ + DiffMatchPatch.prototype.diffLinesToChars = function (text1, text2) { + var lineArray, lineHash, chars1, chars2; + lineArray = []; // E.g. lineArray[4] === 'Hello\n' + lineHash = {}; // E.g. lineHash['Hello\n'] === 4 + + // '\x00' is a valid character, but various debuggers don't like it. + // So we'll insert a junk entry to avoid generating a null character. + lineArray[0] = ""; + + /** + * Split a text into an array of strings. Reduce the texts to a string of + * hashes where each Unicode character represents one line. + * Modifies linearray and linehash through being a closure. + * @param {string} text String to encode. + * @return {string} Encoded string. + * @private + */ + function diffLinesToCharsMunge(text) { + var chars, lineStart, lineEnd, lineArrayLength, line; + chars = ""; + + // Walk the text, pulling out a substring for each line. + // text.split('\n') would would temporarily double our memory footprint. + // Modifying text would create many large strings to garbage collect. + lineStart = 0; + lineEnd = -1; + + // Keeping our own length variable is faster than looking it up. + lineArrayLength = lineArray.length; + while (lineEnd < text.length - 1) { + lineEnd = text.indexOf("\n", lineStart); + if (lineEnd === -1) { + lineEnd = text.length - 1; + } + line = text.substring(lineStart, lineEnd + 1); + lineStart = lineEnd + 1; + + if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : lineHash[line] !== undefined) { + chars += String.fromCharCode(lineHash[line]); + } else { + chars += String.fromCharCode(lineArrayLength); + lineHash[line] = lineArrayLength; + lineArray[lineArrayLength++] = line; + } + } + return chars; + } + + chars1 = diffLinesToCharsMunge(text1); + chars2 = diffLinesToCharsMunge(text2); + return { + chars1: chars1, + chars2: chars2, + lineArray: lineArray + }; + }; + + /** + * Rehydrate the text in a diff from a string of line hashes to real lines of + * text. + * @param {!Array.} diffs Array of diff tuples. + * @param {!Array.} lineArray Array of unique strings. + * @private + */ + DiffMatchPatch.prototype.diffCharsToLines = function (diffs, lineArray) { + var x, chars, text, y; + for (x = 0; x < diffs.length; x++) { + chars = diffs[x][1]; + text = []; + for (y = 0; y < chars.length; y++) { + text[y] = lineArray[chars.charCodeAt(y)]; + } + diffs[x][1] = text.join(""); + } + }; + + /** + * Reorder and merge like edit sections. Merge equalities. + * Any edit section can move as long as it doesn't cross an equality. + * @param {!Array.} diffs Array of diff tuples. + */ + DiffMatchPatch.prototype.diffCleanupMerge = function (diffs) { + var pointer, countDelete, countInsert, textInsert, textDelete, commonlength, changes, diffPointer, position; + diffs.push([DIFF_EQUAL, ""]); // Add a dummy entry at the end. + pointer = 0; + countDelete = 0; + countInsert = 0; + textDelete = ""; + textInsert = ""; + + while (pointer < diffs.length) { + switch (diffs[pointer][0]) { + case DIFF_INSERT: + countInsert++; + textInsert += diffs[pointer][1]; + pointer++; + break; + case DIFF_DELETE: + countDelete++; + textDelete += diffs[pointer][1]; + pointer++; + break; + case DIFF_EQUAL: + + // Upon reaching an equality, check for prior redundancies. + if (countDelete + countInsert > 1) { + if (countDelete !== 0 && countInsert !== 0) { + + // Factor out any common prefixes. + commonlength = this.diffCommonPrefix(textInsert, textDelete); + if (commonlength !== 0) { + if (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL) { + diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength); + } else { + diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]); + pointer++; + } + textInsert = textInsert.substring(commonlength); + textDelete = textDelete.substring(commonlength); + } + + // Factor out any common suffixies. + commonlength = this.diffCommonSuffix(textInsert, textDelete); + if (commonlength !== 0) { + diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1]; + textInsert = textInsert.substring(0, textInsert.length - commonlength); + textDelete = textDelete.substring(0, textDelete.length - commonlength); + } + } + + // Delete the offending records and add the merged ones. + if (countDelete === 0) { + diffs.splice(pointer - countInsert, countDelete + countInsert, [DIFF_INSERT, textInsert]); + } else if (countInsert === 0) { + diffs.splice(pointer - countDelete, countDelete + countInsert, [DIFF_DELETE, textDelete]); + } else { + diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert, [DIFF_DELETE, textDelete], [DIFF_INSERT, textInsert]); + } + pointer = pointer - countDelete - countInsert + (countDelete ? 1 : 0) + (countInsert ? 1 : 0) + 1; + } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) { + + // Merge this equality with the previous one. + diffs[pointer - 1][1] += diffs[pointer][1]; + diffs.splice(pointer, 1); + } else { + pointer++; + } + countInsert = 0; + countDelete = 0; + textDelete = ""; + textInsert = ""; + break; + } + } + if (diffs[diffs.length - 1][1] === "") { + diffs.pop(); // Remove the dummy entry at the end. + } + + // Second pass: look for single edits surrounded on both sides by equalities + // which can be shifted sideways to eliminate an equality. + // e.g: ABAC -> ABAC + changes = false; + pointer = 1; + + // Intentionally ignore the first and last element (don't need checking). + while (pointer < diffs.length - 1) { + if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) { + + diffPointer = diffs[pointer][1]; + position = diffPointer.substring(diffPointer.length - diffs[pointer - 1][1].length); + + // This is a single edit surrounded by equalities. + if (position === diffs[pointer - 1][1]) { + + // Shift the edit over the previous equality. + diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length); + diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1]; + diffs.splice(pointer - 1, 1); + changes = true; + } else if (diffPointer.substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) { + + // Shift the edit over the next equality. + diffs[pointer - 1][1] += diffs[pointer + 1][1]; + diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1]; + diffs.splice(pointer + 1, 1); + changes = true; + } + } + pointer++; + } + + // If shifts were made, the diff needs reordering and another shift sweep. + if (changes) { + this.diffCleanupMerge(diffs); + } + }; + + return function (o, n) { + var diff, output, text; + diff = new DiffMatchPatch(); + output = diff.DiffMain(o, n); + diff.diffCleanupEfficiency(output); + text = diff.diffPrettyHtml(output); + + return text; + }; + }(); + +}((function() { return this; }())));