passbolt-styleguide
Version:
Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.
95 lines (77 loc) • 3.61 kB
JavaScript
/**
* 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
*/
/**
* Unit tests on FolderSidebar in regard of specifications
*/
import "../../../../../test/mocks/mockClipboard";
import React from "react";
import { defaultAppContext, defaultProps } from "./DisplayResourceFolderDetails.test.data";
import DisplayResourceFolderDetailsPage from "./DisplayResourceFolderDetails.test.page";
import { ActionFeedbackContext } from "../../../contexts/ActionFeedbackContext";
import { denyRbacContext } from "../../../../shared/context/Rbac/RbacContext.test.data";
jest.mock("./DisplayResourceFolderDetailsInformation", () => () => <></>);
jest.mock("./DisplayResourceFolderDetailsActivity", () => () => <></>);
jest.mock("./DisplayResourceFolderDetailsPermissions", () => () => <></>);
beforeEach(() => {
jest.resetModules();
});
describe("See Resource Sidebar", () => {
let page; // The page to test against
const context = defaultAppContext(); // The applicative context
const props = defaultProps(); // The props to pass
const mockContextRequest = (implementation) => jest.spyOn(context.port, "request").mockImplementation(implementation);
const copyClipboardMockImpl = jest.fn();
describe("As LU I can see a folder", () => {
/**
* Given a selected resource
* Then I should see the secondary sidebar
* And I should be able to identify the name
* And I should be able to see the permalink
*/
beforeEach(() => {
page = new DisplayResourceFolderDetailsPage(context, props);
});
it("As LU I should see the folder details", () => {
expect(page.exists()).toBeTruthy();
});
it("As LU I should be able to identify the name and the permalink", async () => {
expect.assertions(3);
mockContextRequest(copyClipboardMockImpl);
jest.spyOn(ActionFeedbackContext._currentValue, "displaySuccess").mockImplementation(() => {});
jest.spyOn(props.clipboardContext, "copy").mockImplementation(() => {});
expect(page.name).toBe(props.resourceWorkspaceContext.details.folder.name);
expect(page.subtitle).toBe("folder");
await page.selectPermalink();
expect(props.clipboardContext.copy).toHaveBeenCalledWith(
`${context.userSettings.getTrustedDomain()}/app/folders/view/${props.resourceWorkspaceContext.details.folder.id}`,
"The permalink has been copied to clipboard.",
);
});
it("I should see the share option when rbac is available", async () => {
expect.assertions(1);
expect(props.shareWith).not.toBeNull();
});
it("I should see the share option when rbac is not defined", async () => {
expect.assertions(1);
expect(props.shareWith).not.toBeNull();
});
it("I should not see the share option when rbac is unavailable", async () => {
expect.assertions(1);
const props = defaultProps(); // The props to pass
props.rbacContext = denyRbacContext();
page = new DisplayResourceFolderDetailsPage(context, props);
expect(props.shareWith).toBeUndefined();
});
});
});