2022-03-10 15:15:09 -08:00
import {
Map as ImmutableMap ,
Record as ImmutableRecord ,
fromJS ,
} from 'immutable' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:17:52 -08:00
import { STATUS _IMPORT } from 'soapbox/actions/importer' ;
2021-11-12 10:18:11 -08:00
import {
STATUS _CREATE _REQUEST ,
STATUS _CREATE _FAIL ,
} from 'soapbox/actions/statuses' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:01:24 -08:00
import reducer from '../statuses' ;
2020-06-09 18:08:07 -07:00
describe ( 'statuses reducer' , ( ) => {
it ( 'should return the initial state' , ( ) => {
expect ( reducer ( undefined , { } ) ) . toEqual ( ImmutableMap ( ) ) ;
} ) ;
2021-11-12 10:18:11 -08:00
2022-01-07 14:57:58 -08:00
describe ( 'STATUS_IMPORT' , ( ) => {
2022-03-08 21:59:59 -08:00
it ( 'parses the status as a Record' , ( ) => {
const status = require ( 'soapbox/__fixtures__/pleroma-quote-post.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const result = reducer ( undefined , action ) . get ( 'AFmFMSpITT9xcOJKcK' ) ;
2022-03-10 15:15:09 -08:00
expect ( ImmutableRecord . isRecord ( result ) ) . toBe ( true ) ;
2022-03-08 21:59:59 -08:00
} ) ;
2022-01-07 14:57:58 -08:00
it ( 'fixes the order of mentions' , ( ) => {
const status = require ( 'soapbox/__fixtures__/status-unordered-mentions.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const expected = [ 'NEETzsche' , 'alex' , 'Lumeinshin' , 'sneeden' ] ;
const result = reducer ( undefined , action )
. getIn ( [ 'AFChectaqZjmOVkXZ2' , 'mentions' ] )
. map ( mention => mention . get ( 'username' ) )
. toJS ( ) ;
expect ( result ) . toEqual ( expected ) ;
} ) ;
2022-01-24 13:08:22 -08:00
it ( 'preserves the quote' , ( ) => {
const quotePost = require ( 'soapbox/__fixtures__/pleroma-quote-post.json' ) ;
const quotedQuotePost = require ( 'soapbox/__fixtures__/pleroma-quote-of-quote-post.json' ) ;
let state = undefined ;
2022-02-20 00:38:22 -08:00
state = reducer ( state , { type : STATUS _IMPORT , status : quotePost } ) ;
state = reducer ( state , { type : STATUS _IMPORT , status : quotedQuotePost . pleroma . quote } ) ;
2022-01-24 13:08:22 -08:00
expect ( state . getIn ( [ 'AFmFMSpITT9xcOJKcK' , 'quote' ] ) ) . toEqual ( 'AFmFLcd6XYVdjWCrOS' ) ;
} ) ;
2022-02-11 15:56:34 -08:00
it ( 'normalizes Mitra attachments' , ( ) => {
const status = require ( 'soapbox/__fixtures__/mitra-status-with-attachments.json' ) ;
2022-02-20 00:38:22 -08:00
const state = reducer ( undefined , { type : STATUS _IMPORT , status } ) ;
2022-02-11 15:56:34 -08:00
2022-03-10 15:15:09 -08:00
const expected = [ {
2022-02-11 15:56:34 -08:00
id : '017eeb0e-e5df-30a4-77a7-a929145cb836' ,
type : 'image' ,
url : 'https://mitra.social/media/8e04e6091bbbac79641b5812508683ce72c38693661c18d16040553f2371e18d.png' ,
preview _url : 'https://mitra.social/media/8e04e6091bbbac79641b5812508683ce72c38693661c18d16040553f2371e18d.png' ,
2022-03-10 15:15:09 -08:00
remote _url : null ,
2022-02-11 15:56:34 -08:00
} , {
id : '017eeb0e-e5e4-2a48-2889-afdebf368a54' ,
type : 'unknown' ,
url : 'https://mitra.social/media/8f72dc2e98572eb4ba7c3a902bca5f69c448fc4391837e5f8f0d4556280440ac' ,
preview _url : 'https://mitra.social/media/8f72dc2e98572eb4ba7c3a902bca5f69c448fc4391837e5f8f0d4556280440ac' ,
2022-03-10 15:15:09 -08:00
remote _url : null ,
2022-02-11 15:56:34 -08:00
} , {
id : '017eeb0e-e5e5-79fd-6054-8b6869b1db49' ,
type : 'unknown' ,
url : 'https://mitra.social/media/55a81a090247cc4fc127e5716bcf7964f6e0df9b584f85f4696c0b994747a4d0.oga' ,
preview _url : 'https://mitra.social/media/55a81a090247cc4fc127e5716bcf7964f6e0df9b584f85f4696c0b994747a4d0.oga' ,
2022-03-10 15:15:09 -08:00
remote _url : null ,
2022-02-11 15:56:34 -08:00
} , {
id : '017eeb0e-e5e6-c416-a444-21e560c47839' ,
type : 'unknown' ,
url : 'https://mitra.social/media/0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0' ,
preview _url : 'https://mitra.social/media/0d96a4ff68ad6d4b6f1f30f713b18d5184912ba8dd389f86aa7710db079abcb0' ,
2022-03-10 15:15:09 -08:00
remote _url : null ,
} ] ;
2022-02-11 15:56:34 -08:00
2022-03-10 15:15:09 -08:00
expect ( state . getIn ( [ '017eeb0e-e5e7-98fe-6b2b-ad02349251fb' , 'media_attachments' ] ) . toJS ( ) ) . toMatchObject ( expected ) ;
2022-02-11 15:56:34 -08:00
} ) ;
2022-03-10 15:15:09 -08:00
it ( 'fixes Pleroma attachments' , ( ) => {
2022-02-11 15:56:34 -08:00
const status = require ( 'soapbox/__fixtures__/pleroma-status-with-attachments.json' ) ;
2022-02-20 00:38:22 -08:00
const action = { type : STATUS _IMPORT , status } ;
2022-02-11 15:56:34 -08:00
const state = reducer ( undefined , action ) ;
2022-03-10 15:15:09 -08:00
const result = state . get ( 'AGNkA21auFR5lnEAHw' ) . media _attachments ;
2022-02-11 15:56:34 -08:00
2022-03-10 15:15:09 -08:00
expect ( result . size ) . toBe ( 4 ) ;
expect ( result . get ( 0 ) . text _url ) . toBe ( undefined ) ;
expect ( result . get ( 1 ) . meta ) . toEqual ( ImmutableMap ( ) ) ;
expect ( result . getIn ( [ 1 , 'pleroma' , 'mime_type' ] ) ) . toBe ( 'application/x-nes-rom' ) ;
2022-02-11 15:56:34 -08:00
} ) ;
2022-02-20 09:44:10 -08:00
it ( 'hides CWs' , ( ) => {
const status = require ( 'soapbox/__fixtures__/status-cw.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const hidden = reducer ( undefined , action ) . getIn ( [ '107831528995252317' , 'hidden' ] ) ;
expect ( hidden ) . toBe ( true ) ;
} ) ;
it ( 'expands CWs when expandSpoilers is enabled' , ( ) => {
const status = require ( 'soapbox/__fixtures__/status-cw.json' ) ;
const action = { type : STATUS _IMPORT , status , expandSpoilers : true } ;
const hidden = reducer ( undefined , action ) . getIn ( [ '107831528995252317' , 'hidden' ] ) ;
expect ( hidden ) . toBe ( false ) ;
} ) ;
2022-02-23 09:37:12 -08:00
it ( 'parses custom emojis' , ( ) => {
const status = require ( 'soapbox/__fixtures__/status-custom-emoji.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const expected = 'Hello <img draggable="false" class="emojione" alt=":ablobcathyper:" title=":ablobcathyper:" src="https://gleasonator.com/emoji/blobcat/ablobcathyper.png"> <img draggable="false" class="emojione" alt=":ageblobcat:" title=":ageblobcat:" src="https://gleasonator.com/emoji/blobcat/ageblobcat.png"> <img draggable="false" class="emojione" alt="😂" title=":joy:" src="/packs/emoji/1f602.svg"> world <img draggable="false" class="emojione" alt="😋" title=":yum:" src="/packs/emoji/1f60b.svg"> test <img draggable="false" class="emojione" alt=":blobcatphoto:" title=":blobcatphoto:" src="https://gleasonator.com/emoji/blobcat/blobcatphoto.png">' ;
const result = reducer ( undefined , action ) . getIn ( [ 'AGm7uC9DaAIGUa4KYK' , 'contentHtml' ] ) ;
expect ( result ) . toBe ( expected ) ;
} ) ;
2022-02-23 20:41:49 -08:00
it ( 'builds search_index' , ( ) => {
const status = require ( 'soapbox/__fixtures__/status-with-poll.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const expected = ` What is tolerance?
Banning , censoring , and deplatforming anyone you disagree with
Promoting free speech , even for people and ideas you dislike ` ;
const result = reducer ( undefined , action ) . getIn ( [ '103874034847713213' , 'search_index' ] ) ;
expect ( result ) . toEqual ( expected ) ;
} ) ;
2022-03-26 08:45:45 -07:00
it ( 'builds search_index with mentions' , ( ) => {
const status = require ( 'soapbox/__fixtures__/pleroma-status-reply-with-mentions.json' ) ;
const action = { type : STATUS _IMPORT , status } ;
const expected = ` DMs are definitely only federated to the servers of the recipients tho. So if I DM a kfcc user, the kfcc admins can see it, but no other instance admins can.
2022-03-26 09:17:27 -07:00
@ crunklord420 @ kiwifarms . cc
2022-03-26 08:45:45 -07:00
2022-03-26 09:17:27 -07:00
@ becassine @ kiwifarms . cc
2022-03-26 08:45:45 -07:00
2022-03-26 09:17:27 -07:00
@ King _Porgi @ poa . st
2022-03-26 08:45:45 -07:00
2022-03-26 09:17:27 -07:00
@ ademan @ thebag . social ` ;
2022-03-26 08:45:45 -07:00
const result = reducer ( undefined , action ) . getIn ( [ 'AHcweewcCh0iPUtMdk' , 'search_index' ] ) ;
expect ( result ) . toEqual ( expected ) ;
} ) ;
2022-01-07 14:57:58 -08:00
} ) ;
2021-11-12 10:18:11 -08:00
describe ( 'STATUS_CREATE_REQUEST' , ( ) => {
it ( 'increments the replies_count of its parent' , ( ) => {
const state = fromJS ( { '123' : { replies _count : 4 } } ) ;
const action = {
type : STATUS _CREATE _REQUEST ,
params : { in _reply _to _id : '123' } ,
} ;
const result = reducer ( state , action ) . getIn ( [ '123' , 'replies_count' ] ) ;
expect ( result ) . toEqual ( 5 ) ;
} ) ;
} ) ;
describe ( 'STATUS_CREATE_FAIL' , ( ) => {
it ( 'decrements the replies_count of its parent' , ( ) => {
const state = fromJS ( { '123' : { replies _count : 5 } } ) ;
const action = {
type : STATUS _CREATE _FAIL ,
params : { in _reply _to _id : '123' } ,
} ;
const result = reducer ( state , action ) . getIn ( [ '123' , 'replies_count' ] ) ;
expect ( result ) . toEqual ( 4 ) ;
} ) ;
} ) ;
2020-06-09 18:08:07 -07:00
} ) ;