2018-08-08 13:22:54 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-12-20 00:45:24 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-08-08 13:22:54 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-12-05 22:59:06 +00:00
|
|
|
import { strict as assert } from 'assert';
|
2021-12-09 09:10:23 +00:00
|
|
|
|
2021-12-05 22:59:06 +00:00
|
|
|
import { ElementSession } from "../session";
|
2018-08-08 13:22:54 +00:00
|
|
|
|
2021-12-05 22:59:06 +00:00
|
|
|
export async function assertDialog(session: ElementSession, expectedTitle: string): Promise<void> {
|
2019-04-16 13:35:31 +00:00
|
|
|
const titleElement = await session.query(".mx_Dialog .mx_Dialog_title");
|
2019-04-02 12:30:41 +00:00
|
|
|
const dialogHeader = await session.innerText(titleElement);
|
2020-05-27 12:39:00 +00:00
|
|
|
assert.equal(dialogHeader, expectedTitle);
|
2019-04-02 12:30:41 +00:00
|
|
|
}
|
2018-08-08 13:22:54 +00:00
|
|
|
|
2021-12-05 22:59:06 +00:00
|
|
|
export async function acceptDialog(session: ElementSession, expectedTitle: string): Promise<void> {
|
2019-04-02 12:30:41 +00:00
|
|
|
const foundDialog = await acceptDialogMaybe(session, expectedTitle);
|
2018-08-14 10:53:16 +00:00
|
|
|
if (!foundDialog) {
|
|
|
|
throw new Error("could not find a dialog");
|
|
|
|
}
|
2018-08-08 13:22:54 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 22:59:06 +00:00
|
|
|
export async function acceptDialogMaybe(session: ElementSession, expectedTitle: string): Promise<boolean> {
|
2019-04-02 12:30:41 +00:00
|
|
|
let primaryButton = null;
|
2018-08-14 10:53:16 +00:00
|
|
|
try {
|
2019-04-16 13:35:31 +00:00
|
|
|
primaryButton = await session.query(".mx_Dialog .mx_Dialog_primary");
|
2019-10-09 15:51:50 +00:00
|
|
|
} catch (err) {
|
2018-08-14 10:53:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-02 12:30:41 +00:00
|
|
|
if (expectedTitle) {
|
|
|
|
await assertDialog(session, expectedTitle);
|
2018-08-14 10:53:16 +00:00
|
|
|
}
|
|
|
|
await primaryButton.click();
|
|
|
|
return true;
|
2018-08-08 13:22:54 +00:00
|
|
|
}
|