From 242fedbfe60a1b55275f1f584306226f6e4eccfd Mon Sep 17 00:00:00 2001 From: picklesrus Date: Mon, 14 Dec 2020 08:45:08 -0500 Subject: [PATCH] Add a test that the constructor properly sets muteExpriresAtMs by converting from seconds to ms. --- test/unit/components/compose-comment.test.jsx | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/test/unit/components/compose-comment.test.jsx b/test/unit/components/compose-comment.test.jsx index 163db76c4..a76acb331 100644 --- a/test/unit/components/compose-comment.test.jsx +++ b/test/unit/components/compose-comment.test.jsx @@ -13,7 +13,7 @@ describe('Compose Comment test', () => { } }); - let store; + let defaultStore; beforeEach(() => { const mockFormat = { format: jest.fn() @@ -23,7 +23,7 @@ describe('Compose Comment test', () => { .mockImplementation(() => mockFormat); mockFormat.format.mockReturnValue(''); - store = mockStore({ + defaultStore = mockStore({ session: { session: { user: {}, @@ -35,7 +35,10 @@ describe('Compose Comment test', () => { }); }); - const getComposeCommentWrapper = props => { + const getComposeCommentWrapper = (props, store) => { + if (!store) { + store = defaultStore; + } const wrapper = shallowWithIntl( { /> , {context: {store}} ); - return wrapper.dive(); // unwrap redux connect(injectIntl(JoinFlow)) + return wrapper.dive(); // unwrap redux connect(injectIntl(ComposeComment)) }; test('Modal & Comment status do not show ', () => { @@ -89,6 +92,34 @@ describe('Compose Comment test', () => { expect(component.find('CommentingStatus').exists()).toEqual(true); global.Date.now = realDateNow; }); + + test('Comment Status initialized properly when muted', () => { + const realDateNow = Date.now.bind(global.Date); + global.Date.now = () => 0; + const mutedStore = mockStore({ + session: { + session: { + user: {}, + permissions: { + mute_status: { + muteExpiresAt: 5, + offenses: [] + } + } + } + } + }); + const component = getComposeCommentWrapper({}, mutedStore); + const commentInstance = component.instance(); + // Check conversion to ms from seconds is done at init time. + expect(commentInstance.state.muteExpiresAtMs).toEqual(5 * 1000); + // Compose box should be hidden if muted unless they got muted due to a comment they just posted. + expect(component.find('FlexRow.compose-comment').exists()).toEqual(false); + expect(component.find('MuteModal').exists()).toEqual(false); + expect(component.find('CommentingStatus').exists()).toEqual(true); + global.Date.now = realDateNow; + }); + test('Comment Status shows when user just submitted a comment that got them muted', () => { const realDateNow = Date.now.bind(global.Date); global.Date.now = () => 0;