Skip to content

Commit 506b1fa

Browse files
committed
Fixed lint issue
1 parent 10ec33a commit 506b1fa

File tree

1 file changed

+47
-50
lines changed

1 file changed

+47
-50
lines changed

app/javascript/components/pages/admin/roles-list/container.spec.js

+47-50
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { fromJS } from "immutable";
22

33
import { mountedComponent, screen, stub } from "../../../../test-utils";
44
import { ACTIONS } from "../../../permissions";
5+
import { lookups } from "../../../../test";
56

67
import RolesList from "./container";
7-
import { lookups } from "../../../../test";
88

99
describe("<RolesList />", () => {
1010
const dataLength = 30;
@@ -15,7 +15,49 @@ describe("<RolesList />", () => {
1515
description: `Test description ${i + 1}`
1616
}));
1717

18-
const initialState = fromJS({
18+
const initialState = fromJS({
19+
records: {
20+
admin: {
21+
roles: {
22+
data,
23+
metadata: { total: dataLength, per: 20, page: 1 },
24+
loading: false,
25+
errors: false
26+
}
27+
}
28+
},
29+
user: {
30+
permissions: {
31+
roles: [ACTIONS.MANAGE]
32+
}
33+
},
34+
forms: {
35+
options: {
36+
lookups: lookups()
37+
}
38+
}
39+
});
40+
41+
42+
stub(window.I18n, "t").withArgs("messages.record_list.of").returns("of").withArgs("buttons.new").returns("New");
43+
44+
it("renders record list table", () => {
45+
mountedComponent(<RolesList />, initialState, ["/admin/roles"]);
46+
expect(screen.getByRole("grid")).toBeInTheDocument();
47+
});
48+
49+
it("should trigger a valid action with next page when clicking next page", () => {
50+
mountedComponent(<RolesList />, initialState, ["/admin/roles"]);
51+
expect(screen.getByText(`1-20 of ${dataLength}`)).toBeInTheDocument();
52+
});
53+
54+
it("should render new button", () => {
55+
mountedComponent(<RolesList />, initialState, ["/admin/roles"]);
56+
expect(screen.getByText(`New`)).toBeInTheDocument();
57+
});
58+
59+
describe("when user can't create role", () => {
60+
const initialStateCreateRole = fromJS({
1961
records: {
2062
admin: {
2163
roles: {
@@ -28,7 +70,7 @@ describe("<RolesList />", () => {
2870
},
2971
user: {
3072
permissions: {
31-
roles: [ACTIONS.MANAGE]
73+
roles: [ACTIONS.READ]
3274
}
3375
},
3476
forms: {
@@ -38,54 +80,9 @@ describe("<RolesList />", () => {
3880
}
3981
});
4082

41-
stubI18n = stub(window.I18n, "t")
42-
.withArgs("messages.record_list.of")
43-
.returns("of")
44-
.withArgs("buttons.new")
45-
.returns("New");
46-
47-
it("renders record list table", () => {
48-
mountedComponent(<RolesList />, initialState, ["/admin/roles"])
49-
expect(screen.getByRole('grid')).toBeInTheDocument();
50-
});
51-
52-
it("should trigger a valid action with next page when clicking next page", () => {
53-
mountedComponent(<RolesList />, initialState, ["/admin/roles"])
54-
expect(screen.getByText(`1-20 of ${dataLength}`)).toBeInTheDocument();
55-
});
56-
57-
it("should render new button", () => {
58-
mountedComponent(<RolesList />, initialState, ["/admin/roles"])
59-
expect(screen.getByText(`New`)).toBeInTheDocument();
60-
});
61-
62-
describe("when user can't create role", () => {
63-
const initialState = fromJS({
64-
records: {
65-
admin: {
66-
roles: {
67-
data,
68-
metadata: { total: dataLength, per: 20, page: 1 },
69-
loading: false,
70-
errors: false
71-
}
72-
}
73-
},
74-
user: {
75-
permissions: {
76-
roles: [ACTIONS.READ]
77-
}
78-
},
79-
forms: {
80-
options: {
81-
lookups: lookups()
82-
}
83-
}
84-
});
85-
8683
it("should not render new button", () => {
87-
mountedComponent(<RolesList />, initialState, ["/admin/roles"])
88-
expect(screen.queryByText(/New/)).not.toBeInTheDocument();
84+
mountedComponent(<RolesList />, initialStateCreateRole, ["/admin/roles"]);
85+
expect(screen.queryByText(/New/)).not.toBeInTheDocument();
8986
});
9087
});
9188
});

0 commit comments

Comments
 (0)