Skip to content

Commit

Permalink
fix: logger LOG_LEVEL env variable + show assignment redirect with
Browse files Browse the repository at this point in the history
queryParams
  • Loading branch information
sjdonado committed Apr 2, 2024
1 parent bc00ab7 commit 7c03da3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 20 deletions.
6 changes: 4 additions & 2 deletions app/routes/_protected.home.$assignmentId.show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export const handle = {
),
};

export const loader = async ({ params }: LoaderFunctionArgs) => {
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
invariant(params.assignmentId, 'Missing assignmentId param');

const { searchParams } = new URL(request.url);

const [row] = await db
.select({
id: assignmentsTable.id,
Expand All @@ -44,7 +46,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
.limit(1);

if (!row) {
return redirectWithToast('/assignments', {
return redirectWithToast(`/assignments?${searchParams.toString()}`, {
message: 'Assignment not found',
type: 'error',
});
Expand Down
4 changes: 3 additions & 1 deletion app/utils/logger.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pino from 'pino';
import pretty from 'pino-pretty';

import { LOG_LEVEL } from '~/config/env.server';

export const stream = pretty({ colorize: true });

export const logger = pino(
{
level: process.env.NODE_ENV === 'test' ? 'fatal' : 'info',
level: LOG_LEVEL,
},
stream
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "remix-serve ./build/server/index.js",
"typecheck": "tsc",
"test": "NODE_ENV=test playwright test --retries=3",
"test": "NODE_ENV=test LOG_LEVEL=fatal playwright test --retries=1",
"test:ui": "NODE_ENV=test DEBUG=pw:webserver playwright test --ui",
"db:drop": "rm -rf db.sqlite*",
"db:check": "drizzle-kit check:sqlite",
Expand Down
49 changes: 38 additions & 11 deletions tests/pages/assignments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ test.describe('Assignments page - Admin', () => {
test.describe('Edit Assignment', () => {
let assignmentTitle: string | null;
let assignmentType: string | null;
let showAssignmentUrl: string | null;
let editAssignmentUrl: string | null;

test.describe.configure({ mode: 'serial' });

test.beforeEach(async ({ page }) => {
const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW);
const showAssignmentLink = assignment.locator('a').first();
const editAssignmentButton = assignment.locator('a').nth(1);

assignmentTitle = await assignment.getByRole('cell').first().textContent();
Expand All @@ -198,6 +200,7 @@ test.describe('Assignments page - Admin', () => {
.locator('span')
.textContent();

showAssignmentUrl = await showAssignmentLink.getAttribute('href');
editAssignmentUrl = await editAssignmentButton.getAttribute('href');

await editAssignmentButton.click();
Expand Down Expand Up @@ -226,10 +229,9 @@ test.describe('Assignments page - Admin', () => {

await expect(page).toHaveURL('/assignments');
await page.waitForLoadState('networkidle');
await page.reload();

const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW);
await expect(assignment.getByRole('cell').first()).toHaveText(title);
await page.goto(showAssignmentUrl!);
await expect(page.locator('h1')).toHaveText(title);

// restore previous title
await page.goto(editAssignmentUrl!);
Expand Down Expand Up @@ -258,17 +260,29 @@ test.describe('Assignments page - Admin', () => {

test('should successfully delete assignment', async ({ page }) => {
const assignment = page.getByRole('row').nth(DELETE_ASSIGNMENT_ROW);
const deleteAssignmentButton = assignment.getByRole('button').nth(1);
const showAssignmentUrl = await assignment
.locator('a')
.first()
.getAttribute('href');

const deleteAssignmentButton = assignment.getByRole('button').nth(1);
await deleteAssignmentButton.click();

const deleteModal = page.locator('dialog[open]');
await expect(deleteModal.locator('h3')).toHaveText('Delete User');

const deleteButton = deleteModal.getByRole('button', { name: 'Delete' });
await deleteButton.click();

await expect(page).toHaveURL('/assignments?page=2');
await page.reload();

const firstResult = page.getByRole('row').nth(DELETE_ASSIGNMENT_ROW);
const firstResultShowUrl = await firstResult
.locator('a')
.first()
.getAttribute('href');

expect(firstResultShowUrl).not.toBe(showAssignmentUrl);
});

test('should go back from delete confirmation modal', async ({ page }) => {
Expand Down Expand Up @@ -404,12 +418,14 @@ test.describe('Assignments page - Teacher', () => {
test.describe('Edit Assignment', () => {
let assignmentTitle: string | null;
let assignmentType: string | null;
let showAssignmentUrl: string | null;
let editAssignmentUrl: string | null;

test.describe.configure({ mode: 'serial' });

test.beforeEach(async ({ page }) => {
const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW);
const showAssignmentLink = assignment.locator('a').first();
const editAssignmentButton = assignment.locator('a').nth(1);

assignmentTitle = await assignment.getByRole('cell').first().textContent();
Expand All @@ -419,6 +435,7 @@ test.describe('Assignments page - Teacher', () => {
.locator('span')
.textContent();

showAssignmentUrl = await showAssignmentLink.getAttribute('href');
editAssignmentUrl = await editAssignmentButton.getAttribute('href');

await editAssignmentButton.click();
Expand Down Expand Up @@ -447,10 +464,9 @@ test.describe('Assignments page - Teacher', () => {

await expect(page).toHaveURL('/assignments');
await page.waitForLoadState('networkidle');
await page.reload();

const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW);
await expect(assignment.getByRole('cell').first()).toHaveText(title);
await page.goto(showAssignmentUrl!);
await expect(page.locator('h1')).toHaveText(title);

// restore previous title
await page.goto(editAssignmentUrl!);
Expand Down Expand Up @@ -479,18 +495,29 @@ test.describe('Assignments page - Teacher', () => {

test('should successfully delete assignment', async ({ page }) => {
const assignment = page.getByRole('row').nth(DELETE_ASSIGNMENT_ROW);
const deleteAssignmentButton = assignment.getByRole('button').nth(1);
const showAssignmentUrl = await assignment
.locator('a')
.first()
.getAttribute('href');

const deleteAssignmentButton = assignment.getByRole('button').nth(1);
await deleteAssignmentButton.click();

const deleteModal = page.locator('dialog[open]');
await expect(deleteModal.locator('h3')).toHaveText('Delete User');

const deleteButton = deleteModal.getByRole('button', { name: 'Delete' });
await deleteButton.click();

await expect(page).toHaveURL('/assignments?page=2');
await expect(assignment).not.toBeVisible();
await page.reload();

const firstResult = page.getByRole('row').nth(DELETE_ASSIGNMENT_ROW);
const firstResultShowUrl = await firstResult
.locator('a')
.first()
.getAttribute('href');

expect(firstResultShowUrl).not.toBe(showAssignmentUrl);
});

test('should go back from delete confirmation modal', async ({ page }) => {
Expand Down
22 changes: 17 additions & 5 deletions tests/pages/users.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test.describe('Users page - Admin', () => {

test('should successfully delete user', async ({ page }) => {
const user = page.getByRole('row').nth(USER_ROW);
const name = await user
const username = await user
.getByRole('cell')
.first()
.getByRole('paragraph')
Expand All @@ -183,18 +183,30 @@ test.describe('Users page - Admin', () => {
await deleteUserButton.click();

const deleteModal = page.locator('dialog[open]');
await expect(deleteModal.locator('h3')).toHaveText('Delete User');

const deleteButton = deleteModal.getByRole('button', { name: 'Delete' });
await deleteButton.click();

await expect(page).toHaveURL('/users?page=2');
await expect(page.getByText(name!).nth(1)).not.toBeVisible();

const searchBar = page.getByPlaceholder('Search users...');
await searchBar.fill(username!);
await searchBar.press('Enter');

await page.waitForLoadState('networkidle');

const firstResult = page.getByRole('row').nth(USER_ROW);
const firstResultUsername = await firstResult
.getByRole('cell')
.first()
.getByRole('paragraph')
.textContent();

expect(firstResultUsername).not.toBe(username);
});

test('should go back from delete confirmation modal', async ({ page }) => {
const user = page.getByRole('row').nth(USER_ROW);
const name = await user.getByRole('cell').first().textContent();

const deleteUserButton = user.getByRole('button');
await deleteUserButton.click();
Expand All @@ -206,7 +218,7 @@ test.describe('Users page - Admin', () => {
await cancelButton.click();

await expect(page).toHaveURL('/users?page=2');
await expect(page.getByText(name!).nth(1)).toBeVisible();
await expect(user).toBeVisible();
});
});
});
Expand Down

0 comments on commit 7c03da3

Please sign in to comment.