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
60 changes: 45 additions & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"parser": "@babel/eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2020,
"sourceType": "module",
"requireConfigFile": false,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
"jsx": true
},
"project": "./tsconfig.json"
},
"env": {
"browser": true,
Expand All @@ -21,10 +21,12 @@
"plugin:jsx-a11y/recommended",
"plugin:react/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:n/recommended",
"plugin:react-hooks/recommended",
"plugin:promise/recommended"
],
"plugin:promise/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"jsx-quotes": [2, "prefer-double"],
"jsx-a11y/no-onchange": "off",
Expand All @@ -34,24 +36,52 @@
"n/no-missing-import": "off",
"n/no-unpublished-import": "off",
"n/no-extraneous-import": "off",
"no-restricted-syntax": ["error", "TemplateLiteral"]
"no-restricted-syntax": ["error", "TemplateLiteral"],
"import/default": "warn",
"semi": "off",
// TypeScript specific rules
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }]
},
"plugins": [
"jsx-a11y",
"jest",
"promise"
"promise",
"@typescript-eslint"
],
"ignorePatterns": [
"node_modules/",
"venv/"
"venv/",
"*.d.ts"
],
"settings": {
"import/core-modules": [ django ],
"import/core-modules": ["django"],
"import/resolver": {
"node": {
"extensions": [".js", ".jsx"]
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"paths": ["src"]
},
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json"
}
},
"react": {
"version": "detect"
}
},
"overrides": [
{
"files": ["*.js", "*.jsx"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
}
}

]
}
6 changes: 0 additions & 6 deletions __mocks__/djangoMock.js

This file was deleted.

8 changes: 0 additions & 8 deletions __mocks__/flipmoveMock.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,47 +1,34 @@
import React from 'react'
import { render, fireEvent, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { describe, test, expect } from 'vitest' // Import from vitest

import AiReport from '../ai_report'

Check warning on line 5 in adhocracy4/comments_async/static/comments_async/__tests__/AiReport.jest.jsx

View workflow job for this annotation

GitHub Actions / build

Using exported name 'AiReport' as identifier for default import

describe('Test AiReport', () => {
const testReport = {
label: [['cattest', 'test label']],
confidence: [['cattest', 0.65]],
explanation: { cattest: [['word', 0.61]] },
show_in_discussion: true
}

test('renders with Read More button', () => {
render(
<AiReport
report={{ label: [['cattest', 'test label']], confidence: [['cattest', 0.65]], explanation: { cattest: [['word', 0.61]] }, show_in_discussion: true }}
/>
)
const comment = screen.getByText('Read more')
expect(comment).toBeInTheDocument()
render(<AiReport report={testReport} />)
expect(screen.getByText('Read more')).toBeInTheDocument()
})

test('functionality of Read More button', () => {
render(
<AiReport
report={{ label: [['cattest', 'test label']], confidence: [['cattest', 0.65]], explanation: { cattest: [['word', 0.61]] }, show_in_discussion: true }}
/>
)
const readMore = screen.getByText('Read more')
expect(readMore).toBeInTheDocument()
test('functionality of Read More button', async () => {
render(<AiReport report={testReport} />)
const button = screen.getByRole('button')
expect(button).toBeInTheDocument()
fireEvent.click(button)
const readLess = screen.getByText('Show less')
expect(readLess).toBeInTheDocument()
expect(readLess).toBeInTheDocument()
const showLessButton = screen.getByText('Show less')
await expect(showLessButton).toHaveTextContent('Show less')
})

test('shows percentage for each label', async () => {
render(
<AiReport
report={{ label: [['cattest', 'test label']], confidence: [0.65], explanation: { cattest: [['word', 0.61]] }, show_in_discussion: true }}
/>
)
const readMore = screen.getByText('Read more')
expect(readMore).toBeInTheDocument()
test('shows percentage for each label', () => {
render(<AiReport report={{ ...testReport, confidence: [0.65] }} />)
const button = screen.getByRole('button')
expect(button).toBeInTheDocument()
fireEvent.click(button)
const percent = screen.getByText(/65%/)
expect(percent).toBeInTheDocument()
expect(screen.getByText(/65%/)).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Comment Component renders comment with creator and comment text 1`] = `
exports[`Comment Component > renders comment with creator and comment text 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
Expand Down Expand Up @@ -219,7 +219,7 @@ exports[`Comment Component renders comment with creator and comment text 1`] = `
id="share-url-undefined"
readonly=""
type="text"
value="http://localhost/?comment=1"
value="http://localhost:3000/?comment=1"
/>
<button
aria-pressed="false"
Expand Down Expand Up @@ -465,7 +465,7 @@ exports[`Comment Component renders comment with creator and comment text 1`] = `
}
`;

exports[`Comment Component renders comment with moderator badge 1`] = `
exports[`Comment Component > renders comment with moderator badge 1`] = `
{
"asFragment": [Function],
"baseElement": <body>
Expand Down Expand Up @@ -689,7 +689,7 @@ exports[`Comment Component renders comment with moderator badge 1`] = `
id="share-url-undefined"
readonly=""
type="text"
value="http://localhost/?comment=1"
value="http://localhost:3000/?comment=1"
/>
<button
aria-pressed="false"
Expand Down
Loading
Loading