Skip to content

Commit bc440d7

Browse files
YomesInctocker
authored andcommitted
Add tests of overlay/underlay with a fetched image
1 parent dce9fc8 commit bc440d7

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/cloudinary-image.component.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,53 @@ describe('CloudinaryImage', () => {
8181
});
8282
});
8383

84+
describe('images with overlay/underlay', () => {
85+
@Component({
86+
template: `
87+
<cl-image responsive id="image1" public-id="responsive_sample.jpg">
88+
<cl-transformation overlay="fetch:http://cloudinary.com/images/old_logo.png"></cl-transformation>
89+
<cl-transformation underlay="fetch:http://cloudinary.com/images/old_logo.png"></cl-transformation>
90+
</cl-image>
91+
<cl-image responsive id="image2" public-id="responsive_sample.jpg">
92+
<cl-transformation overlay="fetch:https://upload.wikimedia.org/wikipedia/commons/2/2b/고창갯벌.jpg"></cl-transformation>
93+
<cl-transformation underlay="fetch:https://upload.wikimedia.org/wikipedia/commons/2/2b/고창갯벌.jpg"></cl-transformation>
94+
</cl-image>
95+
`
96+
})
97+
class TestComponent { }
98+
let fixture: ComponentFixture<TestComponent>;
99+
let des: DebugElement[];
100+
101+
beforeEach(() => {
102+
fixture = TestBed.configureTestingModule({
103+
declarations: [CloudinaryTransformationDirective, CloudinaryImage, TestComponent],
104+
providers: [{ provide: Cloudinary, useValue: localCloudinary }]
105+
}).createComponent(TestComponent);
106+
fixture.detectChanges(); // initial binding
107+
// all elements with an attached CloudinaryImage
108+
des = fixture.debugElement.queryAll(By.directive(CloudinaryImage));
109+
});
110+
111+
it('should serialize a fetch URL', () => {
112+
const img = des[0].children[0].nativeElement as HTMLImageElement;
113+
expect(img.src).toEqual(jasmine.stringMatching
114+
(/l_fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc=\/u_fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc=\/responsive_sample.jpg/));
115+
expect(img.attributes.getNamedItem('data-src').value).toEqual(jasmine.stringMatching(
116+
/l_fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc=\/u_fetch:aHR0cDovL2Nsb3VkaW5hcnkuY29tL2ltYWdlcy9vbGRfbG9nby5wbmc=\/responsive_sample.jpg/));
117+
});
118+
it('should support unicode URLs', () => {
119+
const img = des[1].children[0].nativeElement as HTMLImageElement;
120+
expect(img.src).toEqual(jasmine.stringMatching(
121+
new RegExp('l_fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEvY29tbW9ucy8yLzJiLyVFQSVCMyVB' +
122+
'MCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc=/u_fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEv' +
123+
'Y29tbW9ucy8yLzJiLyVFQSVCMyVBMCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc=/responsive_sample.jpg')));
124+
expect(img.attributes.getNamedItem('data-src').value).toEqual(jasmine.stringMatching(
125+
new RegExp('l_fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEvY29tbW9ucy8yLzJiLyVFQSVCMyVB' +
126+
'MCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc=/u_fetch:aHR0cHM6Ly91cGxvYWQud2lraW1lZGlhLm9yZy93aWtpcGVkaWEv' +
127+
'Y29tbW9ucy8yLzJiLyVFQSVCMyVBMCVFQyVCMCVCRCVFQSVCMCVBRiVFQiVCMiU4Qy5qcGc=/responsive_sample.jpg')));
128+
});
129+
});
130+
84131
describe('missing public-id', () => {
85132
@Component({
86133
template: '<cl-image responsive id="image1"></cl-image>'

0 commit comments

Comments
 (0)