Fixed the group move test by fixing the app (#2625)

This commit is contained in:
Erik Jan de Wit 2022-05-12 15:46:10 +02:00 committed by GitHub
parent 5fd94d12b8
commit 5a18c76d75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 38 deletions

View file

@ -111,28 +111,31 @@ describe("Group test", () => {
masthead.checkNotificationMessage("Group deleted");
});
// This test doesn't seem to do anything. The "Move to" dialog never opens.
// But the test somehow still passes.
it("Should move group to root", async () => {
const groups = ["group1", "group2"];
groupModal
.open("no-groups-in-this-realm-empty-action")
.fillGroupForm(groups[0])
.clickCreate();
groupModal
.open("openCreateGroupModal")
.fillGroupForm(groups[1])
.clickCreate();
listingPage.clickRowDetails(groups[0]).clickDetailMenu("Move to");
describe("Move groups", () => {
const groups = ["group", "group1", "group2"];
before(() => adminClient.createSubGroups(groups));
moveGroupModal.clickRoot().clickMove();
after(() => adminClient.deleteGroups());
it("Should move group to root", () => {
listingPage.goToItemDetails(groups[0]);
sidebarPage.waitForPageLoad();
listingPage.clickRowDetails(groups[1]).clickDetailMenu("Move to");
moveGroupModal.clickMove();
sidebarPage.goToGroups();
new GroupDetailPage().checkListSubGroup(groups);
listingPage.deleteItem(groups[0]);
modalUtils.checkModalTitle("Delete group?").confirmModal();
listingPage.deleteItem(groups[1]);
modalUtils.checkModalTitle("Delete group?").confirmModal();
new GroupDetailPage().checkListSubGroup(groups.slice(0, -1));
});
it("Should move group back", () => {
listingPage.clickRowDetails(groups[1]).clickDetailMenu("Move to");
moveGroupModal.clickRow(groups[0]).clickMove();
sidebarPage.goToGroups();
new GroupDetailPage().checkListSubGroup(["group"]);
});
});
it("Group search", () => {

View file

@ -109,8 +109,11 @@ export const Group = () => {
ok: "common:add",
}}
onConfirm={(groups) => {
onChange([...value, ...groups.map(({ id }) => ({ id }))]);
setSelectedGroups([...selectedGroups, ...groups]);
onChange([
...value,
...(groups || []).map(({ id }) => ({ id })),
]);
setSelectedGroups([...selectedGroups, ...(groups || [])]);
setOpen(false);
}}
onClose={() => {

View file

@ -34,7 +34,7 @@ export const GroupComponent = ({ name, label, helpText }: ComponentProps) => {
ok: "common:select",
}}
onConfirm={(groups) => {
onChange(groups[0].path);
onChange(groups?.[0].path);
setOpen(false);
}}
onClose={() => setOpen(false)}

View file

@ -27,7 +27,7 @@ export type GroupPickerDialogProps = {
type: "selectOne" | "selectMany";
filterGroups?: string[];
text: { title: string; ok: string };
onConfirm: (groups: GroupRepresentation[]) => void;
onConfirm: (groups: GroupRepresentation[] | undefined) => void;
onClose: () => void;
};
@ -131,7 +131,7 @@ export const GroupPickerDialog = ({
variant={ModalVariant.small}
title={t(text.title, {
group1: filterGroups?.[0],
group2: currentGroup() ? currentGroup().name : t("root"),
group2: navigation.length ? currentGroup().name : t("root"),
})}
isOpen
onClose={onClose}
@ -142,7 +142,13 @@ export const GroupPickerDialog = ({
variant="primary"
form="group-form"
onClick={() => {
onConfirm(type === "selectMany" ? selectedRows : [currentGroup()]);
onConfirm(
type === "selectMany"
? selectedRows
: navigation.length
? [currentGroup()]
: undefined
);
}}
isDisabled={type === "selectMany" && selectedRows.length === 0}
>
@ -242,7 +248,7 @@ export const GroupPickerDialog = ({
newSelectedRows = selectedRows.filter(
(r) => r.id !== group.id
);
} else if (group.checked) {
} else {
newSelectedRows = [
...selectedRows,
filter === "" ? group : findSubGroup(group, filter),

View file

@ -231,20 +231,37 @@ export const GroupTable = () => {
onClose={() => setMove(undefined)}
onConfirm={async (group) => {
try {
if (group !== undefined) {
try {
if (group[0].id) {
await adminClient.groups.setOrCreateChild(
{ id: group[0].id },
{ id: group[0].id! },
move
);
} else {
await adminClient.groups.create(move);
}
} catch (error: any) {
if (error.response) {
throw error;
}
}
} else {
await adminClient.groups.del({ id: move.id! });
const { id } = await adminClient.groups.create({
...move,
id: undefined,
});
if (move.subGroups) {
await Promise.all(
move.subGroups.map((s) =>
adminClient.groups.setOrCreateChild(
{ id: id! },
{
...s,
id: undefined,
}
)
)
);
}
}
setMove(undefined);
refresh();
addAlert(t("moveGroupSuccess"), AlertVariant.success);

View file

@ -120,7 +120,7 @@ export const DefaultsGroupsTab = () => {
ok: "common:add",
}}
onConfirm={(groups) => {
addGroups(groups);
addGroups(groups || []);
toggleGroupPicker();
}}
onClose={toggleGroupPicker}

View file

@ -164,7 +164,7 @@ export const UserForm = ({
ok: "users:join",
}}
onConfirm={(groups) => {
user?.id ? addGroups(groups) : addChips(groups);
user?.id ? addGroups(groups || []) : addChips(groups || []);
setOpen(false);
}}
onClose={() => setOpen(false)}

View file

@ -256,7 +256,7 @@ export const UserGroups = ({ user }: UserGroupsProps) => {
}}
onClose={() => setOpen(false)}
onConfirm={(groups) => {
addGroups(groups);
addGroups(groups || []);
setOpen(false);
refresh();
}}