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
50e998fa
Commit
50e998fa
authored
7 years ago
by
Atte Keinänen
Browse files
Options
Downloads
Patches
Plain Diff
Fix isCardDirty and add tests for it and serializeCardForUrl
parent
eb9da7cc
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/lib/card.js
+1
-1
1 addition, 1 deletion
frontend/src/metabase/lib/card.js
frontend/src/metabase/lib/card.spec.js
+85
-0
85 additions, 0 deletions
frontend/src/metabase/lib/card.spec.js
with
86 additions
and
1 deletion
frontend/src/metabase/lib/card.js
+
1
−
1
View file @
50e998fa
...
...
@@ -56,7 +56,7 @@ export function isCardDirty(card, originalCard) {
}
}
else
{
const
origCardSerialized
=
originalCard
?
serializeCardForUrl
(
originalCard
)
:
null
;
const
newCardSerialized
=
card
?
serializeCardForUrl
(
card
)
:
null
;
const
newCardSerialized
=
card
?
serializeCardForUrl
(
_
.
omit
(
card
,
'
original_card_id
'
)
)
:
null
;
return
(
newCardSerialized
!==
origCardSerialized
);
}
}
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/lib/card.spec.js
0 → 100644
+
85
−
0
View file @
50e998fa
import
{
isCardDirty
,
serializeCardForUrl
,
deserializeCardFromUrl
}
from
"
./card
"
;
const
CARD_ID
=
31
;
// TODO Atte Keinänen 8/5/17: Create a reusable version `getCard` for reducing test code duplication
const
getCard
=
({
newCard
=
false
,
hasOriginalCard
=
false
,
isNative
=
false
,
database
=
1
,
display
=
"
table
"
,
queryFields
=
{},
table
=
undefined
,
})
=>
{
const
savedCardFields
=
{
name
:
"
Example Saved Question
"
,
description
:
"
For satisfying your craving for information
"
,
created_at
:
"
2017-04-20T16:52:55.353Z
"
,
id
:
CARD_ID
};
return
{
"
name
"
:
null
,
"
display
"
:
display
,
"
visualization_settings
"
:
{},
"
dataset_query
"
:
{
"
database
"
:
database
,
"
type
"
:
isNative
?
"
native
"
:
"
query
"
,
...(
!
isNative
?
{
query
:
{
...(
table
?
{
"
source_table
"
:
table
}
:
{}),
...
queryFields
}
}
:
{}),
...(
isNative
?
{
native
:
{
query
:
"
SELECT * FROM ORDERS
"
}
}
:
{})
},
...(
newCard
?
{}
:
savedCardFields
),
...(
hasOriginalCard
?
{
"
original_card_id
"
:
CARD_ID
}
:
{})
};
};
describe
(
"
browser
"
,
()
=>
{
describe
(
"
isCardDirty
"
,
()
=>
{
it
(
"
should consider a new card clean if no db table or native query is defined
"
,
()
=>
{
expect
(
isCardDirty
(
getCard
({
newCard
:
true
}),
null
)).
toBe
(
false
);
});
it
(
"
should consider a new card dirty if a db table is chosen
"
,
()
=>
{
expect
(
isCardDirty
(
getCard
({
newCard
:
true
,
table
:
5
}),
null
)).
toBe
(
true
);
});
it
(
"
should consider a new card dirty if there is any content on the native query
"
,
()
=>
{
expect
(
isCardDirty
(
getCard
({
newCard
:
true
,
table
:
5
}),
null
)).
toBe
(
true
);
});
it
(
"
should consider a saved card and a matching original card identical
"
,
()
=>
{
expect
(
isCardDirty
(
getCard
({
hasOriginalCard
:
true
}),
getCard
({
hasOriginalCard
:
false
})
)).
toBe
(
false
);
});
it
(
"
should consider a saved card dirty if the current card doesn't match the last saved version
"
,
()
=>
{
expect
(
isCardDirty
(
getCard
({
hasOriginalCard
:
true
,
queryFields
:
[[
"
field-id
"
,
21
]]}),
getCard
({
hasOriginalCard
:
false
})
)).
toBe
(
true
);
});
});
describe
(
"
serializeCardForUrl
"
,
()
=>
{
it
(
"
should include `original_card_id` property to the serialized URL
"
,
()
=>
{
const
cardAfterSerialization
=
deserializeCardFromUrl
(
serializeCardForUrl
(
getCard
({
hasOriginalCard
:
true
})));
expect
(
cardAfterSerialization
).
toHaveProperty
(
"
original_card_id
"
,
CARD_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