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
fb383fe5
Unverified
Commit
fb383fe5
authored
3 years ago
by
Nemanja Glumac
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve downloading test logic (#18745)
parent
4e445b7b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/test/metabase/scenarios/downloads/reproductions/18382-old-syntax-missing-renamed-columns.cy.spec.js
+83
-57
83 additions, 57 deletions
...tions/18382-old-syntax-missing-renamed-columns.cy.spec.js
with
83 additions
and
57 deletions
frontend/test/metabase/scenarios/downloads/reproductions/18382-old-syntax-missing-renamed-columns.cy.spec.js
+
83
−
57
View file @
fb383fe5
...
...
@@ -5,6 +5,12 @@ const xlsx = require("xlsx");
const
{
REVIEWS
,
REVIEWS_ID
,
PRODUCTS
,
PRODUCTS_ID
}
=
SAMPLE_DATASET
;
/**
* This question might seem a bit overwhelming at the first sight.
* The whole point of this repro was to try to cover as much of the old syntax as possible.
* We want to make sure it still works when loaded into a new(er) Metabase version.
*/
const
questionDetails
=
{
dataset_query
:
{
database
:
1
,
...
...
@@ -33,75 +39,95 @@ const questionDetails = {
},
display
:
"
table
"
,
visualization_settings
:
{
column_settings
:
renameColumns
(),
// Rename columns
column_settings
:
{
[
`["ref",["field",
${
REVIEWS
.
ID
}
,null]]`
]:
{
column_title
:
"
MOD:ID
"
,
},
[
`["ref",["field",
${
REVIEWS
.
REVIEWER
}
,null]]`
]:
{
column_title
:
"
MOD:Reviewer
"
,
},
[
`["ref",["field",
${
PRODUCTS
.
TITLE
}
,null]]`
]:
{
column_title
:
"
MOD:Title
"
,
},
},
// Reorder columns
"
table.columns
"
:
[
{
name
:
"
TITLE
"
,
fieldRef
:
[
"
joined-field
"
,
"
Products
"
,
[
"
field-id
"
,
PRODUCTS
.
TITLE
]],
enabled
:
true
,
},
{
name
:
"
ID
"
,
fieldRef
:
[
"
field-id
"
,
REVIEWS
.
ID
],
enabled
:
true
,
},
{
name
:
"
REVIEWER
"
,
fieldRef
:
[
"
field-id
"
,
REVIEWS
.
REVIEWER
],
enabled
:
true
,
},
],
},
};
const
testCases
=
[
{
type
:
"
csv
"
,
sheetName
:
"
Sheet1
"
},
{
type
:
"
xlsx
"
,
sheetName
:
"
Query result
"
},
];
const
testCases
=
[
"
csv
"
,
"
xlsx
"
];
d
es
cribe
.
skip
(
"
issue 18382
"
,
()
=>
{
beforeEach
(()
=>
{
c
y
.
intercept
(
"
POST
"
,
"
/api/dataset
"
).
as
(
"
dataset
"
)
;
t
es
tCases
.
forEach
(
type
=>
{
const
downloadClassName
=
`.Icon-
${
type
}
`
;
c
onst
endpoint
=
`/api/dataset/
${
type
}
`
;
restore
();
cy
.
signInAsAdmin
();
});
describe
(
"
issue 18382
"
,
()
=>
{
beforeEach
(()
=>
{
// TODO: Please remove this line when issue gets fixed
cy
.
skipOn
(
type
===
"
csv
"
);
cy
.
intercept
(
"
POST
"
,
"
/api/dataset
"
).
as
(
"
dataset
"
);
restore
();
cy
.
signInAsAdmin
();
visitQuestionAdhoc
(
questionDetails
);
cy
.
wait
(
"
@dataset
"
);
});
it
(
`should handle the old syntax in downloads for
${
type
}
(metabase#18382)`
,
()
=>
{
cy
.
url
().
then
(
currentPage
=>
{
cy
.
intercept
(
"
POST
"
,
endpoint
,
req
=>
{
// We must redirect in order to avoid Cypress being stuck on waiting for the new page to load.
// But let's stay on the same page, instead of redirecting to `/` or something else.
req
.
redirect
(
currentPage
);
}).
as
(
"
fileDownload
"
);
});
it
(
"
should handle the old syntax in downloads (metabase#18382)
"
,
()
=>
{
visitQuestionAdhoc
(
questionDetails
);
cy
.
wait
(
"
@dataset
"
);
cy
.
icon
(
"
download
"
).
click
();
cy
.
wrap
(
testCases
).
each
(({
type
,
sheetName
})
=>
{
const
downloadClassName
=
`.Icon-
${
type
}
`
;
const
endpoint
=
`/api/dataset/
${
type
}
`
;
cy
.
log
(
`downloading a
${
type
}
file`
);
cy
.
get
(
downloadClassName
)
.
parent
()
.
parent
()
.
get
(
'
input[name="query"]
'
)
.
invoke
(
"
val
"
)
.
then
(
download_query_params
=>
{
cy
.
request
({
url
:
endpoint
,
method
:
"
POST
"
,
form
:
true
,
body
:
{
query
:
download_query_params
},
encoding
:
"
binary
"
,
}).
then
(
resp
=>
{
const
workbook
=
xlsx
.
read
(
resp
.
body
,
{
cy
.
log
(
`Downloading
${
type
}
file`
);
cy
.
icon
(
"
download
"
).
click
();
// Initiate the file download
cy
.
get
(
downloadClassName
).
click
();
cy
.
wait
(
"
@fileDownload
"
)
.
its
(
"
request
"
)
.
then
(
req
=>
{
// The payload for the xlsx is in the binary form
type
===
"
xlsx
"
&&
Object
.
assign
(
req
,
{
encoding
:
"
binary
"
});
cy
.
request
(
req
).
then
(({
body
})
=>
{
const
{
SheetNames
,
Sheets
}
=
xlsx
.
read
(
body
,
{
type
:
"
binary
"
,
});
expect
(
workbook
.
Sheets
[
sheetName
][
"
A1
"
].
v
).
to
.
eq
(
"
MOD:ID
"
);
expect
(
workbook
.
Sheets
[
sheetName
][
"
B1
"
].
v
).
to
.
eq
(
"
MOD:Reviewer
"
);
expect
(
workbook
.
Sheets
[
sheetName
][
"
C1
"
].
v
).
to
.
eq
(
"
MOD:Title
"
);
const
sheetName
=
SheetNames
[
0
];
const
sheet
=
Sheets
[
sheetName
];
expect
(
sheet
[
"
A1
"
].
v
).
to
.
eq
(
"
MOD:Title
"
);
expect
(
sheet
[
"
B1
"
].
v
).
to
.
eq
(
"
MOD:ID
"
);
expect
(
sheet
[
"
C1
"
].
v
).
to
.
eq
(
"
MOD:Reviewer
"
);
expect
(
workbook
.
Sheets
[
sheetName
][
"
C2
"
].
v
).
to
.
eq
(
"
Aerodynamic Concrete Bench
"
,
);
expect
(
sheet
[
"
A2
"
].
v
).
to
.
eq
(
"
Aerodynamic Concrete Bench
"
);
});
});
});
});
});
function
renameColumns
()
{
return
{
[
`["ref",["field",
${
REVIEWS
.
ID
}
,null]]`
]:
{
column_title
:
"
MOD:ID
"
,
},
[
`["ref",["field",
${
REVIEWS
.
REVIEWER
}
,null]]`
]:
{
column_title
:
"
MOD:Reviewer
"
,
},
[
`["ref",["field",
${
PRODUCTS
.
TITLE
}
,null]]`
]:
{
column_title
:
"
MOD:Title
"
,
},
};
}
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