mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
added testing for TwitterNotification
This commit is contained in:
1 parent
dcee8690c8
commit
e48263838f
11 files changed
+127
-47
No files matched your search
@@ -42,6 +42,7 @@
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
||||
"@babel/preset-env": "^7.4.5",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@types/enzyme": "^3.10.7",
|
||||
"@types/node": "^14.11.5",
|
||||
"@types/react": "^16.9.51",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
/// <reference types="react-scripts" />
|
||||
@@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import TwitterNotification from './TwitterNotification';
|
||||
|
||||
jest.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({t: key => key})
|
||||
}));
|
||||
|
||||
jest.mock('../../../../os/phone/hooks/usePhone', () => ({
|
||||
usePhone: jest.fn().mockReturnValue({ config: {
|
||||
twitter: {
|
||||
showNotifications: true,
|
||||
}
|
||||
} })
|
||||
}));
|
||||
|
||||
jest.mock('../../hooks/useTwitterNotification', () => ({
|
||||
useTwitterNotification: jest.fn().mockReturnValue({ notification: {
|
||||
profile_name: 'test',
|
||||
message: 'test message'
|
||||
} })
|
||||
}));
|
||||
|
||||
|
||||
describe('TwitterNotification', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<TwitterNotification />)
|
||||
})
|
||||
it('renders', () => {
|
||||
expect(wrapper).toBeDefined();
|
||||
});
|
||||
|
||||
it('renders profile name', () => {
|
||||
expect(wrapper.find('.makeStyles-profileName-5').text()).toEqual('@test');
|
||||
});
|
||||
|
||||
it('renders message', () => {
|
||||
expect(wrapper.find('.makeStyles-message-7').text()).toEqual('test message');
|
||||
});
|
||||
});
|
||||
@@ -1,48 +1,50 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { makeStyles, createStyles, Theme } from "@material-ui/core/styles";
|
||||
import TwitterIcon from '@material-ui/icons/Twitter';
|
||||
import { useTwitterNotification } from '../../hooks/useTwitterNotification';
|
||||
import Notification from '../../../../ui/components/Notification';
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
content: {
|
||||
padding: '5px 8px',
|
||||
overflowY: 'hidden'
|
||||
},
|
||||
title: {
|
||||
display: 'flex',
|
||||
flexFlow: 'row nowrap',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center'
|
||||
},
|
||||
titleLeft: {
|
||||
display: 'flex',
|
||||
flexFlow: 'row nowrap',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'center'
|
||||
},
|
||||
icon: {
|
||||
marginTop: '3px',
|
||||
marginRight: '5px'
|
||||
},
|
||||
profileName: {
|
||||
marginBottom: '3px',
|
||||
},
|
||||
justNow: {
|
||||
fontSize: '18px',
|
||||
fontStyle: 'italic',
|
||||
paddingRight: '3px',
|
||||
},
|
||||
message: {
|
||||
fontSize: '16px',
|
||||
overflow: 'hidden',
|
||||
display: '-webkit-box',
|
||||
WebkitLineClamp: 2,
|
||||
WebkitBoxOrient: 'vertical',
|
||||
}
|
||||
});
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
content: {
|
||||
padding: theme.spacing(2),
|
||||
overflowY: 'hidden'
|
||||
},
|
||||
title: {
|
||||
display: 'flex',
|
||||
flexFlow: 'row nowrap',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center'
|
||||
},
|
||||
titleLeft: {
|
||||
display: 'flex',
|
||||
flexFlow: 'row nowrap',
|
||||
justifyContent: 'flex-start',
|
||||
alignItems: 'center'
|
||||
},
|
||||
icon: {
|
||||
marginTop: '3px',
|
||||
marginRight: '5px'
|
||||
},
|
||||
profileName: {
|
||||
marginBottom: '3px',
|
||||
},
|
||||
justNow: {
|
||||
fontSize: '18px',
|
||||
fontStyle: 'italic',
|
||||
paddingRight: '3px',
|
||||
},
|
||||
message: {
|
||||
fontSize: '16px',
|
||||
overflow: 'hidden',
|
||||
display: '-webkit-box',
|
||||
WebkitLineClamp: 2,
|
||||
WebkitBoxOrient: 'vertical',
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
function TwitterNotification() {
|
||||
const classes = useStyles();
|
||||
@@ -52,18 +54,22 @@ function TwitterNotification() {
|
||||
const { config } = usePhone();
|
||||
|
||||
useEffect(() => {
|
||||
setVisible(true);
|
||||
if (notification) {
|
||||
setVisible(true);
|
||||
}
|
||||
}, [notification?.id])
|
||||
|
||||
if (!config?.twitter.showNotifications || !notification) return null;
|
||||
|
||||
const profileName = `@${notification.profile_name?.trim()}`;
|
||||
|
||||
return (
|
||||
<Notification key={notification.id} open={visible} handleClose={() => setVisible(false)}>
|
||||
<div className={classes.content}>
|
||||
<div className={classes.title}>
|
||||
<div className={classes.titleLeft}>
|
||||
<div className={classes.icon}><TwitterIcon /></div>
|
||||
<div className={classes.profileName}>@{notification.profile_name}</div>
|
||||
<div className={classes.profileName}>{profileName}</div>
|
||||
</div>
|
||||
<div className={classes.justNow}>{t("APPS_TWITTER_JUST_NOW")}</div>
|
||||
</div>
|
||||
|
||||
@@ -9,6 +9,11 @@ interface TwitterConfig {
|
||||
maxImages: number;
|
||||
}
|
||||
|
||||
interface NotificationConfig {
|
||||
horizontal: 'left' | 'center' | 'right';
|
||||
vertical: 'bottom' | 'top';
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
Locale: string;
|
||||
KeyTogglePhone: number;
|
||||
@@ -19,4 +24,5 @@ export interface ServerConfig {
|
||||
DestoryChance: number;
|
||||
DestroyPhoneReCheck: number;
|
||||
twitter: TwitterConfig;
|
||||
notificationPosition: NotificationConfig;
|
||||
}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
/// <reference types="react-scripts" />
|
||||
File renamed without changes.
@@ -5,23 +5,29 @@ import Snackbar from '@material-ui/core/Snackbar';
|
||||
import Fade from '@material-ui/core/Fade';
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { useSettings } from "../../apps/settings/hooks/useSettings";
|
||||
import { usePhone } from "../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
paper: {
|
||||
width: '350px',
|
||||
height: '85px',
|
||||
height: '100px',
|
||||
opacity: '0.93',
|
||||
}
|
||||
});
|
||||
|
||||
function Notification({ key, children, handleClose, open }) {
|
||||
function Notification({ children, handleClose, open }) {
|
||||
const classes = useStyles();
|
||||
const { currentTheme } = useSettings();
|
||||
const { config } = usePhone();
|
||||
|
||||
if (!config) return null;
|
||||
|
||||
const { horizontal, vertical } = config.notificationPosition;
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={currentTheme()}>
|
||||
<Snackbar
|
||||
key={key}
|
||||
anchorOrigin={{ vertical: 'top', horizontal: 'left' }}
|
||||
anchorOrigin={{ horizontal, vertical }}
|
||||
ClickAwayListenerProps={{ onClickAway: () => null }}
|
||||
onClose={handleClose}
|
||||
open={open}
|
||||
|
||||
@@ -1762,6 +1762,21 @@
|
||||
dependencies:
|
||||
"@babel/types" "^7.3.0"
|
||||
|
||||
"@types/cheerio@*":
|
||||
version "0.22.22"
|
||||
resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.22.tgz#ae71cf4ca59b8bbaf34c99af7a5d6c8894988f5f"
|
||||
integrity sha512-05DYX4zU96IBfZFY+t3Mh88nlwSMtmmzSYaQkKN48T495VV1dkHSah6qYyDTN5ngaS0i0VonH37m+RuzSM0YiA==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/enzyme@^3.10.7":
|
||||
version "3.10.7"
|
||||
resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.7.tgz#ebdf3b972d293095e09af479e36c772025285e3a"
|
||||
integrity sha512-J+0wduPGAkzOvW7sr6hshGv1gBI3WXLRTczkRKzVPxLP3xAkYxZmvvagSBPw8Z452fZ8TGUxCmAXcb44yLQksw==
|
||||
dependencies:
|
||||
"@types/cheerio" "*"
|
||||
"@types/react" "*"
|
||||
|
||||
"@types/eslint-visitor-keys@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
||||
|
||||
Reference in new issue
Block a user