Commit 1a070a7a authored by Gavin Williams's avatar Gavin Williams Committed by Chromium LUCI CQ

scanning: Refactor variables for scanning app test

Define the commonly used variables outside of the individual tests.

Bug: 1059779
Change-Id: I527e06e824669e3c44c9b226dbfe7e3e0079b264
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2570736
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833390}
parent 172d4d65
...@@ -239,6 +239,62 @@ export function scanningAppTest() { ...@@ -239,6 +239,62 @@ export function scanningAppTest() {
/** @type {?FakeScanService} */ /** @type {?FakeScanService} */
let fakeScanService_ = null; let fakeScanService_ = null;
/** @type {?HTMLSelectElement} */
let scannerSelect = null;
/** @type {?HTMLSelectElement} */
let sourceSelect = null;
/** @type {?HTMLSelectElement} */
let fileTypeSelect = null;
/** @type {?HTMLSelectElement} */
let colorModeSelect = null;
/** @type {?HTMLSelectElement} */
let pageSizeSelect = null;
/** @type {?HTMLSelectElement} */
let resolutionSelect = null;
/** @type {?CrButtonElement} */
let scanButton = null;
/** @type {?CrButtonElement} */
let cancelButton = null;
/** @type {?HTMLElement} */
let statusText = null;
/** @type {?HTMLElement} */
let helperText = null;
/** @type {?HTMLElement} */
let scanProgress = null;
/** @type {?HTMLElement} */
let progressText = null;
/** @type {?HTMLElement} */
let progressBar = null;
/** @type {?HTMLElement} */
let scannedImages = null;
/**
* @type {!Map<!mojoBase.mojom.UnguessableToken,
* !chromeos.scanning.mojom.ScannerCapabilities>}
*/
const capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
capabilities.set(secondScannerId, secondCapabilities);
/** @type {!ScannerArr} */
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
createScanner(secondScannerId, secondScannerName)
];
suiteSetup(() => { suiteSetup(() => {
fakeScanService_ = new FakeScanService(); fakeScanService_ = new FakeScanService();
setScanServiceForTesting(fakeScanService_); setScanServiceForTesting(fakeScanService_);
...@@ -252,6 +308,20 @@ export function scanningAppTest() { ...@@ -252,6 +308,20 @@ export function scanningAppTest() {
fakeScanService_.resetForTest(); fakeScanService_.resetForTest();
scanningApp.remove(); scanningApp.remove();
scanningApp = null; scanningApp = null;
scannerSelect = null;
sourceSelect = null;
fileTypeSelect = null;
colorModeSelect = null;
pageSizeSelect = null;
resolutionSelect = null;
scanButton = null;
cancelButton = null;
statusText = null;
helperText = null;
scanProgress = null;
progressText = null;
progressBar = null;
scannedImages = null;
}); });
/** /**
...@@ -310,47 +380,10 @@ export function scanningAppTest() { ...@@ -310,47 +380,10 @@ export function scanningAppTest() {
} }
test('Scan', () => { test('Scan', () => {
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
createScanner(secondScannerId, secondScannerName)
];
let capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
capabilities.set(secondScannerId, secondCapabilities);
/** @type {!mojoBase.mojom.FilePath} */ /** @type {!mojoBase.mojom.FilePath} */
const lastScannedFilePath = {'path': '/test/path/scan.jpg'}; const lastScannedFilePath = {'path': '/test/path/scan.jpg'};
/** @type {!HTMLSelectElement} */
let scannerSelect;
/** @type {!HTMLSelectElement} */
let sourceSelect;
/** @type {!HTMLSelectElement} */
let fileTypeSelect;
/** @type {!HTMLSelectElement} */
let colorModeSelect;
/** @type {!HTMLSelectElement} */
let pageSizeSelect;
/** @type {!HTMLSelectElement} */
let resolutionSelect;
/** @type {!CrButtonElement} */
let scanButton;
/** @type {!CrButtonElement} */
let cancelButton;
/** @type {!HTMLElement} */
let statusText;
/** @type {!HTMLElement} */
let helperText;
/** @type {!HTMLElement} */
let scanProgress;
/** @type {!HTMLElement} */
let progressText;
/** @type {!HTMLElement} */
let progressBar;
/** @type {!HTMLElement} */
let scannedImages;
return initializeScanningApp(expectedScanners, capabilities) return initializeScanningApp(expectedScanners, capabilities)
.then(() => { .then(() => {
scannerSelect = scanningApp.$$('#scannerSelect').$$('select'); scannerSelect = scanningApp.$$('#scannerSelect').$$('select');
...@@ -399,11 +432,12 @@ export function scanningAppTest() { ...@@ -399,11 +432,12 @@ export function scanningAppTest() {
assertFalse(pageSizeSelect.disabled); assertFalse(pageSizeSelect.disabled);
assertFalse(resolutionSelect.disabled); assertFalse(resolutionSelect.disabled);
assertFalse(scanButton.disabled); assertFalse(scanButton.disabled);
assertTrue(isVisible(scanButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertFalse(isVisible(cancelButton)); assertFalse(
isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
assertEquals('', statusText.textContent.trim()); assertEquals('', statusText.textContent.trim());
assertTrue(isVisible(helperText)); assertTrue(isVisible(/** @type {!HTMLElement} */ (helperText)));
assertFalse(isVisible(scanProgress)); assertFalse(isVisible(/** @type {!HTMLElement} */ (scanProgress)));
assertFalse(isVisible( assertFalse(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
scanningApp.$$('scan-done-section')))); scanningApp.$$('scan-done-section'))));
...@@ -424,10 +458,10 @@ export function scanningAppTest() { ...@@ -424,10 +458,10 @@ export function scanningAppTest() {
assertTrue(pageSizeSelect.disabled); assertTrue(pageSizeSelect.disabled);
assertTrue(resolutionSelect.disabled); assertTrue(resolutionSelect.disabled);
assertTrue(scanButton.disabled); assertTrue(scanButton.disabled);
assertFalse(isVisible(scanButton)); assertFalse(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertTrue(isVisible(cancelButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
assertFalse(isVisible(helperText)); assertFalse(isVisible(/** @type {!HTMLElement} */ (helperText)));
assertTrue(isVisible(scanProgress)); assertTrue(isVisible(/** @type {!HTMLElement} */ (scanProgress)));
assertFalse(isVisible( assertFalse(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
scanningApp.$$('scan-done-section')))); scanningApp.$$('scan-done-section'))));
...@@ -467,7 +501,7 @@ export function scanningAppTest() { ...@@ -467,7 +501,7 @@ export function scanningAppTest() {
true, lastScannedFilePath); true, lastScannedFilePath);
}) })
.then(() => { .then(() => {
assertTrue(isVisible(scannedImages)); assertTrue(isVisible(/** @type {!HTMLElement} */ (scannedImages)));
assertEquals(2, scannedImages.querySelectorAll('img').length); assertEquals(2, scannedImages.querySelectorAll('img').length);
assertTrue(isVisible( assertTrue(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
...@@ -489,33 +523,20 @@ export function scanningAppTest() { ...@@ -489,33 +523,20 @@ export function scanningAppTest() {
assertFalse(pageSizeSelect.disabled); assertFalse(pageSizeSelect.disabled);
assertFalse(resolutionSelect.disabled); assertFalse(resolutionSelect.disabled);
assertFalse(scanButton.disabled); assertFalse(scanButton.disabled);
assertTrue(isVisible(scanButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertFalse(isVisible(cancelButton)); assertFalse(
assertTrue(isVisible(helperText)); isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
assertFalse(isVisible(scanProgress)); assertTrue(isVisible(/** @type {!HTMLElement} */ (helperText)));
assertFalse(isVisible(/** @type {!HTMLElement} */ (scanProgress)));
assertFalse(isVisible( assertFalse(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
scanningApp.$$('scan-done-section')))); scanningApp.$$('scan-done-section'))));
assertFalse(isVisible(scannedImages)); assertFalse(isVisible(/** @type {!HTMLElement} */ (scannedImages)));
assertEquals(0, scannedImages.querySelectorAll('img').length); assertEquals(0, scannedImages.querySelectorAll('img').length);
}); });
}); });
test('CancelScan', () => { test('CancelScan', () => {
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
createScanner(secondScannerId, secondScannerName)
];
let capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
capabilities.set(secondScannerId, secondCapabilities);
/** @type {!CrButtonElement} */
let scanButton;
/** @type {!CrButtonElement} */
let cancelButton;
return initializeScanningApp(expectedScanners, capabilities) return initializeScanningApp(expectedScanners, capabilities)
.then(() => { .then(() => {
scanButton = scanButton =
...@@ -528,8 +549,9 @@ export function scanningAppTest() { ...@@ -528,8 +549,9 @@ export function scanningAppTest() {
// Before the scan button is clicked, the scan button should be // Before the scan button is clicked, the scan button should be
// visible and enabled, and the cancel button shouldn't be visible. // visible and enabled, and the cancel button shouldn't be visible.
assertFalse(scanButton.disabled); assertFalse(scanButton.disabled);
assertTrue(isVisible(scanButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertFalse(isVisible(cancelButton)); assertFalse(
isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
// Click the Scan button and wait till the scan is started. // Click the Scan button and wait till the scan is started.
scanButton.click(); scanButton.click();
...@@ -540,8 +562,8 @@ export function scanningAppTest() { ...@@ -540,8 +562,8 @@ export function scanningAppTest() {
// button should be disabled and not visible, and the cancel button // button should be disabled and not visible, and the cancel button
// should be visible. // should be visible.
assertTrue(scanButton.disabled); assertTrue(scanButton.disabled);
assertFalse(isVisible(scanButton)); assertFalse(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertTrue(isVisible(cancelButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
// Simulate a progress update and verify the progress bar and text are // Simulate a progress update and verify the progress bar and text are
// updated correctly. // updated correctly.
...@@ -561,8 +583,9 @@ export function scanningAppTest() { ...@@ -561,8 +583,9 @@ export function scanningAppTest() {
.then(() => { .then(() => {
// After canceling is complete, the scan button should be visible and // After canceling is complete, the scan button should be visible and
// enabled, and the cancel button shouldn't be visible. // enabled, and the cancel button shouldn't be visible.
assertTrue(isVisible(scanButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
assertFalse(isVisible(cancelButton)); assertFalse(
isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
assertTrue(scanningApp.$$('#toast').open); assertTrue(scanningApp.$$('#toast').open);
assertFalse(isVisible( assertFalse(isVisible(
/** @type {!HTMLElement} */ (scanningApp.$$('#infoIcon')))); /** @type {!HTMLElement} */ (scanningApp.$$('#infoIcon'))));
...@@ -575,18 +598,6 @@ export function scanningAppTest() { ...@@ -575,18 +598,6 @@ export function scanningAppTest() {
}); });
test('CancelScanFailed', () => { test('CancelScanFailed', () => {
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
];
let capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
/** @type {!CrButtonElement} */
let scanButton;
/** @type {!CrButtonElement} */
let cancelButton;
return initializeScanningApp(expectedScanners, capabilities) return initializeScanningApp(expectedScanners, capabilities)
.then(() => { .then(() => {
scanButton = scanButton =
...@@ -631,26 +642,16 @@ export function scanningAppTest() { ...@@ -631,26 +642,16 @@ export function scanningAppTest() {
// button visible. // button visible.
assertTrue( assertTrue(
isVisible(scanningApp.$$('#scanPreview').$$('#scanProgress'))); isVisible(scanningApp.$$('#scanPreview').$$('#scanProgress')));
assertTrue(isVisible(cancelButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (cancelButton)));
assertFalse( assertFalse(
isVisible(scanningApp.$$('#scanPreview').$$('#helperText'))); isVisible(scanningApp.$$('#scanPreview').$$('#helperText')));
assertFalse(isVisible(scanButton)); assertFalse(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
}); });
}); });
test('ScanFailedToStart', () => { test('ScanFailedToStart', () => {
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
];
let capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
fakeScanService_.setFailStartScan(true); fakeScanService_.setFailStartScan(true);
/** @type {!CrButtonElement} */
let scanButton;
return initializeScanningApp(expectedScanners, capabilities) return initializeScanningApp(expectedScanners, capabilities)
.then(() => { .then(() => {
scanButton = scanButton =
...@@ -674,14 +675,12 @@ export function scanningAppTest() { ...@@ -674,14 +675,12 @@ export function scanningAppTest() {
scanningApp.$$('#toastText').textContent.trim()); scanningApp.$$('#toastText').textContent.trim());
assertFalse(scanButton.disabled); assertFalse(scanButton.disabled);
assertTrue(isVisible(scanButton)); assertTrue(isVisible(/** @type {!CrButtonElement} */ (scanButton)));
}); });
}); });
test('PanelContainerContent', () => { test('PanelContainerContent', () => {
const scanners = []; return initializeScanningApp(expectedScanners, capabilities).then(() => {
const capabilities = new Map();
return initializeScanningApp(scanners, capabilities).then(() => {
const panelContainer = scanningApp.$$('.panel-container'); const panelContainer = scanningApp.$$('.panel-container');
assertTrue(!!panelContainer); assertTrue(!!panelContainer);
...@@ -694,10 +693,7 @@ export function scanningAppTest() { ...@@ -694,10 +693,7 @@ export function scanningAppTest() {
}); });
test('MoreSettingsToggle', () => { test('MoreSettingsToggle', () => {
const scanners = [createScanner(firstScannerId, firstScannerName)]; return initializeScanningApp(expectedScanners, capabilities)
const capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
return initializeScanningApp(scanners, capabilities)
.then(() => { .then(() => {
return fakeScanService_.whenCalled('getScannerCapabilities'); return fakeScanService_.whenCalled('getScannerCapabilities');
}) })
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment