Skip to content

Commit

Permalink
Merge pull request #8160 from michaelchadwick/frontend-5727-fix-lm-se…
Browse files Browse the repository at this point in the history
…arch-bug

Fix course LM search bug
  • Loading branch information
dartajax authored Sep 25, 2024
2 parents 79ca8f5 + 16468cf commit 86e2498
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
19 changes: 10 additions & 9 deletions packages/ilios-common/addon/components/learningmaterial-search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
</span>
</div>
<span class="learning-material-description">
{{! template-lint-disable no-triple-curlies }}
{{! template-lint-disable no-triple-curlies }}
{{{learningMaterial.description}}}
</span>
</span>
{{#if learningMaterial.status.title}}
<span class="learning-material-status">
{{learningMaterial.status.title}}
</span>
<span class="learning-material-status">
{{learningMaterial.status.title}}
</span>
{{/if}}
<ul class="learning-material-properties">
<li>
{{t "general.owner"}}:
{{learningMaterial.owningUser.fullName}}
</li>
{{#if learningMaterial.originalAuthor}}
<li>
{{t "general.contentAuthor"}}:
{{learningMaterial.originalAuthor}}
</li>
<li>
{{t "general.contentAuthor"}}:
{{learningMaterial.originalAuthor}}
</li>
{{/if}}
<li>
{{t "general.uploadDate"}}:
Expand All @@ -62,6 +62,7 @@
<button
disabled={{if this.searchMore.isRunning true}}
type="button"
data-test-show-more
{{on "click" (perform this.searchMore)}}
>
{{#if this.searchMore.isRunning}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class LearningMaterialSearchComponent extends Component {
'order_by[title]': 'ASC',
});

const lms = results;
const lms = results.slice();
this.searchReturned = true;
this.searching = false;
this.searchPage = 1;
Expand Down Expand Up @@ -59,7 +59,8 @@ export default class LearningMaterialSearchComponent extends Component {
offset: this.searchPage * this.searchResultsPerPage,
'order_by[title]': 'ASC',
});
const lms = results;

const lms = results.slice();
this.searchPage = this.searchPage + 1;
this.hasMoreSearchResults = lms.length > this.searchResultsPerPage;
if (this.hasMoreSearchResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,35 @@ module('Integration | Component | learningmaterial search', function (hooks) {

test('search shows results', async function (assert) {
this.server.createList('learning-material', 2);
await render(hbs`<LearningmaterialSearch />
`);
await render(hbs`<LearningmaterialSearch />`);
await component.search.set('material');
assert.strictEqual(component.searchResults.length, 2);
});

test('empty search clears results', async function (assert) {
this.server.createList('learning-material', 2);
await render(hbs`<LearningmaterialSearch />
`);
await render(hbs`<LearningmaterialSearch />`);
await component.search.set(' material ');
assert.strictEqual(component.searchResults.length, 2);
await component.search.set(' ');
assert.strictEqual(component.searchResults.length, 0);
});

test('search does not show Search More button if result count is same as searchResultsPerPage', async function (assert) {
this.set('searchResultsPerPage', 50);
this.server.createList('learning-material', this.searchResultsPerPage);
await render(hbs`<LearningmaterialSearch />`);
await component.search.set(' material ');
assert.strictEqual(component.searchResults.length, this.searchResultsPerPage);
assert.dom('[data-test-show-more]').doesNotExist();
});

test('search shows Search More button if result count above searchResultsPerPage', async function (assert) {
this.set('searchResultsPerPage', 50);
this.server.createList('learning-material', this.searchResultsPerPage + 1);
await render(hbs`<LearningmaterialSearch />`);
await component.search.set(' material ');
assert.strictEqual(component.searchResults.length, this.searchResultsPerPage + 1);
assert.dom('[data-test-show-more]').exists();
});
});

0 comments on commit 86e2498

Please sign in to comment.