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