|
1 | | -// import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 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"; |
2 | 4 |
|
3 | | -// import { IkImageComponent } from '../../lib/src/imagekitio-angular/ik-image/ik-image.component'; |
4 | | -// import { ImageKitConfiguration } from '../../lib/src/imagekitio-angular/imagekit.service'; |
| 5 | +describe("IkImageComponent", () => { |
| 6 | + let component: IkImageComponent; |
| 7 | + let imageKitService: ImagekitService; |
5 | 8 |
|
6 | | -describe('IkImageComponent', () => { |
7 | | - // let component: IkImageComponent; |
8 | | - // let fixture: ComponentFixture<IkImageComponent>; |
| 9 | + beforeEach(() => { |
| 10 | + imageKitService = new ImagekitService({ |
| 11 | + urlEndpoint: "url", |
| 12 | + publicKey: "pub", |
| 13 | + authenticationEndpoint: "auth" |
| 14 | + }); |
| 15 | + let elRef: ElementRef; |
| 16 | + component = new IkImageComponent(elRef, imageKitService); |
| 17 | + }); |
| 18 | + |
| 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-"); |
| 22 | + }); |
| 23 | + |
| 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-"); |
| 27 | + }); |
9 | 28 |
|
10 | | - // beforeEach(async(() => { |
11 | | - // TestBed.configureTestingModule({ |
12 | | - // declarations: [ IkImageComponent ], |
13 | | - // providers: [ImageKitConfiguration] |
14 | | - // }) |
15 | | - // .compileComponents(); |
16 | | - // })); |
| 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"); |
| 33 | + }); |
17 | 34 |
|
18 | | - // beforeEach(() => { |
19 | | - // fixture = TestBed.createComponent(IkImageComponent); |
20 | | - // component = fixture.componentInstance; |
21 | | - // fixture.detectChanges(); |
22 | | - // }); |
| 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"); |
| 42 | + }); |
23 | 43 |
|
24 | | - it('is dummy and should pass', () => { |
25 | | - expect(true).toBeTruthy(); |
| 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"); |
26 | 51 | }); |
| 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 | + |
27 | 102 | }); |
0 commit comments