Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: current vs changed #151

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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
14 changes: 9 additions & 5 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {beforeEach, afterEach, expect, jest, test} from '@jest/globals'
import type {Action, ErrorLevel} from '../src/config'
import type {ConfigPayload} from '../src/config'

beforeEach(() => {
process.env['INPUT_LIST'] = ''
Expand All @@ -19,11 +19,15 @@ afterEach(() => {
})

test('config', async () => {
expect(require('../src/config')).toMatchObject({
const config = await import('../src/config')

const expected: ConfigPayload = {
list: [],
matches: '',
error: 'error' as ErrorLevel,
action: 'check' as Action,
error: 'error',
action: 'check',
token: 'some-token'
})
}

expect<ConfigPayload>(config).toMatchObject(expected)
})
62 changes: 60 additions & 2 deletions __tests__/detect.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, describe, test} from '@jest/globals'
import {getDiff} from '../src/detect'
import {getCurrentChecked, getCurrentUnchecked, getDiff} from '../src/detect'

describe('getDiff', () => {
test('should return checked and unchecked items', () => {
Expand Down Expand Up @@ -35,8 +35,66 @@ added line
- [ ] item 2-4 unchecked
`

const {checked, unchecked} = getDiff(previousBody, currentBody)
const {checked, unchecked} = getDiff(
previousBody.split('\n'),
currentBody.split('\n')
)
expect(checked).toEqual(['item 2-1 checked', 'item 2-3 checked'])
expect(unchecked).toEqual(['item 1 unchecked', 'item 2-4 unchecked'])
})
})

describe('getCurrentChecked', () => {
test('should return all checked items', () => {
const currentBody = `
# Title line
normal line
abnormal line - [ ] item 3
abnormal line - [x] item 4
added line

- [x] item 0 unchanged
- [ ] item 1 unchecked
- [ ] item 2 unchanged
- [x] item 2-1 checked
- [ ] item 2-2 unchanged
- [x] item 2-3 checked
- [ ] item 2-4 unchecked
`

const checked = getCurrentChecked(currentBody.split('\n'))
expect(checked).toEqual([
'item 0 unchanged',
'item 2-1 checked',
'item 2-3 checked'
])
})
})

describe('getCurrentUnChecked', () => {
test('should return all unchecked items', () => {
const currentBody = `
# Title line
normal line
abnormal line - [ ] item 3
abnormal line - [x] item 4
added line

- [x] item 0 unchanged
- [ ] item 1 unchecked
- [ ] item 2 unchanged
- [x] item 2-1 checked
- [ ] item 2-2 unchanged
- [x] item 2-3 checked
- [ ] item 2-4 unchecked
`

const checked = getCurrentUnchecked(currentBody.split('\n'))
expect(checked).toEqual([
'item 1 unchecked',
'item 2 unchanged',
'item 2-2 unchanged',
'item 2-4 unchecked'
])
})
})
Loading
Loading