Skip to content

Commit

Permalink
refactor: Clean up old test
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Jan 25, 2023
1 parent cbe5616 commit b3d58b0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
27 changes: 3 additions & 24 deletions app/configurator/configurator-state.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import {
applyTableDimensionToFilters,
deriveFiltersFromFields,
getFiltersByMappingStatus,
getLocalStorageKey,
handleChartFieldChanged,
handleChartOptionChanged,
initChartStateFromChart,
initChartStateFromCube,
initChartStateFromLocalStorage,
moveFilterField,
updateColorMapping,
} from "@/configurator/configurator-state";
Expand Down Expand Up @@ -86,7 +84,9 @@ afterEach(() => {

describe("initChartStateFromChart", () => {
const setup = ({ chartConfig }: { chartConfig: object }) => {
mockedApi.fetchChartConfig.mockResolvedValue(chartConfig);
mockedApi.fetchChartConfig.mockResolvedValue(
chartConfig as ReturnType<typeof api.fetchChartConfig>
);
};
it("should fetch work if existing chart is valid", async () => {
setup({
Expand All @@ -112,27 +112,6 @@ describe("initChartStateFromChart", () => {
});
});

describe("initChartFromLocalStorage", () => {
it("should initialize from localStorage if valid", async () => {
localStorage.setItem(
getLocalStorageKey("viz1234"),
JSON.stringify({ state: "CONFIGURING_CHART", ...fakeVizFixture })
);
const state = await initChartStateFromLocalStorage("viz1234");
expect(state).not.toBeUndefined();
});

it("should return undefined and remove key from localStorage if invalid", async () => {
jest.spyOn(console, "warn").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {});

localStorage.setItem(getLocalStorageKey("viz1234"), "abcde");
const state = await initChartStateFromLocalStorage("viz1234");
expect(state).toBeUndefined();
expect(localStorage.getItem(getLocalStorageKey("viz1234"))).toBe(null);
});
});

describe("initChartStateFromCube", () => {
const setup = ({ cubeMetadata }: { cubeMetadata: object }) => {
const client = new Client({
Expand Down
4 changes: 0 additions & 4 deletions app/configurator/configurator-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ export type ConfiguratorStateAction =
export type ActionType<ConfiguratorStateAction> =
ConfiguratorStateAction[keyof ConfiguratorStateAction];

const LOCALSTORAGE_PREFIX = "vizualize-configurator-state";
export const getLocalStorageKey = (chartId: string) =>
`${LOCALSTORAGE_PREFIX}:${chartId}`;

const getStateWithCurrentDataSource = (state: ConfiguratorState) => {
const dataSource = getDataSourceFromLocalStorage();

Expand Down

0 comments on commit b3d58b0

Please sign in to comment.