* Added test for draft_scheduled_post and header component * Added test for drafts_button/index.ts * Added test for send_button/index.ts * Added test for servers/scheduled_post.ts queries * Added test for global_scheduled_post_list/index.ts * Added test for rescheduled draft index file and minor update * Added test for core option and index * Added test for scheduled post options * Added test for send_draft index file * updated test for draft_scheduled_post and draft_scheduled_post_header * Updated test for drafts_button index * Updated test for send_button index * Updated test for server/scheduled_post * Updated test for global_scheduled_post/index * removed the unnecessary config and team data to populate in db for test * Update app/components/draft_scheduled_post/draft_scheduled_post.test.tsx Co-authored-by: Daniel Espino García <larkox@gmail.com> * linter fixes --------- Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: Daniel Espino García <larkox@gmail.com>
99 lines
3.5 KiB
TypeScript
99 lines
3.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
|
|
import {Screens} from '@constants';
|
|
import {SYSTEM_IDENTIFIERS} from '@constants/database';
|
|
import DatabaseManager from '@database/manager';
|
|
import {renderWithEverything} from '@test/intl-test-helper';
|
|
import TestHelper from '@test/test_helper';
|
|
|
|
import DraftsButton from './drafts_button';
|
|
|
|
import EnhancedDraftButton from './index';
|
|
|
|
import type ServerDataOperator from '@database/operator/server_data_operator';
|
|
import type {Database} from '@nozbe/watermelondb';
|
|
|
|
jest.mock('./drafts_button', () => ({
|
|
__esModule: true,
|
|
default: jest.fn(),
|
|
}));
|
|
|
|
jest.mocked(DraftsButton).mockImplementation((props) => React.createElement('DraftsButton', {...props, testID: 'drafts-button'}));
|
|
|
|
describe('DraftsButton', () => {
|
|
|
|
const serverUrl = 'server-1';
|
|
const teamId = 'team1';
|
|
let database: Database;
|
|
let operator: ServerDataOperator;
|
|
|
|
beforeEach(async () => {
|
|
await DatabaseManager.init([serverUrl]);
|
|
const serverDatabaseAndOperator = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
database = serverDatabaseAndOperator.database;
|
|
operator = serverDatabaseAndOperator.operator;
|
|
|
|
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.CURRENT_TEAM_ID, value: teamId}], prepareRecordsOnly: false});
|
|
await operator.handleTeam({teams: [TestHelper.fakeTeam({id: teamId})], prepareRecordsOnly: false});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
});
|
|
|
|
it('should correctly show isActiveTab if the last channel id Global_DRAFTS', async () => {
|
|
await operator.handleTeamChannelHistory({
|
|
teamChannelHistories: [
|
|
{channel_ids: [Screens.GLOBAL_DRAFTS], id: teamId},
|
|
],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedDraftButton
|
|
shouldHighlightActive={false}
|
|
draftsCount={0}
|
|
scheduledPostCount={0}
|
|
scheduledPostHasError={false}
|
|
/>, {database});
|
|
|
|
const draftsButton = getByTestId('drafts-button');
|
|
expect(draftsButton.props.isActiveTab).toBe(true);
|
|
});
|
|
|
|
it('should correctly show isActiveTab if the last channel id is not Global_DRAFTS', async () => {
|
|
await operator.handleTeamChannelHistory({
|
|
teamChannelHistories: [
|
|
{channel_ids: ['channel1'], id: teamId},
|
|
],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedDraftButton
|
|
shouldHighlightActive={false}
|
|
draftsCount={0}
|
|
scheduledPostCount={0}
|
|
scheduledPostHasError={false}
|
|
/>, {database});
|
|
|
|
const draftsButton = getByTestId('drafts-button');
|
|
expect(draftsButton.props.isActiveTab).toBe(false);
|
|
});
|
|
|
|
it('if shouldHightlightActive is true and no last channel id is present, then isActiveTab should be true', async () => {
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedDraftButton
|
|
shouldHighlightActive={true}
|
|
draftsCount={0}
|
|
scheduledPostCount={0}
|
|
scheduledPostHasError={false}
|
|
/>, {database});
|
|
|
|
const draftsButton = getByTestId('drafts-button');
|
|
expect(draftsButton.props.isActiveTab).toBe(true);
|
|
});
|
|
});
|