Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F27327244
TestingCtaDrawer
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Jdlrobson
Nov 29 2018, 11:30 PM
2018-11-29 23:30:13 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
TestingCtaDrawer
View Options
diff --git a/tests/node-qunit/mobile.startup/CtaDrawer.test.js b/tests/node-qunit/mobile.startup/CtaDrawer.test.js
new file mode 100644
index 000000000..caec52177
--- /dev/null
+++ b/tests/node-qunit/mobile.startup/CtaDrawer.test.js
@@ -0,0 +1,74 @@
+var
+ // Imports
+ CtaDrawer,
+ dom = require( '../utils/dom' ),
+ Drawer,
+ jQuery = require( '../utils/jQuery' ),
+ mw = require( '../utils/mw' ),
+ oo = require( '../utils/oo' ),
+ sandbox,
+ sinon = require( 'sinon' ),
+
+ // Variables
+ parent;
+
+function stripWhitespaceHTML( str ) {
+ return str.replace( /\s+/g, ' ' )
+ // strip spaces before opening tags
+ .replace( / </g, '<' );
+}
+QUnit.module( 'MobileFrontend CtaDrawer.js', {
+ beforeEach: function () {
+ var parentID = 'ctaDrawerParent';
+
+ sandbox = sinon.sandbox.create();
+
+ // Set up required by all Views.
+ dom.setUp( sandbox, global );
+ jQuery.setUp( sandbox, global );
+ oo.setUp( sandbox, global );
+
+ // Additional CtaDrawer global dependency.
+ mw.setUp( sandbox, global );
+
+ // Dynamically import Drawer and CtaDrawer to use fresh sandboxed dependencies.
+ Drawer = require( '../../../src/mobile.startup/Drawer' );
+ CtaDrawer = require( '../../../src/mobile.startup/CtaDrawer' );
+
+ sandbox.stub( global.mw, 'msg' )
+ .withArgs( 'mobile-frontend-watchlist-cta-button-login' )
+ .returns( 'login' )
+ .withArgs( 'mobile-frontend-watchlist-cta-button-signup' )
+ .returns( 'sign up' );
+ // Rewire the prototype, not the instance, since this property is used during construction.
+ sandbox.stub( Drawer.prototype, 'appendToElement', '#' + parentID );
+
+ // Create a disposable host Element. See T209129.
+ parent = document.createElement( 'div' );
+ parent.id = parentID;
+ document.documentElement.appendChild( parent );
+ },
+
+ afterEach: function () {
+ // Discard host Element.
+ document.documentElement.removeChild( parent );
+ parent = undefined;
+
+ CtaDrawer = undefined;
+ Drawer = undefined;
+
+ jQuery.tearDown();
+
+ sandbox.restore();
+ }
+} );
+
+QUnit.test( 'HTML is valid', function ( assert ) {
+ var subject = new CtaDrawer();
+
+ sinon.assert.match(
+ stripWhitespaceHTML( subject.$el.get( 0 ).outerHTML ),
+ '<div class="drawer position-fixed view-border-box"><div class="mw-ui-icon mw-ui-icon-mf-arrow mw-ui-icon-element cancel" title=""></div><p></p><a href="Special:UserLogin" class="mw-ui-button mw-ui-progressive ">mobile-frontend-watchlist-cta-button-login</a><div><a href="Special:UserLogin" class="mw-ui-anchor mw-ui-progressive ">mobile-frontend-watchlist-cta-button-signup</a></div></div>'
+ );
+ assert.ok( true );
+} );
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6743880
Default Alt Text
TestingCtaDrawer (2 KB)
Attached To
Mode
P7871 TestingCtaDrawer
Attached
Detach File
Event Timeline
Log In to Comment