Skip to content

Commit

Permalink
[FIX] tests: fix component tests and their organization
Browse files Browse the repository at this point in the history
1. UI tests would sometimes do queries on document but it is more
   correct to rely on `fixture` as ATM? we cannot ensure that a fixture
   is alone in the document. Note that this commit only fixes the
   potentially problematic occurences. Related to point 2.
2. Some tests were nested in describe section that would mount useless
   components.

Part-of: #2261
  • Loading branch information
rrahir committed Mar 23, 2023
1 parent e42786a commit 115e1d2
Show file tree
Hide file tree
Showing 13 changed files with 690 additions and 712 deletions.
2 changes: 1 addition & 1 deletion tests/components/__snapshots__/context_menu.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Standalone context menu tests Context Menu context menu simple rendering 1`] = `
exports[`Context Menu integration tests context menu simple rendering 1`] = `
<div
class="o-menu"
>
Expand Down
35 changes: 17 additions & 18 deletions tests/components/bottom_bar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ async function mountBottomBar(
): Promise<{ parent: Parent; model: Model }> {
let parent: Component;
({ fixture, parent } = await mountComponent(Parent, { model, env, props: { model } }));
return { parent: parent as Parent, model: parent.props.model };
return { parent: parent as Parent, model };
}

describe("BottomBar component", () => {
test("simple rendering", async () => {
await mountBottomBar();

expect(fixture.querySelector(".o-spreadsheet-bottom-bar")).toMatchSnapshot();
});

test("Can create a new sheet", async () => {
const { model } = await mountBottomBar();

const dispatch = jest.spyOn(model, "dispatch");
mockUuidV4To(model, 42);
const activeSheetId = model.getters.getActiveSheetId();
Expand Down Expand Up @@ -112,7 +110,6 @@ describe("BottomBar component", () => {

test("Can open context menu of a sheet", async () => {
await mountBottomBar();

expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
triggerMouseEvent(".o-sheet", "contextmenu");
await nextTick();
Expand All @@ -121,15 +118,13 @@ describe("BottomBar component", () => {

test("Can open context menu of a sheet with the arrow", async () => {
await mountBottomBar();

expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
await click(fixture, ".o-sheet-icon");
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
});

test("Click on the arrow when the context menu is open should close it", async () => {
await mountBottomBar();

expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
await click(fixture, ".o-sheet-icon");
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
Expand Down Expand Up @@ -165,10 +160,11 @@ describe("BottomBar component", () => {
});

test("Can move right a sheet", async () => {
const { model } = await mountBottomBar();
const dispatch = jest.spyOn(model, "dispatch");
const model = new Model();
createSheet(model, { sheetId: "42" });
await nextTick();
await mountBottomBar(model);
const dispatch = jest.spyOn(model, "dispatch");

triggerMouseEvent(".o-sheet", "contextmenu");
await nextTick();
const sheetId = model.getters.getActiveSheetId();
Expand All @@ -180,12 +176,13 @@ describe("BottomBar component", () => {
});

test("Can move left a sheet", async () => {
const { model } = await mountBottomBar();
const model = new Model();
createSheet(model, { sheetId: "42", activate: true });
await mountBottomBar(model);
const dispatch = jest.spyOn(model, "dispatch");
createSheet(model, { sheetId: "42" });
activateSheet(model, "42");
await nextTick();
triggerMouseEvent(".o-sheet[data-id='42']", "contextmenu");

const target = fixture.querySelectorAll(".o-sheet")[1]!;
triggerMouseEvent(target, "contextmenu");
await nextTick();
const sheetId = model.getters.getActiveSheetId();
await click(fixture, ".o-menu-item[data-name='move_left'");
Expand All @@ -196,10 +193,10 @@ describe("BottomBar component", () => {
});

test("Can hide a sheet", async () => {
const { model } = await mountBottomBar();
const dispatch = jest.spyOn(model, "dispatch");
const model = new Model();
createSheet(model, { sheetId: "42" });
activateSheet(model, "42");
await mountBottomBar(model);
const dispatch = jest.spyOn(model, "dispatch");

triggerMouseEvent(".o-sheet", "contextmenu");
await nextTick();
Expand All @@ -211,9 +208,10 @@ describe("BottomBar component", () => {
});

test("Hide sheet menu is not visible if there's only one visible sheet", async () => {
const { model } = await mountBottomBar();
const model = new Model();
createSheet(model, { sheetId: "42" });
hideSheet(model, "42");
await mountBottomBar(model);

triggerMouseEvent(".o-sheet", "contextmenu");
await nextTick();
Expand Down Expand Up @@ -366,6 +364,7 @@ describe("BottomBar component", () => {
const { model } = await mountBottomBar();
const sheet = model.getters.getActiveSheetId();
createSheet(model, { sheetId: "42" });

expect(fixture.querySelectorAll(".o-menu")).toHaveLength(0);
await click(fixture, ".o-list-sheets");
expect(fixture.querySelectorAll(".o-menu")).toHaveLength(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/components/charts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let sheetId: string;

let parent: Spreadsheet;

describe("figures", () => {
describe("charts", () => {
beforeEach(async () => {
mockChartData = mockChart();
chartId = "someuuid";
Expand Down
Loading

0 comments on commit 115e1d2

Please sign in to comment.