From 724051cd19676f48ac7504176cd4fa45cda0c4db Mon Sep 17 00:00:00 2001 From: ToMaarton Date: Fri, 18 Oct 2024 12:29:32 +0200 Subject: [PATCH] added unit test for feature --- app/models/photo-album.js | 4 ++-- tests/unit/models/photo-album-test.js | 29 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/unit/models/photo-album-test.js diff --git a/app/models/photo-album.js b/app/models/photo-album.js index 2320c1fe1..bf22a1544 100644 --- a/app/models/photo-album.js +++ b/app/models/photo-album.js @@ -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; - } + }) return counter; } diff --git a/tests/unit/models/photo-album-test.js b/tests/unit/models/photo-album-test.js new file mode 100644 index 000000000..4e606d361 --- /dev/null +++ b/tests/unit/models/photo-album-test.js @@ -0,0 +1,29 @@ +import { run } from '@ember/runloop'; +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"); + assert.equal(album.amountOfTaggedPhotos, 2, "Amount of tags in album is correct"); + }); +}); \ No newline at end of file