Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
0c5179b3
Commit
0c5179b3
authored
7 years ago
by
Atte Keinänen
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for utils.spec.js
parent
73689990
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/visualizations/lib/utils.js
+4
-3
4 additions, 3 deletions
frontend/src/metabase/visualizations/lib/utils.js
frontend/src/metabase/visualizations/lib/utils.spec.js
+171
-0
171 additions, 0 deletions
frontend/src/metabase/visualizations/lib/utils.spec.js
with
175 additions
and
3 deletions
frontend/src/metabase/visualizations/lib/utils.js
+
4
−
3
View file @
0c5179b3
...
...
@@ -249,11 +249,12 @@ function wrapMethod(object, name, method) {
}
}
}
// TODO Atte Keinänen 5/30/17 Extract to metabase-lib card/question logic
export
const
cardHasBecomeDirty
=
(
nextCard
,
previousCard
)
=>
!
_
.
isEqual
(
previousCard
.
dataset_query
,
nextCard
.
dataset_query
)
||
previousCard
.
display
!==
nextCard
.
display
;
export
function
getCardAfterVisualizationClick
(
nextCard
,
previousCard
)
{
const
cardIsDirty
=
!
_
.
isEqual
(
previousCard
.
dataset_query
,
nextCard
.
dataset_query
)
||
previousCard
.
display
!==
nextCard
.
display
;
if
(
cardIsDirty
)
{
if
(
cardHasBecomeDirty
(
nextCard
,
previousCard
))
{
const
isMultiseriesQuestion
=
!
nextCard
.
id
;
const
alreadyHadLineage
=
!!
previousCard
.
original_card_id
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/visualizations/lib/utils.spec.js
0 → 100644
+
171
−
0
View file @
0c5179b3
import
{
cardHasBecomeDirty
,
getCardAfterVisualizationClick
}
from
"
./utils
"
;
import
_
from
"
underscore
"
;
// TODO Atte Keinänen 5/31/17 Rewrite tests using metabase-lib methods instead of a raw format
const
baseQuery
=
{
"
database
"
:
1
,
"
type
"
:
"
query
"
,
"
query
"
:
{
"
source_table
"
:
2
,
"
aggregation
"
:
[
[
"
count
"
]
],
"
breakout
"
:
[
[
"
field-id
"
,
2
]
]
}
};
const
derivedQuery
=
{
...
baseQuery
,
"
query
"
:
{
...
baseQuery
.
query
,
"
filter
"
:
[
"
time-interval
"
,
[
"
field-id
"
,
1
],
-
7
,
"
day
"
]
}
};
const
breakoutMultiseriesQuery
=
{
...
baseQuery
,
"
query
"
:
{
...
baseQuery
.
query
,
"
breakout
"
:
[
...
baseQuery
.
query
.
breakout
,
[
"
fk->
"
,
1
,
10
]
]
}
};
const
derivedBreakoutMultiseriesQuery
=
{
...
breakoutMultiseriesQuery
,
"
query
"
:
{
...
breakoutMultiseriesQuery
.
query
,
"
filter
"
:
[
"
time-interval
"
,
[
"
field-id
"
,
1
],
-
7
,
"
day
"
]
}
};
const
savedCard
=
{
id
:
3
,
dataset_query
:
baseQuery
,
display
:
"
line
"
};
const
clonedSavedCard
=
{
id
:
3
,
dataset_query
:
_
.
clone
(
baseQuery
),
display
:
"
line
"
};
const
dirtyCardOnlyOriginalId
=
{
original_card_id
:
7
,
dataset_query
:
baseQuery
,
display
:
"
line
"
};
const
derivedCard
=
{
...
dirtyCardOnlyOriginalId
,
dataset_query
:
derivedQuery
};
const
derivedCardModifiedId
=
{
...
savedCard
,
dataset_query
:
derivedQuery
};
const
derivedDirtyCard
=
{
...
dirtyCardOnlyOriginalId
,
dataset_query
:
derivedQuery
};
const
derivedCardWithDifferentDisplay
=
{
...
savedCard
,
display
:
"
table
"
};
const
savedMultiseriesCard
=
{
...
savedCard
,
dataset_query
:
breakoutMultiseriesQuery
};
const
derivedMultiseriesCard
=
{
// id is not present when drilling through series / multiseries
dataset_query
:
derivedBreakoutMultiseriesQuery
,
display
:
savedCard
.
display
};
const
newCard
=
{
dataset_query
:
baseQuery
,
display
:
"
line
"
};
const
modifiedNewCard
=
{
dataset_query
:
derivedQuery
,
display
:
"
line
"
};
describe
(
"
metabase/visualization/lib/utils
"
,
()
=>
{
describe
(
"
cardHasBecomeDirty
"
,
()
=>
{
it
(
"
should consider cards with different display types dirty
"
,
()
=>
{
// mostly for action widget actions that only change the display type
expect
(
cardHasBecomeDirty
(
derivedCardWithDifferentDisplay
,
savedCard
)).
toEqual
(
true
);
});
it
(
"
should consider cards with different data data dirty
"
,
()
=>
{
expect
(
cardHasBecomeDirty
(
derivedCard
,
savedCard
)).
toEqual
(
true
);
});
it
(
"
should consider cards with same display type and data clean
"
,
()
=>
{
// i.e. the card is practically the same as original card
expect
(
cardHasBecomeDirty
(
clonedSavedCard
,
savedCard
)).
toEqual
(
false
);
});
});
describe
(
"
getCardAfterVisualizationClick
"
,
()
=>
{
it
(
"
should use the id of a previous card in case of a multi-breakout visualization
"
,
()
=>
{
expect
(
getCardAfterVisualizationClick
(
derivedMultiseriesCard
,
savedMultiseriesCard
))
.
toMatchObject
({
original_card_id
:
savedMultiseriesCard
.
id
})
});
// TODO: Atte Keinänen 5/31/17 This scenario is a little fuzzy at the moment as there have been
// some specific corner cases where the id in previousCard is wrong/missing
// We should validate that previousCard always has an id as it should
it
(
"
if the new card contains the id it's more reliable to use it for initializing lineage
"
,
()
=>
{
expect
(
getCardAfterVisualizationClick
(
derivedCardModifiedId
,
savedCard
))
.
toMatchObject
({
original_card_id
:
derivedCardModifiedId
.
id
})
});
it
(
"
should be able to continue the lineage even if the previous question was dirty already
"
,
()
=>
{
expect
(
getCardAfterVisualizationClick
(
derivedDirtyCard
,
dirtyCardOnlyOriginalId
))
.
toMatchObject
({
original_card_id
:
dirtyCardOnlyOriginalId
.
original_card_id
})
});
it
(
"
should just pass the new question if the previous question was new
"
,
()
=>
{
expect
(
getCardAfterVisualizationClick
(
modifiedNewCard
,
newCard
))
.
toMatchObject
(
modifiedNewCard
)
});
it
(
"
should populate original_card_id even if the question isn't modified
"
,
()
=>
{
// This is the hack to interoperate with questionUrlWithParameters when
// dashboard parameters are applied to a dashcards
expect
(
getCardAfterVisualizationClick
(
clonedSavedCard
,
savedCard
))
.
toMatchObject
({
original_card_id
:
savedCard
.
id
})
});
})
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment