mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-24 04:22:10 -05:00
* Initial * Progress * Initial UI * Can submit request * Progress * Show text if no scrims * Can cancel request, tabs * Delete post * Popover if can't delete * Request rows * Progress * Scrim page initial * Fix migration order * Progress * Progress * Works again * Make it compile * Make it compile again * Work * Progress * Progress * Progress * Associations initial * Association visibility work * notFoundVisibility form fields initial * Progress * Association leave/join + reset invite code * Progress * Select test * Merge branch 'rewrite' into scrims * Remeda for groupBy * Select with search * Outline styling for select * Select done? * Fix prop names * Paginated badges * Less important * Select no results * Handle limiting select width * UserSearch non-working * Fix problem from merge * Remove UserSearch for now * Remove todo * Flaggable * Remove TODOs * i18n start + styling * Progress * i18n done * Add association e2e test * E2E tests * Done? * Couple leftovers
122 lines
3.0 KiB
TypeScript
122 lines
3.0 KiB
TypeScript
import { add } from "date-fns";
|
|
import { describe, expect, it } from "vitest";
|
|
import { dateToDatabaseTimestamp } from "~/utils/dates";
|
|
import * as Association from "./Association";
|
|
|
|
describe("isVisible", () => {
|
|
it("should return true if visibility is null", () => {
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: null,
|
|
time: new Date(),
|
|
associations: null,
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
|
|
it("should return false if not member of the association", () => {
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: { forAssociation: 1 },
|
|
time: new Date(),
|
|
associations: null,
|
|
};
|
|
expect(Association.isVisible(args)).toBe(false);
|
|
});
|
|
|
|
it("should return true if member of the association", () => {
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: { forAssociation: 1 },
|
|
time: new Date(),
|
|
associations: {
|
|
actual: [{ id: 1 }],
|
|
virtual: [],
|
|
},
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
|
|
it("should return true if member of the virtual association", () => {
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: { forAssociation: "+1" },
|
|
time: new Date(),
|
|
associations: {
|
|
actual: [],
|
|
virtual: ["+1"],
|
|
},
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
|
|
it("should return false if not yet visible", () => {
|
|
const visibleAt = add(new Date(), { days: 1 });
|
|
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: {
|
|
forAssociation: "+1",
|
|
notFoundInstructions: [
|
|
{ at: dateToDatabaseTimestamp(visibleAt), forAssociation: 1 },
|
|
],
|
|
},
|
|
time: new Date(),
|
|
associations: {
|
|
actual: [{ id: 1 }],
|
|
virtual: [],
|
|
},
|
|
};
|
|
expect(Association.isVisible(args)).toBe(false);
|
|
});
|
|
|
|
it("should return true if has become visible", () => {
|
|
const visibleAt = add(new Date(), { days: 1 });
|
|
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: {
|
|
forAssociation: "+1",
|
|
notFoundInstructions: [
|
|
{ at: dateToDatabaseTimestamp(visibleAt), forAssociation: 1 },
|
|
],
|
|
},
|
|
time: add(new Date(), { days: 2 }),
|
|
associations: {
|
|
actual: [{ id: 1 }],
|
|
virtual: [],
|
|
},
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
|
|
it("should return true if has become public", () => {
|
|
const visibleAt = add(new Date(), { days: 1 });
|
|
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: {
|
|
forAssociation: "+1",
|
|
notFoundInstructions: [
|
|
{ at: dateToDatabaseTimestamp(visibleAt), forAssociation: null },
|
|
],
|
|
},
|
|
time: add(new Date(), { days: 2 }),
|
|
associations: {
|
|
actual: [],
|
|
virtual: [],
|
|
},
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
|
|
it("should return true if has become public (no associations)", () => {
|
|
const visibleAt = add(new Date(), { days: 1 });
|
|
|
|
const args: Association.IsVisibleArgs = {
|
|
visibility: {
|
|
forAssociation: "+1",
|
|
notFoundInstructions: [
|
|
{ at: dateToDatabaseTimestamp(visibleAt), forAssociation: null },
|
|
],
|
|
},
|
|
time: add(new Date(), { days: 2 }),
|
|
associations: null,
|
|
};
|
|
expect(Association.isVisible(args)).toBe(true);
|
|
});
|
|
});
|