Stores refactor: convert TypingStore; rename TestStores to TestSdkContext (#9454)
This commit is contained in:
@@ -25,10 +25,10 @@ import { WidgetLayoutStore } from "../src/stores/widgets/WidgetLayoutStore";
|
||||
import WidgetStore from "../src/stores/WidgetStore";
|
||||
|
||||
/**
|
||||
* A class which provides the same API as Stores but adds additional unsafe setters which can
|
||||
* A class which provides the same API as SdkContextClass but adds additional unsafe setters which can
|
||||
* replace individual stores. This is useful for tests which need to mock out stores.
|
||||
*/
|
||||
export class TestStores extends SdkContextClass {
|
||||
export class TestSdkContext extends SdkContextClass {
|
||||
public _RightPanelStore?: RightPanelStore;
|
||||
public _RoomNotificationStateStore?: RoomNotificationStateStore;
|
||||
public _RoomViewStore?: RoomViewStore;
|
||||
@@ -27,7 +27,7 @@ import { MatrixDispatcher } from '../../src/dispatcher/dispatcher';
|
||||
import { UPDATE_EVENT } from '../../src/stores/AsyncStore';
|
||||
import { ActiveRoomChangedPayload } from '../../src/dispatcher/payloads/ActiveRoomChangedPayload';
|
||||
import { SpaceStoreClass } from '../../src/stores/spaces/SpaceStore';
|
||||
import { TestStores } from '../TestStores';
|
||||
import { TestSdkContext } from '../TestSdkContext';
|
||||
|
||||
// mock out the injected classes
|
||||
jest.mock('../../src/PosthogAnalytics');
|
||||
@@ -77,7 +77,7 @@ describe('RoomViewStore', function() {
|
||||
// Make the RVS to test
|
||||
dis = new MatrixDispatcher();
|
||||
slidingSyncManager = new MockSlidingSyncManager();
|
||||
const stores = new TestStores();
|
||||
const stores = new TestSdkContext();
|
||||
stores._SlidingSyncManager = slidingSyncManager;
|
||||
stores._PosthogAnalytics = new MockPosthogAnalytics();
|
||||
stores._SpaceStore = new MockSpaceStore();
|
||||
|
||||
@@ -17,13 +17,14 @@ limitations under the License.
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
||||
import TypingStore from "../../src/stores/TypingStore";
|
||||
import { LOCAL_ROOM_ID_PREFIX } from "../../src/models/LocalRoom";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
import { TestSdkContext } from "../TestSdkContext";
|
||||
|
||||
jest.mock("../../src/settings/SettingsStore", () => ({
|
||||
getValue: jest.fn(),
|
||||
monitorSetting: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("TypingStore", () => {
|
||||
@@ -37,11 +38,12 @@ describe("TypingStore", () => {
|
||||
const localRoomId = LOCAL_ROOM_ID_PREFIX + "test";
|
||||
|
||||
beforeEach(() => {
|
||||
typingStore = new TypingStore();
|
||||
mockClient = {
|
||||
sendTyping: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
MatrixClientPeg.get = () => mockClient;
|
||||
const context = new TestSdkContext();
|
||||
context.client = mockClient;
|
||||
typingStore = new TypingStore(context);
|
||||
mocked(SettingsStore.getValue).mockImplementation((setting: string) => {
|
||||
return settings[setting];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user