Skip to content

Commit

Permalink
added unit test for feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ToMaarton committed Oct 18, 2024
1 parent 0f81f0d commit 724051c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/photo-album.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default class PhotoAlbum extends Model {

get amountOfTaggedPhotos() {
var counter = 0;
for (var photo of this.photos._objects) {
this.photos.content.forEach((photo) => {
counter += photo.amountOfTags > 0 ? 1 : 0;
}
})

Check failure on line 42 in app/models/photo-album.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `;`
return counter;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/models/photo-album-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { run } from '@ember/runloop';

Check failure on line 1 in tests/unit/models/photo-album-test.js

View workflow job for this annotation

GitHub Actions / Lint

'run' is defined but never used
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

let album;
let photos = [];

module('Unit | Model | photo-album', function (hooks) {
setupTest(hooks);

hooks.beforeEach(function () {
const store = this.owner.lookup('service:store');
photos = [
store.createRecord('Photo'),
store.createRecord('Photo'),
store.createRecord('Photo'),
];
album = store.createRecord('PhotoAlbum', { photos });
});

test('Photo count', function (assert) {
assert.expect(2);
photos[0].amountOfTags = 0;
photos[1].amountOfTags = 1;
photos[2].amountOfTags = 5;
assert.equal(album.amountOfPhotos, 3, "Amount of photos is correct");

Check failure on line 26 in tests/unit/models/photo-album-test.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"Amount·of·photos·is·correct"` with `'Amount·of·photos·is·correct'`
assert.equal(album.amountOfTaggedPhotos, 2, "Amount of tags in album is correct");

Check failure on line 27 in tests/unit/models/photo-album-test.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `album.amountOfTaggedPhotos,·2,·"Amount·of·tags·in·album·is·correct"` with `⏎······album.amountOfTaggedPhotos,⏎······2,⏎······'Amount·of·tags·in·album·is·correct'⏎····`
});
});

Check failure on line 29 in tests/unit/models/photo-album-test.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎`

0 comments on commit 724051c

Please sign in to comment.