Skip to content

Commit

Permalink
fix(findSubGraph): removed tests due to false confidence and unrealis…
Browse files Browse the repository at this point in the history
…tic UX
  • Loading branch information
asalem1 committed May 19, 2020
1 parent cc6027b commit 80d9205
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 37 deletions.
91 changes: 91 additions & 0 deletions ui/src/variables/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,97 @@ export const defaultGraph: VariableNode[] = [
},
]

export const defaultVariables: Variable[] = [
{
id: '05b740973c68e000',
orgID: '05b740945a91b000',
name: 'static',
description: '',
selected: ['defbuck'],
arguments: {
type: 'constant',
values: ['beans', 'defbuck'],
},
createdAt: '2020-05-19T06:00:00.113169-07:00',
updatedAt: '2020-05-19T06:00:00.113169-07:00',
labels: [],
links: {
self: '/api/v2/variables/05b740973c68e000',
labels: '/api/v2/variables/05b740973c68e000/labels',
org: '/api/v2/orgs/05b740945a91b000',
},
status: RemoteDataState.Done,
},
{
id: '05b740974228e000',
orgID: '05b740945a91b000',
name: 'dependent',
description: '',
selected: [],
arguments: {
type: 'query',
values: {
query:
'from(bucket: v.static)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r["_measurement"] == "test")\n |> keep(columns: ["container_name"])\n |> rename(columns: {"container_name": "_value"})\n |> last()\n |> group()',
language: 'flux',
results: [],
},
},
createdAt: '2020-05-19T06:00:00.136597-07:00',
updatedAt: '2020-05-19T06:00:00.136597-07:00',
labels: [],
links: {
self: '/api/v2/variables/05b740974228e000',
labels: '/api/v2/variables/05b740974228e000/labels',
org: '/api/v2/orgs/05b740945a91b000',
},
status: RemoteDataState.Loading,
},
{
orgID: '',
id: 'timeRangeStart',
name: 'timeRangeStart',
arguments: {
type: 'system',
values: [
[
{
magnitude: 1,
unit: 'h',
},
],
],
},
status: RemoteDataState.Done,
labels: [],
selected: [],
},
{
orgID: '',
id: 'timeRangeStop',
name: 'timeRangeStop',
arguments: {
type: 'system',
values: ['now()'],
},
status: RemoteDataState.Done,
labels: [],
selected: [],
},
{
orgID: '',
id: 'windowPeriod',
name: 'windowPeriod',
arguments: {
type: 'system',
values: [10000],
},
status: RemoteDataState.Done,
labels: [],
selected: [],
},
]

export const defaultVariable: Variable[] = [
{
id: '05b73f4bffe8e000',
Expand Down
38 changes: 2 additions & 36 deletions ui/src/variables/utils/hydrateVars.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// Utils
import {ValueFetcher} from 'src/variables/utils/ValueFetcher'
import {hydrateVars, findSubgraph} from 'src/variables/utils/hydrateVars'
import {hydrateVars} from 'src/variables/utils/hydrateVars'

// Mocks
import {
createVariable,
defaultVariable,
defaultSubGraph,
defaultGraph,
} from 'src/variables/mocks'
import {createVariable} from 'src/variables/mocks'

// Types
import {Variable, CancellationError, RemoteDataState} from 'src/types'
import {VariableNode} from 'src/variables/utils/hydrateVars'

class FakeFetcher implements ValueFetcher {
responses = {}
Expand Down Expand Up @@ -325,31 +319,3 @@ describe('hydrate vars', () => {
cancel()
})
})

describe('findSubgraph', () => {
test('find subgraphs', async () => {
const actual = await findSubgraph(defaultGraph, defaultVariable)

// We expect the end state of the graph to be:
//
// digraph {
// a -> b
// b -> c
// c -> d
// d -> e
// d -> b
// f -> g
// a [fontcolor = "red"]
// b [fontcolor = "red"]
// c [fontcolor = "red"]
// d [fontcolor = "red"]
// e [fontcolor = "green"]
// f [fontcolor = "green"]
// g [fontcolor = "green"]
// }
//
// NOTE: these return falsy and not an empty array, because they are skipped
// within hydrateVars as not belonging to the graph
expect(actual).toEqual(defaultSubGraph)
})
})
2 changes: 1 addition & 1 deletion ui/src/variables/utils/hydrateVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const collectAncestors = (
- The node for one of the passed variables depends on this node
*/
export const findSubgraph = (
const findSubgraph = (
graph: VariableNode[],
variables: Variable[]
): VariableNode[] => {
Expand Down

0 comments on commit 80d9205

Please sign in to comment.