Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <[email protected]>
  • Loading branch information
t3chguy committed Jan 31, 2025
1 parent 5a19f8c commit f88b8f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions test/unit-tests/Terms-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/

import { MatrixEvent, EventType, SERVICE_TYPES, Policy, Terms } from "matrix-js-sdk/src/matrix";
import { EventType, MatrixEvent, Policy, SERVICE_TYPES, Terms } from "matrix-js-sdk/src/matrix";
import { screen, within } from "jest-matrix-react";

import { startTermsFlow, Service } from "../../src/Terms";
import { dialogTermsInteractionCallback, Service, startTermsFlow } from "../../src/Terms";
import { getMockClientWithEventEmitter } from "../test-utils";
import { MatrixClientPeg } from "../../src/MatrixClientPeg";

Expand Down Expand Up @@ -183,3 +184,29 @@ describe("Terms", function () {
]);
});
});

describe("dialogTermsInteractionCallback", () => {
it("should render a dialog with the expected terms", async () => {
dialogTermsInteractionCallback(
[
{
service: new Service(SERVICE_TYPES.IS, "http://base_url", "access_token"),
policies: {
sample: {
version: "VERSION",
en: {
name: "Terms",
url: "http://base_url/terms",
},
},
},
},
],
[],
);

const dialog = await screen.findByRole("dialog");
expect(within(dialog).getByRole("link")).toHaveAttribute("href", "http://base_url/terms");
expect(dialog).toMatchSnapshot();

Check failure on line 210 in test/unit-tests/Terms-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

dialogTermsInteractionCallback › should render a dialog with the expected terms

expect(received).toMatchSnapshot() Snapshot name: `dialogTermsInteractionCallback should render a dialog with the expected terms 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: <div aria-describedby="mx_Dialog_content" aria-labelledby="mx_BaseDialog_title" class="" data-focus-lock-disabled="false" role="dialog" > <div class="mx_Dialog_header" > <h1 class="mx_Heading_h3 mx_Dialog_title" id="mx_BaseDialog_title" > Terms of Service </h1> </div> <div id="mx_Dialog_content" > <p> To continue you need to accept the terms of this service. </p> <table class="mx_TermsDialog_termsTable" > <tbody> <tr class="mx_TermsDialog_termsTableHeader" > <th> Service </th> <th> Summary </th> <th> Document </th> <th> Accept </th> </tr> <tr> <td class="mx_TermsDialog_service" > <div> Identity server <br /> ( base_url ) </div> </td> <td class="mx_TermsDialog_summary" > <div> Find others by phone or email <br /> Be found by phone or email </div> </td> <td> <a class="mx_ExternalLink" href="http://base_url/terms" rel="noreferrer noopener" target="_blank" > Terms <i class="mx_ExternalLink_icon" /> </a> </td> <td> <input type="checkbox" /> </td> </tr> </tbody> </table> </div> <div class="mx_Dialog_buttons" > <span class="mx_Dialog_buttons_row" > <button data-testid="dialog-cancel-button" type="button" > Cancel </button> <button class="mx_Dialog_primary" data-testid="dialog-primary-button" disabled="" type="button" > Next </button> </span> </div> </div> at Object.toMatchSnapshot (test/unit-tests/Terms-test.tsx:210:24)
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ describe("DiscoverySettings", () => {

render(<DiscoverySettings />, { wrapper: DiscoveryWrapper });

expect(await screen.findByText("Let people find you")).toBeInTheDocument();
expect(screen.queryByRole("link")).not.toBeInTheDocument();
});
});

0 comments on commit f88b8f3

Please sign in to comment.