Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Files]: Updates the query state in the store.
Updates the query on user input or clear calls. Adds a unit tests for search container. Bug: b:241868715 Change-Id: Id8621bd3e6cb5f595af56aef38074bd1cefabcbd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4113041 Reviewed-by: Luciano Pacheco <lucmult@chromium.org> Commit-Queue: Bo Majewski <majewski@chromium.org> Cr-Commit-Position: refs/heads/main@{#1085190}
- Loading branch information
Bo Majewski
authored and
Chromium LUCI CQ
committed
Dec 19, 2022
1 parent
4fb8ef4
commit 1ed7238
Showing
5 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
ui/file_manager/file_manager/containers/search_container_unittest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {CrInputElement} from 'chrome://resources/cr_elements/cr_input/cr_input.js'; | ||
|
||
import {EntryLocation} from '../externs/entry_location.js'; | ||
import {State} from '../externs/ts/state.js'; | ||
import {VolumeManager} from '../externs/volume_manager.js'; | ||
import {waitDeepEquals} from '../state/for_tests.js'; | ||
import {getEmptyState, getStore, Store} from '../state/store.js'; | ||
|
||
import {SearchContainer} from './search_container.js'; | ||
|
||
|
||
const searchWrapper: HTMLElement = document.createElement('div'); | ||
const optionsContainer: HTMLElement = document.createElement('div'); | ||
const pathContainer: HTMLElement = document.createElement('div'); | ||
|
||
let store: Store|undefined; | ||
let searchContainer: SearchContainer|undefined; | ||
|
||
function setupStore(): Store { | ||
const store = getStore(); | ||
store.init(getEmptyState()); | ||
return store; | ||
} | ||
|
||
/** | ||
* Creates new <search-container> element for each test. | ||
*/ | ||
export function setUp() { | ||
const root = document.createElement('div'); | ||
document.body.replaceChildren(root); | ||
searchWrapper.innerHTML = ` | ||
<cr-button id="search-button" tabindex="0"> | ||
<div class="icon"></div> | ||
</cr-button> | ||
<div id="search-box"> | ||
<cr-input type="search" disabled placeholder="Search"> | ||
<cr-button class="clear" slot="suffix" tabindex="0" has-tooltip> | ||
<div class="icon"></div> | ||
</cr-button> | ||
</cr-input> | ||
</div>`; | ||
root.appendChild(searchWrapper); | ||
root.appendChild(optionsContainer); | ||
root.appendChild(pathContainer); | ||
|
||
store = setupStore(); | ||
const volumeManager: VolumeManager = { | ||
getLocationInfo: (_entry: Entry): EntryLocation => { | ||
return new EntryLocation(); | ||
}, | ||
} as unknown as VolumeManager; | ||
|
||
searchContainer = new SearchContainer( | ||
volumeManager, searchWrapper, optionsContainer, pathContainer); | ||
} | ||
|
||
export async function testQueryUpdated() { | ||
// Test 1: Enter a query. | ||
const input = searchWrapper.querySelector('cr-input') as CrInputElement; | ||
input.value = 'hello'; | ||
input.dispatchEvent(new Event('input', { | ||
bubbles: true, | ||
cancelable: true, | ||
})); | ||
const want1 = { | ||
query: 'hello', | ||
status: undefined, | ||
options: undefined, | ||
}; | ||
await waitDeepEquals(store!, want1, (state: State) => { | ||
return state.search; | ||
}); | ||
|
||
// Test 2: Clear the query. | ||
searchContainer!.clear(); | ||
const want2 = { | ||
query: '', | ||
status: undefined, | ||
options: undefined, | ||
}; | ||
await waitDeepEquals(store!, want2, (state: State) => { | ||
return state.search; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters