|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events"; |
| 18 | +import { |
| 19 | + ILocationContent, |
| 20 | + LocationAssetType, |
| 21 | + M_ASSET, |
| 22 | + M_LOCATION, |
| 23 | + M_TIMESTAMP, |
| 24 | +} from "matrix-js-sdk/src/@types/location"; |
| 25 | +import { makeLocationContent } from "matrix-js-sdk/src/content-helpers"; |
| 26 | + |
| 27 | +import { isSelfLocation } from "../../../src/utils/location"; |
| 28 | + |
| 29 | +describe("isSelfLocation", () => { |
| 30 | + it("Returns true for a full m.asset event", () => { |
| 31 | + const content = makeLocationContent("", '0'); |
| 32 | + expect(isSelfLocation(content)).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it("Returns true for a missing m.asset", () => { |
| 36 | + const content = { |
| 37 | + body: "", |
| 38 | + msgtype: "m.location", |
| 39 | + geo_uri: "", |
| 40 | + [M_LOCATION.name]: { uri: "" }, |
| 41 | + [TEXT_NODE_TYPE.name]: "", |
| 42 | + [M_TIMESTAMP.name]: 0, |
| 43 | + // Note: no m.asset! |
| 44 | + }; |
| 45 | + expect(isSelfLocation(content as ILocationContent)).toBe(true); |
| 46 | + }); |
| 47 | + |
| 48 | + it("Returns true for a missing m.asset type", () => { |
| 49 | + const content = { |
| 50 | + body: "", |
| 51 | + msgtype: "m.location", |
| 52 | + geo_uri: "", |
| 53 | + [M_LOCATION.name]: { uri: "" }, |
| 54 | + [TEXT_NODE_TYPE.name]: "", |
| 55 | + [M_TIMESTAMP.name]: 0, |
| 56 | + [M_ASSET.name]: { |
| 57 | + // Note: no type! |
| 58 | + }, |
| 59 | + }; |
| 60 | + expect(isSelfLocation(content as ILocationContent)).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it("Returns false for an unknown asset type", () => { |
| 64 | + const content = makeLocationContent( |
| 65 | + undefined, /* text */ |
| 66 | + "geo:foo", |
| 67 | + 0, |
| 68 | + undefined, /* description */ |
| 69 | + "org.example.unknown" as unknown as LocationAssetType); |
| 70 | + expect(isSelfLocation(content)).toBe(false); |
| 71 | + }); |
| 72 | +}); |
0 commit comments