|
| 1 | +/** |
| 2 | + * @jest-environment node |
| 3 | + */ |
| 4 | +import { |
| 5 | + AdvancedImage, |
| 6 | + accessibility, |
| 7 | + lazyload, |
| 8 | + placeholder, |
| 9 | + responsive, |
| 10 | +} from "../../src"; |
| 11 | +import { CloudinaryImage } from "@cloudinary/url-gen/assets/CloudinaryImage"; |
| 12 | +import { createSSRApp } from "vue"; |
| 13 | +import { renderToString } from "vue/server-renderer"; |
| 14 | +import { testIf } from "./utils"; |
| 15 | + |
| 16 | +const cloudinaryImage = new CloudinaryImage( |
| 17 | + "sample", |
| 18 | + { cloudName: "demo" }, |
| 19 | + { analytics: false } |
| 20 | +); |
| 21 | + |
| 22 | +const renderApp = (data?: { plugins: Array<unknown> }) => { |
| 23 | + const app = createSSRApp({ |
| 24 | + template: '<AdvancedImage :cldImg="cldImg" :plugins="plugins" />', |
| 25 | + data: () => ({ |
| 26 | + cldImg: cloudinaryImage, |
| 27 | + ...data, |
| 28 | + }), |
| 29 | + components: { AdvancedImage }, |
| 30 | + }); |
| 31 | + return renderToString(app); |
| 32 | +}; |
| 33 | + |
| 34 | +describe("ssr", () => { |
| 35 | + testIf( |
| 36 | + !(process.env.VUE3_TEST_ENV === "DIST"), |
| 37 | + "creates an img with analytics using src", |
| 38 | + async () => { |
| 39 | + const html = await renderApp(); |
| 40 | + |
| 41 | + expect(html).toMatch( |
| 42 | + '<img src="https://res.cloudinary.com/demo/image/upload/sample' |
| 43 | + ); |
| 44 | + } |
| 45 | + ); |
| 46 | + |
| 47 | + testIf( |
| 48 | + !(process.env.VUE3_TEST_ENV === "DIST"), |
| 49 | + "should render accessibility transformation with accessibility", |
| 50 | + async () => { |
| 51 | + const html = await renderApp({ |
| 52 | + plugins: [accessibility()], |
| 53 | + }); |
| 54 | + |
| 55 | + expect(html).toMatch( |
| 56 | + '<img src="https://res.cloudinary.com/demo/image/upload/co_black,e_colorize:70/sample' |
| 57 | + ); |
| 58 | + } |
| 59 | + ); |
| 60 | + |
| 61 | + testIf( |
| 62 | + !(process.env.VUE3_TEST_ENV === "DIST"), |
| 63 | + "should render the placeholder image in SSR", |
| 64 | + async () => { |
| 65 | + const html = await renderApp({ |
| 66 | + plugins: [placeholder()], |
| 67 | + }); |
| 68 | + |
| 69 | + expect(html).toMatch( |
| 70 | + '<img src="https://res.cloudinary.com/demo/image/upload/e_vectorize/q_auto/f_svg/sample' |
| 71 | + ); |
| 72 | + } |
| 73 | + ); |
| 74 | + |
| 75 | + testIf( |
| 76 | + !(process.env.VUE3_TEST_ENV === "DIST"), |
| 77 | + "should render original image when responsive", |
| 78 | + async () => { |
| 79 | + const html = await renderApp({ |
| 80 | + plugins: [responsive()], |
| 81 | + }); |
| 82 | + |
| 83 | + expect(html).toMatch( |
| 84 | + '<img src="https://res.cloudinary.com/demo/image/upload/sample' |
| 85 | + ); |
| 86 | + } |
| 87 | + ); |
| 88 | + |
| 89 | + testIf( |
| 90 | + !(process.env.VUE3_TEST_ENV === "DIST"), |
| 91 | + "should render original image when lazy loaded", |
| 92 | + async () => { |
| 93 | + const html = await renderApp({ |
| 94 | + plugins: [lazyload()], |
| 95 | + }); |
| 96 | + |
| 97 | + expect(html).toMatch( |
| 98 | + '<img src="https://res.cloudinary.com/demo/image/upload/sample' |
| 99 | + ); |
| 100 | + } |
| 101 | + ); |
| 102 | +}); |
0 commit comments