Move the Javascript tests to use Jasmine/Karma

This commit is contained in:
Gus Brodman 2019-06-07 18:13:38 -04:00
parent e378855093
commit b644a9f4c9
12 changed files with 4012 additions and 689 deletions

View file

@ -16,28 +16,25 @@ goog.setTestOnly();
goog.require('goog.dispose');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.jsunit');
goog.require('registry.Component');
goog.require('registry.Console');
describe("component test", function() {
let mocks;
var mocks = new goog.testing.MockControl();
beforeEach(function() {
mocks = new goog.testing.MockControl();
});
afterEach(function() {
mocks.$tearDown();
});
function setUp() {
mocks = new goog.testing.MockControl();
}
function tearDown() {
mocks.$tearDown();
}
function testCreationAndDisposal_dontTouchConsoleObject() {
var console = mocks.createStrictMock(registry.Console);
mocks.$replayAll();
var component = new registry.Component(console);
goog.dispose(component);
mocks.$verifyAll();
}
it("testCreationAndDisposal_dontTouchConsoleObject", function() {
var console = mocks.createStrictMock(registry.Console);
mocks.$replayAll();
var component = new registry.Component(console);
goog.dispose(component);
mocks.$verifyAll();
});
});

View file

@ -19,112 +19,105 @@ goog.require('goog.dom.classlist');
goog.require('goog.json');
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.testing');
goog.require('registry.util');
describe("console tests", function() {
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
const test = {
testXsrfToken: 'testToken',
testClientId: 'daddy',
mockControl: new goog.testing.MockControl()
};
const test = {
testXsrfToken: 'testToken',
testClientId: 'daddy',
mockControl: new goog.testing.MockControl()
};
function setUp() {
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,
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();
});
registry.registrar.ConsoleTestUtil.setup(test);
const regNavlist = $('reg-navlist');
const active = regNavlist.querySelector('a[href="#contact-us"]');
assertTrue(active != null);
}
function tearDown() {
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
}
function testButter() {
registry.registrar.ConsoleTestUtil.visit(test, {
productName: 'Foo Registry'
afterEach(function() {
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
});
registry.util.butter('butter msg');
const butter = goog.dom.getElementByClass(goog.getCssName('kd-butterbar'));
assertNotNull(butter.innerHTML.match(/.*butter msg.*/));
assertTrue(goog.dom.classlist.contains(butter, goog.getCssName('shown')));
}
/** Authed user with no path op specified should nav to welcome page. */
function testShowLoginOrDash() {
registry.registrar.ConsoleTestUtil.visit(test, {
productName: 'Foo Registry'
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);
});
assertNotNull(goog.dom.getElement('domain-registrar-dashboard'));
}
function testNavToResources() {
registry.registrar.ConsoleTestUtil.visit(test, {
path: 'resources',
xsrfToken: test.testXsrfToken,
technicalDocsUrl: 'http://example.com/techdocs',
readonly: 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();
});
const xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-settings', xhr.getLastUri());
assertEquals(test.testXsrfToken,
xhr.getLastRequestHeaders()['X-CSRF-Token']);
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
driveFolderId: 'blahblah'
}]
}));
assertContains('blahblah', $('reg-resources-driveLink').getAttribute('href'));
}
function testNavToContactUs() {
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'
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('/registrar-settings').toEqual(xhr.getLastUri());
expect(test.testXsrfToken).toEqual(
xhr.getLastRequestHeaders()['X-CSRF-Token']);
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
driveFolderId: 'blahblah'
}]
}));
expect($('reg-resources-driveLink').getAttribute('href')).toContain('blahblah');
});
const xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue(xhr.isActive());
assertEquals('/registrar-settings', xhr.getLastUri());
assertEquals(test.testXsrfToken,
xhr.getLastRequestHeaders()['X-CSRF-Token']);
const passcode = '5-5-5-5-5';
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
phonePasscode: passcode
}]
}));
assertEquals(passcode,
goog.dom.getTextContent($('domain-registrar-phone-passcode')));
}
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('/registrar-settings').toEqual(xhr.getLastUri());
expect(test.testXsrfToken).toEqual(
xhr.getLastRequestHeaders()['X-CSRF-Token']);
const passcode = '5-5-5-5-5';
xhr.simulateResponse(200, goog.json.serialize({
status: 'SUCCESS',
message: 'OK',
results: [{
phonePasscode: passcode
}]
}));
expect(passcode).toEqual(
goog.dom.getTextContent($('domain-registrar-phone-passcode')));
});
});

View file

@ -19,353 +19,347 @@ goog.require('goog.dispose');
goog.require('goog.dom');
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.testing');
goog.require('registry.util');
describe("contact settings test", function() {
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
let testContact = null;
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
let testContact = null;
const test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
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);
}
function tearDown() {
goog.dispose(test.console);
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
}
function testCollectionView() {
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]
}]
}
);
assertEquals(1, $('admin-contacts').childNodes.length);
assertEquals(1, $('other-contacts').childNodes.length);
// XXX: Needs more field testing.
}
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]
}]
}
);
assertEquals(testContact.name, $('contacts[0].name').value);
assertEquals(testContact.emailAddress, $('contacts[0].emailAddress').value);
assertEquals(testContact.phoneNumber, $('contacts[0].phoneNumber').value);
assertEquals(testContact.faxNumber, $('contacts[0].faxNumber').value);
// XXX: Types are no longer broken out as individual settings, so relying on
// screenshot test.
}
// XXX: Should be hoisted.
function testItemEditButtons() {
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'));
}
function testItemEdit() {
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]));
}
function testChangeContactTypes() {
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]));
}
function testOneOfManyUpdate() {
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
}]
}
);
}
function testDomainWhoisAbuseContactOverride() {
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}]});
}
function testDelete() {
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
}]
}
);
}
/**
* @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'
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(1).toEqual($('admin-contacts').childNodes.length);
expect(1).toEqual($('other-contacts').childNodes.length);
// XXX: Needs more field testing.
});
/**
* 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();
}
it("testItemView", function() {
testItemView();
expect(testContact.name).toEqual($('contacts[0].name').value);
expect(testContact.emailAddress).toEqual($('contacts[0].emailAddress').value);
expect(testContact.phoneNumber).toEqual($('contacts[0].phoneNumber').value);
expect(testContact.faxNumber).toEqual($('contacts[0].faxNumber').value);
// 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]
}]
}
);
}
delete contact['type'];
return contact;
}
/**
* @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;
}
});

View file

@ -18,119 +18,117 @@ goog.require('goog.dispose');
goog.require('goog.dom');
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.testing');
goog.require('registry.util');
describe('security settings test', function() {
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
const $ = goog.dom.getRequiredElement;
const stubs = new goog.testing.PropertyReplacer();
const expectedRegistrar = {
ipAddressWhitelist: [],
phonePasscode: '12345',
clientCertificate: null,
clientCertificateHash: null,
failoverClientCertificate: null
};
const expectedRegistrar = {
ipAddressWhitelist: [],
phonePasscode: '12345',
clientCertificate: null,
clientCertificateHash: null,
failoverClientCertificate: null
};
const test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
const test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
xsrfToken: test.testXsrfToken,
clientId: test.testClientId,
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);
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
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
afterEach(function() {
goog.dispose(test.console);
goog.testing.net.XhrIo.cleanup();
stubs.reset();
test.mockControl.$tearDown();
});
registry.testing.assertReqMockRsp(
test.testXsrfToken,
'/registrar-settings',
{op: 'read', id: 'testClientId', args: {}},
{
status: 'SUCCESS',
message: 'OK',
results: [expectedRegistrar]
});
assertEquals(expectedRegistrar.phonePasscode,
registry.util.parseForm('item').phonePasscode);
}
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(expectedRegistrar.phonePasscode).toEqual(registry.util.parseForm('item').phonePasscode);
}
function testEdit() {
testView();
it("testView", function() {
testView();
});
registry.testing.click($('reg-app-btn-edit'));
it("testEdit", function() {
testView();
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'));
registry.testing.click($('reg-app-btn-edit'));
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'));
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'));
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.
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'));
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]});
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.
delete expectedRegistrar['clientCertificateHash'];
registry.testing.assertObjectEqualsPretty(
expectedRegistrar, registry.util.parseForm('item'));
}
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'));
});
});

View file

@ -19,152 +19,148 @@ goog.require('goog.dom');
goog.require('goog.dom.classlist');
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.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 $ = goog.dom.getRequiredElement;
const $$ = goog.dom.getRequiredElementByClass;
const stubs = new goog.testing.PropertyReplacer();
const test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
const test = {
testXsrfToken: '༼༎෴ ༎༽',
testClientId: 'testClientId',
mockControl: new goog.testing.MockControl()
};
function setUp() {
registry.testing.addToDocument('<div id="test"/>');
registry.testing.addToDocument('<div class="kd-butterbar"/>');
registry.registrar.ConsoleTestUtil.renderConsoleMain($('test'), {
xsrfToken: test.testXsrfToken,
clientId: test.testClientId,
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);
});
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
registry.registrar.ConsoleTestUtil.setup(test);
}
function tearDown() {
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
afterEach(function() {
goog.dispose(test.console);
stubs.reset();
goog.testing.net.XhrIo.cleanup();
test.mockControl.$tearDown();
});
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);
}
/**
* 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 testEdit() {
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]
});
}
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();
});
function testEditFieldError_insertsError() {
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'));
assertTrue(goog.dom.classlist.contains(msgBox, 'kd-errormessage'));
assertTrue(goog.dom.classlist.contains($('phoneNumber'), 'kd-formerror'));
assertEquals(errMsg, goog.dom.getTextContent(msgBox));
}
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(errMsg).toEqual(goog.dom.getTextContent(msgBox));
});
function testEditNonFieldError_showsButterBar() {
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
});
assertEquals(errMsg, goog.dom.getTextContent($$('kd-butterbar-text')));
}
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(errMsg).toEqual(goog.dom.getTextContent($$('kd-butterbar-text')));
});
});

View file

@ -53,8 +53,7 @@ registry.testing.click = function(element) {
* @param {!Element} element
*/
registry.testing.assertVisible = function(element) {
assertTrue('Element should have CSS "shown" class',
goog.dom.classlist.contains(element, 'shown'));
expect(goog.dom.classlist.contains(element, 'shown')).toBe(true);
};
@ -63,8 +62,7 @@ registry.testing.assertVisible = function(element) {
* @param {!Element} element
*/
registry.testing.assertHidden = function(element) {
assertTrue('Element should have CSS "hidden" class',
goog.dom.classlist.contains(element, 'hidden'));
expect(goog.dom.classlist.contains(element, 'hidden')).toBe(true);
};
@ -75,7 +73,7 @@ registry.testing.assertHidden = function(element) {
*/
registry.testing.assertObjectEqualsPretty = function(a, b) {
try {
assertObjectEquals(a, b);
expect(a).toEqual(b);
} catch (e) {
e.message = e.message + '\n' +
'expected: ' + registry.testing.pretty_.format(a) + '\n' +
@ -96,8 +94,8 @@ registry.testing.assertObjectEqualsPretty = function(a, b) {
registry.testing.assertReqMockRsp =
function(xsrfToken, path, expectReqJson, mockRspJson) {
var xhr = goog.testing.net.XhrIo.getSendInstances().pop();
assertTrue('XHR is active.', xhr.isActive());
assertEquals(path, xhr.getLastUri());
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(