Skip to content

Commit

Permalink
feature(linter): added test groups, adjusted test command
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed Aug 25, 2019
1 parent 9474885 commit 3de47ee
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 72 deletions.
146 changes: 75 additions & 71 deletions __tests__/state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,100 +71,104 @@ afterEach(() => {
jest.resetModules();
})

test('isActive listener', () => {
expect.assertions(2)

browser.runtime.onMessage.listener({ name: 'isActive' }, {}, (response) => {
expect(response).toEqual({
name: 'isActive',
value: true
describe('State listener responds to messages', () => {
test('isActive listener', () => {
expect.assertions(2)

browser.runtime.onMessage.listener({ name: 'isActive' }, {}, (response) => {
expect(response).toEqual({
name: 'isActive',
value: true
})
})
})

window.settings.isActive = false
window.settings.isActive = false

browser.runtime.onMessage.listener({ name: 'isActive' }, {}, (response) => {
expect(response).toEqual({
name: 'isActive',
value: false
browser.runtime.onMessage.listener({ name: 'isActive' }, {}, (response) => {
expect(response).toEqual({
name: 'isActive',
value: false
})
})
})
})

test('comments listener', () => {
function XMLHttpRequest() {
return {
send() {
if (typeof this.onreadystatechange() === 'function') {
this.onreadystatechange()
test('comments listener', () => {
function XMLHttpRequest() {
return {
send() {
if (typeof this.onreadystatechange() === 'function') {
this.onreadystatechange()
}
},
open() {
this.readyState = 4
this.status = 200
this.response = JSON.stringify(dictionary)
}
},
open() {
this.readyState = 4
this.status = 200
this.response = JSON.stringify(dictionary)
}
}
}
global.XMLHttpRequest = XMLHttpRequest
global.XMLHttpRequest = XMLHttpRequest

browser.runtime.onMessage.listener({ name: 'comments' })
browser.runtime.onMessage.listener({ name: 'comments' })

expect(window.settings.comments).toEqual(dictionary)
})
expect(window.settings.comments).toEqual(dictionary)
})

test('idle listener', () => {
expect.assertions(4)
jest.useFakeTimers()
let lastId
let lastMessage
browser.tabs.sendMessage = (id, message) => {
if (message.name === 'animate') {
lastId = id
lastMessage = message
test('idle listener', () => {
expect.assertions(4)
jest.useFakeTimers()
let lastId
let lastMessage
browser.tabs.sendMessage = (id, message) => {
if (message.name === 'animate') {
lastId = id
lastMessage = message
}
}
}

window.settings.isActive = false
browser.runtime.onMessage.listener({ name: 'idle' })
jest.runAllTimers()
window.settings.isActive = false
browser.runtime.onMessage.listener({ name: 'idle' })
jest.runAllTimers()

expect(lastId).toBeUndefined()
expect(lastMessage).toBeUndefined()
expect(lastId).toBeUndefined()
expect(lastMessage).toBeUndefined()

window.settings.isActive = true
browser.runtime.onMessage.listener({ name: 'idle' })
jest.runAllTimers()
window.settings.isActive = true
browser.runtime.onMessage.listener({ name: 'idle' })
jest.runAllTimers()

expect(lastId).toEqual(1)
expect(lastMessage).toEqual({
name: 'animate',
value: true
expect(lastId).toEqual(1)
expect(lastMessage).toEqual({
name: 'animate',
value: true
})
})
})

it('should toggle button icons on click', () => {
expect.assertions(tabs.length * 2)
describe('Toolbar controls are working', () => {
it('should toggle button icons on click', () => {
expect.assertions(tabs.length * 2)

browser.browserAction.setIcon = (payload) => {
expect(payload.path).toBeDefined()
expect(payload.tabId).toBeDefined()
}
browser.browserAction.setIcon = (payload) => {
expect(payload.path).toBeDefined()
expect(payload.tabId).toBeDefined()
}

browser.browserAction.onClicked.listener()
})
browser.browserAction.onClicked.listener()
})

it('should toggle isActive status on click', () => {
expect.assertions(tabs.length * 2)
window.settings.isActive = true
it('should toggle isActive status on click', () => {
expect.assertions(tabs.length * 2)
window.settings.isActive = true

browser.tabs.sendMessage = (tabId, message) => {
expect(tabId).toBeDefined()
expect(message).toEqual({
name: 'isActive',
value: false
})
}
browser.tabs.sendMessage = (tabId, message) => {
expect(tabId).toBeDefined()
expect(message).toEqual({
name: 'isActive',
value: false
})
}

browser.browserAction.onClicked.listener()
browser.browserAction.onClicked.listener()
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Clippy MS Word Office asistant is now back to help inside your browser!",
"main": "src/index.js",
"scripts": {
"test": "jest",
"test": "jest --verbose",
"build": "web-ext build --ignore-files .nvmrc .editorconfig .eslintrc package*.json src/assets/img/screenshots",
"lint": "eslint --max-warnings=0 src"
},
Expand Down

0 comments on commit 3de47ee

Please sign in to comment.