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"); masthead.checkNotificationMessage("Group deleted");
}); });
// This test doesn't seem to do anything. The "Move to" dialog never opens. describe("Move groups", () => {
// But the test somehow still passes. const groups = ["group", "group1", "group2"];
it("Should move group to root", async () => { before(() => adminClient.createSubGroups(groups));
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");
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(); sidebarPage.goToGroups();
new GroupDetailPage().checkListSubGroup(groups); new GroupDetailPage().checkListSubGroup(groups.slice(0, -1));
listingPage.deleteItem(groups[0]); });
modalUtils.checkModalTitle("Delete group?").confirmModal();
listingPage.deleteItem(groups[1]); it("Should move group back", () => {
modalUtils.checkModalTitle("Delete group?").confirmModal(); listingPage.clickRowDetails(groups[1]).clickDetailMenu("Move to");
moveGroupModal.clickRow(groups[0]).clickMove();
sidebarPage.goToGroups();
new GroupDetailPage().checkListSubGroup(["group"]);
});
}); });
it("Group search", () => { it("Group search", () => {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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