Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleydavis committed Jun 28, 2024
1 parent 57675b3 commit 4795a5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 51 deletions.
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"source": "src/index.html",
"scripts": {
"s": "pnpm start",
"start": "cross-env NODE_ENV=development BASE_URL=http://localhost:3000 GOOGLE_API_KEY=\"\" webpack serve --open",
"start": "cross-env NODE_ENV=development ENABLE_AUTH=false BASE_URL=http://localhost:3000 GOOGLE_API_KEY=\"\" webpack serve --open",
"start:prod": "cross-env NODE_ENV=development ENABLE_AUTH=true BASE_URL=https://photosphere-api.codecapers.com.au GOOGLE_API_KEY=\"\" webpack serve --open",
"sp": "pnpm run start:prod",
"start:no-open": "cross-env NODE_ENV=development BASE_URL=http://localhost:3000 GOOGLE_API_KEY=\"\" webpack serve",
"start:no-open": "cross-env NODE_ENV=development ENABLE_AUTH=false BASE_URL=http://localhost:3000 GOOGLE_API_KEY=\"\" webpack serve",
"b": "pnpm build",
"build": "cross-env NODE_ENV=production BASE_URL=https://photosphere-api.codecapers.com.au webpack --mode production --devtool source-map",
"build": "cross-env NODE_ENV=production BASE_URL=https://photosphere-api.codecapers.com.au ENABLE_AUTH=true webpack --mode production --devtool source-map",
"test": "jest --coverage",
"test:watch": "jest --watch",
"start-backend-for-e2e-tests": "cd ../backend && pnpm run start-for-e2e-tests",
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/test/e2e/frontend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ describe("frontend tests", () => {

expect(uploadedFiles.length).toBe(1);

const [ assetId ] = uploadedFiles;

//
// Check that the uploaded assets appears in the gallery.
//
Expand Down
60 changes: 14 additions & 46 deletions packages/user-interface/src/test/lib/layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe("layout", () => {
const galleryWidth = 600;
const targetRowHeight = 200;
const rows = computePartialLayout(undefined, [], galleryWidth, targetRowHeight);
expect(rows).toEqual([]);
expect(rows).toEqual({
galleryHeight: 0,
rows: []
});
});

test("can layout a gallery with a single item", () => {
Expand All @@ -23,9 +26,10 @@ describe("layout", () => {
const galleryWidth = 600;
const targetRowHeight = 200;
const layout = computePartialLayout(undefined, gallery, galleryWidth, targetRowHeight);
expect(layout.rows.length).toBe(1);

expect(layout.rows.length).toBe(2);

const row = layout.rows[0];
const row = layout.rows[1];
expect(row.items.length).toBe(1);
expect(row.items[0]._id).toBe(1);
});
Expand Down Expand Up @@ -53,9 +57,9 @@ describe("layout", () => {
const galleryWidth = 600;
const targetRowHeight = 200;
const layout = computePartialLayout(undefined, items, galleryWidth, targetRowHeight);
expect(layout.rows.length).toBe(1);
expect(layout.rows.length).toBe(2);

const row = layout.rows[0];
const row = layout.rows[1];
expect(row.items.length).toBe(3);
expect(row.items[0]._id).toBe(1);
expect(row.items[1]._id).toBe(2);
Expand Down Expand Up @@ -85,14 +89,14 @@ describe("layout", () => {
const galleryWidth = 600;
const targetRowHeight = 200;
const layout = computePartialLayout(undefined, items, galleryWidth, targetRowHeight);
expect(layout.rows.length).toBe(2);
expect(layout.rows.length).toBe(3);

const firstRow = layout.rows[0];
const firstRow = layout.rows[1];
expect(firstRow.items.length).toBe(2);
expect(firstRow.items[0]._id).toBe(1);
expect(firstRow.items[1]._id).toBe(2);

const secondRow = layout.rows[1];
const secondRow = layout.rows[2];
expect(secondRow.items.length).toBe(1);
expect(secondRow.items[0]._id).toBe(3);
});
Expand All @@ -117,7 +121,7 @@ describe("layout", () => {
const galleryWidth = 600;
const targetRowHeight = 200;
const layout = computePartialLayout(undefined, items, galleryWidth, targetRowHeight);
const firstRow = layout.rows[0];
const firstRow = layout.rows[1];
expect(firstRow.items.length).toBe(2);
expect(firstRow.height).toBeGreaterThan(targetRowHeight);

Expand All @@ -129,7 +133,7 @@ describe("layout", () => {
expect(item2.thumbWidth).toBeGreaterThan(items[1].width);
expect(item2.thumbHeight).toBeGreaterThan(items[1].height);

const secondRow = layout.rows[1];
const secondRow = layout.rows[2];
expect(secondRow.items.length).toBe(1);
expect(secondRow.height).toBeCloseTo(targetRowHeight);

Expand All @@ -138,40 +142,4 @@ describe("layout", () => {
expect(item3.thumbHeight).toBeCloseTo(items[2].height);

});

test("items with a different group wrap to the next row", () => {

const items: any[] = [
{
_id: 1,
width: 100,
height: 200,
group: "a",
},
{
_id: 2,
width: 100,
height: 200,
group: "b",
},
{
_id: 3,
width: 100,
height: 200,
group: "b",
},
];

const galleryWidth = 600;
const targetRowHeight = 200;
const layout = computePartialLayout(undefined, items, galleryWidth, targetRowHeight);

expect(layout.rows.length).toBe(2);
expect(layout.rows[0].items.length).toBe(1);
expect(layout.rows[0].items[0]._id).toBe(1);
expect(layout.rows[1].items.length).toBe(2);
expect(layout.rows[1].items[0]._id).toBe(2);
expect(layout.rows[1].items[1]._id).toBe(3);
});

});

0 comments on commit 4795a5f

Please sign in to comment.