2019-08-06 16:11:30 +02:00
import Photo from "model/photo" ;
2019-08-09 16:03:14 +02:00
import MockAdapter from "axios-mock-adapter" ;
import Api from "common/api" ;
2019-08-13 08:09:55 +02:00
let chai = require ( '../../../node_modules/chai/chai' ) ;
let assert = chai . assert ;
2019-08-09 16:03:14 +02:00
const mock = new MockAdapter ( Api ) ;
mock
. onPost ( ) . reply ( 200 )
. onDelete ( ) . reply ( 200 ) ;
2019-08-06 16:11:30 +02:00
2019-08-07 12:18:04 +02:00
describe ( "model/photo" , ( ) => {
2019-08-06 16:11:30 +02:00
it ( "should get photo entity name" , ( ) => {
const values = { id : 5 , PhotoTitle : "Crazy Cat" } ;
const photo = new Photo ( values ) ;
const result = photo . getEntityName ( ) ;
assert . equal ( result , "Crazy Cat" ) ;
} ) ;
2019-12-04 15:14:04 +01:00
it ( "should get photo uuid" , ( ) => {
2019-08-06 16:11:30 +02:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoUUID : 789 } ;
const photo = new Photo ( values ) ;
const result = photo . getId ( ) ;
2019-12-04 15:14:04 +01:00
assert . equal ( result , 789 ) ;
2019-08-06 16:11:30 +02:00
} ) ;
it ( "should get photo title" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoUUID : 789 } ;
const photo = new Photo ( values ) ;
const result = photo . getTitle ( ) ;
assert . equal ( result , "Crazy Cat" ) ;
} ) ;
it ( "should get photo color brown" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoColor : "brown" } ;
const photo = new Photo ( values ) ;
const result = photo . getColor ( ) ;
assert . equal ( result , "grey lighten-2" ) ;
} ) ;
it ( "should get photo color grey" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoColor : "grey" } ;
const photo = new Photo ( values ) ;
const result = photo . getColor ( ) ;
assert . equal ( result , "grey lighten-2" ) ;
} ) ;
it ( "should get photo color pink" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoColor : "pink" } ;
const photo = new Photo ( values ) ;
const result = photo . getColor ( ) ;
assert . equal ( result , "pink lighten-4" ) ;
} ) ;
it ( "should get photo maps link" , ( ) => {
2019-12-20 20:23:16 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoLat : 36.442881666666665 , PhotoLng : 28.229493333333334 } ;
2019-08-06 16:11:30 +02:00
const photo = new Photo ( values ) ;
const result = photo . getGoogleMapsLink ( ) ;
assert . equal ( result , "https://www.google.com/maps/place/36.442881666666665,28.229493333333334" ) ;
} ) ;
2019-08-07 12:18:04 +02:00
it ( "should get photo thumbnail url" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileHash : 345982 } ;
const photo = new Photo ( values ) ;
const result = photo . getThumbnailUrl ( "tile500" ) ;
assert . equal ( result , "/api/v1/thumbnails/345982/tile500" ) ;
} ) ;
it ( "should get photo download url" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileHash : 345982 } ;
const photo = new Photo ( values ) ;
const result = photo . getDownloadUrl ( ) ;
assert . equal ( result , "/api/v1/download/345982" ) ;
} ) ;
it ( "should get photo thumbnail src set" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileHash : 345982 } ;
const photo = new Photo ( values ) ;
const result = photo . getThumbnailSrcset ( ) ;
assert . equal ( result , "/api/v1/thumbnails/345982/fit_720 720w, /api/v1/thumbnails/345982/fit_1280 1280w, /api/v1/thumbnails/345982/fit_1920 1920w, /api/v1/thumbnails/345982/fit_2560 2560w, /api/v1/thumbnails/345982/fit_3840 3840w" ) ;
} ) ;
it ( "should calculate photo size" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileWidth : 500 , FileHeight : 200 } ;
const photo = new Photo ( values ) ;
const result = photo . calculateSize ( 500 , 200 ) ;
assert . equal ( result . width , 500 ) ;
assert . equal ( result . height , 200 ) ;
} ) ;
it ( "should calculate photo size with srcAspectRatio < maxAspectRatio" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileWidth : 500 , FileHeight : 200 } ;
const photo = new Photo ( values ) ;
const result = photo . calculateSize ( 300 , 50 ) ;
assert . equal ( result . width , 125 ) ;
assert . equal ( result . height , 50 ) ;
} ) ;
it ( "should calculate photo size with srcAspectRatio > maxAspectRatio" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileWidth : 500 , FileHeight : 200 } ;
const photo = new Photo ( values ) ;
const result = photo . calculateSize ( 400 , 300 ) ;
assert . equal ( result . width , 400 ) ;
assert . equal ( result . height , 160 ) ;
} ) ;
it ( "should get thumbnail sizes" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , FileWidth : 500 , FileHeight : 200 } ;
const photo = new Photo ( values ) ;
const result = photo . getThumbnailSizes ( ) ;
assert . equal ( result , "(min-width: 2560px) 3840px, (min-width: 1920px) 2560px, (min-width: 1280px) 1920px, (min-width: 720px) 1280px, 720px" ) ;
} ) ;
it ( "should get date string" , ( ) => {
2019-09-19 23:23:39 +02:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , TakenAt : "2012-07-08T14:45:39Z" , TimeZone : "UTC" } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . getDateString ( ) ;
2019-09-19 23:23:39 +02:00
assert . equal ( result , "July 8, 2012, 2:45 PM UTC" ) ;
2019-08-07 12:18:04 +02:00
} ) ;
it ( "should test whether photo has location" , ( ) => {
2019-12-20 20:23:16 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoLat : 36.442881666666665 , PhotoLng : 28.229493333333334 } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . hasLocation ( ) ;
assert . equal ( result , true ) ;
} ) ;
it ( "should test whether photo has location" , ( ) => {
2019-12-20 20:23:16 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , PhotoLat : 0 , PhotoLng : 0 } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . hasLocation ( ) ;
assert . equal ( result , false ) ;
} ) ;
it ( "should get location" , ( ) => {
2019-12-28 20:24:20 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , LocationID : 6 , LocType : "viewpoint" , LocLabel : "Cape Point, South Africa" , LocCountry : "South Africa" } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . getLocation ( ) ;
2019-12-20 20:23:16 +01:00
assert . equal ( result , "Cape Point, South Africa" ) ;
2019-08-07 12:18:04 +02:00
} ) ;
it ( "should get location" , ( ) => {
2019-12-28 20:24:20 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , LocationID : 6 , LocType : "viewpoint" , LocLabel : "Cape Point, State, South Africa" , LocCountry : "South Africa" , LocCity : "Cape Town" , LocCounty : "County" , LocState : "State" } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . getLocation ( ) ;
2019-12-20 20:23:16 +01:00
assert . equal ( result , "Cape Point, State, South Africa" ) ;
2019-08-07 12:18:04 +02:00
} ) ;
it ( "should get location" , ( ) => {
2019-12-27 05:18:52 +01:00
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , LocType : "viewpoint" , LocName : "Cape Point" , LocCountry : "Africa" , LocCity : "Cape Town" , LocCounty : "County" , LocState : "State" } ;
2019-08-07 12:18:04 +02:00
const photo = new Photo ( values ) ;
const result = photo . getLocation ( ) ;
assert . equal ( result , "Unknown" ) ;
} ) ;
it ( "should get location" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , CountryName : "Africa" , LocCity : "Cape Town" } ;
const photo = new Photo ( values ) ;
const result = photo . getLocation ( ) ;
2019-12-20 23:05:44 +01:00
assert . equal ( result , "Unknown" ) ;
2019-08-07 12:18:04 +02:00
} ) ;
it ( "should get camera" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , CameraModel : "EOSD10" , CameraMake : "Canon" } ;
const photo = new Photo ( values ) ;
const result = photo . getCamera ( ) ;
assert . equal ( result , "Canon EOSD10" ) ;
} ) ;
2019-08-06 16:11:30 +02:00
2019-08-07 14:16:37 +02:00
it ( "should get camera" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" } ;
const photo = new Photo ( values ) ;
const result = photo . getCamera ( ) ;
assert . equal ( result , "Unknown" ) ;
} ) ;
2019-08-07 12:27:57 +02:00
it ( "should get collection resource" , ( ) => {
const result = Photo . getCollectionResource ( ) ;
assert . equal ( result , "photos" ) ;
} ) ;
it ( "should get model name" , ( ) => {
const result = Photo . getModelName ( ) ;
assert . equal ( result , "Photo" ) ;
} ) ;
2019-08-09 13:50:07 +02:00
it ( "should like photo" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , CountryName : "Africa" , PhotoFavorite : false } ;
const photo = new Photo ( values ) ;
assert . equal ( photo . PhotoFavorite , false ) ;
photo . like ( ) ;
assert . equal ( photo . PhotoFavorite , true ) ;
} ) ;
it ( "should unlike photo" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , CountryName : "Africa" , PhotoFavorite : true } ;
const photo = new Photo ( values ) ;
assert . equal ( photo . PhotoFavorite , true ) ;
photo . unlike ( ) ;
assert . equal ( photo . PhotoFavorite , false ) ;
} ) ;
it ( "should toggle like" , ( ) => {
const values = { ID : 5 , PhotoTitle : "Crazy Cat" , CountryName : "Africa" , PhotoFavorite : true } ;
const photo = new Photo ( values ) ;
assert . equal ( photo . PhotoFavorite , true ) ;
photo . toggleLike ( ) ;
assert . equal ( photo . PhotoFavorite , false ) ;
photo . toggleLike ( ) ;
assert . equal ( photo . PhotoFavorite , true ) ;
} ) ;
2019-09-19 23:23:39 +02:00
} ) ;