1- import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
2- import { ElementRef } from '@angular/core' ;
3- import { IkImageComponent } from '../../lib/src/imagekitio-angular/ik-image/ik-image.component' ;
4- import { ImagekitService } from '../../lib/src/imagekitio-angular/imagekit.service' ;
1+ import { ElementRef } from "@angular/core" ;
2+ import { IkImageComponent } from "../../lib/src/imagekitio-angular/ik-image/ik-image.component" ;
3+ import { ImagekitService } from "../../lib/src/imagekitio-angular/imagekit.service" ;
54
6- describe ( ' IkImageComponent' , ( ) => {
5+ describe ( " IkImageComponent" , ( ) => {
76 let component : IkImageComponent ;
87 let imageKitService : ImagekitService ;
98
@@ -17,30 +16,87 @@ describe('IkImageComponent', () => {
1716 component = new IkImageComponent ( elRef , imageKitService ) ;
1817 } ) ;
1918
20- it ( ' setUrl should create correct URL when src is provided' , ( ) => {
21- component . setUrl ( ' abc' ) ;
22- expect ( component . url ) . toContain ( ' /abc?ik-sdk-version=angular-' ) ;
19+ it ( " setUrl should create correct URL when src is provided" , ( ) => {
20+ component . setUrl ( " abc" ) ;
21+ expect ( component . url ) . toContain ( " /abc?ik-sdk-version=angular-" ) ;
2322 } ) ;
2423
25- it ( ' setUrl should create correct URL when path is provided' , ( ) => {
26- component . setUrl ( null , ' def' ) ;
27- expect ( component . url ) . toContain ( ' /url/def?ik-sdk-version=angular-' ) ;
24+ it ( " setUrl should create correct URL when path is provided" , ( ) => {
25+ component . setUrl ( null , " def" ) ;
26+ expect ( component . url ) . toContain ( " /url/def?ik-sdk-version=angular-" ) ;
2827 } ) ;
2928
30- it ( 'setUrl should create correct lqipURL in addition to URL when lqip is provided' , ( ) => {
31- component . setUrl ( 'abc' , null , null , { active : true , quality : 1 } ) ;
32- expect ( component . url ) . toContain ( '/abc?ik-sdk-version=angular-' ) ;
33- expect ( component . lqipUrl ) . toContain ( 'tr=q-1' ) ;
34- console . log ( component . lqipUrl )
29+ it ( "setUrl should create correct lqipURL in addition to URL when lqip is provided" , ( ) => {
30+ component . setUrl ( "abc" , null , null , { active : true , quality : 1 } ) ;
31+ expect ( component . url ) . toContain ( "/abc?ik-sdk-version=angular-" ) ;
32+ expect ( component . lqipUrl ) . toContain ( "tr=q-1" ) ;
3533 } ) ;
3634
37- it ( 'lqipload should create correct url format if path is provided' , ( ) => {
38- const lqipURl = component . lqipload ( 10 , '/abc?ik-sdk-version=angular-0.0.0' , '/xyz' ) ;
39- expect ( lqipURl ) . toContain ( 'tr:q-10' ) ;
35+ it ( "lqipload should create correct query parameters if path is provided" , ( ) => {
36+ const lqipURl = component . lqipload (
37+ 10 ,
38+ "/abc?ik-sdk-version=angular-0.0.0" ,
39+ "/xyz"
40+ ) ;
41+ expect ( lqipURl ) . toContain ( "tr:q-10" ) ;
4042 } ) ;
4143
42- it ( 'lqipload should create corrext url format if path is not provided' , ( ) => {
43- const lqipURl = component . lqipload ( 10 , '/abc?ik-sdk-version=angular-0.0.0' , null ) ;
44- expect ( lqipURl ) . toContain ( 'tr=q-10' ) ;
44+ it ( "lqipload should create correct query parameters if path is not provided" , ( ) => {
45+ const lqipURl = component . lqipload (
46+ 10 ,
47+ "/abc?ik-sdk-version=angular-0.0.0" ,
48+ null
49+ ) ;
50+ expect ( lqipURl ) . toContain ( "tr=q-10" ) ;
4551 } ) ;
52+
53+ it ( "setUrl should add transformations in query parameters" , ( ) => {
54+ const transformation = [
55+ { height : "200" , width : "200" } ,
56+ {
57+ rotation : "90"
58+ }
59+ ] ;
60+ component . setUrl ( "abc" , null , transformation ) ;
61+ expect ( component . url ) . toContain ( "&tr=h-200%2Cw-200%3Art-90" ) ;
62+ } ) ;
63+
64+ it ( "setUrl should handle the presence and absence of leading slash in path parameters" , ( ) => {
65+ let comp : IkImageComponent ;
66+ let iKService : ImagekitService ;
67+ iKService = new ImagekitService ( {
68+ urlEndpoint : "https://ik.imagekit.io/company/" ,
69+ publicKey : "abc" ,
70+ authenticationEndpoint : "http://example.com/auth"
71+ } ) ;
72+ let elRef : ElementRef ;
73+ comp = new IkImageComponent ( elRef , iKService ) ;
74+ comp . setUrl ( null , "/abc.png" ) ;
75+ expect ( comp . url ) . toContain ( "https://ik.imagekit.io/company/abc.png?ik-sdk-version=angular-" ) ;
76+ comp . setUrl ( null , "abc.png" ) ;
77+ expect ( comp . url ) . toContain ( "https://ik.imagekit.io/company/abc.png?ik-sdk-version=angular-" ) ;
78+ } ) ;
79+
80+ it ( "setUrl should handle the presence and absence of leading slash in urlEndpoint parameters" , ( ) => {
81+ let comp : IkImageComponent ;
82+ let iKService : ImagekitService ;
83+ iKService = new ImagekitService ( {
84+ urlEndpoint : "https://ik.imagekit.io/company" ,
85+ publicKey : "abc" ,
86+ authenticationEndpoint : "http://example.com/auth"
87+ } ) ;
88+ let elRef : ElementRef ;
89+ comp = new IkImageComponent ( elRef , iKService ) ;
90+
91+ comp . setUrl ( null , "/abc.png" ) ;
92+ expect ( comp . url ) . toContain ( "https://ik.imagekit.io/company/abc.png?ik-sdk-version=angular-" ) ;
93+ iKService = new ImagekitService ( {
94+ urlEndpoint : "https://ik.imagekit.io/company/" ,
95+ publicKey : "abc" ,
96+ authenticationEndpoint : "http://example.com/auth"
97+ } ) ;
98+ comp . setUrl ( null , "/def.png" ) ;
99+ expect ( comp . url ) . toContain ( "https://ik.imagekit.io/company/def.png?ik-sdk-version=angular-" ) ;
100+ } ) ;
101+
46102} ) ;
0 commit comments