Skip to content
Merged
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
20 changes: 8 additions & 12 deletions tests/gui/data/upload.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fs from 'fs'
import path from 'path'

import { getPage } from '../helper/browser'

describe('classification', () => {
/** @type {Awaited<ReturnType<getPage>>} */
let page
let buf
beforeEach(async () => {
page = await getPage()

Expand All @@ -27,24 +25,22 @@ describe('classification', () => {
return canvas.toDataURL()
})
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const buf = Buffer.from(data, 'base64')
await fs.promises.writeFile('image_upload.png', buf)
buf = Buffer.from(data, 'base64')
})

afterEach(async () => {
await fs.promises.unlink('image_upload.png')
await page?.close()
})

test('initialize', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_upload.png'))
const uploadFileInput = page.locator('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles({ name: 'image_upload.png', mimeType: 'image/png', buffer: buf })

const svg = await page.waitForSelector('#plot-area svg')
await svg.waitForSelector('.points .datas circle')
expect((await svg.$$('.points .datas circle')).length).toBe(1)
const svg = page.locator('#plot-area svg')
await svg.locator('.points .datas circle').waitFor()
await expect(svg.locator('.points .datas circle').count()).resolves.toBe(1)
})
})
67 changes: 28 additions & 39 deletions tests/gui/view/adaptive_thresholding.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fs from 'fs'
import path from 'path'

import { getPage } from '../helper/browser'

describe('segmentation', () => {
Expand Down Expand Up @@ -28,55 +25,47 @@ describe('segmentation', () => {
})
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const buf = Buffer.from(data, 'base64')
await fs.promises.writeFile('image_adaptive_thresholding.png', buf)

const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')
const uploadFileInput = page.locator('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles({
name: 'image_adaptive_thresholding.png',
mimeType: 'image/png',
buffer: buf,
})

const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('adaptive_thresholding')
})

afterEach(async () => {
await fs.promises.unlink('image_adaptive_thresholding.png')
await page?.close()
})

test('initialize', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_adaptive_thresholding.png'))
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('adaptive_thresholding')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')

const methods = await buttons.waitForSelector('[name=method]')
await expect((await methods.getProperty('value')).jsonValue()).resolves.toBe('mean')
const k = await buttons.waitForSelector('[name=k]')
await expect((await k.getProperty('value')).jsonValue()).resolves.toBe('3')
const c = await buttons.waitForSelector('[name=c]')
await expect((await c.getProperty('value')).jsonValue()).resolves.toBe('2')
const methods = buttons.locator('[name=method]')
await expect(methods.inputValue()).resolves.toBe('mean')
const k = buttons.locator('[name=k]')
await expect(k.inputValue()).resolves.toBe('3')
const c = buttons.locator('[name=c]')
await expect(c.inputValue()).resolves.toBe('2')
})

test('learn', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_adaptive_thresholding.png'))

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('adaptive_thresholding')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(1)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(1)

const fitButton = await buttons.waitForSelector('input[value=Fit]')
await fitButton.evaluate(el => el.click())
const fitButton = buttons.locator('input[value=Fit]')
await fitButton.dispatchEvent('click')

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(2)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(2)
})
})
45 changes: 22 additions & 23 deletions tests/gui/view/automatic_thresholding.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fs from 'fs'
import path from 'path'

import { getPage } from '../helper/browser'

describe('segmentation', () => {
Expand Down Expand Up @@ -28,52 +25,54 @@ describe('segmentation', () => {
})
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const buf = Buffer.from(data, 'base64')
await fs.promises.writeFile('image_automatic_thresholding.png', buf)

const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_automatic_thresholding.png'))
const uploadFileInput = page.locator('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles({
name: 'image_automatic_thresholding.png',
mimeType: 'image/png',
buffer: buf,
})

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('automatic_thresholding')
})

afterEach(async () => {
await fs.promises.unlink('image_automatic_thresholding.png')
await page?.close()
})

test('initialize', async () => {
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

const epoch = await buttons.waitForSelector('[name=epoch]')
const epoch = buttons.locator('[name=epoch]')
await expect(epoch.textContent()).resolves.toBe('0')
})

test('learn', async () => {
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(1)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(1)

const epoch = await buttons.waitForSelector('[name=epoch]')
const epoch = buttons.locator('[name=epoch]')
await expect(epoch.textContent()).resolves.toBe('0')
const threshold = await buttons.waitForSelector('span:last-child', { state: 'attached' })
const threshold = buttons.locator('span:last-child', { state: 'attached' })
await expect(threshold.textContent()).resolves.toBe('')

const initButton = await buttons.waitForSelector('input[value=Initialize]')
await initButton.evaluate(el => el.click())
const stepButton = await buttons.waitForSelector('input[value=Step]:enabled')
await stepButton.evaluate(el => el.click())
const initButton = buttons.locator('input[value=Initialize]')
await initButton.dispatchEvent('click')
const stepButton = buttons.locator('input[value=Step]:enabled')
await stepButton.dispatchEvent('click')

await expect(epoch.textContent()).resolves.toBe('1')
await expect(threshold.textContent()).resolves.toMatch(/^[0-9.]+$/)

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(2)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(2)
})
})
66 changes: 28 additions & 38 deletions tests/gui/view/balanced_histogram.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fs from 'fs'
import path from 'path'

import { getPage } from '../helper/browser'

describe('segmentation', () => {
Expand Down Expand Up @@ -28,54 +25,47 @@ describe('segmentation', () => {
})
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const buf = Buffer.from(data, 'base64')
await fs.promises.writeFile('image_balanced_histogram.png', buf)
})

afterEach(async () => {
await fs.promises.unlink('image_balanced_histogram.png')
await page?.close()
})

test('initialize', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_balanced_histogram.png'))
const uploadFileInput = page.locator('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles({
name: 'image_balanced_histogram.png',
mimeType: 'image/png',
buffer: buf,
})

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('balanced_histogram')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
})

const mincount = await buttons.waitForSelector('input:nth-of-type(1)')
await expect((await mincount.getProperty('value')).jsonValue()).resolves.toBe('100')
afterEach(async () => {
await page?.close()
})

test('learn', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')
test('initialize', async () => {
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_balanced_histogram.png'))
const mincount = buttons.locator('input:nth-of-type(1)')
await expect(mincount.inputValue()).resolves.toBe('100')
})

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('balanced_histogram')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
test('learn', async () => {
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(1)
const threshold = await buttons.waitForSelector('span:last-child', { state: 'attached' })
await expect(threshold.evaluate(el => el.textContent)).resolves.toBe('')
await expect(page.locator('#image-area canvas').count()).resolves.toBe(1)
const threshold = buttons.locator('span:last-child')
await expect(threshold.textContent()).resolves.toBe('')

const fitButton = await buttons.waitForSelector('input[value=Fit]')
await fitButton.evaluate(el => el.click())
const fitButton = buttons.locator('input[value=Fit]')
await fitButton.dispatchEvent('click')

await expect(threshold.evaluate(el => el.textContent)).resolves.toMatch(/^[0-9.]+$/)
await expect(page.$$('#image-area canvas')).resolves.toHaveLength(2)
await expect(threshold.textContent()).resolves.toMatch(/^[0-9.]+$/)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(2)
})
})
62 changes: 24 additions & 38 deletions tests/gui/view/otsu.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import fs from 'fs'
import path from 'path'

import { getPage } from '../helper/browser'

describe('segmentation', () => {
Expand Down Expand Up @@ -28,54 +25,43 @@ describe('segmentation', () => {
})
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const buf = Buffer.from(data, 'base64')
await fs.promises.writeFile('image_otsu.png', buf)
})

afterEach(async () => {
await fs.promises.unlink('image_otsu.png')
await page?.close()
})

test('initialize', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
const dataSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_otsu.png'))
const uploadFileInput = page.locator('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles({ name: 'image_otsu.png', mimeType: 'image/png', buffer: buf })

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
const taskSelectBox = page.locator('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
const modelSelectBox = page.locator('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('otsu')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
})

const threshold = await buttons.waitForSelector('span:last-child', { state: 'attached' })
await expect(threshold.evaluate(el => el.textContent)).resolves.toBe('')
afterEach(async () => {
await page?.close()
})

test('learn', async () => {
const dataSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(2) select')
await dataSelectBox.selectOption('upload')
test('initialize', async () => {
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

const uploadFileInput = await page.waitForSelector('#ml_selector #data_menu input[type=file]')
await uploadFileInput.setInputFiles(path.resolve('image_otsu.png'))
const threshold = buttons.locator('span:last-child')
await expect(threshold.textContent()).resolves.toBe('')
})

const taskSelectBox = await page.waitForSelector('#ml_selector dl:first-child dd:nth-child(5) select')
await taskSelectBox.selectOption('SG')
const modelSelectBox = await page.waitForSelector('#ml_selector .model_selection #mlDisp')
await modelSelectBox.selectOption('otsu')
const methodMenu = await page.waitForSelector('#ml_selector #method_menu')
const buttons = await methodMenu.waitForSelector('.buttons')
test('learn', async () => {
const methodMenu = page.locator('#ml_selector #method_menu')
const buttons = methodMenu.locator('.buttons')

await expect(page.$$('#image-area canvas')).resolves.toHaveLength(1)
const threshold = await buttons.waitForSelector('span:last-child', { state: 'attached' })
await expect(threshold.evaluate(el => el.textContent)).resolves.toBe('')
await expect(page.locator('#image-area canvas').count()).resolves.toBe(1)
const threshold = buttons.locator('span:last-child')
await expect(threshold.textContent()).resolves.toBe('')

const fitButton = await buttons.waitForSelector('input[value=Fit]')
await fitButton.evaluate(el => el.click())
const fitButton = buttons.locator('input[value=Fit]')
await fitButton.dispatchEvent('click')

await expect(threshold.evaluate(el => el.textContent)).resolves.toMatch(/^[0-9.]+$/)
await expect(page.$$('#image-area canvas')).resolves.toHaveLength(2)
await expect(threshold.textContent()).resolves.toMatch(/^[0-9.]+$/)
await expect(page.locator('#image-area canvas').count()).resolves.toBe(2)
})
})
Loading