Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-reeves committed Dec 28, 2020
2 parents 456baac + 4243785 commit f361de4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/GherkinEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ const GherkinEditor = React.forwardRef((props, ref) => {
return
}

const session = aceEditorRef.current.editor.getSession()

if (!gherkinAnnotator) {
const { editor } = aceEditorRef.current
gherkinAnnotator = new GherkinAnnotator(editor.getSession())
gherkinAnnotator = new GherkinAnnotator(session)
} else {
gherkinAnnotator.setSession(session)
}
}, [isLinterActivated])

Expand Down
15 changes: 14 additions & 1 deletion src/components/GherkinEditor/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'
import { render } from '@testing-library/react'
import GherkinEditor from '.'
import GherkinAnnotator, { annotate, setLanguage, setMode } from 'modules/gherkin-annotator'
import GherkinAnnotator, { annotate, setLanguage, setMode, setSession } from 'modules/gherkin-annotator'

jest.mock('modules/gherkin-annotator')

beforeEach(() => {
GherkinAnnotator.mockClear()
annotate.mockClear()
setSession.mockClear()
setLanguage.mockClear()
setMode.mockClear()
})
Expand Down Expand Up @@ -141,6 +142,18 @@ describe('GherkinEditor', () => {
})
})

describe('when linter status changes', () => {
it('reset the annotator ression', () => {
const { rerender } = render(<GherkinEditor showGutter activateLinter />)

rerender(<GherkinEditor showGutter />)
rerender(<GherkinEditor showGutter activateLinter />)

expect(GherkinAnnotator).toHaveBeenCalledTimes(1)
expect(setSession).toHaveBeenCalledTimes(1)
})
})

describe('when linter is deactivated', () => {
it('does not instanciate linter', () => {
render(<GherkinEditor initialValue='Given a scenario' showGutter activateLinter={false} />)
Expand Down
3 changes: 3 additions & 0 deletions src/modules/gherkin-annotator/__mocks__/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const setSession = jest.fn()
const setLanguage = jest.fn()
const setMode = jest.fn()
const annotate = jest.fn()

const GherkinAnnotator = jest.fn().mockImplementation(() => {
return {
setSession,
setLanguage,
setMode,
annotate
Expand All @@ -13,6 +15,7 @@ const GherkinAnnotator = jest.fn().mockImplementation(() => {
export default GherkinAnnotator

export {
setSession,
setLanguage,
setMode,
annotate
Expand Down
4 changes: 4 additions & 0 deletions src/modules/gherkin-annotator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default class {
this.mode = ''
}

setSession(session) {
this.session = session
}

setLanguage(language) {
this.language = language
}
Expand Down
13 changes: 13 additions & 0 deletions src/modules/gherkin-annotator/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ describe('GherkinAnnotator', () => {
})
})

describe('.setSession(session)', () => {
afterEach(() => {
gherkinAnnotator.setSession(session)
})

it('set the session properly', () => {
const newSession = { foo: 'bar' }

gherkinAnnotator.setSession(newSession)
expect(gherkinAnnotator.session).toEqual(newSession)
})
})

describe('.setLanguage(language)', () => {
it('set the language properly', () => {
gherkinAnnotator.setLanguage('fr')
Expand Down

0 comments on commit f361de4

Please sign in to comment.