about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-11 00:38:58 +0200
committerGitHub <noreply@github.com>2017-04-11 00:38:58 +0200
commit12f72e1740cd91929419c82c6b782393e306994c (patch)
tree32cca940d79de94adf447bae3c98f2c4b4c76750 /spec
parentb57eed4584fbaa3bf83964bda804f27495b6f1fc (diff)
When avatar/header are GIF, generate static versions (#1428)
* When avatar/header are GIF, generate static versions.
Account API returns "avatar"/"avatar_static", "header"/"header_static"
Static version is the same as original for other cases
Web UI de-animates avatars in toots, lists of users

Fix #441, fix #596, prerequisite for #1064

* Fix JS test

* Add rake task to generate static avatars/headers from GIF ones, add test
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/files/avatar.gifbin0 -> 85810 bytes
-rw-r--r--spec/javascript/components/avatar.test.jsx12
-rw-r--r--spec/models/account_spec.rb20
3 files changed, 23 insertions, 9 deletions
diff --git a/spec/fixtures/files/avatar.gif b/spec/fixtures/files/avatar.gif
new file mode 100644
index 000000000..d929801e5
--- /dev/null
+++ b/spec/fixtures/files/avatar.gif
Binary files differdiff --git a/spec/javascript/components/avatar.test.jsx b/spec/javascript/components/avatar.test.jsx
index 852e13a89..7131bbec7 100644
--- a/spec/javascript/components/avatar.test.jsx
+++ b/spec/javascript/components/avatar.test.jsx
@@ -6,16 +6,10 @@ import Avatar from '../../../app/assets/javascripts/components/components/avatar
 describe('<Avatar />', () => {
   const src = '/path/to/image.jpg';
   const size = 100;
-  const wrapper = render(<Avatar src={src} size={size} />);
+  const wrapper = render(<Avatar src={src} animate size={size} />);
 
-  it('renders an img element with the given src', () => {
-    expect(wrapper.find('img')).to.have.attr('src', `${src}`);
-  });
-
-  it('renders an img element of the given size', () => {
-    ['width', 'height'].map((attr) => {
-      expect(wrapper.find('img')).to.have.attr(attr, `${size}`);
-    });
+  it('renders a div element with the given src as background', () => {
+    expect(wrapper.find('div')).to.have.style('background-image', `url(${src})`);
   });
 
   it('renders a div element of the given size', () => {
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 0906bb0ae..fb367ab7a 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -421,4 +421,24 @@ RSpec.describe Account, type: :model do
       end
     end
   end
+
+  describe 'static avatars' do
+    describe 'when GIF' do
+      it 'creates a png static style' do
+        subject.avatar = attachment_fixture('avatar.gif')
+        subject.save
+
+        expect(subject.avatar_static_url).to_not eq subject.avatar_original_url
+      end
+    end
+
+    describe 'when non-GIF' do
+      it 'does not create extra static style' do
+        subject.avatar = attachment_fixture('attachment.jpg')
+        subject.save
+
+        expect(subject.avatar_static_url).to eq subject.avatar_original_url
+      end
+    end
+  end
 end