This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Stop using the js-sdk's compare function #12782
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a3b9d1
Stop using the js-sdk's compare function
dbkr 5201fe1
add test
dbkr 8a41cdd
Fix tests
dbkr ee27480
Move spy to the right place
dbkr ec99e56
Add ANOTHER test
dbkr 1296955
Merge branch 'develop' into dbkr/stop_using_js_sdk_compare
dbkr 1d60ceb
Add test for integration manager ordering
dbkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright 2024 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix"; | ||
import { mocked } from "jest-mock"; | ||
|
||
import { IntegrationManagers } from "../../src/integrations/IntegrationManagers"; | ||
import { stubClient } from "../test-utils"; | ||
|
||
describe("IntegrationManagers", () => { | ||
let client: MatrixClient; | ||
let intMgrs: IntegrationManagers; | ||
|
||
beforeEach(() => { | ||
client = stubClient(); | ||
mocked(client).getAccountData.mockReturnValue({ | ||
getContent: jest.fn().mockReturnValue({ | ||
foo: { | ||
id: "foo", | ||
content: { | ||
type: "m.integration_manager", | ||
url: "http://foo/ui", | ||
data: { | ||
api_url: "http://foo/api", | ||
}, | ||
}, | ||
}, | ||
bar: { | ||
id: "bar", | ||
content: { | ||
type: "m.integration_manager", | ||
url: "http://bar/ui", | ||
data: { | ||
api_url: "http://bar/api", | ||
}, | ||
}, | ||
}, | ||
}), | ||
} as unknown as MatrixEvent); | ||
|
||
intMgrs = new IntegrationManagers(); | ||
intMgrs.startWatching(); | ||
}); | ||
|
||
afterEach(() => { | ||
intMgrs.stopWatching(); | ||
}); | ||
|
||
describe("getOrderedManagers", () => { | ||
it("should return integration managers in alphabetical order", () => { | ||
const orderedManagers = intMgrs.getOrderedManagers(); | ||
|
||
expect(orderedManagers[0].id).toBe("bar"); | ||
expect(orderedManagers[1].id).toBe("foo"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matrix-js-sdk/src/utils
is intended to be reusable though not necessarily stable. Given we use a load of utils from that export why are you picking on this one in particular?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it was instantiated at the module level, it was running before modernizr when I was trying to write the test. I figure rather than rearranging stuff to try to get the execution order right, the best way to fix this was to just not arbitrarily instantiate a static collator and instead make one when we need it, at which point the compare function is adding no value at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But element-web can't assume any of its dependencies don't do that. Sure we can fix that in the js-sdk but not in other dependencies. So instead we should write our code to defensively handle that situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree, although I'd need to dig more into exactly what order things get run in to do so. This felt like a thing that was still worth doing anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a case of removing the import here https://github.com/element-hq/element-web/blob/develop/src/vector/url_utils.ts#L17 given it is imported by https://github.com/element-hq/element-web/blob/develop/src/vector/index.ts#L24C40-L24C49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although that said, if you strongly think that's a better thing to do than this then I'll stop killing myself trying to get the test coverage on this PR up to the bar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a band-aid for a single cause, which is quite esoteric given that https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator#browser_compatibility has been supported for years, so instead making the "bootloader" resilient to any such calls for more recent APIs in dependencies we control and those we do not would be more sane IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well, test didn't involve fixing other app bugs like the other one did, so this may as well live as tidy-up fix anyway. We might want to consider just loading a small stub from the HTML and loading the full app as an async import, which would give us more flexibility to do loading screens and such as well as have complete control over what executes in the stub.