mirror of
https://github.com/discourse/discourse.git
synced 2025-01-01 16:06:19 +08:00
FIX: An off-by-one error in glimmer topic list (#30372)
`findIndex` returns -1 when no element is found, but the `start` boundary can't be less than 0.
This commit is contained in:
parent
dc3379430d
commit
b2dc32f41c
|
@ -143,7 +143,10 @@ export default class TopicList extends Component {
|
|||
|
||||
// work backwards
|
||||
// this is more efficient cause we keep appending to list
|
||||
const start = topics.findIndex((topic) => !topic.get("pinned"));
|
||||
const start = Math.max(
|
||||
topics.findIndex((topic) => !topic.get("pinned")),
|
||||
0
|
||||
);
|
||||
let lastVisitedTopic, topic;
|
||||
|
||||
for (let i = topics.length - 1; i >= start; i--) {
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
import { getOwner } from "@ember/owner";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { module, test } from "qunit";
|
||||
import HbrTopicList from "discourse/components/topic-list";
|
||||
import TopicList from "discourse/components/topic-list/list";
|
||||
import BulkSelectHelper from "discourse/lib/bulk-select-helper";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
|
||||
module("Integration | Component | topic-list", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("bulk select", async function (assert) {
|
||||
const bulkSelectHelper = new BulkSelectHelper(this);
|
||||
const store = getOwner(this).lookup("service:store");
|
||||
const topics = [
|
||||
store.createRecord("topic", { id: 24234 }),
|
||||
store.createRecord("topic", { id: 24235 }),
|
||||
];
|
||||
|
||||
await render(<template>
|
||||
<HbrTopicList
|
||||
@canBulkSelect={{true}}
|
||||
@bulkSelectHelper={{bulkSelectHelper}}
|
||||
@topics={{topics}}
|
||||
/>
|
||||
</template>);
|
||||
|
||||
assert.strictEqual(bulkSelectHelper.selected.length, 0, "defaults to 0");
|
||||
|
||||
await click("button.bulk-select");
|
||||
assert.true(bulkSelectHelper.bulkSelectEnabled, "bulk select is enabled");
|
||||
|
||||
await click("button.bulk-select-all");
|
||||
assert.strictEqual(
|
||||
bulkSelectHelper.selected.length,
|
||||
2,
|
||||
"clicking Select All selects all loaded topics"
|
||||
);
|
||||
assert.true(
|
||||
bulkSelectHelper.autoAddTopicsToBulkSelect,
|
||||
"clicking Select All turns on the autoAddTopicsToBulkSelect flag"
|
||||
);
|
||||
|
||||
await click("button.bulk-clear-all");
|
||||
assert.strictEqual(
|
||||
bulkSelectHelper.selected.length,
|
||||
0,
|
||||
"clicking Clear All deselects all topics"
|
||||
);
|
||||
assert.false(
|
||||
bulkSelectHelper.autoAddTopicsToBulkSelect,
|
||||
"clicking Clear All turns off the autoAddTopicsToBulkSelect flag"
|
||||
);
|
||||
});
|
||||
|
||||
test("renders a list of all-pinned topics", async function (assert) {
|
||||
const currentUser = getOwner(this).lookup("service:current-user");
|
||||
currentUser.set("previous_visit_at", +new Date());
|
||||
const store = getOwner(this).lookup("service:store");
|
||||
const topics = [
|
||||
store.createRecord("topic", { id: 24234, pinned: true }),
|
||||
store.createRecord("topic", { id: 24235, pinned: true }),
|
||||
];
|
||||
|
||||
await render(<template>
|
||||
<TopicList @topics={{topics}} @highlightLastVisited={{true}} />
|
||||
</template>);
|
||||
|
||||
assert.dom(".topic-status .d-icon-thumbtack").exists({ count: 2 });
|
||||
});
|
||||
});
|
|
@ -1,62 +0,0 @@
|
|||
import { getOwner } from "@ember/owner";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { module, test } from "qunit";
|
||||
import BulkSelectHelper from "discourse/lib/bulk-select-helper";
|
||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
|
||||
module("Integration | Component | topic-list", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test("bulk select", async function (assert) {
|
||||
const store = getOwner(this).lookup("service:store");
|
||||
this.setProperties({
|
||||
topics: [
|
||||
store.createRecord("topic", { id: 24234 }),
|
||||
store.createRecord("topic", { id: 24235 }),
|
||||
],
|
||||
bulkSelectHelper: new BulkSelectHelper(this),
|
||||
});
|
||||
|
||||
await render(hbs`
|
||||
<TopicList
|
||||
@canBulkSelect={{true}}
|
||||
@bulkSelectHelper={{this.bulkSelectHelper}}
|
||||
@topics={{this.topics}}
|
||||
/>
|
||||
`);
|
||||
|
||||
assert.strictEqual(
|
||||
this.bulkSelectHelper.selected.length,
|
||||
0,
|
||||
"defaults to 0"
|
||||
);
|
||||
await click("button.bulk-select");
|
||||
assert.true(
|
||||
this.bulkSelectHelper.bulkSelectEnabled,
|
||||
"bulk select is enabled"
|
||||
);
|
||||
|
||||
await click("button.bulk-select-all");
|
||||
assert.strictEqual(
|
||||
this.bulkSelectHelper.selected.length,
|
||||
2,
|
||||
"clicking Select All selects all loaded topics"
|
||||
);
|
||||
assert.true(
|
||||
this.bulkSelectHelper.autoAddTopicsToBulkSelect,
|
||||
"clicking Select All turns on the autoAddTopicsToBulkSelect flag"
|
||||
);
|
||||
|
||||
await click("button.bulk-clear-all");
|
||||
assert.strictEqual(
|
||||
this.bulkSelectHelper.selected.length,
|
||||
0,
|
||||
"clicking Clear All deselects all topics"
|
||||
);
|
||||
assert.false(
|
||||
this.bulkSelectHelper.autoAddTopicsToBulkSelect,
|
||||
"clicking Clear All turns off the autoAddTopicsToBulkSelect flag"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user