diff --git a/__tests__/ButtonSetter.test.js b/__tests__/ButtonSetter.test.js index c010e7f6..0f41ec77 100644 --- a/__tests__/ButtonSetter.test.js +++ b/__tests__/ButtonSetter.test.js @@ -1,9 +1,5 @@ // import * as main from '../src/main'; -import { - SHOW_ON_TIMELINE, - isFalse, - SHOW_ON_TWEET_DETAIL, -} from '../src/constants'; +import { SHOW_ON_TIMELINE, isFalse, SHOW_ON_TWEET_DETAIL } from '../src/constants'; import { ButtonSetter } from '../src/ButtonSetter'; function makeAllEnabledOptions() { @@ -26,9 +22,7 @@ describe('ButtonSetter', () => { buttonSetter.setButtonOnTimeline(makeAllEnabledOptions()); expect(buttonSetter._setButtonOnTimeline).toHaveBeenCalledTimes(1); - expect( - buttonSetter._setButtonOnReactLayoutTimeline - ).not.toHaveBeenCalled(); + expect(buttonSetter._setButtonOnReactLayoutTimeline).not.toHaveBeenCalled(); }); it('新しいレイアウト(React)', () => { @@ -43,9 +37,7 @@ describe('ButtonSetter', () => { expect(buttonSetter._setButtonOnTimeline).not.toHaveBeenCalled(); - expect( - buttonSetter._setButtonOnReactLayoutTimeline - ).toHaveBeenCalledTimes(1); + expect(buttonSetter._setButtonOnReactLayoutTimeline).toHaveBeenCalledTimes(1); }); }); @@ -136,7 +128,7 @@ describe('ButtonSetter', () => { actionList.appendChild(button); } - imgSrcs.forEach(src => { + imgSrcs.forEach((src) => { const div = document.createElement('div'); div.classList.add('AdaptiveMedia-photoContainer'); @@ -147,7 +139,7 @@ describe('ButtonSetter', () => { media.appendChild(div); }); - extraElements.forEach(element => media.appendChild(element)); + extraElements.forEach((element) => media.appendChild(element)); root.appendChild(media); root.appendChild(actionList); @@ -169,26 +161,14 @@ describe('ButtonSetter', () => { buttonSetter._setButtonOnTimeline(options); expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); - expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-timeline' - ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.classList.contains( - 'ProfileTweet-actionList' - ) - ).toBeTruthy(); + expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual('tooi-button-container-timeline'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.classList.contains('ProfileTweet-actionList')).toBeTruthy(); }); it('画像1枚ツイート3つにボタンつけようとする', () => { - const imgSrcsSet = [ - ['https://g.co/img1'], - ['https://g.co/img2'], - ['https://g.co/img3'], - ]; - imgSrcsSet.forEach(imgSrcs => { + const imgSrcsSet = [['https://g.co/img1'], ['https://g.co/img2'], ['https://g.co/img3']]; + imgSrcsSet.forEach((imgSrcs) => { makeTweet(imgSrcs); }); @@ -200,42 +180,21 @@ describe('ButtonSetter', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { + expect(buttonSetter.setButton.mock.calls[index][0].className).toStrictEqual('tooi-button-container-timeline'); + expect(buttonSetter.setButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); expect( - buttonSetter.setButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-timeline'); - expect( - buttonSetter.setButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[index][0].target.classList.contains( - 'ProfileTweet-actionList' - ) + buttonSetter.setButton.mock.calls[index][0].target.classList.contains('ProfileTweet-actionList'), ).toBeTruthy(); }); }); it('画像4枚ツイート3つにボタンつけようとする', () => { const imgSrcsSet = [ - [ - 'https://g.co/img11', - 'https://g.co/img12', - 'https://g.co/img13', - 'https://g.co/img14', - ], - [ - 'https://g.co/img21', - 'https://g.co/img22', - 'https://g.co/img23', - 'https://g.co/img24', - ], - [ - 'https://g.co/img31', - 'https://g.co/img32', - 'https://g.co/img33', - 'https://g.co/img34', - ], + ['https://g.co/img11', 'https://g.co/img12', 'https://g.co/img13', 'https://g.co/img14'], + ['https://g.co/img21', 'https://g.co/img22', 'https://g.co/img23', 'https://g.co/img24'], + ['https://g.co/img31', 'https://g.co/img32', 'https://g.co/img33', 'https://g.co/img34'], ]; - imgSrcsSet.forEach(imgSrcs => { + imgSrcsSet.forEach((imgSrcs) => { makeTweet(imgSrcs); }); @@ -247,16 +206,10 @@ describe('ButtonSetter', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { + expect(buttonSetter.setButton.mock.calls[index][0].className).toStrictEqual('tooi-button-container-timeline'); + expect(buttonSetter.setButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); expect( - buttonSetter.setButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-timeline'); - expect( - buttonSetter.setButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[index][0].target.classList.contains( - 'ProfileTweet-actionList' - ) + buttonSetter.setButton.mock.calls[index][0].target.classList.contains('ProfileTweet-actionList'), ).toBeTruthy(); }); }); @@ -360,11 +313,7 @@ describe('ButtonSetter', () => { * @param {HTMLElement[]} extraElements * @param {boolean} hasButton */ - const makeTweetDetail = ( - imgSrcs, - extraElements = [], - hasButton = false - ) => { + const makeTweetDetail = (imgSrcs, extraElements = [], hasButton = false) => { const root = document.createElement('div'); root.classList.add('permalink-tweet-container'); @@ -376,7 +325,7 @@ describe('ButtonSetter', () => { actionList.appendChild(button); } - imgSrcs.forEach(src => { + imgSrcs.forEach((src) => { const media = document.createElement('div'); media.classList.add('AdaptiveMedia-photoContainer'); @@ -387,7 +336,7 @@ describe('ButtonSetter', () => { root.appendChild(media); }); - extraElements.forEach(element => root.appendChild(element)); + extraElements.forEach((element) => root.appendChild(element)); root.appendChild(actionList); document.body.appendChild(root); @@ -408,26 +357,13 @@ describe('ButtonSetter', () => { buttonSetter._setButtonOnTweetDetail(options); expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); - expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-detail' - ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.classList.contains( - 'ProfileTweet-actionList' - ) - ).toBeTruthy(); + expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual('tooi-button-container-detail'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.classList.contains('ProfileTweet-actionList')).toBeTruthy(); }); it('画像4枚ツイート詳細にボタンつけようとする', () => { - const imgSrcs = [ - 'https://g.co/img1', - 'https://g.co/img2', - 'https://g.co/img3', - 'https://g.co/img4', - ]; + const imgSrcs = ['https://g.co/img1', 'https://g.co/img2', 'https://g.co/img3', 'https://g.co/img4']; makeTweetDetail(imgSrcs); const buttonSetter = new ButtonSetter(); @@ -437,17 +373,9 @@ describe('ButtonSetter', () => { buttonSetter._setButtonOnTweetDetail(options); expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); - expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-detail' - ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.classList.contains( - 'ProfileTweet-actionList' - ) - ).toBeTruthy(); + expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual('tooi-button-container-detail'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.classList.contains('ProfileTweet-actionList')).toBeTruthy(); }); it('画像でないツイート1つにボタンつけない', () => { @@ -455,9 +383,7 @@ describe('ButtonSetter', () => { makeTweetDetail(imgSrcs); const media = document.querySelectorAll('.AdaptiveMedia-photoContainer'); - media.forEach(medium => - medium.classList.remove('AdaptiveMedia-photoContainer') - ); + media.forEach((medium) => medium.classList.remove('AdaptiveMedia-photoContainer')); const buttonSetter = new ButtonSetter(); buttonSetter.setButton = jest.fn(); @@ -487,7 +413,7 @@ describe('ButtonSetter', () => { // 画像を全部消す const media = document.querySelectorAll('.AdaptiveMedia-photoContainer'); - media.forEach(medium => medium.parentNode.removeChild(medium)); + media.forEach((medium) => medium.parentNode.removeChild(medium)); const buttonSetter = new ButtonSetter(); buttonSetter.setButton = jest.fn(); @@ -592,26 +518,16 @@ describe('ButtonSetter', () => { buttonSetter._setButtonOnReactLayoutTimeline(options); expect(buttonSetter.setReactLayoutButton).toHaveBeenCalledTimes(1); - expect( - buttonSetter.setReactLayoutButton.mock.calls[0][0].className - ).toStrictEqual('tooi-button-container-react-timeline'); - expect( - buttonSetter.setReactLayoutButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setReactLayoutButton.mock.calls[0][0].target.getAttribute( - 'role' - ) - ).toStrictEqual('group'); + expect(buttonSetter.setReactLayoutButton.mock.calls[0][0].className).toStrictEqual( + 'tooi-button-container-react-timeline', + ); + expect(buttonSetter.setReactLayoutButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setReactLayoutButton.mock.calls[0][0].target.getAttribute('role')).toStrictEqual('group'); }); it('画像1枚ツイート3つにボタンつけようとする', () => { - const imgSrcsSet = [ - ['https://g.co/img1'], - ['https://g.co/img2'], - ['https://g.co/img3'], - ]; - imgSrcsSet.forEach(imgSrcs => { + const imgSrcsSet = [['https://g.co/img1'], ['https://g.co/img2'], ['https://g.co/img3']]; + imgSrcsSet.forEach((imgSrcs) => { makeReactTweet(imgSrcs); }); @@ -623,42 +539,23 @@ describe('ButtonSetter', () => { expect(buttonSetter.setReactLayoutButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { - expect( - buttonSetter.setReactLayoutButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-react-timeline'); - expect( - buttonSetter.setReactLayoutButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setReactLayoutButton.mock.calls[ - index - ][0].target.getAttribute('role') - ).toStrictEqual('group'); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].className).toStrictEqual( + 'tooi-button-container-react-timeline', + ); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].target.getAttribute('role')).toStrictEqual( + 'group', + ); }); }); it('画像4枚ツイート3つにボタンつけようとする', () => { const imgSrcsSet = [ - [ - 'https://g.co/img11', - 'https://g.co/img12', - 'https://g.co/img13', - 'https://g.co/img14', - ], - [ - 'https://g.co/img21', - 'https://g.co/img22', - 'https://g.co/img23', - 'https://g.co/img24', - ], - [ - 'https://g.co/img31', - 'https://g.co/img32', - 'https://g.co/img33', - 'https://g.co/img34', - ], + ['https://g.co/img11', 'https://g.co/img12', 'https://g.co/img13', 'https://g.co/img14'], + ['https://g.co/img21', 'https://g.co/img22', 'https://g.co/img23', 'https://g.co/img24'], + ['https://g.co/img31', 'https://g.co/img32', 'https://g.co/img33', 'https://g.co/img34'], ]; - imgSrcsSet.forEach(imgSrcs => { + imgSrcsSet.forEach((imgSrcs) => { makeReactTweet(imgSrcs); }); @@ -670,17 +567,13 @@ describe('ButtonSetter', () => { expect(buttonSetter.setReactLayoutButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { - expect( - buttonSetter.setReactLayoutButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-react-timeline'); - expect( - buttonSetter.setReactLayoutButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setReactLayoutButton.mock.calls[ - index - ][0].target.getAttribute('role') - ).toStrictEqual('group'); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].className).toStrictEqual( + 'tooi-button-container-react-timeline', + ); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setReactLayoutButton.mock.calls[index][0].target.getAttribute('role')).toStrictEqual( + 'group', + ); }); }); @@ -740,8 +633,7 @@ describe('ButtonSetter', () => { }); it('ツイートなかったら何もしない', () => { - document.body.innerHTML = - '
'; + document.body.innerHTML = '
'; const buttonSetter = new ButtonSetter(); buttonSetter.setReactLayoutButton = jest.fn(); @@ -768,7 +660,7 @@ describe('ButtonSetter', () => { /** * @argument {string?} color 色 */ - const makeActionButton = color => { + const makeActionButton = (color) => { const button = document.createElement('div'); button.classList.add('ProfileTweet-actionButton'); if (color) { @@ -795,9 +687,7 @@ describe('ButtonSetter', () => { it('actionButtonのcolorあったらその色が返る', () => { makeActionButton('#123456'); const buttonSetter = new ButtonSetter(); - expect(buttonSetter.getActionButtonColor()).toStrictEqual( - 'rgb(18, 52, 86)' - ); + expect(buttonSetter.getActionButtonColor()).toStrictEqual('rgb(18, 52, 86)'); }); }); @@ -805,7 +695,7 @@ describe('ButtonSetter', () => { /** * @argument {string?} color 色 */ - const makeReactActionButton = color => { + const makeReactActionButton = (color) => { const group = document.createElement('div'); group.setAttribute('role', 'group'); const button = document.createElement('div'); @@ -825,33 +715,25 @@ describe('ButtonSetter', () => { it('actionButtonなかったらデフォルト', () => { const buttonSetter = new ButtonSetter(); - expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual( - '#697b8c' - ); + expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual('#697b8c'); }); it('actionButtonのcolor空文字ならデフォルト', () => { makeReactActionButton(''); const buttonSetter = new ButtonSetter(); - expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual( - '#697b8c' - ); + expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual('#697b8c'); }); it('actionButtonのcolorなかったらデフォルト', () => { makeReactActionButton(null); const buttonSetter = new ButtonSetter(); - expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual( - '#697b8c' - ); + expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual('#697b8c'); }); it('actionButtonのcolorあったらその色が返る', () => { makeReactActionButton('#123456'); const buttonSetter = new ButtonSetter(); - expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual( - 'rgb(18, 52, 86)' - ); + expect(buttonSetter.getReactLayoutActionButtonColor()).toStrictEqual('rgb(18, 52, 86)'); }); }); }); diff --git a/__tests__/ButtonSetterTweetDeck.test.js b/__tests__/ButtonSetterTweetDeck.test.js index cdf7b65e..8097e6e6 100644 --- a/__tests__/ButtonSetterTweetDeck.test.js +++ b/__tests__/ButtonSetterTweetDeck.test.js @@ -1,8 +1,4 @@ -import { - SHOW_ON_TWEETDECK_TIMELINE, - isFalse, - SHOW_ON_TWEETDECK_TWEET_DETAIL, -} from '../src/constants'; +import { SHOW_ON_TWEETDECK_TIMELINE, isFalse, SHOW_ON_TWEETDECK_TWEET_DETAIL } from '../src/constants'; import { ButtonSetterTweetDeck } from '../src/ButtonSetterTweetDeck'; function makeAllEnabledOptions() { @@ -36,7 +32,7 @@ describe('ButtonSetterTweetDeck', () => { footer.appendChild(button); } - imgSrcs.forEach(src => { + imgSrcs.forEach((src) => { const div = document.createElement('div'); div.classList.add(...['js-media-image-link', ...extraClassNames]); div.style.backgroundImage = `url("${src}")`; @@ -64,23 +60,15 @@ describe('ButtonSetterTweetDeck', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-tweetdeck-timeline' + 'tooi-button-container-tweetdeck-timeline', ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.tagName).toStrictEqual('FOOTER'); }); it('画像1枚ツイート3つにボタンつけようとする', () => { - const imgSrcsSet = [ - ['https://g.co/img1'], - ['https://g.co/img2'], - ['https://g.co/img3'], - ]; - imgSrcsSet.forEach(imgSrcs => { + const imgSrcsSet = [['https://g.co/img1'], ['https://g.co/img2'], ['https://g.co/img3']]; + imgSrcsSet.forEach((imgSrcs) => { makeTweet(imgSrcs); }); @@ -92,40 +80,21 @@ describe('ButtonSetterTweetDeck', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { - expect( - buttonSetter.setButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-tweetdeck-timeline'); - expect( - buttonSetter.setButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[index][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[index][0].className).toStrictEqual( + 'tooi-button-container-tweetdeck-timeline', + ); + expect(buttonSetter.setButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[index][0].target.tagName).toStrictEqual('FOOTER'); }); }); it('画像4枚ツイート3つにボタンつけようとする', () => { const imgSrcsSet = [ - [ - 'https://g.co/img11', - 'https://g.co/img12', - 'https://g.co/img13', - 'https://g.co/img14', - ], - [ - 'https://g.co/img21', - 'https://g.co/img22', - 'https://g.co/img23', - 'https://g.co/img24', - ], - [ - 'https://g.co/img31', - 'https://g.co/img32', - 'https://g.co/img33', - 'https://g.co/img34', - ], + ['https://g.co/img11', 'https://g.co/img12', 'https://g.co/img13', 'https://g.co/img14'], + ['https://g.co/img21', 'https://g.co/img22', 'https://g.co/img23', 'https://g.co/img24'], + ['https://g.co/img31', 'https://g.co/img32', 'https://g.co/img33', 'https://g.co/img34'], ]; - imgSrcsSet.forEach(imgSrcs => { + imgSrcsSet.forEach((imgSrcs) => { makeTweet(imgSrcs); }); @@ -137,15 +106,11 @@ describe('ButtonSetterTweetDeck', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { - expect( - buttonSetter.setButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-tweetdeck-timeline'); - expect( - buttonSetter.setButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[index][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[index][0].className).toStrictEqual( + 'tooi-button-container-tweetdeck-timeline', + ); + expect(buttonSetter.setButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[index][0].target.tagName).toStrictEqual('FOOTER'); }); }); @@ -245,11 +210,7 @@ describe('ButtonSetterTweetDeck', () => { * @param {string[]} extraClassNames * @param {boolean} hasButton */ - const makeTweetDetail = ( - imgSrcs, - extraClassNames = [], - hasButton = false - ) => { + const makeTweetDetail = (imgSrcs, extraClassNames = [], hasButton = false) => { const root = document.createElement('div'); root.classList.add('js-tweet-detail'); @@ -280,11 +241,9 @@ describe('ButtonSetterTweetDeck', () => { aTag.appendChild(img); media.appendChild(aTag); } else { - imgSrcs.forEach(src => { + imgSrcs.forEach((src) => { const aTag = document.createElement('a'); - aTag.classList.add( - ...['js-media-image-link', 'media-image', ...extraClassNames] - ); + aTag.classList.add(...['js-media-image-link', 'media-image', ...extraClassNames]); aTag.style.backgroundImage = `url("${src}")`; media.appendChild(aTag); }); @@ -310,24 +269,13 @@ describe('ButtonSetterTweetDeck', () => { buttonSetter.setButtonOnTweetDetail(options); expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); - expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-tweetdeck-detail' - ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual('tooi-button-container-tweetdeck-detail'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.tagName).toStrictEqual('FOOTER'); }); it('画像4枚ツイート詳細にボタンつけようとする', () => { - const imgSrcs = [ - 'https://g.co/img1', - 'https://g.co/img2', - 'https://g.co/img3', - 'https://g.co/img4', - ]; + const imgSrcs = ['https://g.co/img1', 'https://g.co/img2', 'https://g.co/img3', 'https://g.co/img4']; makeTweetDetail(imgSrcs); const buttonSetter = new ButtonSetterTweetDeck(); @@ -337,39 +285,18 @@ describe('ButtonSetterTweetDeck', () => { buttonSetter.setButtonOnTweetDetail(options); expect(buttonSetter.setButton).toHaveBeenCalledTimes(1); - expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual( - 'tooi-button-container-tweetdeck-detail' - ); - expect( - buttonSetter.setButton.mock.calls[0][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[0][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[0][0].className).toStrictEqual('tooi-button-container-tweetdeck-detail'); + expect(buttonSetter.setButton.mock.calls[0][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[0][0].target.tagName).toStrictEqual('FOOTER'); }); it('画像4枚ツイート詳細3つにボタンつけようとする', () => { const imgSrcsSet = [ - [ - 'https://g.co/img11', - 'https://g.co/img12', - 'https://g.co/img13', - 'https://g.co/img14', - ], - [ - 'https://g.co/img21', - 'https://g.co/img22', - 'https://g.co/img23', - 'https://g.co/img24', - ], - [ - 'https://g.co/img31', - 'https://g.co/img32', - 'https://g.co/img33', - 'https://g.co/img34', - ], + ['https://g.co/img11', 'https://g.co/img12', 'https://g.co/img13', 'https://g.co/img14'], + ['https://g.co/img21', 'https://g.co/img22', 'https://g.co/img23', 'https://g.co/img24'], + ['https://g.co/img31', 'https://g.co/img32', 'https://g.co/img33', 'https://g.co/img34'], ]; - imgSrcsSet.forEach(imgSrcs => { + imgSrcsSet.forEach((imgSrcs) => { makeTweetDetail(imgSrcs); }); @@ -381,15 +308,11 @@ describe('ButtonSetterTweetDeck', () => { expect(buttonSetter.setButton).toHaveBeenCalledTimes(3); imgSrcsSet.forEach((imgSrcs, index) => { - expect( - buttonSetter.setButton.mock.calls[index][0].className - ).toStrictEqual('tooi-button-container-tweetdeck-detail'); - expect( - buttonSetter.setButton.mock.calls[index][0].getImgSrcs() - ).toMatchObject(imgSrcs); - expect( - buttonSetter.setButton.mock.calls[index][0].target.tagName - ).toStrictEqual('FOOTER'); + expect(buttonSetter.setButton.mock.calls[index][0].className).toStrictEqual( + 'tooi-button-container-tweetdeck-detail', + ); + expect(buttonSetter.setButton.mock.calls[index][0].getImgSrcs()).toMatchObject(imgSrcs); + expect(buttonSetter.setButton.mock.calls[index][0].target.tagName).toStrictEqual('FOOTER'); }); }); @@ -397,13 +320,8 @@ describe('ButtonSetterTweetDeck', () => { const imgSrcs = ['https://g.co/video1']; makeTweetDetail(imgSrcs, ['is-video']); - const media = [ - ...document.querySelectorAll('.media-img'), - ...document.querySelectorAll('.media-image'), - ]; - media.forEach(medium => - medium.classList.remove('media-img', 'media-image') - ); + const media = [...document.querySelectorAll('.media-img'), ...document.querySelectorAll('.media-image')]; + media.forEach((medium) => medium.classList.remove('media-img', 'media-image')); const buttonSetter = new ButtonSetterTweetDeck(); buttonSetter.setButton = jest.fn(); @@ -449,9 +367,7 @@ describe('ButtonSetterTweetDeck', () => { makeTweetDetail(imgSrcs); const media = document.querySelectorAll('.media-image'); - Array.from(media).forEach(medium => - medium.parentNode.removeChild(medium) - ); + Array.from(media).forEach((medium) => medium.parentNode.removeChild(medium)); const buttonSetter = new ButtonSetterTweetDeck(); buttonSetter.setButton = jest.fn(); @@ -592,9 +508,7 @@ describe('ButtonSetterTweetDeck', () => { it('背景画像がURL', () => { element.style.backgroundImage = 'url("http://g.co/img1")'; - expect(buttonSetter.getBackgroundImageUrl(element)).toStrictEqual( - 'http://g.co/img1' - ); + expect(buttonSetter.getBackgroundImageUrl(element)).toStrictEqual('http://g.co/img1'); }); it('背景画像が空文字', () => { diff --git a/__tests__/Constants.test.js b/__tests__/Constants.test.js index c7e37d51..b5afe687 100644 --- a/__tests__/Constants.test.js +++ b/__tests__/Constants.test.js @@ -35,9 +35,7 @@ describe('定数', () => { it('TweetDeck', () => { expect(HOST_TWEETDECK_TWITTER_COM).toBe('tweetdeck.twitter.com'); expect(SHOW_ON_TWEETDECK_TIMELINE).toBe('SHOW_ON_TWEETDECK_TIMELINE'); - expect(SHOW_ON_TWEETDECK_TWEET_DETAIL).toBe( - 'SHOW_ON_TWEETDECK_TWEET_DETAIL' - ); + expect(SHOW_ON_TWEETDECK_TWEET_DETAIL).toBe('SHOW_ON_TWEETDECK_TWEET_DETAIL'); }); it('画像ページ', () => { @@ -85,7 +83,7 @@ describe('定数', () => { describe('どのページかのフラグ', () => { const originalLocation = window.location; beforeAll(() => { - delete window.location; + window.location = undefined; }); afterAll(() => { window.location = originalLocation; @@ -114,7 +112,7 @@ describe('定数', () => { describe('Chrome拡張機能かのフラグ', () => { const originalChrome = window.chrome; beforeAll(() => { - delete window.chrome; + window.chrome = undefined; }); afterAll(() => { window.chrome = originalChrome; diff --git a/__tests__/Utils.test.js b/__tests__/Utils.test.js index 1c35bbbe..cbfb78a4 100644 --- a/__tests__/Utils.test.js +++ b/__tests__/Utils.test.js @@ -131,7 +131,7 @@ describe('Utils', () => { ]; describe('collectUrlParams 画像urlの要素を集める', () => { - cases.forEach(singleCase => { + cases.forEach((singleCase) => { const { title, url, params } = singleCase; it(`${title}`, () => { expect(collectUrlParams(url)).toStrictEqual(makeResultParams(params)); @@ -144,19 +144,15 @@ describe('Utils', () => { }); describe('formatUrl 画像URLを https~?format=〜&name=orig に揃える', () => { - cases.forEach(singleCase => { + cases.forEach((singleCase) => { const { title, url, params } = singleCase; it(`${title}`, () => { - expect(formatUrl(url)).toBe( - `https://pbs.twimg.com/media/hogefuga123?format=${params.format}&name=orig` - ); + expect(formatUrl(url)).toBe(`https://pbs.twimg.com/media/hogefuga123?format=${params.format}&name=orig`); }); }); it('twitterの画像URLでないときそのまま', () => { - expect(formatUrl('https://twitter.com/tos')).toBe( - 'https://twitter.com/tos' - ); + expect(formatUrl('https://twitter.com/tos')).toBe('https://twitter.com/tos'); }); it('空文字渡すと null が返る', () => { @@ -165,7 +161,7 @@ describe('Utils', () => { }); describe('getImageFilenameByUrl 画像のファイル名をつくる', () => { - cases.forEach(singleCase => { + cases.forEach((singleCase) => { const { title, url, filename } = singleCase; it(`${title}`, () => { expect(getImageFilenameByUrl(url)).toBe(filename); @@ -183,9 +179,7 @@ describe('Utils', () => { window.open = jest.fn(); openImages(['https://pbs.twimg.com/media/1st?format=jpg&name=orig']); expect(window.open.mock.calls.length).toBe(1); - expect(window.open.mock.calls[0][0]).toBe( - 'https://pbs.twimg.com/media/1st?format=jpg&name=orig' - ); + expect(window.open.mock.calls[0][0]).toBe('https://pbs.twimg.com/media/1st?format=jpg&name=orig'); }); it('画像URLを2つ渡したとき逆順に開く', () => { @@ -195,12 +189,8 @@ describe('Utils', () => { 'https://pbs.twimg.com/media/2nd?format=jpg&name=orig', ]); expect(window.open.mock.calls.length).toBe(2); - expect(window.open.mock.calls[0][0]).toBe( - 'https://pbs.twimg.com/media/2nd?format=jpg&name=orig' - ); - expect(window.open.mock.calls[1][0]).toBe( - 'https://pbs.twimg.com/media/1st?format=jpg&name=orig' - ); + expect(window.open.mock.calls[0][0]).toBe('https://pbs.twimg.com/media/2nd?format=jpg&name=orig'); + expect(window.open.mock.calls[1][0]).toBe('https://pbs.twimg.com/media/1st?format=jpg&name=orig'); }); it('画像URLを4つ渡したとき逆順に開く', () => { @@ -212,18 +202,10 @@ describe('Utils', () => { 'https://pbs.twimg.com/media/4th?format=jpg&name=orig', ]); expect(window.open.mock.calls.length).toBe(4); - expect(window.open.mock.calls[0][0]).toBe( - 'https://pbs.twimg.com/media/4th?format=jpg&name=orig' - ); - expect(window.open.mock.calls[1][0]).toBe( - 'https://pbs.twimg.com/media/3rd?format=jpg&name=orig' - ); - expect(window.open.mock.calls[2][0]).toBe( - 'https://pbs.twimg.com/media/2nd?format=jpg&name=orig' - ); - expect(window.open.mock.calls[3][0]).toBe( - 'https://pbs.twimg.com/media/1st?format=jpg&name=orig' - ); + expect(window.open.mock.calls[0][0]).toBe('https://pbs.twimg.com/media/4th?format=jpg&name=orig'); + expect(window.open.mock.calls[1][0]).toBe('https://pbs.twimg.com/media/3rd?format=jpg&name=orig'); + expect(window.open.mock.calls[2][0]).toBe('https://pbs.twimg.com/media/2nd?format=jpg&name=orig'); + expect(window.open.mock.calls[3][0]).toBe('https://pbs.twimg.com/media/1st?format=jpg&name=orig'); }); it('画像URLでないURLを1つ渡したときもそのまま開く', () => { @@ -248,13 +230,9 @@ describe('Utils', () => { 'https://pbs.twimg.com/media/2nd?format=jpg&name=orig', ]); expect(window.open.mock.calls.length).toBe(3); - expect(window.open.mock.calls[0][0]).toBe( - 'https://pbs.twimg.com/media/2nd?format=jpg&name=orig' - ); + expect(window.open.mock.calls[0][0]).toBe('https://pbs.twimg.com/media/2nd?format=jpg&name=orig'); expect(window.open.mock.calls[1][0]).toBe('https://twitter.com/tos'); - expect(window.open.mock.calls[2][0]).toBe( - 'https://pbs.twimg.com/media/1st?format=jpg&name=orig' - ); + expect(window.open.mock.calls[2][0]).toBe('https://pbs.twimg.com/media/1st?format=jpg&name=orig'); }); it('要素0個の配列を渡したとき開かない', () => { @@ -268,7 +246,7 @@ describe('Utils', () => { describe('Chrome拡張機能のとき', () => { const originalChrome = window.chrome; beforeAll(() => { - delete window.chrome; + window.chrome = undefined; window.chrome = { runtime: { id: 'id' } }; }); afterAll(() => { @@ -277,12 +255,10 @@ describe('Utils', () => { it('初期設定を取得できる', async () => { const expected = {}; - OPTION_KEYS.forEach(key => { + OPTION_KEYS.forEach((key) => { expected[key] = isTrue; }); - window.chrome.runtime.sendMessage = jest.fn((_, callback) => - callback({ data: {} }) - ); + window.chrome.runtime.sendMessage = jest.fn((_, callback) => callback({ data: {} })); await expect(updateOptions()).resolves.toStrictEqual(expected); }); @@ -291,20 +267,16 @@ describe('Utils', () => { OPTION_KEYS.forEach((key, i) => { expected[key] = i % 2 === 0 ? isTrue : isFalse; }); - window.chrome.runtime.sendMessage = jest.fn((_, callback) => - callback({ data: { ...expected } }) - ); + window.chrome.runtime.sendMessage = jest.fn((_, callback) => callback({ data: { ...expected } })); await expect(updateOptions()).resolves.toStrictEqual(expected); }); it('設定が取得できなかったら初期設定', async () => { const expected = {}; - OPTION_KEYS.forEach(key => { + OPTION_KEYS.forEach((key) => { expected[key] = isTrue; }); - window.chrome.runtime.sendMessage = jest.fn((_, callback) => - callback({}) - ); + window.chrome.runtime.sendMessage = jest.fn((_, callback) => callback({})); await expect(updateOptions()).resolves.toStrictEqual(expected); }); }); @@ -312,7 +284,7 @@ describe('Utils', () => { describe('Chrome拡張機能でないとき', () => { const originalChrome = window.chrome; beforeAll(() => { - delete window.chrome; + window.chrome = undefined; window.chrome = undefined; }); afterAll(() => { @@ -321,7 +293,7 @@ describe('Utils', () => { it('初期設定を取得できる', async () => { const expected = {}; - OPTION_KEYS.forEach(key => { + OPTION_KEYS.forEach((key) => { expected[key] = isTrue; }); await expect(updateOptions()).resolves.toStrictEqual(expected); @@ -443,7 +415,7 @@ describe('Utils', () => { describe('getButtonSetter ボタン設置するクラスのゲッタ', () => { const originalLocation = window.location; beforeAll(() => { - delete window.location; + window.location = undefined; }); afterAll(() => { window.location = originalLocation; diff --git a/__tests__/popup.test.js b/__tests__/popup.test.js index 1717946d..aeceb58e 100644 --- a/__tests__/popup.test.js +++ b/__tests__/popup.test.js @@ -19,7 +19,7 @@ describe('Popup', () => { const optionsText = OPTIONS_TEXT; const optionKeys = OPTION_KEYS; const optionsEnabled = {}; - optionKeys.forEach(key => { + optionKeys.forEach((key) => { optionsEnabled[key] = true; }); @@ -42,7 +42,7 @@ describe('Popup', () => { const optionKeys = OPTION_KEYS; const optionsEnabled = {}; const expectOptions = {}; - optionKeys.forEach(key => { + optionKeys.forEach((key) => { optionsEnabled[key] = true; expectOptions[key] = isTrue; });