@planningcenter/chat-react-native 4.7.1-qa-staging.0 → 4.7.1-qa-1092.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversations/conversation_actions.d.ts.map +1 -1
- package/build/components/conversations/conversation_actions.js +186 -322
- package/build/components/conversations/conversation_actions.js.map +1 -1
- package/build/components/group_conversation_list.d.ts.map +1 -1
- package/build/components/group_conversation_list.js +0 -1
- package/build/components/group_conversation_list.js.map +1 -1
- package/build/contexts/conversations_context.d.ts +1 -3
- package/build/contexts/conversations_context.d.ts.map +1 -1
- package/build/contexts/conversations_context.js +27 -32
- package/build/contexts/conversations_context.js.map +1 -1
- package/build/hooks/use_conversation.d.ts.map +1 -1
- package/build/hooks/use_conversation.js +1 -1
- package/build/hooks/use_conversation.js.map +1 -1
- package/build/hooks/use_features.d.ts +0 -1
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -2
- package/build/hooks/use_features.js.map +1 -1
- package/build/navigation/index.d.ts +0 -5
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +0 -5
- package/build/navigation/index.js.map +1 -1
- package/build/screens/conversation_details_screen.d.ts.map +1 -1
- package/build/screens/conversation_details_screen.js +394 -460
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversations/conversations_screen.d.ts.map +1 -1
- package/build/screens/conversations/conversations_screen.js +10 -18
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/index.d.ts +0 -1
- package/build/screens/index.d.ts.map +1 -1
- package/build/screens/index.js +0 -1
- package/build/screens/index.js.map +1 -1
- package/build/types/resources/conversation_membership.d.ts +0 -1
- package/build/types/resources/conversation_membership.d.ts.map +1 -1
- package/build/types/resources/conversation_membership.js.map +1 -1
- package/package.json +3 -3
- package/src/components/conversations/__tests__/conversation_actions.test.tsx +2 -76
- package/src/components/conversations/conversation_actions.tsx +4 -68
- package/src/components/group_conversation_list.tsx +1 -4
- package/src/contexts/conversations_context.tsx +1 -6
- package/src/hooks/use_conversation.ts +0 -1
- package/src/hooks/use_features.ts +0 -1
- package/src/navigation/index.tsx +0 -8
- package/src/screens/__tests__/conversation_details_screen.test.tsx +1 -49
- package/src/screens/conversation_details_screen.tsx +0 -19
- package/src/screens/conversations/__tests__/conversations_screen.test.tsx +0 -1
- package/src/screens/conversations/conversations_screen.tsx +0 -2
- package/src/screens/index.ts +0 -1
- package/src/types/resources/conversation_membership.ts +0 -1
- package/build/components/display/toast.d.ts +0 -3
- package/build/components/display/toast.d.ts.map +0 -1
- package/build/components/display/toast.js +0 -224
- package/build/components/display/toast.js.map +0 -1
- package/build/hooks/use_hide_conversation.d.ts +0 -107
- package/build/hooks/use_hide_conversation.d.ts.map +0 -1
- package/build/hooks/use_hide_conversation.js +0 -238
- package/build/hooks/use_hide_conversation.js.map +0 -1
- package/build/hooks/use_hide_conversations_enabled.d.ts +0 -2
- package/build/hooks/use_hide_conversations_enabled.d.ts.map +0 -1
- package/build/hooks/use_hide_conversations_enabled.js +0 -18
- package/build/hooks/use_hide_conversations_enabled.js.map +0 -1
- package/build/screens/conversation_actions_screen.d.ts +0 -7
- package/build/screens/conversation_actions_screen.d.ts.map +0 -1
- package/build/screens/conversation_actions_screen.js +0 -89
- package/build/screens/conversation_actions_screen.js.map +0 -1
- package/build/utils/toast_store.d.ts +0 -21
- package/build/utils/toast_store.d.ts.map +0 -1
- package/build/utils/toast_store.js +0 -27
- package/build/utils/toast_store.js.map +0 -1
- package/src/components/display/__tests__/toast.test.tsx +0 -55
- package/src/components/display/toast.tsx +0 -115
- package/src/hooks/__tests__/use_hide_conversation.test.tsx +0 -147
- package/src/hooks/use_hide_conversation.ts +0 -118
- package/src/hooks/use_hide_conversations_enabled.ts +0 -7
- package/src/screens/__tests__/conversation_actions_screen.test.tsx +0 -79
- package/src/screens/conversation_actions_screen.tsx +0 -53
- package/src/utils/toast_store.ts +0 -45
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import { useNavigation } from '@react-navigation/native';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { StyleSheet } from 'react-native';
|
|
5
|
-
import FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet';
|
|
6
|
-
import { useConversation } from '../hooks/use_conversation';
|
|
7
|
-
import { useHideConversation } from '../hooks/use_hide_conversation';
|
|
8
|
-
import { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled';
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
export const ConversationActionsScreenOptions = getFormSheetScreenOptions({
|
|
11
|
-
headerTitle: 'Conversation actions'
|
|
12
|
-
});
|
|
13
|
-
export function ConversationActionsScreen(t0) {
|
|
14
|
-
const $ = _c(14);
|
|
15
|
-
const {
|
|
16
|
-
route
|
|
17
|
-
} = t0;
|
|
18
|
-
const navigation = useNavigation();
|
|
19
|
-
const styles = useStyles();
|
|
20
|
-
const {
|
|
21
|
-
data: conversation
|
|
22
|
-
} = useConversation(route.params);
|
|
23
|
-
let t1;
|
|
24
|
-
if ($[0] !== conversation) {
|
|
25
|
-
t1 = {
|
|
26
|
-
conversation
|
|
27
|
-
};
|
|
28
|
-
$[0] = conversation;
|
|
29
|
-
$[1] = t1;
|
|
30
|
-
} else {
|
|
31
|
-
t1 = $[1];
|
|
32
|
-
}
|
|
33
|
-
const {
|
|
34
|
-
hidden,
|
|
35
|
-
setHidden,
|
|
36
|
-
isPending
|
|
37
|
-
} = useHideConversation(t1);
|
|
38
|
-
const hideConversationsEnabled = useHideConversationsEnabled();
|
|
39
|
-
let t2;
|
|
40
|
-
if ($[2] !== hidden || $[3] !== navigation || $[4] !== setHidden) {
|
|
41
|
-
t2 = () => {
|
|
42
|
-
setHidden(!hidden);
|
|
43
|
-
navigation.goBack();
|
|
44
|
-
};
|
|
45
|
-
$[2] = hidden;
|
|
46
|
-
$[3] = navigation;
|
|
47
|
-
$[4] = setHidden;
|
|
48
|
-
$[5] = t2;
|
|
49
|
-
} else {
|
|
50
|
-
t2 = $[5];
|
|
51
|
-
}
|
|
52
|
-
const handleHidePress = t2;
|
|
53
|
-
let t3;
|
|
54
|
-
if ($[6] !== handleHidePress || $[7] !== hidden || $[8] !== hideConversationsEnabled || $[9] !== isPending) {
|
|
55
|
-
t3 = hideConversationsEnabled && /*#__PURE__*/_jsx(FormSheet.Action, {
|
|
56
|
-
onPress: handleHidePress,
|
|
57
|
-
title: hidden ? "Unhide conversation" : "Hide conversation",
|
|
58
|
-
iconName: hidden ? "general.showEye" : "general.hideEye",
|
|
59
|
-
disabled: isPending,
|
|
60
|
-
accessibilityHint: hidden ? "Shows this conversation in your conversation list again." : "Hides this conversation from your conversation list."
|
|
61
|
-
});
|
|
62
|
-
$[6] = handleHidePress;
|
|
63
|
-
$[7] = hidden;
|
|
64
|
-
$[8] = hideConversationsEnabled;
|
|
65
|
-
$[9] = isPending;
|
|
66
|
-
$[10] = t3;
|
|
67
|
-
} else {
|
|
68
|
-
t3 = $[10];
|
|
69
|
-
}
|
|
70
|
-
let t4;
|
|
71
|
-
if ($[11] !== styles.formSheetContent || $[12] !== t3) {
|
|
72
|
-
t4 = /*#__PURE__*/_jsx(FormSheet.Root, {
|
|
73
|
-
style: styles.formSheetContent,
|
|
74
|
-
children: t3
|
|
75
|
-
});
|
|
76
|
-
$[11] = styles.formSheetContent;
|
|
77
|
-
$[12] = t3;
|
|
78
|
-
$[13] = t4;
|
|
79
|
-
} else {
|
|
80
|
-
t4 = $[13];
|
|
81
|
-
}
|
|
82
|
-
return t4;
|
|
83
|
-
}
|
|
84
|
-
const useStyles = () => StyleSheet.create({
|
|
85
|
-
formSheetContent: {
|
|
86
|
-
paddingTop: 16
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
//# sourceMappingURL=conversation_actions_screen.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversation_actions_screen.js","names":["useNavigation","React","StyleSheet","FormSheet","getFormSheetScreenOptions","useConversation","useHideConversation","useHideConversationsEnabled","jsx","_jsx","ConversationActionsScreenOptions","headerTitle","ConversationActionsScreen","t0","$","_c","route","navigation","styles","useStyles","data","conversation","params","t1","hidden","setHidden","isPending","hideConversationsEnabled","t2","goBack","handleHidePress","t3","Action","title","iconName","accessibilityHint","t4","formSheetContent","Root","style","children","create","paddingTop"],"sources":["../../src/screens/conversation_actions_screen.tsx"],"sourcesContent":["import { StaticScreenProps, useNavigation } from '@react-navigation/native'\nimport React from 'react'\nimport { StyleSheet } from 'react-native'\nimport FormSheet, { getFormSheetScreenOptions } from '../components/primitive/form_sheet'\nimport { useConversation } from '../hooks/use_conversation'\nimport { useHideConversation } from '../hooks/use_hide_conversation'\nimport { useHideConversationsEnabled } from '../hooks/use_hide_conversations_enabled'\n\nexport const ConversationActionsScreenOptions = getFormSheetScreenOptions({\n headerTitle: 'Conversation actions',\n})\n\nexport type ConversationActionsScreenProps = StaticScreenProps<{\n conversation_id: number\n}>\n\nexport function ConversationActionsScreen({ route }: ConversationActionsScreenProps) {\n const navigation = useNavigation()\n const styles = useStyles()\n const { data: conversation } = useConversation(route.params)\n const { hidden, setHidden, isPending } = useHideConversation({ conversation })\n const hideConversationsEnabled = useHideConversationsEnabled()\n\n const handleHidePress = () => {\n setHidden(!hidden)\n navigation.goBack()\n }\n\n return (\n <FormSheet.Root style={styles.formSheetContent}>\n {hideConversationsEnabled && (\n <FormSheet.Action\n onPress={handleHidePress}\n title={hidden ? 'Unhide conversation' : 'Hide conversation'}\n iconName={hidden ? 'general.showEye' : 'general.hideEye'}\n disabled={isPending}\n accessibilityHint={\n hidden\n ? 'Shows this conversation in your conversation list again.'\n : 'Hides this conversation from your conversation list.'\n }\n />\n )}\n </FormSheet.Root>\n )\n}\n\nconst useStyles = () =>\n StyleSheet.create({\n formSheetContent: {\n paddingTop: 16,\n },\n })\n"],"mappings":";AAAA,SAA4BA,aAAa,QAAQ,0BAA0B;AAC3E,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,cAAc;AACzC,OAAOC,SAAS,IAAIC,yBAAyB,QAAQ,oCAAoC;AACzF,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,mBAAmB,QAAQ,gCAAgC;AACpE,SAASC,2BAA2B,QAAQ,yCAAyC;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAErF,OAAO,MAAMC,gCAAgC,GAAGN,yBAAyB,CAAC;EACxEO,WAAW,EAAE;AACf,CAAC,CAAC;AAMF,OAAO,SAAAC,0BAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAAmC;IAAAC;EAAA,IAAAH,EAAyC;EACjF,MAAAI,UAAA,GAAmBjB,aAAa,CAAC,CAAC;EAClC,MAAAkB,MAAA,GAAeC,SAAS,CAAC,CAAC;EAC1B;IAAAC,IAAA,EAAAC;EAAA,IAA+BhB,eAAe,CAACW,KAAK,CAAAM,MAAO,CAAC;EAAA,IAAAC,EAAA;EAAA,IAAAT,CAAA,QAAAO,YAAA;IACCE,EAAA;MAAAF;IAAe,CAAC;IAAAP,CAAA,MAAAO,YAAA;IAAAP,CAAA,MAAAS,EAAA;EAAA;IAAAA,EAAA,GAAAT,CAAA;EAAA;EAA7E;IAAAU,MAAA;IAAAC,SAAA;IAAAC;EAAA,IAAyCpB,mBAAmB,CAACiB,EAAgB,CAAC;EAC9E,MAAAI,wBAAA,GAAiCpB,2BAA2B,CAAC,CAAC;EAAA,IAAAqB,EAAA;EAAA,IAAAd,CAAA,QAAAU,MAAA,IAAAV,CAAA,QAAAG,UAAA,IAAAH,CAAA,QAAAW,SAAA;IAEtCG,EAAA,GAAAA,CAAA;MACtBH,SAAS,CAAC,CAACD,MAAM,CAAC;MAClBP,UAAU,CAAAY,MAAO,CAAC,CAAC;IAAA,CACpB;IAAAf,CAAA,MAAAU,MAAA;IAAAV,CAAA,MAAAG,UAAA;IAAAH,CAAA,MAAAW,SAAA;IAAAX,CAAA,MAAAc,EAAA;EAAA;IAAAA,EAAA,GAAAd,CAAA;EAAA;EAHD,MAAAgB,eAAA,GAAwBF,EAGvB;EAAA,IAAAG,EAAA;EAAA,IAAAjB,CAAA,QAAAgB,eAAA,IAAAhB,CAAA,QAAAU,MAAA,IAAAV,CAAA,QAAAa,wBAAA,IAAAb,CAAA,QAAAY,SAAA;IAIIK,EAAA,GAAAJ,wBAYA,iBAZAlB,IAAA,CAAAN,SAAA,CAAA6B,MAAA;MAEYF,OAAe,EAAfA,eAAe;MACjBG,KAAoD,EAApDT,MAAM,GAAN,qBAAoD,GAApD,mBAAoD;MACjDU,QAA8C,EAA9CV,MAAM,GAAN,iBAA8C,GAA9C,iBAA8C;MAC9CE,QAAS,EAATA,SAAS;MAEjBS,iBAE0D,EAF1DX,MAAM,GAAN,0DAE0D,GAF1D;IAE0D,CAGhE,CAAC;IAAAV,CAAA,MAAAgB,eAAA;IAAAhB,CAAA,MAAAU,MAAA;IAAAV,CAAA,MAAAa,wBAAA;IAAAb,CAAA,MAAAY,SAAA;IAAAZ,CAAA,OAAAiB,EAAA;EAAA;IAAAA,EAAA,GAAAjB,CAAA;EAAA;EAAA,IAAAsB,EAAA;EAAA,IAAAtB,CAAA,SAAAI,MAAA,CAAAmB,gBAAA,IAAAvB,CAAA,SAAAiB,EAAA;IAbHK,EAAA,gBAAA3B,IAAA,CAAAN,SAAA,CAAAmC,IAAA;MAAuBC,KAAuB,EAAvBrB,MAAM,CAAAmB,gBAAiB;MAAAG,QAAA,EAC3CT;IAYA,CACa,CAAC;IAAAjB,CAAA,OAAAI,MAAA,CAAAmB,gBAAA;IAAAvB,CAAA,OAAAiB,EAAA;IAAAjB,CAAA,OAAAsB,EAAA;EAAA;IAAAA,EAAA,GAAAtB,CAAA;EAAA;EAAA,OAdjBsB,EAciB;AAAA;AAIrB,MAAMjB,SAAS,GAAGA,CAAA,KAChBjB,UAAU,CAACuC,MAAM,CAAC;EAChBJ,gBAAgB,EAAE;IAChBK,UAAU,EAAE;EACd;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface ToastAction {
|
|
2
|
-
label: string;
|
|
3
|
-
onPress: () => void;
|
|
4
|
-
}
|
|
5
|
-
export interface ToastOptions {
|
|
6
|
-
title: string;
|
|
7
|
-
subtitle?: string;
|
|
8
|
-
action?: ToastAction;
|
|
9
|
-
}
|
|
10
|
-
export interface ToastState extends ToastOptions {
|
|
11
|
-
id: number;
|
|
12
|
-
}
|
|
13
|
-
type Listener = () => void;
|
|
14
|
-
export declare const toastStore: {
|
|
15
|
-
getSnapshot: () => ToastState | null;
|
|
16
|
-
subscribe: (listener: Listener) => () => void;
|
|
17
|
-
};
|
|
18
|
-
export declare function showToast(options: ToastOptions): void;
|
|
19
|
-
export declare function dismissToast(id?: number): void;
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=toast_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toast_store.d.ts","sourceRoot":"","sources":["../../src/utils/toast_store.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,UAAW,SAAQ,YAAY;IAC9C,EAAE,EAAE,MAAM,CAAA;CACX;AAED,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAA;AAQ1B,eAAO,MAAM,UAAU;;0BAEC,QAAQ;CAM/B,CAAA;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,QAG9C;AAED,wBAAgB,YAAY,CAAC,EAAE,CAAC,EAAE,MAAM,QAMvC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
let currentToast = null;
|
|
2
|
-
let nextId = 1;
|
|
3
|
-
const listeners = new Set();
|
|
4
|
-
const emit = () => listeners.forEach(listener => listener());
|
|
5
|
-
export const toastStore = {
|
|
6
|
-
getSnapshot: () => currentToast,
|
|
7
|
-
subscribe: listener => {
|
|
8
|
-
listeners.add(listener);
|
|
9
|
-
return () => {
|
|
10
|
-
listeners.delete(listener);
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export function showToast(options) {
|
|
15
|
-
currentToast = {
|
|
16
|
-
...options,
|
|
17
|
-
id: nextId++
|
|
18
|
-
};
|
|
19
|
-
emit();
|
|
20
|
-
}
|
|
21
|
-
export function dismissToast(id) {
|
|
22
|
-
if (!currentToast) return;
|
|
23
|
-
if (id !== undefined && currentToast.id !== id) return;
|
|
24
|
-
currentToast = null;
|
|
25
|
-
emit();
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=toast_store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toast_store.js","names":["currentToast","nextId","listeners","Set","emit","forEach","listener","toastStore","getSnapshot","subscribe","add","delete","showToast","options","id","dismissToast","undefined"],"sources":["../../src/utils/toast_store.ts"],"sourcesContent":["export interface ToastAction {\n label: string\n onPress: () => void\n}\n\nexport interface ToastOptions {\n title: string\n subtitle?: string\n action?: ToastAction\n}\n\nexport interface ToastState extends ToastOptions {\n id: number\n}\n\ntype Listener = () => void\n\nlet currentToast: ToastState | null = null\nlet nextId = 1\nconst listeners = new Set<Listener>()\n\nconst emit = () => listeners.forEach(listener => listener())\n\nexport const toastStore = {\n getSnapshot: () => currentToast,\n subscribe: (listener: Listener) => {\n listeners.add(listener)\n return () => {\n listeners.delete(listener)\n }\n },\n}\n\nexport function showToast(options: ToastOptions) {\n currentToast = { ...options, id: nextId++ }\n emit()\n}\n\nexport function dismissToast(id?: number) {\n if (!currentToast) return\n if (id !== undefined && currentToast.id !== id) return\n\n currentToast = null\n emit()\n}\n"],"mappings":"AAiBA,IAAIA,YAA+B,GAAG,IAAI;AAC1C,IAAIC,MAAM,GAAG,CAAC;AACd,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;AAErC,MAAMC,IAAI,GAAGA,CAAA,KAAMF,SAAS,CAACG,OAAO,CAACC,QAAQ,IAAIA,QAAQ,CAAC,CAAC,CAAC;AAE5D,OAAO,MAAMC,UAAU,GAAG;EACxBC,WAAW,EAAEA,CAAA,KAAMR,YAAY;EAC/BS,SAAS,EAAGH,QAAkB,IAAK;IACjCJ,SAAS,CAACQ,GAAG,CAACJ,QAAQ,CAAC;IACvB,OAAO,MAAM;MACXJ,SAAS,CAACS,MAAM,CAACL,QAAQ,CAAC;IAC5B,CAAC;EACH;AACF,CAAC;AAED,OAAO,SAASM,SAASA,CAACC,OAAqB,EAAE;EAC/Cb,YAAY,GAAG;IAAE,GAAGa,OAAO;IAAEC,EAAE,EAAEb,MAAM;EAAG,CAAC;EAC3CG,IAAI,CAAC,CAAC;AACR;AAEA,OAAO,SAASW,YAAYA,CAACD,EAAW,EAAE;EACxC,IAAI,CAACd,YAAY,EAAE;EACnB,IAAIc,EAAE,KAAKE,SAAS,IAAIhB,YAAY,CAACc,EAAE,KAAKA,EAAE,EAAE;EAEhDd,YAAY,GAAG,IAAI;EACnBI,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { act, fireEvent, render } from '@testing-library/react-native'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
4
|
-
import { dismissToast, showToast } from '../../../utils/toast_store'
|
|
5
|
-
import { Toast, TOAST_DURATION_MS } from '../toast'
|
|
6
|
-
|
|
7
|
-
const safeAreaMetrics = {
|
|
8
|
-
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
9
|
-
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const renderToast = () =>
|
|
13
|
-
render(
|
|
14
|
-
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
15
|
-
<Toast />
|
|
16
|
-
</SafeAreaProvider>
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
describe('Toast', () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.useFakeTimers()
|
|
22
|
-
dismissToast()
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
jest.useRealTimers()
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('runs the action and dismisses when the action is pressed', () => {
|
|
30
|
-
const onUndo = jest.fn()
|
|
31
|
-
const view = renderToast()
|
|
32
|
-
act(() =>
|
|
33
|
-
showToast({
|
|
34
|
-
title: 'Conversation hidden',
|
|
35
|
-
subtitle: 'Subtitle',
|
|
36
|
-
action: { label: 'Undo', onPress: onUndo },
|
|
37
|
-
})
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
expect(view.getByText('Subtitle')).toBeTruthy()
|
|
41
|
-
fireEvent.press(view.getByText('Undo'))
|
|
42
|
-
|
|
43
|
-
expect(onUndo).toHaveBeenCalledTimes(1)
|
|
44
|
-
expect(view.queryByText('Conversation hidden')).toBeNull()
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('dismisses itself after a delay', () => {
|
|
48
|
-
const view = renderToast()
|
|
49
|
-
act(() => showToast({ title: 'Conversation hidden' }))
|
|
50
|
-
|
|
51
|
-
act(() => jest.advanceTimersByTime(TOAST_DURATION_MS))
|
|
52
|
-
|
|
53
|
-
expect(view.queryByText('Conversation hidden')).toBeNull()
|
|
54
|
-
})
|
|
55
|
-
})
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useSyncExternalStore } from 'react'
|
|
2
|
-
import { AccessibilityInfo, StyleSheet, View } from 'react-native'
|
|
3
|
-
import Animated, { FadeInDown, FadeOutDown, ReduceMotion } from 'react-native-reanimated'
|
|
4
|
-
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
5
|
-
import { useReduceMotion, useTheme } from '../../hooks'
|
|
6
|
-
import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../utils/styles'
|
|
7
|
-
import { dismissToast, toastStore } from '../../utils/toast_store'
|
|
8
|
-
import { Text } from './text'
|
|
9
|
-
import { TextButton } from './text_button'
|
|
10
|
-
|
|
11
|
-
export const TOAST_DURATION_MS = 5000
|
|
12
|
-
|
|
13
|
-
export function Toast() {
|
|
14
|
-
const toast = useSyncExternalStore(toastStore.subscribe, toastStore.getSnapshot)
|
|
15
|
-
const styles = useStyles()
|
|
16
|
-
const reduceMotion = useReduceMotion() ? ReduceMotion.Always : ReduceMotion.Never
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
if (!toast) return
|
|
20
|
-
|
|
21
|
-
AccessibilityInfo.announceForAccessibility(
|
|
22
|
-
[toast.title, toast.subtitle].filter(Boolean).join('. ')
|
|
23
|
-
)
|
|
24
|
-
const timeout = setTimeout(() => dismissToast(toast.id), TOAST_DURATION_MS)
|
|
25
|
-
return () => clearTimeout(timeout)
|
|
26
|
-
}, [toast])
|
|
27
|
-
|
|
28
|
-
useEffect(() => () => dismissToast(), [])
|
|
29
|
-
|
|
30
|
-
if (!toast) return null
|
|
31
|
-
|
|
32
|
-
const { id, title, subtitle, action } = toast
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<View style={styles.container} pointerEvents="box-none">
|
|
36
|
-
<Animated.View
|
|
37
|
-
key={id}
|
|
38
|
-
entering={FadeInDown.duration(200).reduceMotion(reduceMotion)}
|
|
39
|
-
exiting={FadeOutDown.duration(200).reduceMotion(reduceMotion)}
|
|
40
|
-
style={styles.toast}
|
|
41
|
-
accessibilityLiveRegion="polite"
|
|
42
|
-
testID="toast"
|
|
43
|
-
>
|
|
44
|
-
<View style={styles.content}>
|
|
45
|
-
<Text
|
|
46
|
-
style={styles.title}
|
|
47
|
-
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
48
|
-
accessibilityRole="alert"
|
|
49
|
-
>
|
|
50
|
-
{title}
|
|
51
|
-
</Text>
|
|
52
|
-
{Boolean(subtitle) && (
|
|
53
|
-
<Text
|
|
54
|
-
variant="footnote"
|
|
55
|
-
style={styles.subtitle}
|
|
56
|
-
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
57
|
-
>
|
|
58
|
-
{subtitle}
|
|
59
|
-
</Text>
|
|
60
|
-
)}
|
|
61
|
-
</View>
|
|
62
|
-
{action && (
|
|
63
|
-
<TextButton
|
|
64
|
-
textStyle={styles.actionText}
|
|
65
|
-
maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}
|
|
66
|
-
onPress={() => {
|
|
67
|
-
dismissToast(id)
|
|
68
|
-
action.onPress()
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
{action.label}
|
|
72
|
-
</TextButton>
|
|
73
|
-
)}
|
|
74
|
-
</Animated.View>
|
|
75
|
-
</View>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const useStyles = () => {
|
|
80
|
-
const { colors } = useTheme()
|
|
81
|
-
const { bottom } = useSafeAreaInsets()
|
|
82
|
-
|
|
83
|
-
return StyleSheet.create({
|
|
84
|
-
container: {
|
|
85
|
-
position: 'absolute',
|
|
86
|
-
left: 0,
|
|
87
|
-
right: 0,
|
|
88
|
-
bottom: bottom + 16,
|
|
89
|
-
paddingHorizontal: 16,
|
|
90
|
-
},
|
|
91
|
-
toast: {
|
|
92
|
-
flexDirection: 'row',
|
|
93
|
-
alignItems: 'center',
|
|
94
|
-
gap: 16,
|
|
95
|
-
paddingVertical: 12,
|
|
96
|
-
paddingHorizontal: 16,
|
|
97
|
-
borderRadius: 8,
|
|
98
|
-
backgroundColor: colors.fillColorNeutral010,
|
|
99
|
-
},
|
|
100
|
-
content: {
|
|
101
|
-
flex: 1,
|
|
102
|
-
gap: 2,
|
|
103
|
-
},
|
|
104
|
-
title: {
|
|
105
|
-
color: colors.fillColorNeutral100Inverted,
|
|
106
|
-
fontWeight: '600',
|
|
107
|
-
},
|
|
108
|
-
subtitle: {
|
|
109
|
-
color: colors.fillColorNeutral070,
|
|
110
|
-
},
|
|
111
|
-
actionText: {
|
|
112
|
-
color: colors.fillColorNeutral100Inverted,
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
-
import { act, renderHook } from '@testing-library/react-native'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { Alert } from 'react-native'
|
|
5
|
-
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
6
|
-
import type { ConversationResource } from '../../types'
|
|
7
|
-
import { getConversationsRequestArgs } from '../../utils/request/conversation'
|
|
8
|
-
import { dismissToast, toastStore } from '../../utils/toast_store'
|
|
9
|
-
import { getConversationRequestArgs } from '../use_conversation'
|
|
10
|
-
import {
|
|
11
|
-
HIDDEN_AND_SILENCED_TOAST_SUBTITLE,
|
|
12
|
-
HIDDEN_TOAST_SUBTITLE,
|
|
13
|
-
useHideConversation,
|
|
14
|
-
} from '../use_hide_conversation'
|
|
15
|
-
import { getRequestQueryKey } from '../use_suspense_api'
|
|
16
|
-
|
|
17
|
-
const mockPatch = jest.fn()
|
|
18
|
-
jest.mock('../use_api_client', () => ({
|
|
19
|
-
useApiClient: () => ({ chat: { patch: mockPatch } }),
|
|
20
|
-
}))
|
|
21
|
-
|
|
22
|
-
const conversation = { id: 7, muted: false } as ConversationResource
|
|
23
|
-
const otherConversation = { id: 8, muted: false } as ConversationResource
|
|
24
|
-
const conversationKey = getRequestQueryKey(getConversationRequestArgs({ conversation_id: 7 }))
|
|
25
|
-
const allKey = getRequestQueryKey(getConversationsRequestArgs({ gids: 'all' }))
|
|
26
|
-
const unreadKey = getRequestQueryKey(
|
|
27
|
-
getConversationsRequestArgs({ gids: 'all', show_unread: true })
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const listData = (conversations: ConversationResource[]) => ({
|
|
31
|
-
pages: [{ data: conversations, links: {}, meta: { count: conversations.length } }],
|
|
32
|
-
pageParams: [{}],
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const listIds = (queryKey: unknown[]) =>
|
|
36
|
-
(
|
|
37
|
-
queryClient.getQueryData(queryKey) as ReturnType<typeof listData> | undefined
|
|
38
|
-
)?.pages[0].data.map(({ id }) => id)
|
|
39
|
-
|
|
40
|
-
const buildQueryClient = () =>
|
|
41
|
-
buildTestQueryClient({ defaultOptions: { queries: { gcTime: Infinity } } })
|
|
42
|
-
|
|
43
|
-
let queryClient = buildQueryClient()
|
|
44
|
-
|
|
45
|
-
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
46
|
-
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
const renderHide = (target: ConversationResource = conversation) =>
|
|
50
|
-
renderHook(() => useHideConversation({ conversation: target }), { wrapper })
|
|
51
|
-
|
|
52
|
-
describe('useHideConversation', () => {
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
queryClient = buildQueryClient()
|
|
55
|
-
queryClient.setQueryData(allKey, listData([conversation, otherConversation]))
|
|
56
|
-
queryClient.setQueryData(unreadKey, listData([conversation]))
|
|
57
|
-
queryClient.setQueryData(conversationKey, {
|
|
58
|
-
data: { id: 7, conversationMembership: { muted: false } },
|
|
59
|
-
})
|
|
60
|
-
mockPatch.mockReset()
|
|
61
|
-
dismissToast()
|
|
62
|
-
jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
afterEach(() => {
|
|
66
|
-
jest.restoreAllMocks()
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('removes the conversation from every list before the request resolves', async () => {
|
|
70
|
-
mockPatch.mockReturnValue(new Promise(() => {}))
|
|
71
|
-
const { result } = renderHide()
|
|
72
|
-
|
|
73
|
-
await act(async () => result.current.setHidden(true))
|
|
74
|
-
|
|
75
|
-
expect(listIds(allKey)).toEqual([8])
|
|
76
|
-
expect(listIds(unreadKey)).toEqual([])
|
|
77
|
-
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
78
|
-
data: { id: 7, conversationMembership: { muted: false, hidden: true } },
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('patches hidden on the membership', async () => {
|
|
83
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
84
|
-
const { result } = renderHide()
|
|
85
|
-
|
|
86
|
-
await act(() => result.current.mutateAsync(true))
|
|
87
|
-
|
|
88
|
-
expect(mockPatch).toHaveBeenCalledWith({
|
|
89
|
-
url: '/me/conversations/7/conversation_membership',
|
|
90
|
-
data: {
|
|
91
|
-
data: { type: 'ConversationMembership', attributes: { hidden: true } },
|
|
92
|
-
fields: { ConversationMembership: 'hidden' },
|
|
93
|
-
},
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it.each([
|
|
98
|
-
[false, HIDDEN_TOAST_SUBTITLE],
|
|
99
|
-
[true, HIDDEN_AND_SILENCED_TOAST_SUBTITLE],
|
|
100
|
-
])('shows an undo toast for muted=%s', async (muted, subtitle) => {
|
|
101
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
102
|
-
const { result } = renderHide({ ...conversation, muted })
|
|
103
|
-
|
|
104
|
-
await act(() => result.current.mutateAsync(true))
|
|
105
|
-
|
|
106
|
-
expect(toastStore.getSnapshot()).toMatchObject({
|
|
107
|
-
title: 'Conversation hidden',
|
|
108
|
-
subtitle,
|
|
109
|
-
action: { label: 'Undo' },
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('restores the lists and unhides on undo', async () => {
|
|
114
|
-
mockPatch.mockResolvedValue({ data: {} })
|
|
115
|
-
const { result } = renderHide()
|
|
116
|
-
await act(() => result.current.mutateAsync(true))
|
|
117
|
-
|
|
118
|
-
await act(async () => toastStore.getSnapshot()?.action?.onPress())
|
|
119
|
-
|
|
120
|
-
expect(listIds(allKey)).toEqual([7, 8])
|
|
121
|
-
expect(listIds(unreadKey)).toEqual([7])
|
|
122
|
-
expect(mockPatch).toHaveBeenLastCalledWith(
|
|
123
|
-
expect.objectContaining({
|
|
124
|
-
data: expect.objectContaining({
|
|
125
|
-
data: { type: 'ConversationMembership', attributes: { hidden: false } },
|
|
126
|
-
}),
|
|
127
|
-
})
|
|
128
|
-
)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('puts the conversation back and alerts when hiding fails', async () => {
|
|
132
|
-
mockPatch.mockRejectedValue(new Error('nope'))
|
|
133
|
-
const { result } = renderHide()
|
|
134
|
-
|
|
135
|
-
await act(() => result.current.mutateAsync(true).catch(() => {}))
|
|
136
|
-
|
|
137
|
-
expect(listIds(allKey)).toEqual([7, 8])
|
|
138
|
-
expect(queryClient.getQueryData(conversationKey)).toEqual({
|
|
139
|
-
data: { id: 7, conversationMembership: { muted: false, hidden: false } },
|
|
140
|
-
})
|
|
141
|
-
expect(toastStore.getSnapshot()).toBeNull()
|
|
142
|
-
expect(Alert.alert).toHaveBeenCalledWith(
|
|
143
|
-
'Oops',
|
|
144
|
-
"Couldn't hide this conversation. Please try again."
|
|
145
|
-
)
|
|
146
|
-
})
|
|
147
|
-
})
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { InfiniteData, QueryKey, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2
|
-
import { Alert } from 'react-native'
|
|
3
|
-
import {
|
|
4
|
-
ApiCollection,
|
|
5
|
-
ApiResource,
|
|
6
|
-
ConversationMembershipResource,
|
|
7
|
-
ConversationResource,
|
|
8
|
-
} from '../types'
|
|
9
|
-
import { deleteRecordInPagesData } from '../utils/cache/page_mutations'
|
|
10
|
-
import { Haptic } from '../utils/native_adapters'
|
|
11
|
-
import { getConversationsRequestArgs } from '../utils/request/conversation'
|
|
12
|
-
import { showToast } from '../utils/toast_store'
|
|
13
|
-
import { useApiClient } from './use_api_client'
|
|
14
|
-
import { getConversationRequestArgs } from './use_conversation'
|
|
15
|
-
import { getRequestQueryKey } from './use_suspense_api'
|
|
16
|
-
|
|
17
|
-
type ConversationsData = InfiniteData<ApiCollection<ConversationResource>>
|
|
18
|
-
type ListsSnapshot = Array<[QueryKey, ConversationsData | undefined]>
|
|
19
|
-
|
|
20
|
-
export const HIDDEN_TOAST_TITLE = 'Conversation hidden'
|
|
21
|
-
export const HIDDEN_TOAST_SUBTITLE = "It'll come back if someone sends a new message."
|
|
22
|
-
export const HIDDEN_AND_SILENCED_TOAST_SUBTITLE =
|
|
23
|
-
"It's silenced too, so it stays hidden until you unhide it."
|
|
24
|
-
|
|
25
|
-
export const useHideConversation = ({ conversation }: { conversation: ConversationResource }) => {
|
|
26
|
-
const apiClient = useApiClient()
|
|
27
|
-
const queryClient = useQueryClient()
|
|
28
|
-
const listsQueryKey = [getConversationsRequestArgs().url]
|
|
29
|
-
const conversationQueryKey = getRequestQueryKey(
|
|
30
|
-
getConversationRequestArgs({ conversation_id: conversation.id })
|
|
31
|
-
)
|
|
32
|
-
const hidden = !!conversation.conversationMembership?.hidden
|
|
33
|
-
|
|
34
|
-
const setMembershipHidden = (value: boolean) =>
|
|
35
|
-
queryClient.setQueryData<ApiResource<ConversationResource>>(conversationQueryKey, prev => {
|
|
36
|
-
if (!prev?.data) return prev
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
...prev,
|
|
40
|
-
data: {
|
|
41
|
-
...prev.data,
|
|
42
|
-
conversationMembership: { ...prev.data.conversationMembership, hidden: value },
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const removeFromLists = () =>
|
|
48
|
-
queryClient.setQueriesData<ConversationsData>({ queryKey: listsQueryKey }, prev => {
|
|
49
|
-
if (!prev?.pages) return prev
|
|
50
|
-
|
|
51
|
-
return deleteRecordInPagesData({ data: prev, record: { id: conversation.id } })
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
const restoreLists = (lists: ListsSnapshot) => {
|
|
55
|
-
lists.forEach(([queryKey, data]) => {
|
|
56
|
-
queryClient.setQueryData<ConversationsData>(queryKey, data)
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const { mutate: setHidden, ...mutation } = useMutation({
|
|
61
|
-
mutationKey: ['hideConversation', conversation.id],
|
|
62
|
-
scope: { id: `hideConversation-${conversation.id}` },
|
|
63
|
-
onMutate: async (value: boolean) => {
|
|
64
|
-
await queryClient.cancelQueries({ queryKey: listsQueryKey })
|
|
65
|
-
const previousLists = queryClient.getQueriesData<ConversationsData>({
|
|
66
|
-
queryKey: listsQueryKey,
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (value) removeFromLists()
|
|
70
|
-
setMembershipHidden(value)
|
|
71
|
-
|
|
72
|
-
return { previousLists }
|
|
73
|
-
},
|
|
74
|
-
mutationFn: (value: boolean) =>
|
|
75
|
-
apiClient.chat.patch<ApiResource<ConversationMembershipResource>>({
|
|
76
|
-
url: `/me/conversations/${conversation.id}/conversation_membership`,
|
|
77
|
-
data: {
|
|
78
|
-
data: { type: 'ConversationMembership', attributes: { hidden: value } },
|
|
79
|
-
fields: { ConversationMembership: 'hidden' },
|
|
80
|
-
},
|
|
81
|
-
}),
|
|
82
|
-
onSuccess: (_response, value, { previousLists }) => {
|
|
83
|
-
Haptic.notificationSuccess()
|
|
84
|
-
|
|
85
|
-
if (!value) {
|
|
86
|
-
queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
showToast({
|
|
91
|
-
title: HIDDEN_TOAST_TITLE,
|
|
92
|
-
subtitle: conversation.muted ? HIDDEN_AND_SILENCED_TOAST_SUBTITLE : HIDDEN_TOAST_SUBTITLE,
|
|
93
|
-
action: {
|
|
94
|
-
label: 'Undo',
|
|
95
|
-
onPress: () => {
|
|
96
|
-
restoreLists(previousLists)
|
|
97
|
-
setHidden(false)
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
},
|
|
102
|
-
onError: (_error, value, context) => {
|
|
103
|
-
if (!value) queryClient.invalidateQueries({ queryKey: listsQueryKey })
|
|
104
|
-
else if (context) restoreLists(context.previousLists)
|
|
105
|
-
setMembershipHidden(!value)
|
|
106
|
-
Alert.alert(
|
|
107
|
-
'Oops',
|
|
108
|
-
`Couldn't ${value ? 'hide' : 'unhide'} this conversation. Please try again.`
|
|
109
|
-
)
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
hidden,
|
|
115
|
-
setHidden,
|
|
116
|
-
...mutation,
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { DefaultTheme, ThemeProvider } from '@react-navigation/native'
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react-native'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
5
|
-
import type { ConversationResource } from '../../types'
|
|
6
|
-
import { ConversationActionsScreen } from '../conversation_actions_screen'
|
|
7
|
-
|
|
8
|
-
const mockNavigation = { goBack: jest.fn() }
|
|
9
|
-
jest.mock('@react-navigation/native', () => ({
|
|
10
|
-
...jest.requireActual('@react-navigation/native'),
|
|
11
|
-
useNavigation: () => mockNavigation,
|
|
12
|
-
}))
|
|
13
|
-
jest.mock('@react-navigation/elements', () => ({
|
|
14
|
-
...jest.requireActual('@react-navigation/elements'),
|
|
15
|
-
useHeaderHeight: () => 0,
|
|
16
|
-
}))
|
|
17
|
-
|
|
18
|
-
const conversation = { type: 'Conversation', id: 7, title: 'Youth Group' } as ConversationResource
|
|
19
|
-
jest.mock('../../hooks/use_conversation', () => ({
|
|
20
|
-
useConversation: () => ({ data: conversation }),
|
|
21
|
-
}))
|
|
22
|
-
|
|
23
|
-
let mockHidden = false
|
|
24
|
-
const mockSetHidden = jest.fn()
|
|
25
|
-
jest.mock('../../hooks/use_hide_conversation', () => ({
|
|
26
|
-
useHideConversation: () => ({ hidden: mockHidden, setHidden: mockSetHidden, isPending: false }),
|
|
27
|
-
}))
|
|
28
|
-
|
|
29
|
-
let mockHideEnabled = true
|
|
30
|
-
jest.mock('../../hooks/use_hide_conversations_enabled', () => ({
|
|
31
|
-
useHideConversationsEnabled: () => mockHideEnabled,
|
|
32
|
-
}))
|
|
33
|
-
|
|
34
|
-
const safeAreaMetrics = {
|
|
35
|
-
frame: { x: 0, y: 0, width: 390, height: 844 },
|
|
36
|
-
insets: { top: 0, right: 0, bottom: 0, left: 0 },
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const renderScreen = () =>
|
|
40
|
-
render(
|
|
41
|
-
<SafeAreaProvider initialMetrics={safeAreaMetrics}>
|
|
42
|
-
<ThemeProvider value={DefaultTheme}>
|
|
43
|
-
<ConversationActionsScreen route={{ params: { conversation_id: 7 } }} />
|
|
44
|
-
</ThemeProvider>
|
|
45
|
-
</SafeAreaProvider>
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
describe('ConversationActionsScreen', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
mockHidden = false
|
|
51
|
-
mockHideEnabled = true
|
|
52
|
-
jest.clearAllMocks()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('offers nothing when the flag is off', () => {
|
|
56
|
-
mockHideEnabled = false
|
|
57
|
-
const { queryByText } = renderScreen()
|
|
58
|
-
|
|
59
|
-
expect(queryByText('Hide conversation')).toBeNull()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('hides the conversation and closes the sheet', () => {
|
|
63
|
-
const { getByText } = renderScreen()
|
|
64
|
-
|
|
65
|
-
fireEvent.press(getByText('Hide conversation'))
|
|
66
|
-
|
|
67
|
-
expect(mockSetHidden).toHaveBeenCalledWith(true)
|
|
68
|
-
expect(mockNavigation.goBack).toHaveBeenCalledTimes(1)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('unhides a hidden conversation', () => {
|
|
72
|
-
mockHidden = true
|
|
73
|
-
const { getByText } = renderScreen()
|
|
74
|
-
|
|
75
|
-
fireEvent.press(getByText('Unhide conversation'))
|
|
76
|
-
|
|
77
|
-
expect(mockSetHidden).toHaveBeenCalledWith(false)
|
|
78
|
-
})
|
|
79
|
-
})
|