123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- var t = require('assert')
- var defaults = require('./utils/defaults')
- module.exports = ({popup, advanced, content}) => {
- before(async () => {
- await defaults({popup, advanced, content})
- })
- describe('validate input', () => {
- before(async () => {
- // advanced
- await advanced.bringToFront()
- })
- it('missing name and url', async () => {
- // both empty
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = ''
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = ''
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- t.equal(
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list')
- }),
- null,
- 'should not add theme with missing name and url'
- )
- })
- it('missing name', async () => {
- // empty name
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = ''
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- t.equal(
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list')
- }),
- null,
- 'should not add theme with missing name'
- )
- })
- it('missing url', async () => {
- // empty url
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'hey'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = ''
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- t.equal(
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list')
- }),
- null,
- 'should not add theme with missing url'
- )
- })
- it('duplicate name from the default themes', async () => {
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'github'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- t.equal(
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list')
- }),
- null,
- 'should not add theme with duplicate name'
- )
- })
- })
- describe('add', () => {
- before(async () => {
- await advanced.bringToFront()
- })
- it('add custom theme', async () => {
- // add theme
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'file:///hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- await advanced.waitFor(300)
- t.equal(
- await advanced.evaluate(() =>
- document.querySelectorAll('.m-themes .m-list li').length
- ),
- 1,
- 'the new theme should be added to the list of custom themes'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-list .m-title').innerText
- ),
- 'a custom theme',
- 'the custom theme name should be set in the list'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-add-theme [placeholder=Name]').innerText
- ),
- '',
- 'cleanup name input'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-add-theme [placeholder~=URL]').innerText
- ),
- '',
- 'cleanup url input'
- )
- })
- it('duplicate name from the custom themes', async () => {
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- t.equal(
- await advanced.evaluate(() =>
- document.querySelectorAll('.m-themes .m-list').length
- ),
- 1,
- 'should not add theme with duplicate name'
- )
- })
- it('preserve state', async () => {
- await advanced.reload()
- await advanced.waitFor(300)
- t.equal(
- await advanced.evaluate(() =>
- document.querySelectorAll('.m-themes .m-list').length
- ),
- 1,
- 'the new theme should be added to the list of custom themes'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-list .m-title').innerText
- ),
- 'a custom theme',
- 'the custom theme name should be set in the list'
- )
- })
- })
- describe('choose', () => {
- before(async () => {
- // advanced
- await advanced.bringToFront()
- // add theme
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'file:///hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- })
- it('choose custom theme from the popup', async () => {
- // popup
- await popup.bringToFront()
- await popup.reload()
- // theme tab
- await popup.click('.m-tabs a:nth-of-type(1)')
- // select the first theme
- await popup.select('.m-panel:nth-of-type(1) select', 'a custom theme')
- t.equal(
- await popup.evaluate(() =>
- state.theme.name
- ),
- 'a custom theme',
- 'custom theme should be selected'
- )
- await popup.reload()
- await popup.waitFor(300)
- t.equal(
- await popup.evaluate(() =>
- state.theme.name
- ),
- 'a custom theme',
- 'custom theme should be selected'
- )
- })
- it('theme should be added to the content', async () => {
- await content.goto('http://localhost:3000/correct-content-type')
- await content.bringToFront()
- await content.waitFor(300)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_theme').getAttribute('href')
- ),
- 'file:///hey',
- 'custom theme should be embedded'
- )
- })
- })
- describe('update url', () => {
- before(async () => {
- // advanced
- await advanced.bringToFront()
- // add theme
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'file:///hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- // popup
- await popup.bringToFront()
- await popup.reload()
- // theme tab
- await popup.click('.m-tabs a:nth-of-type(1)')
- // select the first theme
- await popup.select('.m-panel:nth-of-type(1) select', 'a custom theme')
- })
- it('update custom theme url', async () => {
- // advanced
- await advanced.bringToFront()
- // expand theme
- if (!await advanced.evaluate(() => document.querySelector('.m-themes .m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
- await advanced.click('.m-themes .m-list li:nth-of-type(1)')
- }
- // update theme
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-option:nth-of-type(2) input').value = 'file:///hi'
- document.querySelector('.m-themes .m-option:nth-of-type(2) input').dispatchEvent(new Event('keyup'))
- })
- // there is debounce timeout of 750ms in the options UI
- await advanced.waitFor(800)
- // reload
- await advanced.reload()
- await advanced.waitFor(300)
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-option:nth-of-type(2) input').value
- ),
- 'file:///hi',
- 'the custom theme URL should be updated'
- )
- })
- it('check content', async () => {
- await content.goto('http://localhost:3000/correct-content-type')
- await content.bringToFront()
- await content.waitFor(300)
- t.equal(
- await content.evaluate(() =>
- document.querySelector('#_theme').getAttribute('href')
- ),
- 'file:///hi',
- 'custom theme url should be updated'
- )
- })
- })
- describe('update name', () => {
- before(async () => {
- // advanced
- await advanced.bringToFront()
- // add theme
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'file:///hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- // popup
- await popup.bringToFront()
- await popup.reload()
- // theme tab
- await popup.click('.m-tabs a:nth-of-type(1)')
- // select the first theme
- await popup.select('.m-panel:nth-of-type(1) select', 'a custom theme')
- // advanced
- await advanced.bringToFront()
- // expand theme
- if (!await advanced.evaluate(() => document.querySelector('.m-themes .m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
- await advanced.click('.m-themes .m-list li:nth-of-type(1)')
- }
- })
- it('update custom theme name', async () => {
- // update theme
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-option:nth-of-type(1) input').value = 'a very custom theme'
- document.querySelector('.m-themes .m-option:nth-of-type(1) input').dispatchEvent(new Event('keyup'))
- })
- // there is debounce timeout of 750ms in the options UI
- await advanced.waitFor(800)
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-list .m-title').innerText
- ),
- 'a very custom theme',
- 'the custom theme name should be updated in the list title'
- )
- // reload
- await advanced.reload()
- await advanced.waitFor(300)
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-list .m-title').innerText
- ),
- 'a very custom theme',
- 'the custom theme name should be updated in the list title'
- )
- t.equal(
- await advanced.evaluate(() =>
- document.querySelector('.m-themes .m-option:nth-of-type(1) input').value
- ),
- 'a very custom theme',
- 'the custom theme name should be updated'
- )
- })
- it('check popup', async () => {
- // popup
- await popup.bringToFront()
- await popup.reload()
- // theme tab
- await popup.click('.m-tabs a:nth-of-type(1)')
- t.equal(
- await popup.evaluate(() =>
- document.querySelector('.m-panel:nth-of-type(1) select option').innerText
- ),
- 'a very custom theme',
- 'the custom theme should be updated'
- )
- })
- it('check content', async () => {
- await content.goto('http://localhost:3000/correct-content-type')
- await content.bringToFront()
- await content.waitFor(300)
- t.ok(
- /github\.css$/.test(
- await content.evaluate(() =>
- document.querySelector('#_theme').getAttribute('href')
- )
- ),
- 'defaults to github theme if the custom theme was active'
- )
- })
- })
- describe('remove', () => {
- before(async () => {
- // advanced
- await advanced.bringToFront()
- // add theme
- await advanced.evaluate(() => {
- document.querySelector('.m-add-theme [placeholder=Name]').value = 'a custom theme'
- document.querySelector('.m-add-theme [placeholder=Name]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme [placeholder~=URL]').value = 'file:///hey'
- document.querySelector('.m-add-theme [placeholder~=URL]').dispatchEvent(new Event('change'))
- document.querySelector('.m-add-theme button').click()
- })
- // advanced
- await advanced.bringToFront()
- // expand theme
- if (!await advanced.evaluate(() => document.querySelector('.m-themes .m-list li:nth-of-type(1)').classList.contains('m-expanded'))) {
- await advanced.click('.m-themes .m-list li:nth-of-type(1)')
- }
- })
- it('remove custom theme', async () => {
- // remove
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list button').click()
- })
- t.equal(
- await advanced.evaluate(() => {
- document.querySelector('.m-themes .m-list')
- }),
- null,
- 'should not have any themes'
- )
- })
- })
- }
|