|
| 1 | +import { TestBed } from '@angular/core/testing'; |
| 2 | +import { Attachment } from 'stream-chat'; |
| 3 | +import { AttachmentConfigurationService } from './attachment-configuration.service'; |
| 4 | + |
| 5 | +describe('AttachmentConfigurationService', () => { |
| 6 | + let service: AttachmentConfigurationService; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + service = TestBed.inject(AttachmentConfigurationService); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should provide the correct configuration for image attachments', () => { |
| 13 | + let attachment: Attachment = { |
| 14 | + img_url: 'url/to/img', |
| 15 | + thumb_url: 'different/url', |
| 16 | + }; |
| 17 | + |
| 18 | + expect( |
| 19 | + service.getImageAttachmentConfiguration(attachment, 'single') |
| 20 | + ).toEqual({ |
| 21 | + url: 'url/to/img', |
| 22 | + height: '300px', |
| 23 | + width: '', |
| 24 | + }); |
| 25 | + |
| 26 | + attachment = { |
| 27 | + thumb_url: 'url/to/img', |
| 28 | + }; |
| 29 | + |
| 30 | + expect( |
| 31 | + service.getImageAttachmentConfiguration(attachment, 'single') |
| 32 | + ).toEqual({ |
| 33 | + url: 'url/to/img', |
| 34 | + height: '300px', |
| 35 | + width: '', |
| 36 | + }); |
| 37 | + |
| 38 | + attachment = { |
| 39 | + image_url: 'url/to/img', |
| 40 | + }; |
| 41 | + |
| 42 | + expect( |
| 43 | + service.getImageAttachmentConfiguration(attachment, 'single') |
| 44 | + ).toEqual({ |
| 45 | + url: 'url/to/img', |
| 46 | + height: '300px', |
| 47 | + width: '', |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should call #customImageAttachmentConfigurationHandler, if provided', () => { |
| 52 | + const spy = jasmine.createSpy(); |
| 53 | + service.customImageAttachmentConfigurationHandler = spy; |
| 54 | + const attachment: Attachment = { |
| 55 | + img_url: 'url/to/img', |
| 56 | + thumb_url: 'different/url', |
| 57 | + }; |
| 58 | + service.getImageAttachmentConfiguration(attachment, 'carousel'); |
| 59 | + |
| 60 | + expect(spy).toHaveBeenCalledWith(attachment, 'carousel'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should provide the correct configuration for gallery image attachments', () => { |
| 64 | + const attachment: Attachment = { |
| 65 | + img_url: 'url/to/img', |
| 66 | + }; |
| 67 | + |
| 68 | + expect( |
| 69 | + service.getImageAttachmentConfiguration(attachment, 'gallery') |
| 70 | + ).toEqual({ |
| 71 | + url: 'url/to/img', |
| 72 | + height: '', |
| 73 | + width: '', |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should provide the correct configuration for image attachments inside the carousel', () => { |
| 78 | + const attachment: Attachment = { |
| 79 | + img_url: 'url/to/img', |
| 80 | + }; |
| 81 | + |
| 82 | + expect( |
| 83 | + service.getImageAttachmentConfiguration(attachment, 'carousel') |
| 84 | + ).toEqual({ |
| 85 | + url: 'url/to/img', |
| 86 | + height: '', |
| 87 | + width: '', |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should provide the correct configuration for video attachments', () => { |
| 92 | + const attachment: Attachment = { |
| 93 | + asset_url: 'url/to/video', |
| 94 | + }; |
| 95 | + |
| 96 | + expect(service.getVideoAttachmentConfiguration(attachment)).toEqual({ |
| 97 | + url: 'url/to/video', |
| 98 | + height: '100%', |
| 99 | + width: '100%', |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should call #customVideoAttachmentConfigurationHandler, if provided', () => { |
| 104 | + const spy = jasmine.createSpy(); |
| 105 | + service.customVideoAttachmentConfigurationHandler = spy; |
| 106 | + const attachment: Attachment = { |
| 107 | + img_url: 'url/to/video', |
| 108 | + thumb_url: 'different/url', |
| 109 | + }; |
| 110 | + service.getVideoAttachmentConfiguration(attachment); |
| 111 | + |
| 112 | + expect(spy).toHaveBeenCalledWith(attachment); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should provide the correct configuration for GIFs', () => { |
| 116 | + let attachment: Attachment = { |
| 117 | + image_url: 'link/to/GIF', |
| 118 | + }; |
| 119 | + |
| 120 | + expect(service.getGiphyAttachmentConfiguration(attachment)).toEqual({ |
| 121 | + url: 'link/to/GIF', |
| 122 | + height: '300px', |
| 123 | + width: '', |
| 124 | + }); |
| 125 | + |
| 126 | + /* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
| 127 | + attachment = { |
| 128 | + image_url: 'link/to/GIF', |
| 129 | + giphy: { |
| 130 | + fixed_height_downsampled: { |
| 131 | + height: '200', |
| 132 | + width: '400', |
| 133 | + url: 'link/to/smaller/GIF', |
| 134 | + }, |
| 135 | + } as any, |
| 136 | + }; |
| 137 | + /* eslint-enable @typescript-eslint/no-unsafe-assignment */ |
| 138 | + |
| 139 | + expect(service.getGiphyAttachmentConfiguration(attachment)).toEqual({ |
| 140 | + url: 'link/to/smaller/GIF', |
| 141 | + height: '200px', |
| 142 | + width: '400px', |
| 143 | + }); |
| 144 | + }); |
| 145 | + |
| 146 | + it('should call #customGiphyAttachmentConfigurationHandler, if provided', () => { |
| 147 | + const spy = jasmine.createSpy(); |
| 148 | + service.customGiphyAttachmentConfigurationHandler = spy; |
| 149 | + |
| 150 | + /* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
| 151 | + const attachment = { |
| 152 | + image_url: 'link/to/GIF', |
| 153 | + giphy: { |
| 154 | + fixed_height_downsampled: { |
| 155 | + height: '200', |
| 156 | + width: '400', |
| 157 | + url: 'link/to/smaller/GIF', |
| 158 | + }, |
| 159 | + } as any, |
| 160 | + }; |
| 161 | + /* eslint-enable @typescript-eslint/no-unsafe-assignment */ |
| 162 | + |
| 163 | + service.getGiphyAttachmentConfiguration(attachment); |
| 164 | + |
| 165 | + expect(spy).toHaveBeenCalledWith(attachment); |
| 166 | + }); |
| 167 | + |
| 168 | + it('should provide correct configuration for scraped images', () => { |
| 169 | + let attachment: Attachment = { |
| 170 | + image_url: 'url/to/img', |
| 171 | + thumb_url: 'different/url', |
| 172 | + }; |
| 173 | + |
| 174 | + expect(service.getScrapedImageAttachmentConfiguration(attachment)).toEqual({ |
| 175 | + url: 'url/to/img', |
| 176 | + width: '', |
| 177 | + height: '', |
| 178 | + }); |
| 179 | + |
| 180 | + attachment = { |
| 181 | + thumb_url: 'different/url', |
| 182 | + }; |
| 183 | + |
| 184 | + expect(service.getScrapedImageAttachmentConfiguration(attachment)).toEqual({ |
| 185 | + url: 'different/url', |
| 186 | + width: '', |
| 187 | + height: '', |
| 188 | + }); |
| 189 | + }); |
| 190 | + |
| 191 | + it('should call #customScrapedImageAttachmentConfigurationHandler, if provided', () => { |
| 192 | + const spy = jasmine.createSpy(); |
| 193 | + service.customScrapedImageAttachmentConfigurationHandler = spy; |
| 194 | + const attachment = { |
| 195 | + image_url: 'link/to/url', |
| 196 | + }; |
| 197 | + service.getScrapedImageAttachmentConfiguration(attachment); |
| 198 | + |
| 199 | + expect(spy).toHaveBeenCalledWith(attachment); |
| 200 | + }); |
| 201 | +}); |
0 commit comments