forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workspace list pr (opensearch-project#285)
* feat: add workspace list Signed-off-by: tygao <[email protected]> * update index.ts Signed-off-by: tygao <[email protected]> * test: update workspace plugin test Signed-off-by: tygao <[email protected]> * remove extra file and add test for modal Signed-off-by: tygao <[email protected]> * test: add tests for workspace util Signed-off-by: tygao <[email protected]> * test: update test for delete_workspace_modal Signed-off-by: tygao <[email protected]> * test: update test for delete_workspace_modal Signed-off-by: tygao <[email protected]> * test: update test for workspace list Signed-off-by: tygao <[email protected]> * rename and update test Signed-off-by: tygao <[email protected]> * add tests for workspace list Signed-off-by: tygao <[email protected]> --------- Signed-off-by: tygao <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,426 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { debounce } from './debounce'; | ||
|
||
describe('debounce', () => { | ||
let fn: Function; | ||
beforeEach(() => { | ||
fn = jest.fn(); | ||
jest.useFakeTimers(); | ||
}); | ||
afterEach(() => { | ||
jest.clearAllTimers(); | ||
}); | ||
|
||
test('it should call the debounced fn once at the end of the quiet time', () => { | ||
const debounced = debounce(fn, 1000); | ||
|
||
for (let i = 0; i < 100; i++) { | ||
debounced(i); | ||
} | ||
|
||
jest.advanceTimersByTime(1001); | ||
expect(fn).toBeCalledTimes(1); | ||
expect(fn).toBeCalledWith(99); | ||
}); | ||
|
||
test("with a leading invocation, it should call the debounced fn once, if the time doens't pass", () => { | ||
const debounced = debounce(fn, 1000, true); | ||
|
||
for (let i = 0; i < 100; i++) { | ||
debounced(i); | ||
} | ||
|
||
jest.advanceTimersByTime(999); | ||
|
||
expect(fn).toBeCalledTimes(1); | ||
expect(fn).toBeCalledWith(0); | ||
}); | ||
|
||
test('with a leading invocation, it should call the debounced fn twice (at the beginning and at the end)', () => { | ||
const debounced = debounce(fn, 1000, true); | ||
|
||
for (let i = 0; i < 100; i++) { | ||
debounced(i); | ||
} | ||
|
||
jest.advanceTimersByTime(1500); | ||
|
||
expect(fn).toBeCalledTimes(2); | ||
expect(fn).toBeCalledWith(0); | ||
expect(fn).toBeCalledWith(99); | ||
}); | ||
}); |
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,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @param func The function to be debounced. | ||
* @param delay The time in milliseconds to wait before invoking the function again after the last invocation. | ||
* @param leading An optional parameter that, when true, allows the function to be invoked immediately upon the first call. | ||
*/ | ||
export const debounce = (func: Function, delay: number, leading?: boolean) => { | ||
let timerId: NodeJS.Timeout; | ||
|
||
return (...args: any) => { | ||
if (!timerId && leading) { | ||
func(...args); | ||
} | ||
clearTimeout(timerId); | ||
|
||
timerId = setTimeout(() => func(...args), delay); | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -38,3 +38,4 @@ export { | |
getWorkspaceIdFromUrl, | ||
cleanWorkspaceId, | ||
} from '../../utils'; | ||
export { debounce } from './debounce'; |
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
134 changes: 134 additions & 0 deletions
134
...blic/components/delete_workspace_modal/__snapshots__/delete_workspace_modal.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.