albumCommitModifyPromise.test.ets 4.0 KB
Newer Older
Y
yangbo 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Y
yangbo 已提交
16
import userFileManager from '@ohos.filemanagement.userFileManager';
Y
yangbo 已提交
17
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
18
import dataSharePredicates from '@ohos.data.dataSharePredicates';
Y
yangbo 已提交
19 20 21 22 23

import {
    sleep,
    albumFetchOps,
    checkPresetsAssets,
Y
yangbo 已提交
24
    checkAssetsCount,
Y
yangbo 已提交
25 26 27 28 29 30
    getPermission,
} from '../../../../../../common';


export default function albumCommitModifyPromise(abilityContext) {
    describe('albumCommitModifyPromise', function () {
Y
yangbo 已提交
31
        const userfilemgr = userFileManager.getUserFileMgr(abilityContext);
Y
yangbo 已提交
32 33 34
        beforeAll(async function () {
            console.info('beforeAll case');
            await getPermission();
Y
yangbo 已提交
35
            await checkPresetsAssets(userfilemgr, 'ActsUserFileMgrAlbumJsTest');
Y
yangbo 已提交
36 37 38 39 40 41 42 43 44 45 46 47
        });
        beforeEach(function () {
            console.info('beforeEach case');
        });
        afterEach(async function () {
            console.info('afterEach case');
            await sleep()
        });
        afterAll(function () {
            console.info('afterAll case');
        });

Y
yangbo 已提交
48
        const albumCommitModify = async function (done, testNum, fetchOp, expectAlbumCount = 1) {
Y
yangbo 已提交
49
            try {
Y
yangbo 已提交
50
                const fetchAlbumResult = await userfilemgr.getPhotoAlbums(fetchOp);
Y
yangbo 已提交
51
                const albumCountPass = await checkAssetsCount(done, testNum, fetchAlbumResult, expectAlbumCount);
Y
yangbo 已提交
52
                if (!albumCountPass) return;
Y
yangbo 已提交
53
                const album = await fetchAlbumResult.getFirstObject();
54 55
                const oldName = album.albumName;
                const albumUri = album.albumUri;
Y
yangbo 已提交
56 57
                const newName = 'newAlbumNamePromise';
                fetchAlbumResult.close();
Y
yangbo 已提交
58 59
                album.albumName = newName;
                await album.commitModify();
60 61 62 63 64 65 66 67 68 69 70 71
                let predicates = new dataSharePredicates.DataSharePredicates();
                predicates.equalTo(userFileManager.AlbumKey.URI.toString(), albumUri);
                let ops = {
                    predicates: predicates
                };
                const newResult = await userfilemgr.getPhotoAlbums(ops);
                const checkAlbumCountPass = await checkAssetsCount(done, testNum, newResult, expectAlbumCount);
                if (!checkAlbumCountPass) return;
                const newAlbum = await newResult.getFirstObject();
                expect(newAlbum.albumName).assertEqual(newName);
                newAlbum.albumName = oldName;
                await newAlbum.commitModify();
Y
yangbo 已提交
72 73 74 75 76 77 78 79 80 81 82
                done();
            } catch (error) {
                console.info(`${testNum}, failed error: ${error}`)
                expect(false).assertTrue();
                done();
            }
        }

        /**
         * @tc.number    : SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01
         * @tc.name      : commitModify
Y
yangbo 已提交
83
         * @tc.desc      : album modify albumname
Y
yangbo 已提交
84 85
         * @tc.size      : MEDIUM
         * @tc.type      : Function
86
         * @tc.level     : Level 2
Y
yangbo 已提交
87
         */
88
        it('SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01', 2, async function (done) {
Y
yangbo 已提交
89 90
            const testNum = 'SUB_USERFILE_MGR_ALBUM_COMMITMODIFY_PROMISE_01';
            let currentFetchOp = albumFetchOps(testNum, 'Pictures/', 'DynamicPro');
Y
yangbo 已提交
91
            await albumCommitModify(done, testNum, currentFetchOp);
Y
yangbo 已提交
92 93 94 95 96
        });
    });
}