2018-07-20 02:33:11 +08:00
import componentTest from "helpers/component-test";
moduleForComponent("admin-report", {
integration: true
});
componentTest("default", {
template: "{{admin-report dataSourceName='signups'}}",
2018-07-25 02:12:09 +08:00
async test(assert) {
assert.ok(exists(".admin-report.signups"));
2018-08-17 22:19:25 +08:00
assert.ok(exists(".admin-report.signups", "it defaults to table mode"));
2018-07-25 02:12:09 +08:00
assert.equal(
2018-08-17 22:19:25 +08:00
find(".header .item.report")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"Signups",
"it has a title"
);
assert.equal(
2018-08-17 22:19:25 +08:00
find(".header .info").attr("data-tooltip"),
2018-07-25 02:12:09 +08:00
"New account registrations for this period",
"it has a description"
);
assert.equal(
2018-08-17 22:19:25 +08:00
find(".admin-report-table thead tr th:first-child .title")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"Day",
"it has col headers"
);
assert.equal(
2018-08-17 22:19:25 +08:00
find(".admin-report-table thead tr th:nth-child(2) .title")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"Count",
"it has col headers"
);
assert.equal(
2018-08-17 22:19:25 +08:00
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(1)")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"June 16, 2018",
"it has rows"
);
assert.equal(
2018-08-17 22:19:25 +08:00
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"12",
"it has rows"
);
2018-08-01 05:35:13 +08:00
assert.ok(exists(".total-row"), "it has totals");
2018-07-25 02:12:09 +08:00
2018-08-17 22:19:25 +08:00
await click(".admin-report-table-header.y .sort-btn");
2018-07-25 02:12:09 +08:00
assert.equal(
2018-08-17 22:19:25 +08:00
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
2018-07-25 02:12:09 +08:00
.text()
.trim(),
"7",
"it can sort rows"
);
2018-07-20 02:33:11 +08:00
}
});
componentTest("options", {
template: "{{admin-report dataSourceName='signups' reportOptions=options}}",
beforeEach() {
this.set("options", {
table: {
perPage: 4,
total: false
}
});
},
test(assert) {
2018-07-25 02:12:09 +08:00
assert.ok(exists(".pagination"), "it paginates the results");
assert.equal(
find(".pagination button").length,
3,
"it creates the correct number of pages"
);
assert.notOk(exists(".totals-sample-table"), "it hides totals");
2018-07-20 02:33:11 +08:00
}
});
componentTest("switch modes", {
2018-08-17 22:19:25 +08:00
template: "{{admin-report dataSourceName='signups' showFilteringUI=true}}",
2018-07-20 02:33:11 +08:00
2018-07-25 02:12:09 +08:00
async test(assert) {
2018-08-17 22:19:25 +08:00
await click(".mode-btn.chart");
2018-07-25 02:12:09 +08:00
2018-08-17 22:19:25 +08:00
assert.notOk(exists(".admin-report-table"), "it removes the table");
assert.ok(exists(".admin-report-chart"), "it shows the chart");
2018-07-20 02:33:11 +08:00
}
});
componentTest("timeout", {
template: "{{admin-report dataSourceName='signups_timeout'}}",
test(assert) {
2018-08-01 09:23:28 +08:00
assert.ok(exists(".alert-error.timeout"), "it displays a timeout error");
2018-07-20 02:33:11 +08:00
}
});
2018-07-26 02:28:41 +08:00
componentTest("no data", {
template: "{{admin-report dataSourceName='posts'}}",
test(assert) {
2018-08-01 09:23:28 +08:00
assert.ok(exists(".no-data"), "it displays a no data alert");
}
});
componentTest("exception", {
template: "{{admin-report dataSourceName='signups_exception'}}",
test(assert) {
assert.ok(exists(".alert-error.exception"), "it displays an error");
2018-07-26 02:28:41 +08:00
}
});
2018-08-22 17:25:12 +08:00
componentTest("rate limited", {
beforeEach() {
const response = object => {
return [429, { "Content-Type": "application/json" }, object];
};
// prettier-ignore
2018-08-24 21:28:01 +08:00
server.get("/admin/reports/bulk", () => { //eslint-disable-line
2018-08-22 17:25:12 +08:00
return response({"errors":["You’ ve performed this action too many times. Please wait 10 seconds before trying again."],"error_type":"rate_limit","extras":{"wait_seconds":10}});
});
},
template: "{{admin-report dataSourceName='signups_rate_limited'}}",
test(assert) {
assert.ok(
exists(".alert-error.rate-limited"),
"it displays a rate limited error"
);
}
});
2018-11-12 20:47:24 +08:00
componentTest("not found", {
template: "{{admin-report dataSourceName='not_found'}}",
test(assert) {
assert.ok(
exists(".alert-error.not-found"),
"it displays a not found error"
);
}
});