discourse/test/javascripts/components/admin-report-test.js.es6
Mark VanLandingham 176aa0ac7d
DEV: Import pretender instead of global server var (#8996)
* DEV: Remove server global test variable

* Delete yarn-error.log

* prettier and some eslint fixes

* add global server variable back for plugins

* rename imported server to pretender

* prettier

* support plugin server. usage

* Export pretender as named

* Prettier

* change default pretender export

* fix bad import

* Use pretender() and original default export

* export new Pretender as default

* fix accidental change

* WIP testing

* add pretend handlers in correct location

* move more stuff into the correct pretender

* Consolidated more pretenders

* comment out another bad test

* fix user acceptance tests

* commented out bad test

* fixed another composer server stub

* fix more tests

* fixed tag test pretender

* Fix admin email test

* removed another draft handler

* add back test

* fix and uncomment another test

* remove test that is not useful

* remove commented out lines

* reapply handlers between every test

* no need to re-stub requests now :)

* cleanup from review

* more cleanup
2020-03-02 14:24:31 -05:00

172 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import componentTest from "helpers/component-test";
import pretender from "helpers/create-pretender";
moduleForComponent("admin-report", {
integration: true
});
componentTest("default", {
template: "{{admin-report dataSourceName='signups'}}",
async test(assert) {
assert.ok(exists(".admin-report.signups"));
assert.ok(exists(".admin-report.signups", "it defaults to table mode"));
assert.equal(
find(".header .item.report")
.text()
.trim(),
"Signups",
"it has a title"
);
assert.equal(
find(".header .info").attr("data-tooltip"),
"New account registrations for this period",
"it has a description"
);
assert.equal(
find(".admin-report-table thead tr th:first-child .title")
.text()
.trim(),
"Day",
"it has col headers"
);
assert.equal(
find(".admin-report-table thead tr th:nth-child(2) .title")
.text()
.trim(),
"Count",
"it has col headers"
);
assert.equal(
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(1)")
.text()
.trim(),
"June 16, 2018",
"it has rows"
);
assert.equal(
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"12",
"it has rows"
);
assert.ok(exists(".total-row"), "it has totals");
await click(".admin-report-table-header.y .sort-btn");
assert.equal(
find(".admin-report-table tbody tr:nth-child(1) td:nth-child(2)")
.text()
.trim(),
"7",
"it can sort rows"
);
}
});
componentTest("options", {
template: "{{admin-report dataSourceName='signups' reportOptions=options}}",
beforeEach() {
this.set("options", {
table: {
perPage: 4,
total: false
}
});
},
test(assert) {
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");
}
});
componentTest("switch modes", {
template: "{{admin-report dataSourceName='signups' showFilteringUI=true}}",
async test(assert) {
await click(".mode-btn.chart");
assert.notOk(exists(".admin-report-table"), "it removes the table");
assert.ok(exists(".admin-report-chart"), "it shows the chart");
}
});
componentTest("timeout", {
template: "{{admin-report dataSourceName='signups_timeout'}}",
test(assert) {
assert.ok(exists(".alert-error.timeout"), "it displays a timeout error");
}
});
componentTest("no data", {
template: "{{admin-report dataSourceName='posts'}}",
test(assert) {
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");
}
});
componentTest("rate limited", {
beforeEach() {
pretender.get("/admin/reports/bulk", () => {
return [
429,
{ "Content-Type": "application/json" },
{
errors: [
"Youve 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"
);
}
});
componentTest("not found", {
template: "{{admin-report dataSourceName='not_found'}}",
test(assert) {
assert.ok(
exists(".alert-error.not-found"),
"it displays a not found error"
);
}
});