Skip to content

Commit 4b123f5

Browse files
committed
test: add comprehensive URL generation tests for transformation parameters
1 parent f9007a2 commit 4b123f5

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed

test/url-generation.js

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,39 @@ describe("URL generation", function () {
374374
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path1.jpg`);
375375
});
376376

377+
it('ai remove background external', function () {
378+
const url = imagekit.url({
379+
path: "/test_path1.jpg",
380+
transformation: [{
381+
aiRemoveBackgroundExternal: true
382+
}]
383+
})
384+
385+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:e-removedotbg/test_path1.jpg`);
386+
});
387+
388+
it('ai remove background external true as string', function () {
389+
const url = imagekit.url({
390+
path: "/test_path1.jpg",
391+
transformation: [{
392+
aiRemoveBackgroundExternal: "true"
393+
}]
394+
})
395+
396+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:e-removedotbg/test_path1.jpg`);
397+
});
398+
399+
it('ai remove background external other than true', function () {
400+
const url = imagekit.url({
401+
path: "/test_path1.jpg",
402+
transformation: [{
403+
aiRemoveBackgroundExternal: "false"
404+
}]
405+
})
406+
407+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path1.jpg`);
408+
});
409+
377410
it('gradient with string value', function () {
378411
const url = imagekit.url({
379412
path: "/test_path1.jpg",
@@ -572,6 +605,268 @@ describe("URL generation", function () {
572605
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:t-5/test_path1.jpg`);
573606
});
574607

608+
// Width parameter tests
609+
it('width with number value', function () {
610+
const url = imagekit.url({
611+
path: "/test_path1.jpg",
612+
transformation: [{
613+
width: 400
614+
}]
615+
})
616+
617+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:w-400/test_path1.jpg`);
618+
});
619+
620+
it('width with string value', function () {
621+
const url = imagekit.url({
622+
path: "/test_path1.jpg",
623+
transformation: [{
624+
width: "400"
625+
}]
626+
})
627+
628+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:w-400/test_path1.jpg`);
629+
});
630+
631+
it('width with arithmetic expression', function () {
632+
const url = imagekit.url({
633+
path: "/test_path1.jpg",
634+
transformation: [{
635+
width: "iw_div_2"
636+
}]
637+
})
638+
639+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:w-iw_div_2/test_path1.jpg`);
640+
});
641+
642+
// Height parameter tests
643+
it('height with number value', function () {
644+
const url = imagekit.url({
645+
path: "/test_path1.jpg",
646+
transformation: [{
647+
height: 300
648+
}]
649+
})
650+
651+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300/test_path1.jpg`);
652+
});
653+
654+
it('height with string value', function () {
655+
const url = imagekit.url({
656+
path: "/test_path1.jpg",
657+
transformation: [{
658+
height: "300"
659+
}]
660+
})
661+
662+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300/test_path1.jpg`);
663+
});
664+
665+
it('height with arithmetic expression', function () {
666+
const url = imagekit.url({
667+
path: "/test_path1.jpg",
668+
transformation: [{
669+
height: "ih_mul_0.5"
670+
}]
671+
})
672+
673+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-ih_mul_0.5/test_path1.jpg`);
674+
});
675+
676+
// AspectRatio parameter tests
677+
it('aspectRatio with string value', function () {
678+
const url = imagekit.url({
679+
path: "/test_path1.jpg",
680+
transformation: [{
681+
aspectRatio: "4:3"
682+
}]
683+
})
684+
685+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:ar-4:3/test_path1.jpg`);
686+
});
687+
688+
it('aspectRatio with alternate format', function () {
689+
const url = imagekit.url({
690+
path: "/test_path1.jpg",
691+
transformation: [{
692+
aspectRatio: "4_3"
693+
}]
694+
})
695+
696+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:ar-4_3/test_path1.jpg`);
697+
});
698+
699+
it('aspectRatio with expression', function () {
700+
const url = imagekit.url({
701+
path: "/test_path1.jpg",
702+
transformation: [{
703+
aspectRatio: "iar_div_2"
704+
}]
705+
})
706+
707+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:ar-iar_div_2/test_path1.jpg`);
708+
});
709+
710+
// Background parameter tests
711+
it('background with solid color', function () {
712+
const url = imagekit.url({
713+
path: "/test_path1.jpg",
714+
transformation: [{
715+
background: "FF0000"
716+
}]
717+
})
718+
719+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:bg-FF0000/test_path1.jpg`);
720+
});
721+
722+
it('background with blurred option', function () {
723+
const url = imagekit.url({
724+
path: "/test_path1.jpg",
725+
transformation: [{
726+
background: "blurred"
727+
}]
728+
})
729+
730+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:bg-blurred/test_path1.jpg`);
731+
});
732+
733+
it('background with genfill option', function () {
734+
const url = imagekit.url({
735+
path: "/test_path1.jpg",
736+
transformation: [{
737+
background: "genfill"
738+
}]
739+
})
740+
741+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:bg-genfill/test_path1.jpg`);
742+
});
743+
744+
// Crop parameter tests
745+
it('crop with force value', function () {
746+
const url = imagekit.url({
747+
path: "/test_path1.jpg",
748+
transformation: [{
749+
crop: "force"
750+
}]
751+
})
752+
753+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:c-force/test_path1.jpg`);
754+
});
755+
756+
it('crop with at_max value', function () {
757+
const url = imagekit.url({
758+
path: "/test_path1.jpg",
759+
transformation: [{
760+
crop: "at_max"
761+
}]
762+
})
763+
764+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:c-at_max/test_path1.jpg`);
765+
});
766+
767+
// CropMode parameter tests
768+
it('cropMode with pad_resize value', function () {
769+
const url = imagekit.url({
770+
path: "/test_path1.jpg",
771+
transformation: [{
772+
cropMode: "pad_resize"
773+
}]
774+
})
775+
776+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:cm-pad_resize/test_path1.jpg`);
777+
});
778+
779+
it('cropMode with extract value', function () {
780+
const url = imagekit.url({
781+
path: "/test_path1.jpg",
782+
transformation: [{
783+
cropMode: "extract"
784+
}]
785+
})
786+
787+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:cm-extract/test_path1.jpg`);
788+
});
789+
790+
// Focus parameter tests
791+
it('focus with string value', function () {
792+
const url = imagekit.url({
793+
path: "/test_path1.jpg",
794+
transformation: [{
795+
focus: "center"
796+
}]
797+
})
798+
799+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:fo-center/test_path1.jpg`);
800+
});
801+
802+
it('focus with face detection', function () {
803+
const url = imagekit.url({
804+
path: "/test_path1.jpg",
805+
transformation: [{
806+
focus: "face"
807+
}]
808+
})
809+
810+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:fo-face/test_path1.jpg`);
811+
});
812+
813+
// Quality parameter test
814+
it('quality with number value', function () {
815+
const url = imagekit.url({
816+
path: "/test_path1.jpg",
817+
transformation: [{
818+
quality: 80
819+
}]
820+
})
821+
822+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:q-80/test_path1.jpg`);
823+
});
824+
825+
// Coordinate parameters tests
826+
it('x with number value', function () {
827+
const url = imagekit.url({
828+
path: "/test_path1.jpg",
829+
transformation: [{
830+
x: 10
831+
}]
832+
})
833+
834+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:x-10/test_path1.jpg`);
835+
});
836+
837+
it('y with number value', function () {
838+
const url = imagekit.url({
839+
path: "/test_path1.jpg",
840+
transformation: [{
841+
y: 20
842+
}]
843+
})
844+
845+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:y-20/test_path1.jpg`);
846+
});
847+
848+
it('xCenter with number value', function () {
849+
const url = imagekit.url({
850+
path: "/test_path1.jpg",
851+
transformation: [{
852+
xCenter: 30
853+
}]
854+
})
855+
856+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:xc-30/test_path1.jpg`);
857+
});
858+
859+
it('yCenter with number value', function () {
860+
const url = imagekit.url({
861+
path: "/test_path1.jpg",
862+
transformation: [{
863+
yCenter: 40
864+
}]
865+
})
866+
867+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:yc-40/test_path1.jpg`);
868+
});
869+
575870
it('All combined', function () {
576871
const url = imagekit.url({
577872
path: "/test_path.jpg",

0 commit comments

Comments
 (0)