Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
import { expect, test as setup } from '@playwright/test'
import { PrismaClient } from '@prisma/client'
// import { promises as fs } from 'fs'
// import { sleep } from '../src/lib/general/system.js'
// import { get_pin_code_from_mail } from './lib/get_pin_code_from_mail.js'
import { auth_file_path } from './lib/setup.js'

// async function find_auth_file(): Promise<boolean> {
// try {
// await fs.access(auth_file_path, fs.constants.F_OK)
// return true
// } catch {
// return false
// }
// }

// async function get_pin_code_from_mail(): Promise<string> {
// await sleep(process.env.CI ? 5000 : 1000)
// const pin_code = await get_pin_code_from_mail()
// expect(pin_code).toMatch(/^\d{6}$/)

// return pin_code
// }

async function get_pin_code_from_database(gmail_user: string): Promise<string> {
const prisma_client = new PrismaClient()

Expand All @@ -36,14 +16,10 @@ async function get_pin_code_from_database(gmail_user: string): Promise<string> {
}

setup('sign in', async ({ page }) => {
// if (await find_auth_file()) return

await page.goto('./sign-in', { waitUntil: 'networkidle' })

const gmail_user = process.env.GMAIL_USER ?? ''

// expect(gmail_user).toEqual('iam.o.sin@gmail.com')

await page.getByPlaceholder('Enter email').fill(gmail_user)
await page.getByRole('button', { name: 'Continue' }).click()
await page.waitForURL(/\/pin-code/)
Expand Down
51 changes: 24 additions & 27 deletions e2e/learn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ test.describe('after sign in', () => {
await expect(page).toHaveTitle('Learn - Talk')
})

// test('sign in button', async ({ page }) => {
// await page.getByRole('button', { name: 'Sign in' }).click()
// await expect(page).toHaveURL(/sign-in/)
// })

test('from locale combo box', async ({ page }) => {
await expect(page.getByRole('combobox').nth(0)).toHaveValue('en-US')
})
Expand All @@ -44,31 +39,33 @@ test.describe('after sign in', () => {
await expect(page.getByRole('combobox').last()).toHaveValue('yue-HK')
})

// if (!process.env.CI) {
// test('change locale', async ({ page }) => {
// const locale_combobox = page.getByTestId('from-locale-select')
// await locale_combobox.selectOption('ja-JP')
// await expect(page.locator('.nav-item-text').first()).toHaveText('学ぶ')
if (!process.env.CI) {
test('change locale', async ({ page }) => {
const locale_combobox = page.getByTestId('from-locale-select')

// await page.goto('/', { waitUntil: 'networkidle' })
// await expect(page.locator('.nav-item-text').first()).toHaveText('学ぶ')
await locale_combobox.selectOption('ja-JP')
await expect(page.locator('.nav-item-text').first()).toHaveText('学ぶ')

// await page.goto('./learn', { waitUntil: 'networkidle' })
// const locale_combobox2 = page.getByTestId('from-locale-select')
// await locale_combobox2.selectOption('en-US')
// })
// }
})
await page.goto('/', { waitUntil: 'networkidle' })
await expect(page.locator('.nav-item-text').first()).toHaveText('学ぶ')

await page.goto('./learn', { waitUntil: 'networkidle' })

// TODO: GitHub Actions で動作させるにはデータが必要
// test('If there is text on translate, there is text on main', async ({ page }) => {
// await page.waitForSelector('.text')
// const main_text_count = await page.locator('.text').count()
const locale_combobox2 = page.getByTestId('from-locale-select')

// await page.goto('/translate')
// await page.waitForSelector('.text')
// const translate_page_count = await page.locator('.text').count()
await locale_combobox2.selectOption('en-US')
})

// await expect(main_text_count).toBeGreaterThanOrEqual(translate_page_count)
// })
// test('If there is text on translate, there is text on main', async ({ page }) => {
// await page.waitForSelector('.text')
// const main_text_count = await page.locator('.text').count()

// await page.goto('/translate')
// await page.waitForSelector('.text')
// const translate_page_count = await page.locator('.text').count()

// expect(main_text_count).toBeGreaterThanOrEqual(translate_page_count)
// })
}
})
})
2 changes: 1 addition & 1 deletion e2e/lib/get_pin_code_from_mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function get_pin_code_from_mail(): Promise<string> {
const subjects: string[] = messages.map((message) => {
const header_part = message.parts.find((part) => part.which === 'HEADER')

if (header_part && header_part.body.subject) {
if (header_part?.body.subject) {
return header_part.body.subject[0]
}

Expand Down
37 changes: 18 additions & 19 deletions e2e/translate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ test.describe('after sign in', () => {
await expect(page).toHaveTitle('Translate - Talk')
})

// TODO FIX TEST
// test('clicking a text in the history moves it into the box', async ({ page }) => {
// const history_text = page.locator('.text').first()
// const text = await history_text.innerText()
test('clicking a text in the history moves it into the box', async ({ page }) => {
const history_text = page.locator('.text').first()
const text = await history_text.innerText()

// await history_text.click()
await history_text.click()

// const bottom_textarea = page.getByRole('textbox').first()
const bottom_textarea = page.getByRole('textbox').first()

// await expect(bottom_textarea).toHaveValue(text)
// })
await expect(bottom_textarea).toHaveValue(text)
})

test('check main box heights', async ({ page }) => {
const glass_panels = page.locator('.main-box')
Expand Down Expand Up @@ -104,21 +103,22 @@ test.describe('after sign in', () => {
await expect(history_box).toBeVisible()
})

// TODO: GitHub Actions で動作させると、結果が空文字になる。翻訳ができていない?
test('adding text should display the translation', async ({ page }) => {
await page.waitForSelector('.text-area')
if (!process.env.CI) {
test('adding text should display the translation', async ({ page }) => {
await page.waitForSelector('.text-area')

const from_text_area = page.locator('.text-area').first()
const from_text_area = page.locator('.text-area').first()

await from_text_area.fill('Hello')
await from_text_area.press('Meta+Enter')
await from_text_area.fill('Hello')
await from_text_area.press('Meta+Enter')

await page.waitForTimeout(1000)
await page.waitForTimeout(1000)

const bottom_textarea = page.getByRole('textbox').nth(1)
const bottom_textarea = page.getByRole('textbox').nth(1)

await expect(bottom_textarea).toHaveValue('こんにちは')
})
await expect(bottom_textarea).toHaveValue('こんにちは')
})
}

// test('adding text should add it to the history', async ({ page }) => {
// await page.waitForSelector('.text-area')
Expand Down Expand Up @@ -151,7 +151,6 @@ test.describe('after sign in', () => {

const bottom_textarea = page.getByRole('textbox').nth(1)

// TODO: CHANGE TEST!!!
await expect(bottom_textarea).toHaveValue(/[あa]/)
})

Expand Down
2 changes: 0 additions & 2 deletions server/socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ async function on_message(
socket.emit('message_acknowledged')
} catch (error) {
logger.error(`${client_address} [SOCKET] on_message error`, error)

// TODO: 再ログインを促す
}
}

Expand Down
1 change: 0 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const handle: Handle = async ({ event, resolve }) => {
logger.info(`${client_address} [${event.request.method}] ${event.url}`)
}

// TODO: 実際にこの値を利用する
const response = await resolve(event, {
// eslint-disable-next-line @typescript-eslint/naming-convention
transformPageChunk: ({ html }) =>
Expand Down
8 changes: 0 additions & 8 deletions src/lib/app/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,3 @@ export const logger = createLogger({
console_transport,
],
})

// if (process.env.NODE_ENV !== 'production') {
// logger.add(
// new transports.Console({
// format: format.combine(format.colorize({ all: true }), format.simple()),
// })
// )
// }
2 changes: 1 addition & 1 deletion src/lib/auth/pin_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class PinCode {

public constructor(code: string | undefined) {
if (!code) throw new Error('PIN code is required')
// if (code.length < 6) throw new Error('PIN code is too short')
if (code.length < 6) throw new Error('PIN code is too short')
if (code.length > 50) throw new Error('PIN code is too long')

this._code = code
Expand Down
5 changes: 2 additions & 3 deletions src/lib/auth/pin_code_mailer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { GMAIL_USER } from '$env/static/private'
import { GMAIL_PASS } from '$env/static/private'
import { GMAIL_PASS, GMAIL_USER } from '$env/static/private'
import { App } from '$lib/app/app'
import * as nodemailer from 'nodemailer'
import type SMTPTransport from 'nodemailer/lib/smtp-transport'
import { Email } from './email'
import type { MailSubject } from './mail_subject'
import type { PinCode } from './pin_code'
import { App } from '$lib/app/app'

export class PinCodeMailer {
private readonly _transporter = nodemailer.createTransport({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/speech/speech_by_microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SpeechByMicrosoft implements Speech {

resolve(speech_sound)
} else {
reject('No result')
reject(new Error('No result'))
}
},
(error) => {
Expand Down
1 change: 0 additions & 1 deletion src/lib/speech/text_to_speech_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ApiPath } from '../api/api_path'

export class TextToSpeechUrl {
public constructor(
// TODO: Value Object
private readonly _value: string,
private readonly _locale_code: LocaleCode
) {}
Expand Down
8 changes: 3 additions & 5 deletions src/lib/speech/web_speech_recognition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ interface ISpeechRecognition extends EventTarget {
stop(): void
}

interface ISpeechRecognitionConstructor {
new (): ISpeechRecognition
}
type SpeechRecognitionConstructor = new () => ISpeechRecognition

interface IWindow extends Window {
// eslint-disable-next-line @typescript-eslint/naming-convention
SpeechRecognition: ISpeechRecognitionConstructor
webkitSpeechRecognition: ISpeechRecognitionConstructor
SpeechRecognition: SpeechRecognitionConstructor
webkitSpeechRecognition: SpeechRecognitionConstructor
}

declare const window: IWindow
Expand Down
2 changes: 0 additions & 2 deletions src/lib/text/delete_text_api.test_.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: TO E2E TEST

// import { SpeechLanguageCode } from '$lib/speech/speech_language_code'
// import { SpeechText } from '$lib/speech/speech_text'
// import { expect, test } from 'vitest'
Expand Down
1 change: 0 additions & 1 deletion src/lib/text/text_repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface TextRepository {
find_by_id(text_id: TextId): Promise<Text | null>
find(locale_code: LocaleCode, speech_text: SpeechText): Promise<Text | null>
find_many(locale_code: LocaleCode, limit?: TextLimit): Promise<Text[]>
find_unique(text_id: TextId): Promise<Text | null>
save(locale_code: LocaleCode, speech_text: SpeechText): Promise<Text>
delete(text_id: TextId): Promise<Text>
}
6 changes: 0 additions & 6 deletions src/lib/text/text_repository_prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ export class TextRepositoryPrisma implements TextRepository {
return texts
}

public async find_unique(text_id: TextId): Promise<Text | null> {
const text = await this._prisma_client.text.findUnique({ where: { id: text_id.id } })

return text
}

public async save(locale_code: LocaleCode, speech_text: SpeechText): Promise<Text> {
const locale_repository: LocaleRepository = new LocaleRepositoryPrisma(this._prisma_client)
const locale = await locale_repository.find_unique(locale_code)
Expand Down
1 change: 0 additions & 1 deletion src/lib/translation/translate_with_google_advanced.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: node env に変更する
import { LocaleCode } from '../locale/locale_code'
import { TranslationServiceClient } from '@google-cloud/translate'
import * as dotenv from 'dotenv'
Expand Down
1 change: 0 additions & 1 deletion src/routes/(authn)/pin-code/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const actions: Actions = {

return { credentials: true, missing: false, success: false }

// TODO: Show message on page
// throw redirect(302, '/sign-in')
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { TargetLanguageCode } from 'deepl-node'
export const GET: RequestHandler = async ({ params }) => {
try {
const translation_text = new TranslationText(params.text)
// TODO: DeepLのAPIを使って翻訳する
const target_locale_code = new LocaleCode(params.target_locale_code?.trim() ?? 'en-US')
const deepl_translator = new DeeplTranslator(translation_text)
const translated_text = await deepl_translator.translate(
Expand Down
1 change: 0 additions & 1 deletion tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
'media-border': 'rgb(207, 217, 222)',
'header-background': 'rgba(239, 243, 244, 0.85)',
link: 'rgb(29,155,240)',
// TODO: swap dark and base
base: '#f1f5f9', // slate-100
'base-dark': '#0F172A', // slate-900
primary: {
Expand Down
Loading