UNPKG

passbolt-styleguide

Version:

Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.

140 lines (124 loc) 3.88 kB
/** * Passbolt ~ Open source password manager for teams * Copyright (c) 2020 Passbolt SA (https://www.passbolt.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) 2020 Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 2.11.0 */ import { render, waitFor } from "@testing-library/react"; import React from "react"; import AppContext from "../../../../shared/context/AppContext/AppContext"; import MockTranslationProvider from "../../../test/mock/components/Internationalisation/MockTranslationProvider"; import DeleteResourceFolder from "./DeleteResourceFolder"; import userEvent from "@testing-library/user-event"; /** * The DeleteResourceFolderPage component represented as a page */ export default class DeleteResourceFolderPage { /** * Default constructor * @param appContext An app context * @param props Props to attach */ constructor(appContext, props) { this._page = render( <MockTranslationProvider> <AppContext.Provider value={appContext}> <DeleteResourceFolder {...props}></DeleteResourceFolder> </AppContext.Provider> </MockTranslationProvider>, ); this.user = userEvent.setup(); } /** * Returns true it one can cancel the operation */ get canCancel() { return !this._page.container.querySelector(".cancel").hasAttribute("disabled"); } /** * Returns true it one can close the dialog */ get canClose() { return !this._page.container.querySelector(".dialog-close").hasAttribute("disabled"); } /** * Returns true it one can submit the create operation */ get canSubmit() { return !this._page.container.querySelector('button[type="submit"]').hasAttribute("disabled"); } /** * Returns true it one can change the data */ get canChangeData() { return !this._page.container.querySelector("#delete-cascade").hasAttribute("disabled"); } /** * Toggles flag that determines whether the subfolders must be deleted * @param {boolean} value */ async toggleMustDeleteSubfolders(value) { const input = this._page.container.querySelector("#delete-cascade"); if (value !== input.checked) { await this.user.click(input); await waitFor(() => { expect(input.checked).toBe(value); }); } } /** * Returns the delete button element */ get deleteButton() { return this._page.container.querySelector('button[type=\"submit\"]'); } /** * Returns the cancel button element */ get cancelButton() { return this._page.container.querySelector(".submit-wrapper .cancel"); } /** * Returns the tag name input element */ get tagName() { return this._page.container.querySelector(".form-content p strong"); } /** * Returns the close button element */ get closeButton() { return this._page.container.querySelector(".dialog-close"); } /** * Delete the folder * @param mustDeleteSubfolders True if one wants to delete the subfolders * @param inProgressFn Function called while we wait for React stability */ async delete(mustDeleteSubfolders, inProgressFn = () => {}) { if (mustDeleteSubfolders) { await this.toggleMustDeleteSubfolders(true); } await this.user.click(this.deleteButton); await waitFor(inProgressFn); } /** * Cancels the create operation */ async cancel() { await this.user.click(this.cancelButton); } /** * Close the create operation */ async close() { await this.user.click(this.closeButton); } }