Skip to content

Commit 2cfb36b

Browse files
committed
IKImage bugfix: added e2e test for chained transform and without IKContext
1 parent 5c1aa04 commit 2cfb36b

File tree

2 files changed

+92
-46
lines changed

2 files changed

+92
-46
lines changed

tests/cypress/integration/IKImage.spec.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,42 @@ describe('ImageKit React SDK', () => {
6767
});
6868

6969
describe('State update check', () => {
70-
it('should update image src when click on button', () => {
71-
cy.visit(APP_HOST);
72-
73-
cy.get('.img-transformation').scrollIntoView();
74-
75-
cy.wait(500);
76-
77-
cy.get('.img-transformation')
78-
.should('have.attr', 'src')
79-
.and('include', 'tr:h-200,w-200/default-image.jpg');
80-
81-
cy.get('.btn-to-change-tr').click();
82-
cy.wait(500);
83-
84-
cy.get('.img-transformation')
85-
.should('have.attr', 'src')
86-
.and('include', 'tr:h-200,w-200,r-max/default-image.jpg');
87-
})
88-
})
89-
70+
it('should update image src with chained transformation outside IKContext dynamically', () => {
71+
cy.visit(APP_HOST);
72+
73+
cy.get('.img-transformation-direct').scrollIntoView();
74+
75+
cy.wait(500);
76+
77+
cy.get('.img-transformation-direct')
78+
.should('have.attr', 'src')
79+
.and('include', 'tr:h-300,w-300/default-image.jpg');
80+
81+
cy.get('.btn-to-change-tr-direct').click();
82+
cy.wait(500);
83+
84+
cy.get('.img-transformation-direct')
85+
.should('have.attr', 'src')
86+
.and('include', 'tr:h-200,w-600,r-max:h-200,w-200,rt-180:ot-TEST,oy-50,ox-100,otc-10C0F0/default-image.jpg');
87+
});
88+
it('should update image src within IKContext when button is clicked', () => {
89+
cy.visit(APP_HOST);
90+
91+
cy.get('.img-transformation').scrollIntoView();
92+
93+
cy.wait(500);
94+
95+
cy.get('.img-transformation')
96+
.should('have.attr', 'src')
97+
.and('include', 'tr:h-200,w-200/default-image.jpg');
98+
99+
cy.get('.btn-to-change-tr').click();
100+
cy.wait(500);
101+
102+
cy.get('.img-transformation')
103+
.should('have.attr', 'src')
104+
.and('include', 'tr:h-200,w-200,r-max/default-image.jpg');
105+
});
106+
});
107+
90108
});

tests/test-app/src/App.js

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ function App() {
1818
const onSuccess = res => {
1919
console.log("Success");
2020
console.log(res);
21-
setUploadedImageSource(res.url);
21+
setUploadedImageSource(res.url);
2222
};
2323

2424
const [uploadedImageSource, setUploadedImageSource] = useState();
2525
const [imageTr, setImageTr] = useState([{
26-
"height": "200",
27-
"width": "200"
26+
"height": "200",
27+
"width": "200"
28+
}]);
29+
const [imageTrSansIKContext, setImageTrSansIKContext] = useState([{
30+
"height": "300",
31+
"width": "300"
2832
}]);
2933

3034
return (
@@ -34,25 +38,56 @@ function App() {
3438
<p>Directly using <code>IkImage</code></p>
3539
<IKImage urlEndpoint={urlEndpoint} src={src} />
3640

41+
<p>Dynamic transformation update directly using IKImage</p>
42+
<IKImage
43+
publicKey={publicKey}
44+
urlEndpoint={urlEndpoint}
45+
authenticationEndpoint={authenticationEndpoint}
46+
className={'img-transformation-direct'}
47+
path={path}
48+
transformation={imageTrSansIKContext}
49+
/>
50+
<div>
51+
<p>Click here to apply transformations on the above image</p>
52+
<button
53+
className={'btn-to-change-tr-direct'}
54+
onClick={() => setImageTrSansIKContext([{
55+
"height": "200",
56+
"width": "600",
57+
"radius": "max",
58+
}, {
59+
"height": "200",
60+
"width": "200",
61+
"rotate": 180,
62+
}, {
63+
"ot": "TEST",
64+
"oy": 50,
65+
"ox": 100,
66+
"otc": "10C0F0"
67+
}])}
68+
>Click to apply transformations</button>
69+
</div>
70+
<br />
71+
3772
<p>Using context <code>IKContext</code></p>
3873
<IKContext publicKey={publicKey} urlEndpoint={urlEndpoint} authenticationEndpoint={authenticationEndpoint} >
3974
<p>Let's add an Image</p>
4075
<IKImage src={src} />
4176

4277
<p>Transformation - height and width manipulation</p>
4378
<IKImage className={'img-transformation'} path={path} transformation={imageTr} />
44-
<div>
45-
<p>Click here to apply max radius on above image </p>
46-
<button
47-
className={'btn-to-change-tr'}
48-
onClick={() => setImageTr([{
49-
"height": "200",
50-
"width": "200",
51-
"radius" : "max"
52-
}])}
53-
>Click to apply radius</button>
54-
</div>
55-
<br />
79+
<div>
80+
<p>Click here to apply max radius on above image </p>
81+
<button
82+
className={'btn-to-change-tr'}
83+
onClick={() => setImageTr([{
84+
"height": "200",
85+
"width": "200",
86+
"radius": "max"
87+
}])}
88+
>Click to apply radius</button>
89+
</div>
90+
<br />
5691
<p>Chained transformation</p>
5792
<IKImage path={path} transformation={[{
5893
"height": "200",
@@ -75,7 +110,7 @@ function App() {
75110

76111
<p>Progressive image loading wihtout lazy loading</p>
77112
<IKImage
78-
className={'lqip'}
113+
className={'lqip'}
79114
path={path}
80115
transformation={[{
81116
"height": "200",
@@ -88,7 +123,7 @@ function App() {
88123

89124
<p>Progressive image loading with lazy loading</p>
90125
<IKImage
91-
className={'lazyload-lqip'}
126+
className={'lazyload-lqip'}
92127
path={path}
93128
transformation={[{
94129
"height": "200",
@@ -98,13 +133,6 @@ function App() {
98133
lqip={{ active: true, quality: 20, blur: 30 }}
99134
/>
100135

101-
102-
<p>File upload - To use this funtionality please remember to setup the server</p>
103-
<IKUpload
104-
onError={onError}
105-
onSuccess={onSuccess}
106-
/>
107-
108136
<p>File upload along with upload API options - To use this funtionality please remember to setup the server</p>
109137
<IKUpload
110138
fileName="test.jpg"
@@ -117,8 +145,8 @@ function App() {
117145
onError={onError} onSuccess={onSuccess}
118146
/>
119147

120-
<p>Your above uploaded file will appear here </p>
121-
<IKImage urlEndpoint={urlEndpoint} src={uploadedImageSource} />
148+
<p>Your above uploaded file will appear here </p>
149+
<IKImage urlEndpoint={urlEndpoint} src={uploadedImageSource} />
122150
</IKContext>
123151
</div>
124152
);

0 commit comments

Comments
 (0)