Skip to content

Commit

Permalink
Print Preview: Move copies test to individual file
Browse files Browse the repository at this point in the history
Splitting up long SetCopies test and moving to a separate file. Also
restoring testing of collate checkbox visibility via a new
CollateVisibility test.

Change-Id: If6891f29e597a2d8dd1e628a946c555b61b1441d
Reviewed-on: https://chromium-review.googlesource.com/c/1493393
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Esmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636943}
  • Loading branch information
rbpotter authored and Commit Bot committed Mar 1, 2019
1 parent f8729fb commit 2881418
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 65 deletions.
114 changes: 114 additions & 0 deletions chrome/test/data/webui/print_preview/copies_settings_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('copies_settings_test', function() {
suite('CopiesSettingsTest', function() {
/** @type {?PrintPreviewCopiesSettingsElement} */
let copiesSection = null;

/** @override */
setup(function() {
PolymerTest.clearBody();
copiesSection = document.createElement('print-preview-copies-settings');
copiesSection.settings = {
copies: {
value: '1',
unavailableValue: '1',
valid: true,
available: true,
setByPolicy: false,
key: '',
},
collate: {
value: true,
unavailableValue: false,
valid: true,
available: true,
setByPolicy: false,
key: '',
},
};
copiesSection.disabled = false;
document.body.appendChild(copiesSection);
});

test('collate visibility', async () => {
const collateSection = copiesSection.$$('.checkbox');
assertTrue(collateSection.hidden);

copiesSection.setSetting('copies', 2);
assertFalse(collateSection.hidden);

// Set copies empty.
const copiesInput =
copiesSection.$$('print-preview-number-settings-section').getInput();
await print_preview_test_utils.triggerInputEvent(
copiesInput, '', copiesSection);
assertTrue(collateSection.hidden);

// Set copies valid again.
await print_preview_test_utils.triggerInputEvent(
copiesInput, '3', copiesSection);
assertFalse(collateSection.hidden);

// Set copies invalid.
await print_preview_test_utils.triggerInputEvent(
copiesInput, '0', copiesSection);
assertTrue(collateSection.hidden);
});

// Verifies that setting the copies value using the number input works
// correctly.
test('set copies', async () => {
const copiesInput =
copiesSection.$$('print-preview-number-settings-section').getInput();
assertEquals('1', copiesInput.value);

await print_preview_test_utils.triggerInputEvent(
copiesInput, '2', copiesSection);
assertEquals(2, copiesSection.getSettingValue('copies'));
assertTrue(copiesSection.getSetting('copies').valid);

// Empty entry.
await print_preview_test_utils.triggerInputEvent(
copiesInput, '', copiesSection);
assertEquals(2, copiesSection.getSettingValue('copies'));
assertTrue(copiesSection.getSetting('copies').valid);

// Invalid entry.
await print_preview_test_utils.triggerInputEvent(
copiesInput, '0', copiesSection);
assertEquals(1, copiesSection.getSettingValue('copies'));
assertFalse(copiesSection.getSetting('copies').valid);
});

// Verifies that setting the collate value using the checkbox works
// correctly.
test('set collate', function() {
const collateCheckbox = copiesSection.$.collate;
copiesSection.setSetting('copies', 2);
assertTrue(collateCheckbox.checked);

MockInteractions.tap(collateCheckbox);
assertFalse(collateCheckbox.checked);
collateCheckbox.dispatchEvent(new CustomEvent('change'));
assertFalse(copiesSection.getSettingValue('collate'));
});

// Verifies that the inputs update when the value is updated.
test('update from settings', function() {
const copiesInput =
copiesSection.$$('print-preview-number-settings-section').getInput();
const collateCheckbox = copiesSection.$.collate;

assertEquals('1', copiesInput.value);
copiesSection.setSetting('copies', 3);
assertEquals('3', copiesInput.value);

assertTrue(collateCheckbox.checked);
copiesSection.setSetting('collate', false);
assertFalse(collateCheckbox.checked);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ TEST_F('PrintPreviewSettingsSectionsTest', 'Other', function() {
this.runMochaTest(settings_sections_tests.TestNames.Other);
});

TEST_F('PrintPreviewSettingsSectionsTest', 'SetCopies', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetCopies);
});

TEST_F('PrintPreviewSettingsSectionsTest', 'SetLayout', function() {
this.runMochaTest(settings_sections_tests.TestNames.SetLayout);
});
Expand Down Expand Up @@ -1294,6 +1290,26 @@ TEST_F(
scaling_settings_test.TestNames.InputNotDisabledOnValidityChange);
});

PrintPreviewCopiesSettingsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
return 'chrome://print/new/copies_settings.html';
}

/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
'../settings/test_util.js',
'print_preview_test_utils.js',
'copies_settings_test.js',
]);
}
};

TEST_F('PrintPreviewCopiesSettingsTest', 'All', function() {
mocha.run();
});

PrintPreviewMediaSizeSettingsTest = class extends NewPrintPreviewTest {
/** @override */
get browsePreload() {
Expand Down
61 changes: 0 additions & 61 deletions chrome/test/data/webui/print_preview/settings_section_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ cr.define('settings_sections_tests', function() {
const TestNames = {
SettingsSectionsVisibilityChange: 'settings sections visibility change',
Other: 'other',
SetCopies: 'set copies',
SetLayout: 'set layout',
SetColor: 'set color',
SetMargins: 'set margins',
Expand Down Expand Up @@ -129,66 +128,6 @@ cr.define('settings_sections_tests', function() {
});
});

test(assert(TestNames.SetCopies), function() {
const copiesElement = page.$$('print-preview-copies-settings');
assertFalse(copiesElement.hidden);

// Default value is 1
const copiesInput =
copiesElement.$$('print-preview-number-settings-section').getInput();
assertEquals('1', copiesInput.value);
assertEquals(1, page.settings.copies.value);

// Change to 2
return print_preview_test_utils
.triggerInputEvent(copiesInput, '2', copiesElement)
.then(function() {
assertEquals(2, page.settings.copies.value);

// Collate is true by default.
const collateInput = copiesElement.$.collate;
assertTrue(collateInput.checked);
assertTrue(page.settings.collate.value);

// Uncheck the box.
MockInteractions.tap(collateInput);
assertFalse(collateInput.checked);
collateInput.dispatchEvent(new CustomEvent('change'));
assertFalse(page.settings.collate.value);

// Set an empty value.
return print_preview_test_utils.triggerInputEvent(
copiesInput, '', copiesElement);
})
.then(function() {
// Collate should be hidden now, but no update to the backing value
// occurs.
assertTrue(copiesElement.$$('.checkbox').hidden);
assertTrue(page.settings.copies.valid);
assertEquals(2, page.settings.copies.value);

// If the field is blurred, it will be reset to the default by the
// number-settings-section. Simulate this ocurring.
const numberSettingsSection =
copiesElement.$$('print-preview-number-settings-section');
numberSettingsSection.$.userValue.value = '1';
numberSettingsSection.currentValue = '1';
assertTrue(page.settings.copies.valid);
assertEquals(1, page.settings.copies.value);

// Enter an invalid value.
return print_preview_test_utils.triggerInputEvent(
copiesInput, '0', copiesElement);
})
.then(function() {
// Collate should be hidden. Value is not updated to the invalid
// number. Setting is marked invalid.
assertTrue(copiesElement.$$('.checkbox').hidden);
assertFalse(page.settings.copies.valid);
assertEquals(1, page.settings.copies.value);
});
});

test(assert(TestNames.SetLayout), function() {
const layoutElement = page.$$('print-preview-layout-settings');
assertFalse(layoutElement.hidden);
Expand Down

0 comments on commit 2881418

Please sign in to comment.