diff --git a/javatests/google/registry/ui/js/registrar/BUILD b/javatests/google/registry/ui/js/registrar/BUILD index 2107c6404..cb282707e 100644 --- a/javatests/google/registry/ui/js/registrar/BUILD +++ b/javatests/google/registry/ui/js/registrar/BUILD @@ -13,6 +13,7 @@ closure_js_library( deps = [ "//java/google/registry/ui/js", "//java/google/registry/ui/js/registrar", + "//java/google/registry/ui/soy/registrar", "@io_bazel_rules_closure//closure/library", "@io_bazel_rules_closure//closure/library:testing", ], @@ -28,7 +29,6 @@ closure_js_test( ":console_test_util", "//java/google/registry/ui/js", "//java/google/registry/ui/js/registrar", - "//java/google/registry/ui/soy/registrar", "//javatests/google/registry/ui/js:testing", "@io_bazel_rules_closure//closure/library", "@io_bazel_rules_closure//closure/library:testing", diff --git a/javatests/google/registry/ui/js/registrar/console_test.js b/javatests/google/registry/ui/js/registrar/console_test.js index 1ba16afa8..afb2347bf 100644 --- a/javatests/google/registry/ui/js/registrar/console_test.js +++ b/javatests/google/registry/ui/js/registrar/console_test.js @@ -17,7 +17,6 @@ goog.setTestOnly(); goog.require('goog.dom'); goog.require('goog.dom.classlist'); goog.require('goog.json'); -goog.require('goog.soy'); goog.require('goog.testing.MockControl'); goog.require('goog.testing.PropertyReplacer'); goog.require('goog.testing.asserts'); @@ -25,15 +24,14 @@ goog.require('goog.testing.jsunit'); goog.require('goog.testing.mockmatchers'); goog.require('goog.testing.net.XhrIo'); goog.require('registry.registrar.ConsoleTestUtil'); -goog.require('registry.soy.registrar.console'); goog.require('registry.testing'); goog.require('registry.util'); -var $ = goog.dom.getRequiredElement; -var stubs = new goog.testing.PropertyReplacer(); +const $ = goog.dom.getRequiredElement; +const stubs = new goog.testing.PropertyReplacer(); -var test = { +const test = { testXsrfToken: 'testToken', testClientId: 'daddy', mockControl: new goog.testing.MockControl() @@ -44,24 +42,13 @@ function setUp() { registry.testing.addToDocument('
'); registry.testing.addToDocument(''); stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo); - var testElt = goog.dom.getElement('test'); - goog.soy.renderElement(testElt, registry.soy.registrar.console.main, { + registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), { xsrfToken: test.testXsrfToken, - username: 'blah', - logoutUrl: 'omg', - isAdmin: true, clientId: test.testClientId, - logoFilename: 'logo.png', - productName: 'Nomulus', - integrationEmail: 'integration@example.com', - supportEmail: 'support@example.com', - announcementsEmail: 'announcement@example.com', - supportPhoneNumber: '+1 (888) 555 0123', - technicalDocsUrl: 'http://example.com/techdocs', }); registry.registrar.ConsoleTestUtil.setup(test); - var regNavlist = $('reg-navlist'); - var active = regNavlist.querySelector('a[href="#contact-us"]'); + const regNavlist = $('reg-navlist'); + const active = regNavlist.querySelector('a[href="#contact-us"]'); assertTrue(active != null); } @@ -78,7 +65,7 @@ function testButter() { productName: 'Foo Registry' }); registry.util.butter('butter msg'); - var butter = goog.dom.getElementByClass(goog.getCssName('kd-butterbar')); + const butter = goog.dom.getElementByClass(goog.getCssName('kd-butterbar')); assertNotNull(butter.innerHTML.match(/.*butter msg.*/)); assertTrue(goog.dom.classlist.contains(butter, goog.getCssName('shown'))); } @@ -131,7 +118,7 @@ function testNavToResources() { premiumPriceAckRequired: false, readonly: true, }); - var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); + const xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue(xhr.isActive()); assertEquals('/registrar-settings', xhr.getLastUri()); assertEquals(test.testXsrfToken, @@ -157,12 +144,12 @@ function testNavToContactUs() { announcementsEmail: 'announcement@example.com', supportPhoneNumber: '+1 (888) 555 0123' }); - var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); + const xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue(xhr.isActive()); assertEquals('/registrar-settings', xhr.getLastUri()); assertEquals(test.testXsrfToken, xhr.getLastRequestHeaders()['X-CSRF-Token']); - var passcode = '5-5-5-5-5'; + const passcode = '5-5-5-5-5'; xhr.simulateResponse(200, goog.json.serialize({ status: 'SUCCESS', message: 'OK', diff --git a/javatests/google/registry/ui/js/registrar/console_test_util.js b/javatests/google/registry/ui/js/registrar/console_test_util.js index dc9f31685..2eac0449c 100644 --- a/javatests/google/registry/ui/js/registrar/console_test_util.js +++ b/javatests/google/registry/ui/js/registrar/console_test_util.js @@ -18,9 +18,11 @@ goog.setTestOnly('registry.registrar.ConsoleTestUtil'); goog.require('goog.History'); goog.require('goog.asserts'); goog.require('goog.dom.xml'); +goog.require('goog.soy'); goog.require('goog.testing.mockmatchers'); goog.require('registry.registrar.Console'); goog.require('registry.registrar.EppSession'); +goog.require('registry.soy.registrar.console'); goog.require('registry.xml'); @@ -28,7 +30,7 @@ goog.require('registry.xml'); * Utility method that attaches mocks to a `TestCase`. This was * originally in the ctor for ConsoleTest and should simply be * inherited but jstd_test breaks inheritance in test cases. - * @param {Object} test the test case to configure. + * @param {!Object} test the test case to configure. */ registry.registrar.ConsoleTestUtil.setup = function(test) { test.historyMock = test.mockControl.createLooseMock(goog.History, true); @@ -42,13 +44,41 @@ registry.registrar.ConsoleTestUtil.setup = function(test) { .$returns(test.sessionMock); }; +/** + * Utility method that renders the registry.soy.registrar.console.main element. + * + * This element has a lot of parameters. We use defaults everywhere, but you can + * override them with 'opt_args'. + * + * @param {!Element} element the element whose content we are rendering into. + * @param {?Object=} opt_args override for the default values of the soy params. + */ +registry.registrar.ConsoleTestUtil.renderConsoleMain = function( + element, opt_args) { + const args = opt_args || {}; + goog.soy.renderElement(element, registry.soy.registrar.console.main, { + xsrfToken: args.xsrfToken || 'ignore', + username: args.username || 'jart', + logoutUrl: args.logoutUrl || 'https://logout.url.com', + isAdmin: goog.isDefAndNotNull(args.isAdmin) ? args.isAdmin : true, + clientId: args.clientId || 'ignore', + logoFilename: args.logoFilename || 'logo.png', + productName: args.productName || 'Nomulus', + integrationEmail: args.integrationEmail || 'integration@example.com', + supportEmail: args.supportEmail || 'support@example.com', + announcementsEmail: args.announcementsEmail || 'announcement@example.com', + supportPhoneNumber: args.supportPhoneNumber || '+1 (888) 555 0123', + technicalDocsUrl: args.technicalDocsUrl || 'http://example.com/techdocs', + }); +}; + /** * Simulates visiting a page on the console. Sets path, then mocks * session and calls `handleHashChange_`. - * @param {Object} test the test case to configure. - * @param {Object=} opt_args may include path, isEppLoggedIn. - * @param {Function=} opt_moar extra setup after called just before + * @param {!Object} test the test case to configure. + * @param {?Object=} opt_args may include path, isEppLoggedIn. + * @param {?Function=} opt_moar extra setup after called just before * `$replayAll`. See memegen/3437690. */ registry.registrar.ConsoleTestUtil.visit = function( @@ -72,7 +102,7 @@ registry.registrar.ConsoleTestUtil.visit = function( goog.testing.mockmatchers.isFunction) .$does(function(args, cb) { // XXX: Args should be checked. - var xml = goog.dom.xml.loadXml(opt_args.rspXml); + const xml = goog.dom.xml.loadXml(opt_args.rspXml); goog.asserts.assert(xml != null); cb(registry.xml.convertToJson(xml)); }).$anyTimes(); diff --git a/javatests/google/registry/ui/js/registrar/contact_settings_test.js b/javatests/google/registry/ui/js/registrar/contact_settings_test.js index 330423e62..bf74d59f0 100644 --- a/javatests/google/registry/ui/js/registrar/contact_settings_test.js +++ b/javatests/google/registry/ui/js/registrar/contact_settings_test.js @@ -17,23 +17,21 @@ goog.setTestOnly(); goog.require('goog.array'); goog.require('goog.dispose'); goog.require('goog.dom'); -goog.require('goog.soy'); goog.require('goog.testing.MockControl'); goog.require('goog.testing.PropertyReplacer'); goog.require('goog.testing.asserts'); goog.require('goog.testing.jsunit'); goog.require('goog.testing.net.XhrIo'); goog.require('registry.registrar.ConsoleTestUtil'); -goog.require('registry.soy.registrar.console'); goog.require('registry.testing'); goog.require('registry.util'); -var $ = goog.dom.getRequiredElement; -var stubs = new goog.testing.PropertyReplacer(); -var testContact = null; +const $ = goog.dom.getRequiredElement; +const stubs = new goog.testing.PropertyReplacer(); +let testContact = null; -var test = { +const test = { testXsrfToken: '༼༎෴ ༎༽', testClientId: 'testClientId', mockControl: new goog.testing.MockControl() @@ -44,19 +42,9 @@ function setUp() { registry.testing.addToDocument(''); registry.testing.addToDocument(''); testContact = createTestContact(); - goog.soy.renderElement($('test'), registry.soy.registrar.console.main, { + registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), { xsrfToken: test.testXsrfToken, - username: 'blah', - logoutUrl: 'omg', - isAdmin: true, clientId: test.testClientId, - logoFilename: 'logo.png', - productName: 'Nomulus', - integrationEmail: 'integration@google.com', - supportEmail: 'support@google.com', - announcementsEmail: 'announcements@google.com', - supportPhoneNumber: '123 456 7890', - technicalDocsUrl: 'http://example.com/techdocs' }); stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo); registry.registrar.ConsoleTestUtil.setup(test); @@ -208,7 +196,7 @@ function testOneOfManyUpdate() { xsrfToken: test.testXsrfToken, clientId: test.testClientId }); - var testContacts = [ + const testContacts = [ createTestContact('new1@asdf.com'), testContact, createTestContact('new2@asdf.com') @@ -262,9 +250,9 @@ function testDomainWhoisAbuseContactOverride() { xsrfToken: test.testXsrfToken, clientId: test.testClientId }); - var oldDomainWhoisAbuseContact = createTestContact('old@asdf.com'); + const oldDomainWhoisAbuseContact = createTestContact('old@asdf.com'); oldDomainWhoisAbuseContact.visibleInDomainWhoisAsAbuse = true; - var testContacts = [oldDomainWhoisAbuseContact, testContact]; + const testContacts = [oldDomainWhoisAbuseContact, testContact]; registry.testing.assertReqMockRsp( test.testXsrfToken, '/registrar-settings', @@ -299,7 +287,7 @@ function testDelete() { xsrfToken: test.testXsrfToken, clientId: test.testClientId }); - var testContacts = [ + const testContacts = [ createTestContact('new1@asdf.com'), testContact, createTestContact('new2@asdf.com') @@ -343,10 +331,10 @@ function testDelete() { /** * @param {string=} opt_email - * @return {Object} + * @return {!Object} */ function createTestContact(opt_email) { - var nameMail = opt_email || 'test@example.com'; + const nameMail = opt_email || 'test@example.com'; return { name: nameMail, emailAddress: nameMail, @@ -363,14 +351,14 @@ function createTestContact(opt_email) { /** * Convert parsed formContact to simulated wire form. * @param {!Element} contact - * @return {Object} + * @return {!Object} */ function simulateJsonForContact(contact) { contact.visibleInWhoisAsAdmin = contact.visibleInWhoisAsAdmin == 'true'; contact.visibleInWhoisAsTech = contact.visibleInWhoisAsTech == 'true'; contact.visibleInDomainWhoisAsAbuse = contact.visibleInDomainWhoisAsAbuse == 'true'; contact.types = ''; - for (var tNdx in contact.type) { + for (const tNdx in contact.type) { if (contact.type[tNdx]) { if (contact.types.length > 0) { contact.types += ','; diff --git a/javatests/google/registry/ui/js/registrar/contact_test.js b/javatests/google/registry/ui/js/registrar/contact_test.js index 62781b12c..a639458d0 100644 --- a/javatests/google/registry/ui/js/registrar/contact_test.js +++ b/javatests/google/registry/ui/js/registrar/contact_test.js @@ -16,18 +16,16 @@ goog.setTestOnly(); goog.require('goog.dispose'); goog.require('goog.dom'); -goog.require('goog.soy'); goog.require('goog.testing.MockControl'); goog.require('goog.testing.asserts'); goog.require('goog.testing.jsunit'); goog.require('registry.registrar.ConsoleTestUtil'); -goog.require('registry.soy.registrar.console'); goog.require('registry.testing'); -var $ = goog.dom.getRequiredElement; +const $ = goog.dom.getRequiredElement; -var test = { +const test = { mockControl: new goog.testing.MockControl() }; @@ -35,20 +33,7 @@ var test = { function setUp() { registry.testing.addToDocument(''); registry.testing.addToDocument(''); - goog.soy.renderElement($('test'), registry.soy.registrar.console.main, { - xsrfToken: 'test', - username: 'blah', - logoutUrl: 'omg', - isAdmin: true, - clientId: 'daddy', - logoFilename: 'logo.png', - productName: 'Nomulus', - integrationEmail: 'integration@example.com', - supportEmail: 'support@example.com', - announcementsEmail: 'announcement@example.com', - supportPhoneNumber: '+1 (888) 555 0123', - technicalDocsUrl: 'http://example.com/techdocs' - }); + registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {}); registry.registrar.ConsoleTestUtil.setup(test); } @@ -126,7 +111,7 @@ function testEdit() { /** Contact hash path should nav to contact page. */ function testAddPostalInfo() { testEdit(); - var addPiBtn = $('domain-contact-postalInfo-add-button'); + const addPiBtn = $('domain-contact-postalInfo-add-button'); assertNull(addPiBtn.getAttribute('disabled')); registry.testing.click(addPiBtn); assertTrue(addPiBtn.hasAttribute('disabled')); diff --git a/javatests/google/registry/ui/js/registrar/domain_test.js b/javatests/google/registry/ui/js/registrar/domain_test.js index 44e10d6a8..92630b8a8 100644 --- a/javatests/google/registry/ui/js/registrar/domain_test.js +++ b/javatests/google/registry/ui/js/registrar/domain_test.js @@ -17,7 +17,6 @@ goog.setTestOnly(); goog.require('goog.History'); goog.require('goog.dispose'); goog.require('goog.dom'); -goog.require('goog.soy'); goog.require('goog.testing.MockControl'); goog.require('goog.testing.PropertyReplacer'); goog.require('goog.testing.asserts'); @@ -25,36 +24,23 @@ goog.require('goog.testing.jsunit'); goog.require('goog.testing.mockmatchers'); goog.require('goog.testing.net.XhrIo'); goog.require('registry.registrar.Console'); -goog.require('registry.soy.registrar.console'); +goog.require('registry.registrar.ConsoleTestUtil'); goog.require('registry.testing'); -var $ = goog.dom.getRequiredElement; -var _ = goog.testing.mockmatchers.ignoreArgument; -var stubs = new goog.testing.PropertyReplacer(); -var mocks = new goog.testing.MockControl(); +const $ = goog.dom.getRequiredElement; +const _ = goog.testing.mockmatchers.ignoreArgument; +const stubs = new goog.testing.PropertyReplacer(); +const mocks = new goog.testing.MockControl(); -var historyMock; -var registrarConsole; +let historyMock; +let registrarConsole; function setUp() { registry.testing.addToDocument(''); registry.testing.addToDocument(''); - goog.soy.renderElement($('test'), registry.soy.registrar.console.main, { - xsrfToken: 'ignore', - username: 'jart', - logoutUrl: 'https://justinetunney.com', - isAdmin: true, - clientId: 'ignore', - logoFilename: 'logo.png', - productName: 'Nomulus', - integrationEmail: 'integration@example.com', - supportEmail: 'support@example.com', - announcementsEmail: 'announcement@example.com', - supportPhoneNumber: '+1 (888) 555 0123', - technicalDocsUrl: 'http://example.com/techdocs' - }); + registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {}); stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo); historyMock = mocks.createStrictMock(goog.History); @@ -81,7 +67,7 @@ function tearDown() { /** Handles EPP login. */ function handleLogin() { - var request = registry.testing.loadXml( + const request = registry.testing.loadXml( '' + '