mirror of
https://github.com/google/nomulus.git
synced 2025-07-13 22:45:10 +02:00
Move JS and CSS files to a Javascript source dir (#156)
This commit is contained in:
parent
82f51accbd
commit
e5bafddd2f
43 changed files with 8 additions and 17 deletions
|
@ -1,40 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('registry.Component');
|
||||
goog.require('registry.Console');
|
||||
|
||||
describe("component test", function() {
|
||||
let mocks;
|
||||
|
||||
beforeEach(function() {
|
||||
mocks = new goog.testing.MockControl();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
mocks.$tearDown();
|
||||
});
|
||||
|
||||
it("testCreationAndDisposal_dontTouchConsoleObject", function() {
|
||||
var console = mocks.createStrictMock(registry.Console);
|
||||
mocks.$replayAll();
|
||||
var component = new registry.Component(console);
|
||||
goog.dispose(component);
|
||||
mocks.$verifyAll();
|
||||
});
|
||||
});
|
|
@ -1,120 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.classlist');
|
||||
goog.require('goog.json');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.registrar.ConsoleTestUtil');
|
||||
goog.require('registry.testing');
|
||||
goog.require('registry.util');
|
||||
|
||||
describe("console test", function() {
|
||||
const $ = goog.dom.getRequiredElement;
|
||||
const stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
const test = {
|
||||
testXsrfToken: 'testToken',
|
||||
testClientId: 'daddy',
|
||||
mockControl: new goog.testing.MockControl()
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId,
|
||||
});
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
const regNavlist = $('reg-navlist');
|
||||
const active = regNavlist.querySelector('a[href="#contact-us"]');
|
||||
expect(active).not.toBeNull();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
stubs.reset();
|
||||
test.mockControl.$tearDown();
|
||||
});
|
||||
|
||||
it("testButter", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
productName: 'Foo Registry'
|
||||
});
|
||||
registry.util.butter('butter msg');
|
||||
const butter = goog.dom.getElementByClass(goog.getCssName('kd-butterbar'));
|
||||
expect(butter.innerHTML.match(/.*butter msg.*/)).not.toBeNull();
|
||||
expect(goog.dom.classlist.contains(butter, goog.getCssName('shown'))).toBe(true);
|
||||
});
|
||||
|
||||
/** Authed user with no path op specified should nav to welcome page. */
|
||||
it("testShowLoginOrDash", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
productName: 'Foo Registry'
|
||||
});
|
||||
expect(goog.dom.getElement('domain-registrar-dashboard')).not.toBeNull();
|
||||
});
|
||||
|
||||
it("testNavToResources", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'resources',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
technicalDocsUrl: 'http://example.com/techdocs',
|
||||
readonly: true,
|
||||
});
|
||||
const xhr = goog.testing.net.XhrIo.getSendInstances().pop();
|
||||
expect(xhr.isActive()).toBe(true);
|
||||
expect(xhr.getLastUri()).toEqual('/registrar-settings');
|
||||
expect(xhr.getLastRequestHeaders()['X-CSRF-Token']).toEqual(test.testXsrfToken);
|
||||
xhr.simulateResponse(200, goog.json.serialize({
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
driveFolderId: 'blahblah'
|
||||
}]
|
||||
}));
|
||||
expect($('reg-resources-driveLink').getAttribute('href')).toContain('blahblah');
|
||||
});
|
||||
|
||||
it("testNavToContactUs", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-us',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
productName: 'Domain Registry',
|
||||
integrationEmail: 'integration@example.com',
|
||||
supportEmail: 'support@example.com',
|
||||
announcementsEmail: 'announcement@example.com',
|
||||
supportPhoneNumber: '+1 (888) 555 0123'
|
||||
});
|
||||
const xhr = goog.testing.net.XhrIo.getSendInstances().pop();
|
||||
expect(xhr.isActive()).toBe(true);
|
||||
expect(xhr.getLastUri()).toEqual('/registrar-settings');
|
||||
expect(xhr.getLastRequestHeaders()['X-CSRF-Token']).toEqual(test.testXsrfToken);
|
||||
const passcode = '5-5-5-5-5';
|
||||
xhr.simulateResponse(200, goog.json.serialize({
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
phonePasscode: passcode
|
||||
}]
|
||||
}));
|
||||
expect(goog.dom.getTextContent($('domain-registrar-phone-passcode'))).toEqual(passcode);
|
||||
});
|
||||
});
|
|
@ -1,109 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.provide('registry.registrar.ConsoleTestUtil');
|
||||
goog.setTestOnly('registry.registrar.ConsoleTestUtil');
|
||||
|
||||
goog.require('goog.History');
|
||||
goog.require('goog.soy');
|
||||
goog.require('registry.registrar.Console');
|
||||
goog.require('registry.soy.registrar.console');
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
registry.registrar.ConsoleTestUtil.setup = function(test) {
|
||||
test.historyMock = test.mockControl.createLooseMock(goog.History, true);
|
||||
test.mockControl.createConstructorMock(goog, 'History')()
|
||||
.$returns(test.historyMock);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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: !!args.isAdmin,
|
||||
isOwner: !!args.isOwner,
|
||||
clientId: args.clientId || 'ignore',
|
||||
allClientIds: args.allClientIds || ['clientId1', 'clientId2'],
|
||||
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',
|
||||
environment: args.environment || 'UNITTEST',
|
||||
analyticsConfig: args.analyticsConfig || {googleAnalyticsId: null},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Simulates visiting a page on the console. Sets path, then calls
|
||||
* `handleHashChange_`.
|
||||
* @param {!Object} test the test case to configure.
|
||||
* @param {?Object=} opt_args may include path.
|
||||
* @param {?Function=} opt_moar extra setup after called just before
|
||||
* `$replayAll`. See memegen/3437690.
|
||||
*/
|
||||
registry.registrar.ConsoleTestUtil.visit = function(
|
||||
test, opt_args, opt_moar) {
|
||||
opt_args = opt_args || {};
|
||||
opt_args.path = opt_args.path || '';
|
||||
opt_args.clientId = opt_args.clientId || 'dummyRegistrarId';
|
||||
opt_args.xsrfToken = opt_args.xsrfToken || 'dummyXsrfToken';
|
||||
opt_args.isAdmin = !!opt_args.isAdmin;
|
||||
opt_args.analyticsConfig =
|
||||
opt_args.analyticsConfig || {googleAnalyticsIds: null};
|
||||
|
||||
// set the default isOwner to be the opposite of isAdmin.
|
||||
// That way, if we don't explicitly state them both we get what we'd expect:
|
||||
// {} -> OWNER (the "regular" case of a visitor to the console)
|
||||
// {isOwner:true} -> OWNER
|
||||
// {isAdmin:true} -> ADMIN (the "regular" case of an admin visitor)
|
||||
// {isOwner:true, isAdmin:true} -> OWNER + ADMIN together
|
||||
if (opt_args.isOwner === undefined) {
|
||||
opt_args.isOwner = !opt_args.isAdmin;
|
||||
}
|
||||
test.historyMock.$reset();
|
||||
test.historyMock.getToken().$returns(opt_args.path).$anyTimes();
|
||||
if (opt_moar) {
|
||||
opt_moar();
|
||||
}
|
||||
test.mockControl.$replayAll();
|
||||
/** @type {!registry.registrar.Console} */
|
||||
test.console = new registry.registrar.Console(opt_args);
|
||||
test.console.setUp();
|
||||
// Should be triggered via the History object in test.console.setUp(), but
|
||||
// since we're using a mock that isn't happening. So we call it manually.
|
||||
test.console.handleHashChange();
|
||||
test.mockControl.$verifyAll();
|
||||
};
|
|
@ -1,364 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.registrar.ConsoleTestUtil');
|
||||
goog.require('registry.testing');
|
||||
goog.require('registry.util');
|
||||
|
||||
describe("contact settings test", function() {
|
||||
const $ = goog.dom.getRequiredElement;
|
||||
const stubs = new goog.testing.PropertyReplacer();
|
||||
let testContact = null;
|
||||
|
||||
const test = {
|
||||
testXsrfToken: '༼༎෴ ༎༽',
|
||||
testClientId: 'testClientId',
|
||||
mockControl: new goog.testing.MockControl()
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
testContact = createTestContact();
|
||||
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId,
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(test.console);
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
stubs.reset();
|
||||
test.mockControl.$tearDown();
|
||||
});
|
||||
|
||||
it("testCollectionView", function() {
|
||||
testContactWithoutType = createTestContact('notype@example.com');
|
||||
testContactWithoutType.types = '';
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-settings',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: [testContact, testContactWithoutType]
|
||||
}]
|
||||
}
|
||||
);
|
||||
expect($('admin-contacts').childNodes.length).toEqual(1);
|
||||
expect($('other-contacts').childNodes.length).toEqual(1);
|
||||
// XXX: Needs more field testing.
|
||||
});
|
||||
|
||||
|
||||
it("testItemView", function() {
|
||||
testItemView();
|
||||
expect($('contacts[0].name').value).toEqual(testContact.name);
|
||||
expect($('contacts[0].emailAddress').value).toEqual(testContact.emailAddress);
|
||||
expect($('contacts[0].phoneNumber').value).toEqual(testContact.phoneNumber);
|
||||
expect($('contacts[0].faxNumber').value).toEqual(testContact.faxNumber);
|
||||
// XXX: Types are no longer broken out as individual settings, so relying on
|
||||
// screenshot test.
|
||||
});
|
||||
|
||||
// XXX: Should be hoisted.
|
||||
it("testItemEditButtons", function() {
|
||||
testItemView();
|
||||
registry.testing.assertVisible($('reg-app-btns-edit'));
|
||||
registry.testing.assertHidden($('reg-app-btns-save'));
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
registry.testing.assertHidden($('reg-app-btns-edit'));
|
||||
registry.testing.assertVisible($('reg-app-btns-save'));
|
||||
registry.testing.click($('reg-app-btn-cancel'));
|
||||
registry.testing.assertVisible($('reg-app-btns-edit'));
|
||||
registry.testing.assertHidden($('reg-app-btns-save'));
|
||||
});
|
||||
|
||||
it("testItemEdit", function() {
|
||||
testItemView();
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('contacts[0].name').setAttribute('value', 'bob');
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
testContact.name = 'bob';
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{
|
||||
op: 'update',
|
||||
id: 'testClientId',
|
||||
args: {
|
||||
contacts: [testContact],
|
||||
readonly: false
|
||||
}
|
||||
},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: [testContact]
|
||||
}]
|
||||
}
|
||||
);
|
||||
registry.testing.assertObjectEqualsPretty(
|
||||
testContact,
|
||||
simulateJsonForContact(registry.util.parseForm('item').contacts[0]));
|
||||
});
|
||||
|
||||
it("testChangeContactTypes", function() {
|
||||
testItemView();
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('contacts[0].type.admin').removeAttribute('checked');
|
||||
$('contacts[0].type.legal').setAttribute('checked', 'checked');
|
||||
$('contacts[0].type.marketing').setAttribute('checked', 'checked');
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
testContact.types = 'LEGAL,MARKETING';
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{
|
||||
op: 'update',
|
||||
id: 'testClientId',
|
||||
args: {
|
||||
contacts: [testContact],
|
||||
readonly: false
|
||||
}
|
||||
},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: [testContact]
|
||||
}]
|
||||
}
|
||||
);
|
||||
registry.testing.assertObjectEqualsPretty(
|
||||
testContact,
|
||||
simulateJsonForContact(registry.util.parseForm('item').contacts[0]));
|
||||
});
|
||||
|
||||
it("testOneOfManyUpdate", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-settings/test@example.com',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
const testContacts = [
|
||||
createTestContact('new1@asdf.com'),
|
||||
testContact,
|
||||
createTestContact('new2@asdf.com')
|
||||
];
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: testContacts
|
||||
}]
|
||||
}
|
||||
);
|
||||
// Edit testContact.
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('contacts[1].type.admin').removeAttribute('checked');
|
||||
$('contacts[1].type.legal').setAttribute('checked', 'checked');
|
||||
$('contacts[1].type.marketing').setAttribute('checked', 'checked');
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
|
||||
// Should save them all back, with only testContact changed.
|
||||
testContacts[1].types = 'LEGAL,MARKETING';
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{
|
||||
op: 'update',
|
||||
id: 'testClientId',
|
||||
args: {
|
||||
contacts: testContacts,
|
||||
readonly: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: testContacts
|
||||
}]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("testDomainWhoisAbuseContactOverride", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-settings/test@example.com',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
const oldDomainWhoisAbuseContact = createTestContact('old@asdf.com');
|
||||
oldDomainWhoisAbuseContact.visibleInDomainWhoisAsAbuse = true;
|
||||
const testContacts = [oldDomainWhoisAbuseContact, testContact];
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{status: 'SUCCESS', message: 'OK', results: [{contacts: testContacts}]});
|
||||
// Edit testContact.
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('contacts[1].visibleInDomainWhoisAsAbuse.true')
|
||||
.setAttribute('checked', 'checked');
|
||||
$('contacts[1].visibleInDomainWhoisAsAbuse.false').removeAttribute('checked');
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
|
||||
// Should save them all back, and flip the old abuse contact's visibility
|
||||
// boolean.
|
||||
testContact.visibleInDomainWhoisAsAbuse = true;
|
||||
oldDomainWhoisAbuseContact.visibleInDomainWhoisAsAbuse = false;
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{
|
||||
op: 'update',
|
||||
id: 'testClientId',
|
||||
args: {contacts: testContacts, readonly: false},
|
||||
},
|
||||
{status: 'SUCCESS', message: 'OK', results: [{contacts: testContacts}]});
|
||||
});
|
||||
|
||||
it("testDelete", function() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-settings/test@example.com',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
const testContacts = [
|
||||
createTestContact('new1@asdf.com'),
|
||||
testContact,
|
||||
createTestContact('new2@asdf.com')
|
||||
];
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: testContacts
|
||||
}]
|
||||
}
|
||||
);
|
||||
// Delete testContact.
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
registry.testing.click($('reg-app-btn-delete'));
|
||||
|
||||
// Should save them all back, with testContact gone.
|
||||
goog.array.removeAt(testContacts, 1);
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{
|
||||
op: 'update',
|
||||
id: 'testClientId',
|
||||
args: {contacts: testContacts, readonly: false},
|
||||
},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: testContacts
|
||||
}]
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function testItemView() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'contact-settings/test@example.com',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{
|
||||
contacts: [testContact]
|
||||
}]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} opt_email
|
||||
* @return {!Object}
|
||||
*/
|
||||
function createTestContact(opt_email) {
|
||||
const nameMail = opt_email || 'test@example.com';
|
||||
return {
|
||||
name: nameMail,
|
||||
emailAddress: nameMail,
|
||||
phoneNumber: '+1.2345551234',
|
||||
faxNumber: '+1.2345551234',
|
||||
visibleInWhoisAsAdmin: false,
|
||||
visibleInWhoisAsTech: false,
|
||||
visibleInDomainWhoisAsAbuse: false,
|
||||
types: 'ADMIN'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert parsed formContact to simulated wire form.
|
||||
* @param {!Element} contact
|
||||
* @return {!Object}
|
||||
*/
|
||||
function simulateJsonForContact(contact) {
|
||||
contact.visibleInWhoisAsAdmin = contact.visibleInWhoisAsAdmin == 'true';
|
||||
contact.visibleInWhoisAsTech = contact.visibleInWhoisAsTech == 'true';
|
||||
contact.visibleInDomainWhoisAsAbuse = contact.visibleInDomainWhoisAsAbuse == 'true';
|
||||
contact.types = '';
|
||||
for (const tNdx in contact.type) {
|
||||
if (contact.type[tNdx]) {
|
||||
if (contact.types.length > 0) {
|
||||
contact.types += ',';
|
||||
}
|
||||
contact.types += ('' + tNdx).toUpperCase();
|
||||
}
|
||||
}
|
||||
delete contact['type'];
|
||||
return contact;
|
||||
}
|
||||
});
|
|
@ -1,134 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.registrar.ConsoleTestUtil');
|
||||
goog.require('registry.testing');
|
||||
goog.require('registry.util');
|
||||
|
||||
describe('security settings test', function() {
|
||||
const $ = goog.dom.getRequiredElement;
|
||||
const stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
const expectedRegistrar = {
|
||||
ipAddressWhitelist: [],
|
||||
phonePasscode: '12345',
|
||||
clientCertificate: null,
|
||||
clientCertificateHash: null,
|
||||
failoverClientCertificate: null
|
||||
};
|
||||
|
||||
const test = {
|
||||
testXsrfToken: '༼༎෴ ༎༽',
|
||||
testClientId: 'testClientId',
|
||||
mockControl: new goog.testing.MockControl()
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId,
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(test.console);
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
stubs.reset();
|
||||
test.mockControl.$tearDown();
|
||||
});
|
||||
|
||||
function testView() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'security-settings',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [expectedRegistrar]
|
||||
});
|
||||
expect(registry.util.parseForm('item').phonePasscode).toEqual(expectedRegistrar.phonePasscode);
|
||||
}
|
||||
|
||||
it("testView", function() {
|
||||
testView();
|
||||
});
|
||||
|
||||
it("testEdit", function() {
|
||||
testView();
|
||||
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
|
||||
const form = document.forms.namedItem('item');
|
||||
form.elements['newIp'].value = '1.1.1.1';
|
||||
registry.testing.click($('btn-add-ip'));
|
||||
form.elements['newIp'].value = '2.2.2.2';
|
||||
registry.testing.click($('btn-add-ip'));
|
||||
|
||||
const exampleCert = $('exampleCert').value;
|
||||
const exampleCertHash = '6NKKNBnd2fKFooBINmn3V7L3JOTHh02+2lAqYHdlTgk';
|
||||
form.elements['clientCertificate'].value = exampleCert;
|
||||
form.elements['failoverClientCertificate'].value = 'bourgeois blues';
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'update', id: 'testClientId', args: {
|
||||
clientCertificate: exampleCert,
|
||||
clientCertificateHash: null,
|
||||
failoverClientCertificate: 'bourgeois blues',
|
||||
ipAddressWhitelist: ['1.1.1.1', '2.2.2.2'],
|
||||
phonePasscode: expectedRegistrar.phonePasscode,
|
||||
readonly: false }},
|
||||
{status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [{}]});
|
||||
// XXX: The response above is ignored as the page re-issues a fetch. Should
|
||||
// either provide the real response here and use anyTimes(), or have
|
||||
// resource_component use this directly.
|
||||
|
||||
expectedRegistrar.clientCertificate = exampleCert;
|
||||
expectedRegistrar.clientCertificateHash = exampleCertHash;
|
||||
expectedRegistrar.failoverClientCertificate = 'bourgeois blues';
|
||||
expectedRegistrar.ipAddressWhitelist = ['1.1.1.1/32', '2.2.2.2/32'];
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [expectedRegistrar]});
|
||||
|
||||
delete expectedRegistrar['clientCertificateHash'];
|
||||
registry.testing.assertObjectEqualsPretty(
|
||||
expectedRegistrar, registry.util.parseForm('item'));
|
||||
});
|
||||
});
|
|
@ -1,166 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.classlist');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.registrar.ConsoleTestUtil');
|
||||
goog.require('registry.testing');
|
||||
goog.require('registry.util');
|
||||
|
||||
describe("whois settings test", function() {
|
||||
const $ = goog.dom.getRequiredElement;
|
||||
const $$ = goog.dom.getRequiredElementByClass;
|
||||
const stubs = new goog.testing.PropertyReplacer();
|
||||
|
||||
const test = {
|
||||
testXsrfToken: '༼༎෴ ༎༽',
|
||||
testClientId: 'testClientId',
|
||||
mockControl: new goog.testing.MockControl()
|
||||
};
|
||||
|
||||
beforeEach(function() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId,
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(test.console);
|
||||
stubs.reset();
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
test.mockControl.$tearDown();
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates test registrar.
|
||||
* @return {!Object}
|
||||
*/
|
||||
function createTestRegistrar() {
|
||||
return {
|
||||
emailAddress: 'test2.ui@example.com',
|
||||
clientIdentifier: 'theRegistrar',
|
||||
ianaIdentifier: 1,
|
||||
icannReferralEmail: 'lol@sloth.test',
|
||||
whoisServer: 'foo.bar.baz',
|
||||
url: 'blah.blar',
|
||||
phoneNumber: '+1.2125650000',
|
||||
faxNumber: '+1.2125650001',
|
||||
localizedAddress: {
|
||||
street: ['111 Eighth Avenue', 'Eleventh Floor', 'lol'],
|
||||
city: 'New York',
|
||||
state: 'NY',
|
||||
zip: '10011',
|
||||
countryCode: 'US'
|
||||
}};
|
||||
}
|
||||
|
||||
function testView() {
|
||||
registry.registrar.ConsoleTestUtil.visit(test, {
|
||||
path: 'whois-settings',
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
const testRegistrar = createTestRegistrar();
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'read', id: 'testClientId', args: {}},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [testRegistrar]
|
||||
});
|
||||
const parsed = registry.util.parseForm('item');
|
||||
parsed.ianaIdentifier = parseInt(parsed.ianaIdentifier);
|
||||
registry.testing.assertObjectEqualsPretty(testRegistrar, parsed);
|
||||
}
|
||||
|
||||
it("testView", function() {
|
||||
testView();
|
||||
});
|
||||
|
||||
it("testEdit", function() {
|
||||
testView();
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('emailAddress').value = 'test2.ui@example.com';
|
||||
$('localizedAddress.street[0]').value = 'look at me i am';
|
||||
$('localizedAddress.street[1]').value = 'the mistress of the night';
|
||||
$('localizedAddress.street[2]').value = '';
|
||||
const parsed = registry.util.parseForm('item');
|
||||
parsed.readonly = false;
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'update', id: 'testClientId', args: parsed},
|
||||
{
|
||||
status: 'SUCCESS',
|
||||
message: 'OK',
|
||||
results: [parsed]
|
||||
});
|
||||
});
|
||||
|
||||
it("testEditFieldError_insertsError", function() {
|
||||
testView();
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
$('phoneNumber').value = 'foo';
|
||||
const parsed = registry.util.parseForm('item');
|
||||
parsed.readonly = false;
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
const errMsg = 'Carpe brunchus. --Pablo';
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'update', id: 'testClientId', args: parsed},
|
||||
{
|
||||
status: 'ERROR',
|
||||
field: 'phoneNumber',
|
||||
message: errMsg
|
||||
});
|
||||
const msgBox = goog.dom.getNextElementSibling($('phoneNumber'));
|
||||
expect(goog.dom.classlist.contains(msgBox, 'kd-errormessage')).toBe(true);
|
||||
expect(goog.dom.classlist.contains($('phoneNumber'), 'kd-formerror')).toBe(true);
|
||||
expect(goog.dom.getTextContent(msgBox)).toEqual(errMsg);
|
||||
});
|
||||
|
||||
it("testEditNonFieldError_showsButterBar", function() {
|
||||
testView();
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
const parsed = registry.util.parseForm('item');
|
||||
parsed.readonly = false;
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
const errMsg = 'One must still have chaos in oneself to be able to give ' +
|
||||
'birth to a dancing star. --Nietzsche';
|
||||
registry.testing.assertReqMockRsp(
|
||||
test.testXsrfToken,
|
||||
'/registrar-settings',
|
||||
{op: 'update', id: 'testClientId', args: parsed},
|
||||
{
|
||||
status: 'ERROR',
|
||||
message: errMsg
|
||||
});
|
||||
expect(goog.dom.getTextContent($$('kd-butterbar-text'))).toEqual(errMsg);
|
||||
});
|
||||
});
|
|
@ -1,113 +0,0 @@
|
|||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
goog.provide('registry.testing');
|
||||
goog.setTestOnly('registry.testing');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.classlist');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.format.JsonPrettyPrinter');
|
||||
goog.require('goog.html.testing');
|
||||
goog.require('goog.json');
|
||||
goog.require('goog.testing.events');
|
||||
goog.require('goog.testing.events.Event');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
|
||||
|
||||
/**
|
||||
* Adds specified HTML string to document.
|
||||
* @param {string} html
|
||||
*/
|
||||
registry.testing.addToDocument = function(html) {
|
||||
goog.global.document.body.appendChild(
|
||||
goog.dom.safeHtmlToNode(
|
||||
goog.html.testing.newSafeHtmlForTest(html)));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Simulates a mouse click on a browser element.
|
||||
* @param {!Element} element
|
||||
*/
|
||||
registry.testing.click = function(element) {
|
||||
goog.testing.events.fireBrowserEvent(
|
||||
new goog.testing.events.Event(
|
||||
goog.events.EventType.CLICK, element));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Asserts `element` has 'shown' class.
|
||||
* @param {!Element} element
|
||||
*/
|
||||
registry.testing.assertVisible = function(element) {
|
||||
expect(goog.dom.classlist.contains(element, 'shown')).toBe(true);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Asserts `element` has 'hidden' class.
|
||||
* @param {!Element} element
|
||||
*/
|
||||
registry.testing.assertHidden = function(element) {
|
||||
expect(goog.dom.classlist.contains(element, 'hidden')).toBe(true);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Like `assertObjectEquals` but with a better error message.
|
||||
* @param {?Object} a
|
||||
* @param {?Object} b
|
||||
*/
|
||||
registry.testing.assertObjectEqualsPretty = function(a, b) {
|
||||
try {
|
||||
expect(a).toEqual(b);
|
||||
} catch (e) {
|
||||
e.message = e.message + '\n' +
|
||||
'expected: ' + registry.testing.pretty_.format(a) + '\n' +
|
||||
'got: ' + registry.testing.pretty_.format(b);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* JSON request/response simulator for `ResourceComponent` subclasses.
|
||||
* @param {string} xsrfToken
|
||||
* @param {string} path server resource path.
|
||||
* @param {!Object} expectReqJson assert this object was sent,
|
||||
* e.g. {'op':'read',{}}
|
||||
* @param {!Object} mockRspJson mock a response, e.g. {'set':[]}
|
||||
*/
|
||||
registry.testing.assertReqMockRsp =
|
||||
function(xsrfToken, path, expectReqJson, mockRspJson) {
|
||||
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
|
||||
expect(xhr.isActive()).toBe(true);
|
||||
expect(path).toEqual(xhr.getLastUri());
|
||||
// XXX: XHR header checking should probably be added. Was inconsistent
|
||||
// between admin and registrar consoles.
|
||||
registry.testing.assertObjectEqualsPretty(
|
||||
expectReqJson, JSON.parse(xhr.getLastContent()));
|
||||
xhr.simulateResponse(200, goog.json.serialize(mockRspJson));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* JSON pretty printer.
|
||||
* @type {!goog.format.JsonPrettyPrinter}
|
||||
* @private
|
||||
*/
|
||||
registry.testing.pretty_ = new goog.format.JsonPrettyPrinter(
|
||||
new goog.format.JsonPrettyPrinter.TextDelimiters());
|
Loading…
Add table
Add a link
Reference in a new issue