You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-31 13:44:28 +03:00
Apply prettier formatting
This commit is contained in:
@ -23,13 +23,13 @@ describe("useDebouncedCallback", () => {
|
||||
afterAll(() => jest.useRealTimers());
|
||||
|
||||
function render(enabled: boolean, callback: (...params: any) => void, params: any) {
|
||||
return renderHook(
|
||||
({ enabled, callback, params }) => useDebouncedCallback(enabled, callback, params),
|
||||
{ initialProps: {
|
||||
return renderHook(({ enabled, callback, params }) => useDebouncedCallback(enabled, callback, params), {
|
||||
initialProps: {
|
||||
enabled,
|
||||
callback,
|
||||
params,
|
||||
} });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
it("should be able to handle empty parameters", async () => {
|
||||
|
@ -27,14 +27,12 @@ function LatestResultsComponent({ query, doRequest }) {
|
||||
const [updateQuery, updateResult] = useLatestResult(setValueInternal);
|
||||
useEffect(() => {
|
||||
updateQuery(query);
|
||||
doRequest(query).then(it => {
|
||||
doRequest(query).then((it) => {
|
||||
updateResult(query, it);
|
||||
});
|
||||
}, [doRequest, query, updateQuery, updateResult]);
|
||||
|
||||
return <div>
|
||||
{ value }
|
||||
</div>;
|
||||
return <div>{value}</div>;
|
||||
}
|
||||
|
||||
describe("useLatestResult", () => {
|
||||
|
@ -27,18 +27,14 @@ import { stubClient } from "../test-utils/test-utils";
|
||||
function ProfileInfoComponent({ onClick }) {
|
||||
const profileInfo = useProfileInfo();
|
||||
|
||||
const {
|
||||
ready,
|
||||
loading,
|
||||
profile,
|
||||
} = profileInfo;
|
||||
const { ready, loading, profile } = profileInfo;
|
||||
|
||||
return <div onClick={() => onClick(profileInfo)}>
|
||||
{ (!ready || loading) && `ready: ${ready}, loading: ${loading}` }
|
||||
{ profile && (
|
||||
`Name: ${profile.display_name}`
|
||||
) }
|
||||
</div>;
|
||||
return (
|
||||
<div onClick={() => onClick(profileInfo)}>
|
||||
{(!ready || loading) && `ready: ${ready}, loading: ${loading}`}
|
||||
{profile && `Name: ${profile.display_name}`}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
describe("useProfileInfo", () => {
|
||||
@ -58,12 +54,16 @@ describe("useProfileInfo", () => {
|
||||
it("should display user profile when searching", async () => {
|
||||
const query = "@user:home.server";
|
||||
|
||||
const wrapper = mount(<ProfileInfoComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<ProfileInfoComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
@ -75,12 +75,16 @@ describe("useProfileInfo", () => {
|
||||
});
|
||||
|
||||
it("should work with empty queries", async () => {
|
||||
const wrapper = mount(<ProfileInfoComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query: "",
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<ProfileInfoComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query: "",
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
@ -92,18 +96,19 @@ describe("useProfileInfo", () => {
|
||||
});
|
||||
|
||||
it("should treat invalid mxids as empty queries", async () => {
|
||||
const queries = [
|
||||
"@user",
|
||||
"user@home.server",
|
||||
];
|
||||
const queries = ["@user", "user@home.server"];
|
||||
|
||||
for (const query of queries) {
|
||||
const wrapper = mount(<ProfileInfoComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<ProfileInfoComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
@ -116,15 +121,21 @@ describe("useProfileInfo", () => {
|
||||
});
|
||||
|
||||
it("should recover from a server exception", async () => {
|
||||
cli.getProfileInfo = () => { throw new Error("Oops"); };
|
||||
cli.getProfileInfo = () => {
|
||||
throw new Error("Oops");
|
||||
};
|
||||
const query = "@user:home.server";
|
||||
|
||||
const wrapper = mount(<ProfileInfoComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<ProfileInfoComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
wrapper.simulate("click");
|
||||
@ -138,12 +149,16 @@ describe("useProfileInfo", () => {
|
||||
cli.getProfileInfo = () => null;
|
||||
const query = "@user:home.server";
|
||||
|
||||
const wrapper = mount(<ProfileInfoComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<ProfileInfoComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
wrapper.simulate("click");
|
||||
|
@ -27,18 +27,14 @@ import { stubClient } from "../test-utils/test-utils";
|
||||
function PublicRoomComponent({ onClick }) {
|
||||
const roomDirectory = usePublicRoomDirectory();
|
||||
|
||||
const {
|
||||
ready,
|
||||
loading,
|
||||
publicRooms,
|
||||
} = roomDirectory;
|
||||
const { ready, loading, publicRooms } = roomDirectory;
|
||||
|
||||
return <div onClick={() => onClick(roomDirectory)}>
|
||||
{ (!ready || loading) && `ready: ${ready}, loading: ${loading}` }
|
||||
{ publicRooms[0] && (
|
||||
`Name: ${publicRooms[0].name}`
|
||||
) }
|
||||
</div>;
|
||||
return (
|
||||
<div onClick={() => onClick(roomDirectory)}>
|
||||
{(!ready || loading) && `ready: ${ready}, loading: ${loading}`}
|
||||
{publicRooms[0] && `Name: ${publicRooms[0].name}`}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
describe("usePublicRoomDirectory", () => {
|
||||
@ -50,27 +46,34 @@ describe("usePublicRoomDirectory", () => {
|
||||
|
||||
MatrixClientPeg.getHomeserverName = () => "matrix.org";
|
||||
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
||||
cli.publicRooms = (({ filter: { generic_search_term: query } }) => Promise.resolve({
|
||||
chunk: [{
|
||||
room_id: "hello world!",
|
||||
name: query,
|
||||
world_readable: true,
|
||||
guest_can_join: true,
|
||||
num_joined_members: 1,
|
||||
}],
|
||||
total_room_count_estimate: 1,
|
||||
}));
|
||||
cli.publicRooms = ({ filter: { generic_search_term: query } }) =>
|
||||
Promise.resolve({
|
||||
chunk: [
|
||||
{
|
||||
room_id: "hello world!",
|
||||
name: query,
|
||||
world_readable: true,
|
||||
guest_can_join: true,
|
||||
num_joined_members: 1,
|
||||
},
|
||||
],
|
||||
total_room_count_estimate: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("should display public rooms when searching", async () => {
|
||||
const query = "ROOM NAME";
|
||||
|
||||
const wrapper = mount(<PublicRoomComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<PublicRoomComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(wrapper.text()).toBe("ready: false, loading: false");
|
||||
|
||||
@ -84,12 +87,16 @@ describe("usePublicRoomDirectory", () => {
|
||||
});
|
||||
|
||||
it("should work with empty queries", async () => {
|
||||
const wrapper = mount(<PublicRoomComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query: "",
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<PublicRoomComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query: "",
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
@ -101,15 +108,21 @@ describe("usePublicRoomDirectory", () => {
|
||||
});
|
||||
|
||||
it("should recover from a server exception", async () => {
|
||||
cli.publicRooms = () => { throw new Error("Oops"); };
|
||||
cli.publicRooms = () => {
|
||||
throw new Error("Oops");
|
||||
};
|
||||
const query = "ROOM NAME";
|
||||
|
||||
const wrapper = mount(<PublicRoomComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<PublicRoomComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
wrapper.simulate("click");
|
||||
|
@ -27,19 +27,13 @@ import { stubClient } from "../test-utils";
|
||||
function UserDirectoryComponent({ onClick }) {
|
||||
const userDirectory = useUserDirectory();
|
||||
|
||||
const {
|
||||
ready,
|
||||
loading,
|
||||
users,
|
||||
} = userDirectory;
|
||||
const { ready, loading, users } = userDirectory;
|
||||
|
||||
return <div onClick={() => onClick(userDirectory)}>
|
||||
{ users[0]
|
||||
? (
|
||||
`Name: ${users[0].name}`
|
||||
)
|
||||
: `ready: ${ready}, loading: ${loading}` }
|
||||
</div>;
|
||||
return (
|
||||
<div onClick={() => onClick(userDirectory)}>
|
||||
{users[0] ? `Name: ${users[0].name}` : `ready: ${ready}, loading: ${loading}`}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
describe("useUserDirectory", () => {
|
||||
@ -51,23 +45,30 @@ describe("useUserDirectory", () => {
|
||||
|
||||
MatrixClientPeg.getHomeserverName = () => "matrix.org";
|
||||
cli.getThirdpartyProtocols = () => Promise.resolve({});
|
||||
cli.searchUserDirectory = (({ term: query }) => Promise.resolve({
|
||||
results: [{
|
||||
user_id: "@bob:matrix.org",
|
||||
display_name: query,
|
||||
}] },
|
||||
));
|
||||
cli.searchUserDirectory = ({ term: query }) =>
|
||||
Promise.resolve({
|
||||
results: [
|
||||
{
|
||||
user_id: "@bob:matrix.org",
|
||||
display_name: query,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("search for users in the identity server", async () => {
|
||||
const query = "Bob";
|
||||
|
||||
const wrapper = mount(<UserDirectoryComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<UserDirectoryComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(wrapper.text()).toBe("ready: true, loading: false");
|
||||
|
||||
@ -83,12 +84,16 @@ describe("useUserDirectory", () => {
|
||||
it("should work with empty queries", async () => {
|
||||
const query = "";
|
||||
|
||||
const wrapper = mount(<UserDirectoryComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<UserDirectoryComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
wrapper.simulate("click");
|
||||
@ -98,15 +103,21 @@ describe("useUserDirectory", () => {
|
||||
});
|
||||
|
||||
it("should recover from a server exception", async () => {
|
||||
cli.searchUserDirectory = () => { throw new Error("Oops"); };
|
||||
cli.searchUserDirectory = () => {
|
||||
throw new Error("Oops");
|
||||
};
|
||||
const query = "Bob";
|
||||
|
||||
const wrapper = mount(<UserDirectoryComponent onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}} />);
|
||||
const wrapper = mount(
|
||||
<UserDirectoryComponent
|
||||
onClick={(hook) => {
|
||||
hook.search({
|
||||
limit: 1,
|
||||
query,
|
||||
});
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
await act(async () => {
|
||||
await sleep(1);
|
||||
wrapper.simulate("click");
|
||||
|
Reference in New Issue
Block a user