fleet/frontend/components/config/EnrollSecretTable/EnrollSecretTable.tests.jsx
Gabe Hernandez efb35b537a
add prettier and have it format all fleet application code (#625)
* add prettier and have it format all js code except website:
:

* trying running prettier check in CI

* fix runs on in CI

* change CI job name

* fix prettier erros and fix CI
2021-04-12 14:32:25 +01:00

81 lines
2.7 KiB
JavaScript

import React from "react";
import { shallow, mount } from "enzyme";
import * as copy from "utilities/copy_text";
import EnrollSecretTable, {
EnrollSecretRow,
} from "components/config/EnrollSecretTable/EnrollSecretTable";
describe("EnrollSecretTable", () => {
const defaultProps = {
secrets: [
{ name: "foo", secret: "foo_secret", active: true },
{ name: "bar", secret: "bar_secret", active: true },
{ name: "inactive", secret: "inactive", active: false },
],
};
it("renders properly filtered rows", () => {
const table = shallow(<EnrollSecretTable {...defaultProps} />);
expect(table.find("EnrollSecretRow").length).toEqual(2);
});
it("renders text when empty", () => {
const table = shallow(<EnrollSecretTable secrets={[]} />);
expect(table.find("EnrollSecretRow").length).toEqual(0);
expect(table.find("div").text()).toEqual("No active enroll secrets.");
});
});
describe("EnrollSecretRow", () => {
const defaultProps = { name: "foo", secret: "bar" };
it("should hide secret by default", () => {
const row = mount(<EnrollSecretRow {...defaultProps} />);
const inputField = row.find("InputField").find("input");
expect(inputField.prop("type")).toEqual("password");
});
it("should show secret when enabled", () => {
const row = mount(<EnrollSecretRow {...defaultProps} />);
row.setState({ showSecret: true });
const inputField = row.find("InputField").find("input");
expect(inputField.prop("type")).toEqual("text");
});
it("should change input type when show/hide is clicked", () => {
const row = mount(<EnrollSecretRow {...defaultProps} />);
let inputField = row.find("InputField").find("input");
expect(inputField.prop("type")).toEqual("password");
const showLink = row.find(".enroll-secrets__show-secret");
expect(showLink.find("img").prop("alt")).toEqual("show/hide");
showLink.simulate("click");
inputField = row.find("InputField").find("input");
expect(inputField.prop("type")).toEqual("text");
const hideLink = row.find(".enroll-secrets__show-secret");
expect(showLink.find("img").prop("alt")).toEqual("show/hide");
hideLink.simulate("click");
inputField = row.find("InputField").find("input");
expect(inputField.prop("type")).toEqual("password");
});
it("should call copy when button is clicked", () => {
const row = mount(<EnrollSecretRow {...defaultProps} />);
const spy = jest
.spyOn(copy, "stringToClipboard")
.mockImplementation(() => Promise.resolve());
const copyLink = row
.find(".enroll-secrets__secret-copy-icon")
.find("Button");
copyLink.simulate("click");
expect(spy).toHaveBeenCalledWith(defaultProps.secret);
});
});