From 599129897a745fdd7dc2d8323350e7280c45d0dd Mon Sep 17 00:00:00 2001 From: crockwave Date: Tue, 14 Jul 2020 17:11:05 -0500 Subject: [PATCH] edited accounts and alerts reducer tests --- app/soapbox/__fixtures__/accounts.json | 182 ++++++++++ .../reducers/__tests__/accounts-test.js | 323 ++---------------- .../__tests__/accounts_counters-test.js | 1 - app/soapbox/reducers/__tests__/alerts-test.js | 85 +++-- 4 files changed, 276 insertions(+), 315 deletions(-) create mode 100644 app/soapbox/__fixtures__/accounts.json diff --git a/app/soapbox/__fixtures__/accounts.json b/app/soapbox/__fixtures__/accounts.json new file mode 100644 index 000000000..f10880171 --- /dev/null +++ b/app/soapbox/__fixtures__/accounts.json @@ -0,0 +1,182 @@ +{ + "9w1HhmenIAKBHJiUs4":{ + "header_static":"https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "display_name_html":"Alex Gleason", + "bot":false, + "display_name":"Alex Gleason", + "created_at":"2020-06-12T21:47:28.000Z", + "locked":false, + "emojis":[ + + ], + "header":"https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "url":"https://gleasonator.com/users/alex", + "note":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.", + "acct":"alex@gleasonator.com", + "avatar_static":"https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg", + "username":"alex", + "avatar":"https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg", + "fields":[ + { + "name":"Website", + "value":"https://alexgleason.me", + "name_emojified":"Website", + "value_emojified":"https://alexgleason.me", + "value_plain":"https://alexgleason.me" + }, + { + "name":"Pleroma+Soapbox", + "value":"https://soapbox.pub", + "name_emojified":"Pleroma+Soapbox", + "value_emojified":"https://soapbox.pub", + "value_plain":"https://soapbox.pub" + }, + { + "name":"Email", + "value":"alex@alexgleason.me", + "name_emojified":"Email", + "value_emojified":"alex@alexgleason.me", + "value_plain":"alex@alexgleason.me" + }, + { + "name":"Gender identity", + "value":"Soyboy", + "name_emojified":"Gender identity", + "value_emojified":"Soyboy", + "value_plain":"Soyboy" + } + ], + "pleroma":{ + "hide_follows":false, + "hide_followers_count":false, + "background_image":null, + "confirmation_pending":false, + "is_moderator":false, + "hide_follows_count":false, + "hide_followers":false, + "relationship":{ + "showing_reblogs":true, + "followed_by":false, + "subscribing":false, + "blocked_by":false, + "requested":false, + "domain_blocking":false, + "following":false, + "endorsed":false, + "blocking":false, + "muting":false, + "id":"9w1HhmenIAKBHJiUs4", + "muting_notifications":false + }, + "tags":[ + + ], + "hide_favorites":true, + "is_admin":false, + "skip_thread_containment":false + }, + "source":{ + "fields":[ + + ], + "note":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.", + "pleroma":{ + "actor_type":"Person", + "discoverable":false + }, + "sensitive":false + }, + "id":"9w1HhmenIAKBHJiUs4", + "note_emojified":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements." + }, + "9w1HhmenIAKBHJiUs5":{ + "header_static":"https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "display_name_html":"Alex Gleason", + "bot":false, + "display_name":"Alex Gleason", + "created_at":"2020-06-12T21:47:28.000Z", + "locked":false, + "emojis":[ + + ], + "header":"https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png", + "url":"https://gleasonator.com/users/alex", + "note":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.", + "acct":"alex@gleasonator.com", + "avatar_static":"https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg", + "username":"alex", + "avatar":"https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg", + "fields":[ + { + "name":"Website", + "value":"https://alexgleason.me", + "name_emojified":"Website", + "value_emojified":"https://alexgleason.me", + "value_plain":"https://alexgleason.me" + }, + { + "name":"Pleroma+Soapbox", + "value":"https://soapbox.pub", + "name_emojified":"Pleroma+Soapbox", + "value_emojified":"https://soapbox.pub", + "value_plain":"https://soapbox.pub" + }, + { + "name":"Email", + "value":"alex@alexgleason.me", + "name_emojified":"Email", + "value_emojified":"alex@alexgleason.me", + "value_plain":"alex@alexgleason.me" + }, + { + "name":"Gender identity", + "value":"Soyboy", + "name_emojified":"Gender identity", + "value_emojified":"Soyboy", + "value_plain":"Soyboy" + } + ], + "pleroma":{ + "hide_follows":false, + "hide_followers_count":false, + "background_image":null, + "confirmation_pending":false, + "is_moderator":false, + "hide_follows_count":false, + "hide_followers":false, + "relationship":{ + "showing_reblogs":true, + "followed_by":false, + "subscribing":false, + "blocked_by":false, + "requested":false, + "domain_blocking":false, + "following":false, + "endorsed":false, + "blocking":false, + "muting":false, + "id":"9w1HhmenIAKBHJiUs5", + "muting_notifications":false + }, + "tags":[ + + ], + "hide_favorites":true, + "is_admin":false, + "skip_thread_containment":false + }, + "source":{ + "fields":[ + + ], + "note":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.", + "pleroma":{ + "actor_type":"Person", + "discoverable":false + }, + "sensitive":false + }, + "id":"9w1HhmenIAKBHJiUs5", + "note_emojified":"Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements." + } +} diff --git a/app/soapbox/reducers/__tests__/accounts-test.js b/app/soapbox/reducers/__tests__/accounts-test.js index daae099cd..10cefb3fd 100644 --- a/app/soapbox/reducers/__tests__/accounts-test.js +++ b/app/soapbox/reducers/__tests__/accounts-test.js @@ -1,297 +1,48 @@ import reducer from '../accounts'; import { Map as ImmutableMap } from 'immutable'; -import * as actions from 'soapbox/actions/accounts'; +// import * as actions from 'soapbox/actions/importer'; +// import { take } from 'lodash'; +// import accounts from 'soapbox/__fixtures__/accounts.json'; describe('accounts reducer', () => { it('should return the initial state', () => { expect(reducer(undefined, {})).toEqual(ImmutableMap()); }); - it('should handle ACCOUNT_IMPORT', () => { - const state = ImmutableMap({ }); - const account = { - '9w1HhmenIAKBHJiUs4': { - header_static: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - display_name_html: 'Alex Gleason', - bot: false, - display_name: 'Alex Gleason', - created_at: '2020-06-12T21:47:28.000Z', - locked: false, - emojis: [], - header: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - url: 'https://gleasonator.com/users/alex', - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - acct: 'alex@gleasonator.com', - avatar_static: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - username: 'alex', - avatar: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - fields: [ - { - name: 'Website', - value: 'https://alexgleason.me', - name_emojified: 'Website', - value_emojified: 'https://alexgleason.me', - value_plain: 'https://alexgleason.me', - }, - { - name: 'Pleroma+Soapbox', - value: 'https://soapbox.pub', - name_emojified: 'Pleroma+Soapbox', - value_emojified: 'https://soapbox.pub', - value_plain: 'https://soapbox.pub', - }, - { - name: 'Email', - value: 'alex@alexgleason.me', - name_emojified: 'Email', - value_emojified: 'alex@alexgleason.me', - value_plain: 'alex@alexgleason.me', - }, - { - name: 'Gender identity', - value: 'Soyboy', - name_emojified: 'Gender identity', - value_emojified: 'Soyboy', - value_plain: 'Soyboy', - }, - ], - pleroma: { - hide_follows: false, - hide_followers_count: false, - background_image: null, - confirmation_pending: false, - is_moderator: false, - hide_follows_count: false, - hide_followers: false, - relationship: { - showing_reblogs: true, - followed_by: false, - subscribing: false, - blocked_by: false, - requested: false, - domain_blocking: false, - following: false, - endorsed: false, - blocking: false, - muting: false, - id: '9w1HhmenIAKBHJiUs4', - muting_notifications: false, - }, - tags: [], - hide_favorites: true, - is_admin: false, - skip_thread_containment: false, - }, - source: { - fields: [], - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - pleroma: { - actor_type: 'Person', - discoverable: false, - }, - sensitive: false, - }, - id: '9w1HhmenIAKBHJiUs4', - note_emojified: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - }, - }; - const action = { - type: actions.ACCOUNT_IMPORT, - account: account, - }; - expect(reducer(state, action).toJS()).toMatchObject({ - }); - }); - - it('should handle ACCOUNTS_IMPORT', () => { - const state = ImmutableMap({ }); - const accounts = { - '9w1HhmenIAKBHJiUs4': { - header_static: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - display_name_html: 'Alex Gleason', - bot: false, - display_name: 'Alex Gleason', - created_at: '2020-06-12T21:47:28.000Z', - locked: false, - emojis: [], - header: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - url: 'https://gleasonator.com/users/alex', - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - acct: 'alex@gleasonator.com', - avatar_static: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - username: 'alex', - avatar: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - fields: [ - { - name: 'Website', - value: 'https://alexgleason.me', - name_emojified: 'Website', - value_emojified: 'https://alexgleason.me', - value_plain: 'https://alexgleason.me', - }, - { - name: 'Pleroma+Soapbox', - value: 'https://soapbox.pub', - name_emojified: 'Pleroma+Soapbox', - value_emojified: 'https://soapbox.pub', - value_plain: 'https://soapbox.pub', - }, - { - name: 'Email', - value: 'alex@alexgleason.me', - name_emojified: 'Email', - value_emojified: 'alex@alexgleason.me', - value_plain: 'alex@alexgleason.me', - }, - { - name: 'Gender identity', - value: 'Soyboy', - name_emojified: 'Gender identity', - value_emojified: 'Soyboy', - value_plain: 'Soyboy', - }, - ], - pleroma: { - hide_follows: false, - hide_followers_count: false, - background_image: null, - confirmation_pending: false, - is_moderator: false, - hide_follows_count: false, - hide_followers: false, - relationship: { - showing_reblogs: true, - followed_by: false, - subscribing: false, - blocked_by: false, - requested: false, - domain_blocking: false, - following: false, - endorsed: false, - blocking: false, - muting: false, - id: '9w1HhmenIAKBHJiUs4', - muting_notifications: false, - }, - tags: [], - hide_favorites: true, - is_admin: false, - skip_thread_containment: false, - }, - source: { - fields: [], - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - pleroma: { - actor_type: 'Person', - discoverable: false, - }, - sensitive: false, - }, - id: '9w1HhmenIAKBHJiUs4', - note_emojified: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - }, - '9w1HhmenIAKBHJiUs4': { - header_static: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - display_name_html: 'Alex Gleason', - bot: false, - display_name: 'Alex Gleason', - created_at: '2020-06-12T21:47:28.000Z', - locked: false, - emojis: [], - header: 'https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png', - url: 'https://gleasonator.com/users/alex', - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - acct: 'alex@gleasonator.com', - avatar_static: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - username: 'alex', - avatar: 'https://media.gleasonator.com/accounts/avatars/000/000/001/original/1a630e4c4c64c948.jpg', - fields: [ - { - name: 'Website', - value: 'https://alexgleason.me', - name_emojified: 'Website', - value_emojified: 'https://alexgleason.me', - value_plain: 'https://alexgleason.me', - }, - { - name: 'Pleroma+Soapbox', - value: 'https://soapbox.pub', - name_emojified: 'Pleroma+Soapbox', - value_emojified: 'https://soapbox.pub', - value_plain: 'https://soapbox.pub', - }, - { - name: 'Email', - value: 'alex@alexgleason.me', - name_emojified: 'Email', - value_emojified: 'alex@alexgleason.me', - value_plain: 'alex@alexgleason.me', - }, - { - name: 'Gender identity', - value: 'Soyboy', - name_emojified: 'Gender identity', - value_emojified: 'Soyboy', - value_plain: 'Soyboy', - }, - ], - pleroma: { - hide_follows: false, - hide_followers_count: false, - background_image: null, - confirmation_pending: false, - is_moderator: false, - hide_follows_count: false, - hide_followers: false, - relationship: { - showing_reblogs: true, - followed_by: false, - subscribing: false, - blocked_by: false, - requested: false, - domain_blocking: false, - following: false, - endorsed: false, - blocking: false, - muting: false, - id: '9w1HhmenIAKBHJiUs4', - muting_notifications: false, - }, - tags: [], - hide_favorites: true, - is_admin: false, - skip_thread_containment: false, - }, - source: { - fields: [], - note: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - pleroma: { - actor_type: 'Person', - discoverable: false, - }, - sensitive: false, - }, - id: '9w1HhmenIAKBHJiUs4', - note_emojified: 'Fediverse developer. I come in peace. #vegan #freeculture #atheist #antiporn #gendercritical. Boosts ≠ endorsements.', - }, - }; - const action = { - type: actions.ACCOUNTS_IMPORT, - accounts: accounts, - }; - expect(reducer(state, action).toJS()).toMatchObject({ - }); - }); + // fails to add normalized accounts to state + // it('should handle ACCOUNT_IMPORT', () => { + // const state = ImmutableMap({ }); + // const account = take(accounts, 1); + // const action = { + // type: actions.ACCOUNT_IMPORT, + // account: account, + // }; + // debugger; + // expect(reducer(state, action).toJS()).toMatchObject({ + // }); + // }); - it('should handle ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP', () => { - const state = ImmutableMap({ username: 'curtis' }); - const action = { - type: actions.ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP, - username: 'curtis', - }; - expect(reducer(state, action).toJS()).toMatchObject({ - username: 'curtis', - }); - }); + // fails to add normalized accounts to state + // it('should handle ACCOUNTS_IMPORT', () => { + // const state = ImmutableMap({ }); + // const accounts = take(accounts, 2); + // const action = { + // type: actions.ACCOUNTS_IMPORT, + // accounts: accounts, + // }; + // expect(reducer(state, action).toJS()).toMatchObject({ + // }); + // }); + // + // it('should handle ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP', () => { + // const state = ImmutableMap({ username: 'curtis' }); + // const action = { + // type: actions.ACCOUNT_FETCH_FAIL_FOR_USERNAME_LOOKUP, + // username: 'curtis', + // }; + // expect(reducer(state, action).toJS()).toMatchObject({ + // username: 'curtis', + // }); + // }); }); diff --git a/app/soapbox/reducers/__tests__/accounts_counters-test.js b/app/soapbox/reducers/__tests__/accounts_counters-test.js index ca6272fbd..e708e9deb 100644 --- a/app/soapbox/reducers/__tests__/accounts_counters-test.js +++ b/app/soapbox/reducers/__tests__/accounts_counters-test.js @@ -19,7 +19,6 @@ describe('accounts_counters reducer', () => { // relationship: relationship, // alreadyFollowing: false, // }; - // debugger; // expect(reducer(state, action)).toEqual( // ImmutableList([ accounts_counter_follow ])); // }); diff --git a/app/soapbox/reducers/__tests__/alerts-test.js b/app/soapbox/reducers/__tests__/alerts-test.js index 0e000bf2d..d34de32ce 100644 --- a/app/soapbox/reducers/__tests__/alerts-test.js +++ b/app/soapbox/reducers/__tests__/alerts-test.js @@ -1,43 +1,72 @@ import reducer from '../alerts'; -import { List as ImmutableList } from 'immutable'; -//import * as actions from 'soapbox/actions/alerts'; +import { List as ImmutableList, Map as ImmutableMap } from 'immutable'; +import * as actions from 'soapbox/actions/alerts'; describe('alerts reducer', () => { it('should return the initial state', () => { expect(reducer(undefined, {})).toEqual(ImmutableList()); }); - // it('should handle ALERT_SHOW', () => { - // const state = ImmutableMap({ key: 2 }); - // const action = { - // type: actions.ALERT_SHOW, - // title: 'alert_title', - // message: 'this is an alert message', - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // key: 2, - // }); - // }); + it('should handle ALERT_SHOW', () => { + const state = ImmutableList([]); + const action = { + type: actions.ALERT_SHOW, + title: 'alert_title', + message: 'this is an alert message', + }; + expect(reducer(state, action).toJS()).toMatchObject([ + { + key: 0, + message: 'this is an alert message', + title: 'alert_title', + }, + ]); + }); // it('should handle ALERT_DISMISS', () => { - // const state = ImmutableMap({ key: 2, title: 'title', message: 'message' }); + // const state = ImmutableList([ + // { + // key: 0, + // message: 'message_1', + // title: 'title_1', + // }, + // { + // key: 1, + // message: 'message_2', + // title: 'title_2', + // }, + // ]); // const action = { // type: actions.ALERT_DISMISS, - // alert: { key: 2 }, + // alert: { key: 0 }, // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // key: 2, - // }); - // }); - // - // it('should handle ALERT_CLEAR', () => { - // const state = ImmutableMap({ }); - // const action = { - // type: actions.ALERT_CLEAR, - // key: 2, - // }; - // expect(reducer(state, action).toJS()).toMatchObject({ - // }); + // expect(reducer(state, action).toJS()).toMatchObject([ + // { + // key: 1, + // message: 'message_2', + // title: 'title_2', + // } + // ]); // }); + it('should handle ALERT_CLEAR', () => { + const state = ImmutableList([ + { + key: 0, + message: 'message_1', + title: 'title_1', + }, + { + key: 1, + message: 'message_2', + title: 'title_2', + }, + ]); + const action = { + type: actions.ALERT_CLEAR, + }; + expect(reducer(state, action).toJS()).toMatchObject({ + }); + }); + });