Merge pull request #14925 from ElectronicBlueberry/add-anonymous-users-test-cases

Add automated tests for presenting unavailable options to logged-out users
This commit is contained in:
Björn Grüning
2022-11-28 22:12:02 +01:00
committed by GitHub
3 changed files with 200 additions and 0 deletions
@@ -0,0 +1,110 @@
import { mockModule, getLocalVue } from "jest/helpers";
import { userStore } from "store/userStore";
import Vuex from "vuex";
import HistoryNavigation from "./HistoryNavigation";
import { shallowMount } from "@vue/test-utils";
const localVue = getLocalVue();
const createStore = (currentUser) => {
return new Vuex.Store({
modules: {
user: mockModule(userStore, { currentUser }),
},
});
};
// all options
const expectedOptions = [
"Show Histories Side-by-Side",
"Resume Paused Jobs",
"Copy this History",
"Delete this History",
"Export Tool Citations",
"Export History to File",
"Extract Workflow",
"Share or Publish",
"Set Permissions",
"Make Private",
];
// options enabled for logged-out users
const anonymousOptions = [
"Resume Paused Jobs",
"Delete this History",
"Export Tool Citations",
"Export History to File",
];
// options disabled for logged-out users
const anonymousDisabledOptions = expectedOptions.filter((option) => !anonymousOptions.includes(option));
describe("History Navigation", () => {
it("presents all options to logged-in users", () => {
const store = createStore({
id: "user.id",
email: "user.email",
});
const wrapper = shallowMount(HistoryNavigation, {
propsData: {
history: { id: "current_history_id" },
histories: [],
},
localVue,
store,
provide: { store },
});
const dropDown = wrapper.find("*[data-description='history options']");
const optionElements = dropDown.findAll("b-dropdown-item-stub");
const optionTexts = optionElements.wrappers.map((el) => el.text());
expect(optionTexts).toStrictEqual(expectedOptions);
});
it("disables options for anonymous users", () => {
const store = createStore({});
const wrapper = shallowMount(HistoryNavigation, {
propsData: {
history: { id: "current_history_id" },
histories: [],
},
localVue,
store,
provide: { store },
});
const dropDown = wrapper.find("*[data-description='history options']");
const enabledOptionElements = dropDown.findAll("b-dropdown-item-stub:not([disabled])");
const enabledOptionTexts = enabledOptionElements.wrappers.map((el) => el.text());
expect(enabledOptionTexts).toStrictEqual(anonymousOptions);
const disabledOptionElements = dropDown.findAll("b-dropdown-item-stub[disabled]");
const disabledOptionTexts = disabledOptionElements.wrappers.map((el) => el.text());
expect(disabledOptionTexts).toStrictEqual(anonymousDisabledOptions);
});
it("prompts anonymous users to log in", () => {
const store = createStore({});
const wrapper = shallowMount(HistoryNavigation, {
propsData: {
history: { id: "current_history_id" },
histories: [],
},
localVue,
store,
provide: { store },
});
const dropDown = wrapper.find("*[data-description='history options']");
const disabledOptionElements = dropDown.findAll("b-dropdown-item-stub[disabled]");
disabledOptionElements.wrappers.forEach((option) => {
expect(option.attributes("title").toLowerCase()).toContain("log in");
});
});
});
@@ -0,0 +1,44 @@
import { mockModule, getLocalVue } from "jest/helpers";
import { userStore } from "store/userStore";
import Vuex from "vuex";
import DetailsLayout from "./DetailsLayout";
import { mount } from "@vue/test-utils";
const localVue = getLocalVue();
const createStore = (currentUser) => {
return new Vuex.Store({
modules: {
user: mockModule(userStore, { currentUser }),
},
});
};
describe("DetailsLayout", () => {
it("allows logged-in users to edit details", () => {
const store = createStore({
id: "user.id",
email: "user.email",
});
const wrapper = mount(DetailsLayout, {
localVue,
store,
provide: { store },
});
expect(wrapper.find(".edit-button").attributes("title")).toBe("Edit");
});
it("prompts anonymous users to log in", () => {
const store = createStore({});
const wrapper = mount(DetailsLayout, {
localVue,
store,
provide: { store },
});
expect(wrapper.find(".edit-button").attributes("title")).toContain("Log in");
});
});
@@ -0,0 +1,46 @@
import { mockModule, getLocalVue } from "jest/helpers";
import { userStore } from "store/userStore";
import Vuex from "vuex";
import FavoritesButton from "./FavoritesButton";
import { shallowMount } from "@vue/test-utils";
const localVue = getLocalVue();
const createStore = (currentUser) => {
return new Vuex.Store({
modules: {
user: mockModule(userStore, { currentUser }),
},
});
};
describe("Favorites Button", () => {
it("describes it's function to logged-in users", () => {
const store = createStore({
id: "user.id",
email: "user.email",
});
const wrapper = shallowMount(FavoritesButton, {
localVue,
store,
provide: { store },
});
expect(wrapper.attributes("disabled")).toBeFalsy();
expect(wrapper.attributes("title")).toBe("Show favorites");
});
it("prompts anonymous users to log in", () => {
const store = createStore({});
const wrapper = shallowMount(FavoritesButton, {
localVue,
store,
provide: { store },
});
expect(wrapper.attributes("disabled")).toBeTruthy();
expect(wrapper.attributes("title").toLowerCase()).toContain("log in");
});
});