-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): ensure map type variables can get selected key
- Loading branch information
Showing
4 changed files
with
86 additions
and
2 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
82 changes: 82 additions & 0 deletions
82
ui/src/dashboards/components/variablesControlBar/VariableDropdown.test.tsx
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,82 @@ | ||
// Libraries | ||
import React from 'react' | ||
import {fireEvent} from 'react-testing-library' | ||
|
||
// Components | ||
import VariableDropdown from 'src/dashboards/components/variablesControlBar/VariableDropdown' | ||
|
||
// Utils | ||
import {renderWithRedux} from 'src/mockState' | ||
import {AppState} from 'src/types' | ||
|
||
const values = { | ||
def: 'defbuck', | ||
def2: 'defbuck', | ||
foo: 'foobuck', | ||
goo: 'goobuck', | ||
new: 'newBuck', | ||
} | ||
|
||
const setInitialState = (state: AppState) => { | ||
return { | ||
...state, | ||
orgs: [ | ||
{ | ||
id: '03cbdc8a53a63000', | ||
}, | ||
], | ||
variables: { | ||
status: 'Done', | ||
variables: { | ||
'03cbdc8a53a63000': { | ||
variable: { | ||
id: '03cbdc8a53a63000', | ||
orgID: '03c02466515c1000', | ||
name: 'map_buckets', | ||
description: '', | ||
selected: null, | ||
arguments: { | ||
type: 'map', | ||
values, | ||
}, | ||
labels: [], | ||
}, | ||
status: 'Done', | ||
}, | ||
}, | ||
values: { | ||
'03c8070355fbd000': { | ||
status: 'Done', | ||
values: { | ||
'03cbdc8a53a63000': { | ||
valueType: 'string', | ||
values: Object.values(values), | ||
selectedValue: 'defbuck', | ||
}, | ||
}, | ||
order: ['03cbdc8a53a63000'], | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
describe('Dashboards.Components.VariablesControlBar.VariableDropdown', () => { | ||
describe('if map type', () => { | ||
it('renders dropdown with keys as dropdown items', () => { | ||
const {getByTestId, getAllByTestId} = renderWithRedux( | ||
<VariableDropdown | ||
variableID="03cbdc8a53a63000" | ||
dashboardID="03c8070355fbd000" | ||
/>, | ||
setInitialState | ||
) | ||
|
||
const dropdownClosed = getByTestId('variable-dropdown') | ||
fireEvent.click(dropdownClosed) | ||
const dropdownItems = getAllByTestId(/dropdown--item/) | ||
|
||
expect(dropdownItems.length).toBe(Object.keys(values).length) | ||
}) | ||
}) | ||
}) |
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