Fakultas Ilmu Komputer UI

Commit 4f363f59 authored by Sean Zeliq Urian's avatar Sean Zeliq Urian
Browse files

[RED] implement test for ActivityLog scene

parent 9a755a4a
import React from 'react';
import axios from 'axios';
import renderer from 'react-test-renderer';
import ActivityLog from '.';
import { useMainService } from 'services';
import { AppContext } from 'contexts';
import { mount, shallow } from 'enzyme';
const dummyLog = {
status: 200,
data: {
username: "Test",
is_admin: false,
previous: true,
next: true,
count: 1,
results: [
{
action_type: "Delete",
model_name: "Account",
object_id: "1234",
recorded_at: "2020-05-31T23:03:35.854615+07:00",
},
]
}
}
jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;
const testProps = {
services: {
main: useMainService('dummyToken'),
},
};
it('render ActivityLog component without crashing', () => {
shallow(<ActivityLog />);
});
it('renders correctly', () => {
const instance = renderer.create(
<ActivityLog />
);
expect(instance).toBeTruthy();
});
it('CategoryButton are displayed and clickable', () => {
mockedAxios.request.mockResolvedValue(dummyLog);
const instance = mount(
<AppContext.Provider value={testProps}>
<ActivityLog />
</AppContext.Provider>
);
expect(mockedAxios.request).toBeCalled();
let categoryButton = instance.find('[data-test-id="button-List"]');
categoryButton.at(0).simulate('click');
expect(categoryButton.length).toBeGreaterThan(0)
categoryButton = instance.find('[data-test-id="button-Tabel"]');
categoryButton.at(0).simulate('click');
expect(categoryButton.length).toBeGreaterThan(0)
});
it('ActivityList is displayed when List CategoryButton clicked', () => {
mockedAxios.request.mockResolvedValue(dummyLog);
const instance = mount(
<AppContext.Provider value={testProps}>
<ActivityLog />
</AppContext.Provider>
);
expect(mockedAxios.request).toBeCalled();
let categoryButton = instance.find('[data-test-id="button-List"]');
categoryButton.at(0).simulate('click');
let list = instance.find("#list-activity");
expect(list).toBeTruthy();
});
it('ActivityTabel is not displayed when List CategoryButton clicked', () => {
mockedAxios.request.mockResolvedValue(dummyLog);
const instance = mount(
<AppContext.Provider value={testProps}>
<ActivityLog />
</AppContext.Provider>
);
expect(mockedAxios.request).toBeCalled();
let categoryButton = instance.find('[data-test-id="button-List"]');
categoryButton.at(0).simulate('click');
let tabel = instance.find("#list-activity");
expect(tabel).toEqual({});
});
it('ActivityTabel is displayed when Tabel CategoryButton clicked', () => {
mockedAxios.request.mockResolvedValue(dummyLog);
const instance = mount(
<AppContext.Provider value={testProps}>
<ActivityLog />
</AppContext.Provider>
);
expect(mockedAxios.request).toBeCalled();
let categoryButton = instance.find('[data-test-id="button-Tabel"]');
categoryButton.at(0).simulate('click');
let list = instance.find("Tabel");
expect(list).toBeTruthy();
});
it('ActivityList is not displayed when Tabel CategoryButton clicked', () => {
mockedAxios.request.mockResolvedValue(dummyLog);
const instance = mount(
<AppContext.Provider value={testProps}>
<ActivityLog />
</AppContext.Provider>
);
expect(mockedAxios.request).toBeCalled();
let categoryButton = instance.find('[data-test-id="button-Tabel"]');
categoryButton.at(0).simulate('click');
let list = instance.find("#list-activity");
expect(list).toEqual({});
});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment